Option to allow updates to unstable app versions

This commit is contained in:
Koitharu
2023-02-13 18:44:22 +02:00
parent c119db67e9
commit b6bfef6b50
6 changed files with 26 additions and 5 deletions

View File

@@ -11,6 +11,7 @@ import kotlinx.coroutines.withContext
import okhttp3.OkHttpClient
import okhttp3.Request
import org.koitharu.kotatsu.BuildConfig
import org.koitharu.kotatsu.core.prefs.AppSettings
import org.koitharu.kotatsu.parsers.util.await
import org.koitharu.kotatsu.parsers.util.byte2HexFormatted
import org.koitharu.kotatsu.parsers.util.json.mapJSONNotNull
@@ -31,6 +32,7 @@ private const val CERT_SHA1 = "2C:19:C7:E8:07:61:2B:8E:94:51:1B:FD:72:67:07:64:5
@Singleton
class AppUpdateRepository @Inject constructor(
@ApplicationContext private val context: Context,
private val settings: AppSettings,
private val okHttp: OkHttpClient,
) {
@@ -64,7 +66,7 @@ class AppUpdateRepository @Inject constructor(
val currentVersion = VersionId(BuildConfig.VERSION_NAME)
val available = getAvailableVersions().asArrayList()
available.sortBy { it.versionId }
if (currentVersion.isStable) {
if (currentVersion.isStable && !settings.isUnstableUpdatesAllowed) {
available.retainAll { it.versionId.isStable }
}
available.maxByOrNull { it.versionId }

View File

@@ -170,6 +170,9 @@ class AppSettings @Inject constructor(@ApplicationContext context: Context) {
val isDynamicShortcutsEnabled: Boolean
get() = prefs.getBoolean(KEY_SHORTCUTS, true)
val isUnstableUpdatesAllowed: Boolean
get() = prefs.getBoolean(KEY_UPDATES_UNSTABLE, false)
fun isContentPrefetchEnabled(): Boolean {
val policy = NetworkPolicy.from(prefs.getString(KEY_PREFETCH_CONTENT, null), NetworkPolicy.NEVER)
return policy.isNetworkAllowed(connectivityManager)
@@ -376,6 +379,7 @@ class AppSettings @Inject constructor(@ApplicationContext context: Context) {
const val KEY_LOGGING_ENABLED = "logging"
const val KEY_LOGS_SHARE = "logs_share"
const val KEY_SOURCES_GRID = "sources_grid"
const val KEY_UPDATES_UNSTABLE = "updates_unstable"
// About
const val KEY_APP_UPDATE = "app_update"

View File

@@ -6,12 +6,15 @@ import android.view.View
import androidx.core.net.toUri
import androidx.fragment.app.viewModels
import androidx.preference.Preference
import androidx.preference.SwitchPreferenceCompat
import com.google.android.material.snackbar.Snackbar
import dagger.hilt.android.AndroidEntryPoint
import org.koitharu.kotatsu.BuildConfig
import org.koitharu.kotatsu.R
import org.koitharu.kotatsu.base.ui.BasePreferenceFragment
import org.koitharu.kotatsu.core.github.AppVersion
import org.koitharu.kotatsu.core.github.VersionId
import org.koitharu.kotatsu.core.github.isStable
import org.koitharu.kotatsu.core.logs.FileLogger
import org.koitharu.kotatsu.core.prefs.AppSettings
import org.koitharu.kotatsu.utils.ShareHelper
@@ -31,6 +34,9 @@ class AboutSettingsFragment : BasePreferenceFragment(R.string.about) {
title = getString(R.string.app_version, BuildConfig.VERSION_NAME)
isEnabled = viewModel.isUpdateSupported
}
findPreference<SwitchPreferenceCompat>(AppSettings.KEY_UPDATES_UNSTABLE)?.run {
isEnabled = VersionId(BuildConfig.VERSION_NAME).isStable
}
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {

View File

@@ -421,4 +421,6 @@
<string name="nothing_here">There is nothing here</string>
<string name="scrobbling_empty_hint">To track reading progress, select Menu → Track on the manga details screen.</string>
<string name="services">Services</string>
<string name="allow_unstable_updates">Allow unstable updates</string>
<string name="allow_unstable_updates_summary">Propose updates to beta versions of the app</string>
</resources>

View File

@@ -10,11 +10,18 @@
android:persistent="false"
android:summary="@string/check_for_updates" />
<SwitchPreferenceCompat
android:defaultValue="false"
android:key="updates_unstable"
android:summary="@string/allow_unstable_updates_summary"
android:title="@string/allow_unstable_updates" />
<SwitchPreferenceCompat
android:defaultValue="false"
android:key="logging"
android:summary="@string/enable_logging_summary"
android:title="@string/enable_logging" />
android:title="@string/enable_logging"
app:allowDividerAbove="true" />
<Preference
android:dependency="logging"