From 818fe50f7772e42bff710b471bb0f687ab58ee10 Mon Sep 17 00:00:00 2001 From: arkon Date: Fri, 17 Dec 2021 09:57:37 -0500 Subject: [PATCH] Combine global update item restrictions --- app/build.gradle.kts | 2 +- .../java/eu/kanade/tachiyomi/Migrations.kt | 18 +++--- .../data/library/LibraryUpdateJob.kt | 12 ++-- .../data/library/LibraryUpdateService.kt | 15 +++-- .../data/preference/PreferenceKeys.kt | 7 +-- .../data/preference/PreferenceValues.kt | 7 ++- .../data/preference/PreferencesHelper.kt | 7 +-- .../ui/setting/SettingsLibraryController.kt | 62 +++++++++++++------ app/src/main/res/values/strings.xml | 8 +-- 9 files changed, 83 insertions(+), 55 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index e7fc450eb3..8a43ecf0d0 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -28,7 +28,7 @@ android { applicationId = "eu.kanade.tachiyomi" minSdk = AndroidConfig.minSdk targetSdk = AndroidConfig.targetSdk - versionCode = 71 + versionCode = 72 versionName = "0.12.3" buildConfigField("String", "COMMIT_COUNT", "\"${getCommitCount()}\"") diff --git a/app/src/main/java/eu/kanade/tachiyomi/Migrations.kt b/app/src/main/java/eu/kanade/tachiyomi/Migrations.kt index fe4d13a51d..214a78df56 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/Migrations.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/Migrations.kt @@ -5,8 +5,10 @@ import androidx.core.content.edit import androidx.preference.PreferenceManager import eu.kanade.tachiyomi.data.backup.BackupCreatorJob import eu.kanade.tachiyomi.data.library.LibraryUpdateJob +import eu.kanade.tachiyomi.data.preference.MANGA_ONGOING import eu.kanade.tachiyomi.data.preference.PreferenceKeys import eu.kanade.tachiyomi.data.preference.PreferencesHelper +import eu.kanade.tachiyomi.data.preference.minusAssign import eu.kanade.tachiyomi.data.preference.plusAssign import eu.kanade.tachiyomi.data.track.TrackManager import eu.kanade.tachiyomi.data.updater.AppUpdateJob @@ -50,6 +52,8 @@ object Migrations { return false } + val prefs = PreferenceManager.getDefaultSharedPreferences(context) + if (oldVersion < 14) { // Restore jobs after upgrading to Evernote's job scheduler. if (BuildConfig.INCLUDE_UPDATER) { @@ -96,8 +100,6 @@ object Migrations { } if (oldVersion < 44) { // Reset sorting preference if using removed sort by source - val prefs = PreferenceManager.getDefaultSharedPreferences(context) - val oldSortingMode = prefs.getInt(PreferenceKeys.librarySortingMode, 0) @Suppress("DEPRECATION") @@ -109,7 +111,6 @@ object Migrations { } if (oldVersion < 52) { // Migrate library filters to tri-state versions - val prefs = PreferenceManager.getDefaultSharedPreferences(context) fun convertBooleanPrefToTriState(key: String): Int { val oldPrefValue = prefs.getBoolean(key, false) return if (oldPrefValue) ExtendedNavigationView.Item.TriStateGroup.State.INCLUDE.value @@ -138,7 +139,6 @@ object Migrations { } if (oldVersion < 57) { // Migrate DNS over HTTPS setting - val prefs = PreferenceManager.getDefaultSharedPreferences(context) val wasDohEnabled = prefs.getBoolean("enable_doh", false) if (wasDohEnabled) { prefs.edit { @@ -149,7 +149,6 @@ object Migrations { } if (oldVersion < 59) { // Reset rotation to Free after replacing Lock - val prefs = PreferenceManager.getDefaultSharedPreferences(context) if (prefs.contains("pref_rotation_type_key")) { prefs.edit { putInt("pref_rotation_type_key", 1) @@ -168,7 +167,6 @@ object Migrations { } // Migrate Rotation and Viewer values to default values for viewer_flags - val prefs = PreferenceManager.getDefaultSharedPreferences(context) val newOrientation = when (prefs.getInt("pref_rotation_type_key", 1)) { 1 -> OrientationType.FREE.flagValue 2 -> OrientationType.PORTRAIT.flagValue @@ -197,8 +195,6 @@ object Migrations { } } if (oldVersion < 64) { - val prefs = PreferenceManager.getDefaultSharedPreferences(context) - val oldSortingMode = prefs.getInt(PreferenceKeys.librarySortingMode, 0) val oldSortingDirection = prefs.getBoolean(PreferenceKeys.librarySortingDirection, true) @@ -243,6 +239,12 @@ object Migrations { LibraryUpdateJob.setupTask(context, 12) } } + if (oldVersion < 72) { + val oldUpdateOngoingOnly = prefs.getBoolean("pref_update_only_non_completed_key", true) + if (!oldUpdateOngoingOnly) { + preferences.libraryUpdateMangaRestriction() -= MANGA_ONGOING + } + } return true } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateJob.kt b/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateJob.kt index d6db778fc4..a1d31dfbc6 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateJob.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateJob.kt @@ -8,8 +8,8 @@ import androidx.work.PeriodicWorkRequestBuilder import androidx.work.WorkManager import androidx.work.Worker import androidx.work.WorkerParameters -import eu.kanade.tachiyomi.data.preference.CHARGING -import eu.kanade.tachiyomi.data.preference.ONLY_ON_WIFI +import eu.kanade.tachiyomi.data.preference.DEVICE_CHARGING +import eu.kanade.tachiyomi.data.preference.DEVICE_ONLY_ON_WIFI import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.util.system.isConnectedToWifi import uy.kohesive.injekt.Injekt @@ -39,10 +39,10 @@ class LibraryUpdateJob(private val context: Context, workerParams: WorkerParamet val preferences = Injekt.get() val interval = prefInterval ?: preferences.libraryUpdateInterval().get() if (interval > 0) { - val restrictions = preferences.libraryUpdateRestriction().get() + val restrictions = preferences.libraryUpdateDeviceRestriction().get() val constraints = Constraints.Builder() .setRequiredNetworkType(NetworkType.CONNECTED) - .setRequiresCharging(CHARGING in restrictions) + .setRequiresCharging(DEVICE_CHARGING in restrictions) .build() val request = PeriodicWorkRequestBuilder( @@ -62,8 +62,8 @@ class LibraryUpdateJob(private val context: Context, workerParams: WorkerParamet } fun requiresWifiConnection(preferences: PreferencesHelper): Boolean { - val restrictions = preferences.libraryUpdateRestriction().get() - return ONLY_ON_WIFI in restrictions + val restrictions = preferences.libraryUpdateDeviceRestriction().get() + return DEVICE_ONLY_ON_WIFI in restrictions } } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt b/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt index 1a176584a6..9713d8522d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt @@ -20,6 +20,8 @@ import eu.kanade.tachiyomi.data.download.DownloadService import eu.kanade.tachiyomi.data.library.LibraryUpdateRanker.rankingScheme import eu.kanade.tachiyomi.data.library.LibraryUpdateService.Companion.start import eu.kanade.tachiyomi.data.notification.Notifications +import eu.kanade.tachiyomi.data.preference.MANGA_FULLY_READ +import eu.kanade.tachiyomi.data.preference.MANGA_ONGOING import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.track.EnhancedTrackService import eu.kanade.tachiyomi.data.track.TrackManager @@ -258,12 +260,15 @@ class LibraryUpdateService( listToInclude.minus(listToExclude) } - if (target == Target.CHAPTERS && preferences.updateOnlyNonCompleted()) { - listToUpdate = listToUpdate.filterNot { it.status == SManga.COMPLETED } - } - if (target == Target.CHAPTERS && preferences.updateOnlyCompletelyRead()) { - listToUpdate = listToUpdate.filter { it.unread == 0 } + if (target == Target.CHAPTERS) { + val restrictions = preferences.libraryUpdateMangaRestriction().get() + if (MANGA_ONGOING in restrictions) { + listToUpdate = listToUpdate.filterNot { it.status == SManga.COMPLETED } + } + if (MANGA_FULLY_READ in restrictions) { + listToUpdate = listToUpdate.filter { it.unread == 0 } + } } val selectedScheme = preferences.libraryUpdatePrioritization().get() diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt index 678522bc84..45aee99ff5 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt @@ -99,10 +99,6 @@ object PreferenceKeys { const val jumpToChapters = "jump_to_chapters" - const val updateOnlyNonCompleted = "pref_update_only_non_completed_key" - - const val updateOnlyCompletelyRead = "pref_update_only_completely_read" - const val autoUpdateTrack = "pref_auto_update_manga_sync_key" const val lastUsedSource = "last_catalogue_source" @@ -133,7 +129,8 @@ object PreferenceKeys { const val libraryUpdateInterval = "pref_library_update_interval_key" - const val libraryUpdateRestriction = "library_update_restriction" + const val libraryUpdateDeviceRestriction = "library_update_restriction" + const val libraryUpdateMangaRestriction = "library_update_manga_restriction" const val showUpdatesNavBadge = "library_update_show_tab_badge" diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceValues.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceValues.kt index d06d5c9b43..9dd96b5b72 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceValues.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceValues.kt @@ -2,8 +2,11 @@ package eu.kanade.tachiyomi.data.preference import eu.kanade.tachiyomi.R -const val ONLY_ON_WIFI = "wifi" -const val CHARGING = "ac" +const val DEVICE_ONLY_ON_WIFI = "wifi" +const val DEVICE_CHARGING = "ac" + +const val MANGA_ONGOING = "manga_ongoing" +const val MANGA_FULLY_READ = "manga_fully_read" /** * This class stores the values for the preferences in the application. diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt index 50e4476f2f..78469d3c6d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt @@ -177,10 +177,6 @@ class PreferencesHelper(val context: Context) { fun jumpToChapters() = prefs.getBoolean(Keys.jumpToChapters, false) - fun updateOnlyNonCompleted() = prefs.getBoolean(Keys.updateOnlyNonCompleted, true) - - fun updateOnlyCompletelyRead() = prefs.getBoolean(Keys.updateOnlyCompletelyRead, true) - fun autoUpdateTrack() = prefs.getBoolean(Keys.autoUpdateTrack, true) fun lastUsedSource() = flowPrefs.getLong(Keys.lastUsedSource, -1) @@ -237,7 +233,8 @@ class PreferencesHelper(val context: Context) { fun libraryUpdateInterval() = flowPrefs.getInt(Keys.libraryUpdateInterval, 24) - fun libraryUpdateRestriction() = flowPrefs.getStringSet(Keys.libraryUpdateRestriction, setOf(ONLY_ON_WIFI)) + fun libraryUpdateDeviceRestriction() = flowPrefs.getStringSet(Keys.libraryUpdateDeviceRestriction, setOf(DEVICE_ONLY_ON_WIFI)) + fun libraryUpdateMangaRestriction() = flowPrefs.getStringSet(Keys.libraryUpdateMangaRestriction, setOf(MANGA_FULLY_READ, MANGA_ONGOING)) fun showUpdatesNavBadge() = flowPrefs.getBoolean(Keys.showUpdatesNavBadge, false) fun unreadUpdatesCount() = flowPrefs.getInt("library_unread_updates_count", 0) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsLibraryController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsLibraryController.kt index 01bcf58b5a..ff5e76007f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsLibraryController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsLibraryController.kt @@ -11,8 +11,10 @@ import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.DatabaseHelper import eu.kanade.tachiyomi.data.database.models.Category import eu.kanade.tachiyomi.data.library.LibraryUpdateJob -import eu.kanade.tachiyomi.data.preference.CHARGING -import eu.kanade.tachiyomi.data.preference.ONLY_ON_WIFI +import eu.kanade.tachiyomi.data.preference.DEVICE_CHARGING +import eu.kanade.tachiyomi.data.preference.DEVICE_ONLY_ON_WIFI +import eu.kanade.tachiyomi.data.preference.MANGA_FULLY_READ +import eu.kanade.tachiyomi.data.preference.MANGA_ONGOING import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.preference.asImmediateFlow import eu.kanade.tachiyomi.data.track.TrackManager @@ -156,11 +158,11 @@ class SettingsLibraryController : SettingsController() { } } multiSelectListPreference { - key = Keys.libraryUpdateRestriction + key = Keys.libraryUpdateDeviceRestriction titleRes = R.string.pref_library_update_restriction entriesRes = arrayOf(R.string.connected_to_wifi, R.string.charging) - entryValues = arrayOf(ONLY_ON_WIFI, CHARGING) - defaultValue = setOf(ONLY_ON_WIFI) + entryValues = arrayOf(DEVICE_ONLY_ON_WIFI, DEVICE_CHARGING) + defaultValue = preferences.libraryUpdateDeviceRestriction().defaultValue preferences.libraryUpdateInterval().asImmediateFlow { isVisible = it > 0 } .launchIn(viewScope) @@ -172,12 +174,12 @@ class SettingsLibraryController : SettingsController() { } fun updateSummary() { - val restrictions = preferences.libraryUpdateRestriction().get() + val restrictions = preferences.libraryUpdateDeviceRestriction().get() .sorted() .map { when (it) { - ONLY_ON_WIFI -> context.getString(R.string.connected_to_wifi) - CHARGING -> context.getString(R.string.charging) + DEVICE_ONLY_ON_WIFI -> context.getString(R.string.connected_to_wifi) + DEVICE_CHARGING -> context.getString(R.string.charging) else -> it } } @@ -190,20 +192,42 @@ class SettingsLibraryController : SettingsController() { summary = context.getString(R.string.restrictions, restrictionsText) } - preferences.libraryUpdateRestriction().asFlow() + preferences.libraryUpdateDeviceRestriction().asFlow() .onEach { updateSummary() } .launchIn(viewScope) } - switchPreference { - key = Keys.updateOnlyNonCompleted - titleRes = R.string.pref_update_only_non_completed - defaultValue = true - } - switchPreference { - key = Keys.updateOnlyCompletelyRead - titleRes = R.string.pref_update_only_completely_read - summaryRes = R.string.pref_update_only_completely_read_summary - defaultValue = false + multiSelectListPreference { + key = Keys.libraryUpdateMangaRestriction + titleRes = R.string.pref_library_update_manga_restriction + entriesRes = arrayOf(R.string.pref_update_only_completely_read, R.string.pref_update_only_non_completed) + entryValues = arrayOf(MANGA_FULLY_READ, MANGA_ONGOING) + defaultValue = preferences.libraryUpdateMangaRestriction().defaultValue + + preferences.libraryUpdateInterval().asImmediateFlow { isVisible = it > 0 } + .launchIn(viewScope) + + fun updateSummary() { + val restrictions = preferences.libraryUpdateMangaRestriction().get() + .sorted() + .map { + when (it) { + MANGA_ONGOING -> context.getString(R.string.pref_update_only_non_completed) + MANGA_FULLY_READ -> context.getString(R.string.pref_update_only_completely_read) + else -> it + } + } + val restrictionsText = if (restrictions.isEmpty()) { + context.getString(R.string.none) + } else { + restrictions.joinToString() + } + + summary = context.getString(R.string.restrictions, restrictionsText) + } + + preferences.libraryUpdateMangaRestriction().asFlow() + .onEach { updateSummary() } + .launchIn(viewScope) } preference { key = Keys.libraryUpdateCategories diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 6072de7520..7485f836f1 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -217,13 +217,13 @@ Every 3 days Weekly Update order - Update restrictions + Device restrictions Only on Wi-Fi Charging Restrictions: %s - Only update ongoing manga - Only update completely read manga - Only update manga if there is no unread chapter(completely read) + Manga restrictions + Completely read + Ongoing Show unread count on Updates icon Automatically refresh metadata Check for new cover and details when updating library