mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-05 11:15:12 +01:00
Combine global update item restrictions
This commit is contained in:
parent
6fddad7a77
commit
818fe50f77
@ -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()}\"")
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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<PreferencesHelper>()
|
||||
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<LibraryUpdateJob>(
|
||||
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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()
|
||||
|
@ -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"
|
||||
|
||||
|
@ -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.
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -217,13 +217,13 @@
|
||||
<string name="update_72hour">Every 3 days</string>
|
||||
<string name="update_weekly">Weekly</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="charging">Charging</string>
|
||||
<string name="restrictions">Restrictions: %s</string>
|
||||
<string name="pref_update_only_non_completed">Only update ongoing manga</string>
|
||||
<string name="pref_update_only_completely_read">Only update completely read manga</string>
|
||||
<string name="pref_update_only_completely_read_summary">Only update manga if there is no unread chapter(completely read)</string>
|
||||
<string name="pref_library_update_manga_restriction">Manga restrictions</string>
|
||||
<string name="pref_update_only_completely_read">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_refresh_metadata">Automatically refresh metadata</string>
|
||||
<string name="pref_library_update_refresh_metadata_summary">Check for new cover and details when updating library</string>
|
||||
|
Loading…
Reference in New Issue
Block a user