Combine global update item restrictions

This commit is contained in:
arkon 2021-12-17 09:57:37 -05:00
parent 6fddad7a77
commit 818fe50f77
9 changed files with 83 additions and 55 deletions

View File

@ -28,7 +28,7 @@ android {
applicationId = "eu.kanade.tachiyomi" applicationId = "eu.kanade.tachiyomi"
minSdk = AndroidConfig.minSdk minSdk = AndroidConfig.minSdk
targetSdk = AndroidConfig.targetSdk targetSdk = AndroidConfig.targetSdk
versionCode = 71 versionCode = 72
versionName = "0.12.3" versionName = "0.12.3"
buildConfigField("String", "COMMIT_COUNT", "\"${getCommitCount()}\"") buildConfigField("String", "COMMIT_COUNT", "\"${getCommitCount()}\"")

View File

@ -5,8 +5,10 @@ import androidx.core.content.edit
import androidx.preference.PreferenceManager import androidx.preference.PreferenceManager
import eu.kanade.tachiyomi.data.backup.BackupCreatorJob import eu.kanade.tachiyomi.data.backup.BackupCreatorJob
import eu.kanade.tachiyomi.data.library.LibraryUpdateJob 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.PreferenceKeys
import eu.kanade.tachiyomi.data.preference.PreferencesHelper 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.preference.plusAssign
import eu.kanade.tachiyomi.data.track.TrackManager import eu.kanade.tachiyomi.data.track.TrackManager
import eu.kanade.tachiyomi.data.updater.AppUpdateJob import eu.kanade.tachiyomi.data.updater.AppUpdateJob
@ -50,6 +52,8 @@ object Migrations {
return false return false
} }
val prefs = PreferenceManager.getDefaultSharedPreferences(context)
if (oldVersion < 14) { if (oldVersion < 14) {
// Restore jobs after upgrading to Evernote's job scheduler. // Restore jobs after upgrading to Evernote's job scheduler.
if (BuildConfig.INCLUDE_UPDATER) { if (BuildConfig.INCLUDE_UPDATER) {
@ -96,8 +100,6 @@ object Migrations {
} }
if (oldVersion < 44) { if (oldVersion < 44) {
// Reset sorting preference if using removed sort by source // Reset sorting preference if using removed sort by source
val prefs = PreferenceManager.getDefaultSharedPreferences(context)
val oldSortingMode = prefs.getInt(PreferenceKeys.librarySortingMode, 0) val oldSortingMode = prefs.getInt(PreferenceKeys.librarySortingMode, 0)
@Suppress("DEPRECATION") @Suppress("DEPRECATION")
@ -109,7 +111,6 @@ object Migrations {
} }
if (oldVersion < 52) { if (oldVersion < 52) {
// Migrate library filters to tri-state versions // Migrate library filters to tri-state versions
val prefs = PreferenceManager.getDefaultSharedPreferences(context)
fun convertBooleanPrefToTriState(key: String): Int { fun convertBooleanPrefToTriState(key: String): Int {
val oldPrefValue = prefs.getBoolean(key, false) val oldPrefValue = prefs.getBoolean(key, false)
return if (oldPrefValue) ExtendedNavigationView.Item.TriStateGroup.State.INCLUDE.value return if (oldPrefValue) ExtendedNavigationView.Item.TriStateGroup.State.INCLUDE.value
@ -138,7 +139,6 @@ object Migrations {
} }
if (oldVersion < 57) { if (oldVersion < 57) {
// Migrate DNS over HTTPS setting // Migrate DNS over HTTPS setting
val prefs = PreferenceManager.getDefaultSharedPreferences(context)
val wasDohEnabled = prefs.getBoolean("enable_doh", false) val wasDohEnabled = prefs.getBoolean("enable_doh", false)
if (wasDohEnabled) { if (wasDohEnabled) {
prefs.edit { prefs.edit {
@ -149,7 +149,6 @@ object Migrations {
} }
if (oldVersion < 59) { if (oldVersion < 59) {
// Reset rotation to Free after replacing Lock // Reset rotation to Free after replacing Lock
val prefs = PreferenceManager.getDefaultSharedPreferences(context)
if (prefs.contains("pref_rotation_type_key")) { if (prefs.contains("pref_rotation_type_key")) {
prefs.edit { prefs.edit {
putInt("pref_rotation_type_key", 1) putInt("pref_rotation_type_key", 1)
@ -168,7 +167,6 @@ object Migrations {
} }
// Migrate Rotation and Viewer values to default values for viewer_flags // 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)) { val newOrientation = when (prefs.getInt("pref_rotation_type_key", 1)) {
1 -> OrientationType.FREE.flagValue 1 -> OrientationType.FREE.flagValue
2 -> OrientationType.PORTRAIT.flagValue 2 -> OrientationType.PORTRAIT.flagValue
@ -197,8 +195,6 @@ object Migrations {
} }
} }
if (oldVersion < 64) { if (oldVersion < 64) {
val prefs = PreferenceManager.getDefaultSharedPreferences(context)
val oldSortingMode = prefs.getInt(PreferenceKeys.librarySortingMode, 0) val oldSortingMode = prefs.getInt(PreferenceKeys.librarySortingMode, 0)
val oldSortingDirection = prefs.getBoolean(PreferenceKeys.librarySortingDirection, true) val oldSortingDirection = prefs.getBoolean(PreferenceKeys.librarySortingDirection, true)
@ -243,6 +239,12 @@ object Migrations {
LibraryUpdateJob.setupTask(context, 12) 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 return true
} }

View File

@ -8,8 +8,8 @@ import androidx.work.PeriodicWorkRequestBuilder
import androidx.work.WorkManager import androidx.work.WorkManager
import androidx.work.Worker import androidx.work.Worker
import androidx.work.WorkerParameters import androidx.work.WorkerParameters
import eu.kanade.tachiyomi.data.preference.CHARGING import eu.kanade.tachiyomi.data.preference.DEVICE_CHARGING
import eu.kanade.tachiyomi.data.preference.ONLY_ON_WIFI import eu.kanade.tachiyomi.data.preference.DEVICE_ONLY_ON_WIFI
import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.util.system.isConnectedToWifi import eu.kanade.tachiyomi.util.system.isConnectedToWifi
import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.Injekt
@ -39,10 +39,10 @@ class LibraryUpdateJob(private val context: Context, workerParams: WorkerParamet
val preferences = Injekt.get<PreferencesHelper>() val preferences = Injekt.get<PreferencesHelper>()
val interval = prefInterval ?: preferences.libraryUpdateInterval().get() val interval = prefInterval ?: preferences.libraryUpdateInterval().get()
if (interval > 0) { if (interval > 0) {
val restrictions = preferences.libraryUpdateRestriction().get() val restrictions = preferences.libraryUpdateDeviceRestriction().get()
val constraints = Constraints.Builder() val constraints = Constraints.Builder()
.setRequiredNetworkType(NetworkType.CONNECTED) .setRequiredNetworkType(NetworkType.CONNECTED)
.setRequiresCharging(CHARGING in restrictions) .setRequiresCharging(DEVICE_CHARGING in restrictions)
.build() .build()
val request = PeriodicWorkRequestBuilder<LibraryUpdateJob>( val request = PeriodicWorkRequestBuilder<LibraryUpdateJob>(
@ -62,8 +62,8 @@ class LibraryUpdateJob(private val context: Context, workerParams: WorkerParamet
} }
fun requiresWifiConnection(preferences: PreferencesHelper): Boolean { fun requiresWifiConnection(preferences: PreferencesHelper): Boolean {
val restrictions = preferences.libraryUpdateRestriction().get() val restrictions = preferences.libraryUpdateDeviceRestriction().get()
return ONLY_ON_WIFI in restrictions return DEVICE_ONLY_ON_WIFI in restrictions
} }
} }
} }

View File

@ -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.LibraryUpdateRanker.rankingScheme
import eu.kanade.tachiyomi.data.library.LibraryUpdateService.Companion.start import eu.kanade.tachiyomi.data.library.LibraryUpdateService.Companion.start
import eu.kanade.tachiyomi.data.notification.Notifications 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.preference.PreferencesHelper
import eu.kanade.tachiyomi.data.track.EnhancedTrackService import eu.kanade.tachiyomi.data.track.EnhancedTrackService
import eu.kanade.tachiyomi.data.track.TrackManager import eu.kanade.tachiyomi.data.track.TrackManager
@ -258,12 +260,15 @@ class LibraryUpdateService(
listToInclude.minus(listToExclude) listToInclude.minus(listToExclude)
} }
if (target == Target.CHAPTERS && preferences.updateOnlyNonCompleted()) {
listToUpdate = listToUpdate.filterNot { it.status == SManga.COMPLETED }
}
if (target == Target.CHAPTERS && preferences.updateOnlyCompletelyRead()) { if (target == Target.CHAPTERS) {
listToUpdate = listToUpdate.filter { it.unread == 0 } 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() val selectedScheme = preferences.libraryUpdatePrioritization().get()

View File

@ -99,10 +99,6 @@ object PreferenceKeys {
const val jumpToChapters = "jump_to_chapters" 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 autoUpdateTrack = "pref_auto_update_manga_sync_key"
const val lastUsedSource = "last_catalogue_source" const val lastUsedSource = "last_catalogue_source"
@ -133,7 +129,8 @@ object PreferenceKeys {
const val libraryUpdateInterval = "pref_library_update_interval_key" 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" const val showUpdatesNavBadge = "library_update_show_tab_badge"

View File

@ -2,8 +2,11 @@ package eu.kanade.tachiyomi.data.preference
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
const val ONLY_ON_WIFI = "wifi" const val DEVICE_ONLY_ON_WIFI = "wifi"
const val CHARGING = "ac" 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. * This class stores the values for the preferences in the application.

View File

@ -177,10 +177,6 @@ class PreferencesHelper(val context: Context) {
fun jumpToChapters() = prefs.getBoolean(Keys.jumpToChapters, false) 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 autoUpdateTrack() = prefs.getBoolean(Keys.autoUpdateTrack, true)
fun lastUsedSource() = flowPrefs.getLong(Keys.lastUsedSource, -1) fun lastUsedSource() = flowPrefs.getLong(Keys.lastUsedSource, -1)
@ -237,7 +233,8 @@ class PreferencesHelper(val context: Context) {
fun libraryUpdateInterval() = flowPrefs.getInt(Keys.libraryUpdateInterval, 24) 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 showUpdatesNavBadge() = flowPrefs.getBoolean(Keys.showUpdatesNavBadge, false)
fun unreadUpdatesCount() = flowPrefs.getInt("library_unread_updates_count", 0) fun unreadUpdatesCount() = flowPrefs.getInt("library_unread_updates_count", 0)

View File

@ -11,8 +11,10 @@ import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.database.DatabaseHelper import eu.kanade.tachiyomi.data.database.DatabaseHelper
import eu.kanade.tachiyomi.data.database.models.Category import eu.kanade.tachiyomi.data.database.models.Category
import eu.kanade.tachiyomi.data.library.LibraryUpdateJob import eu.kanade.tachiyomi.data.library.LibraryUpdateJob
import eu.kanade.tachiyomi.data.preference.CHARGING import eu.kanade.tachiyomi.data.preference.DEVICE_CHARGING
import eu.kanade.tachiyomi.data.preference.ONLY_ON_WIFI 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.PreferencesHelper
import eu.kanade.tachiyomi.data.preference.asImmediateFlow import eu.kanade.tachiyomi.data.preference.asImmediateFlow
import eu.kanade.tachiyomi.data.track.TrackManager import eu.kanade.tachiyomi.data.track.TrackManager
@ -156,11 +158,11 @@ class SettingsLibraryController : SettingsController() {
} }
} }
multiSelectListPreference { multiSelectListPreference {
key = Keys.libraryUpdateRestriction key = Keys.libraryUpdateDeviceRestriction
titleRes = R.string.pref_library_update_restriction titleRes = R.string.pref_library_update_restriction
entriesRes = arrayOf(R.string.connected_to_wifi, R.string.charging) entriesRes = arrayOf(R.string.connected_to_wifi, R.string.charging)
entryValues = arrayOf(ONLY_ON_WIFI, CHARGING) entryValues = arrayOf(DEVICE_ONLY_ON_WIFI, DEVICE_CHARGING)
defaultValue = setOf(ONLY_ON_WIFI) defaultValue = preferences.libraryUpdateDeviceRestriction().defaultValue
preferences.libraryUpdateInterval().asImmediateFlow { isVisible = it > 0 } preferences.libraryUpdateInterval().asImmediateFlow { isVisible = it > 0 }
.launchIn(viewScope) .launchIn(viewScope)
@ -172,12 +174,12 @@ class SettingsLibraryController : SettingsController() {
} }
fun updateSummary() { fun updateSummary() {
val restrictions = preferences.libraryUpdateRestriction().get() val restrictions = preferences.libraryUpdateDeviceRestriction().get()
.sorted() .sorted()
.map { .map {
when (it) { when (it) {
ONLY_ON_WIFI -> context.getString(R.string.connected_to_wifi) DEVICE_ONLY_ON_WIFI -> context.getString(R.string.connected_to_wifi)
CHARGING -> context.getString(R.string.charging) DEVICE_CHARGING -> context.getString(R.string.charging)
else -> it else -> it
} }
} }
@ -190,20 +192,42 @@ class SettingsLibraryController : SettingsController() {
summary = context.getString(R.string.restrictions, restrictionsText) summary = context.getString(R.string.restrictions, restrictionsText)
} }
preferences.libraryUpdateRestriction().asFlow() preferences.libraryUpdateDeviceRestriction().asFlow()
.onEach { updateSummary() } .onEach { updateSummary() }
.launchIn(viewScope) .launchIn(viewScope)
} }
switchPreference { multiSelectListPreference {
key = Keys.updateOnlyNonCompleted key = Keys.libraryUpdateMangaRestriction
titleRes = R.string.pref_update_only_non_completed titleRes = R.string.pref_library_update_manga_restriction
defaultValue = true entriesRes = arrayOf(R.string.pref_update_only_completely_read, R.string.pref_update_only_non_completed)
} entryValues = arrayOf(MANGA_FULLY_READ, MANGA_ONGOING)
switchPreference { defaultValue = preferences.libraryUpdateMangaRestriction().defaultValue
key = Keys.updateOnlyCompletelyRead
titleRes = R.string.pref_update_only_completely_read preferences.libraryUpdateInterval().asImmediateFlow { isVisible = it > 0 }
summaryRes = R.string.pref_update_only_completely_read_summary .launchIn(viewScope)
defaultValue = false
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 { preference {
key = Keys.libraryUpdateCategories key = Keys.libraryUpdateCategories

View File

@ -217,13 +217,13 @@
<string name="update_72hour">Every 3 days</string> <string name="update_72hour">Every 3 days</string>
<string name="update_weekly">Weekly</string> <string name="update_weekly">Weekly</string>
<string name="pref_library_update_prioritization">Update order</string> <string name="pref_library_update_prioritization">Update order</string>
<string name="pref_library_update_restriction">Update restrictions</string> <string name="pref_library_update_restriction">Device restrictions</string>
<string name="connected_to_wifi">Only on Wi-Fi</string> <string name="connected_to_wifi">Only on Wi-Fi</string>
<string name="charging">Charging</string> <string name="charging">Charging</string>
<string name="restrictions">Restrictions: %s</string> <string name="restrictions">Restrictions: %s</string>
<string name="pref_update_only_non_completed">Only update ongoing manga</string> <string name="pref_library_update_manga_restriction">Manga restrictions</string>
<string name="pref_update_only_completely_read">Only update completely read manga</string> <string name="pref_update_only_completely_read">Completely read</string>
<string name="pref_update_only_completely_read_summary">Only update manga if there is no unread chapter(completely read)</string> <string name="pref_update_only_non_completed">Ongoing</string>
<string name="pref_library_update_show_tab_badge">Show unread count on Updates icon</string> <string name="pref_library_update_show_tab_badge">Show unread count on Updates icon</string>
<string name="pref_library_update_refresh_metadata">Automatically refresh metadata</string> <string name="pref_library_update_refresh_metadata">Automatically refresh metadata</string>
<string name="pref_library_update_refresh_metadata_summary">Check for new cover and details when updating library</string> <string name="pref_library_update_refresh_metadata_summary">Check for new cover and details when updating library</string>