Hide irrelevant settings if global update isn't enabled

(cherry picked from commit 7d1f5c738362680a86d055374eacc4d86e8d48ca)
This commit is contained in:
arkon 2021-12-17 10:14:04 -05:00 committed by Jobobby04
parent 2bd9d2844f
commit c5c23e623e

View File

@ -5,6 +5,7 @@ import android.os.Bundle
import android.view.LayoutInflater import android.view.LayoutInflater
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import androidx.core.text.buildSpannedString import androidx.core.text.buildSpannedString
import androidx.preference.Preference
import androidx.preference.PreferenceScreen import androidx.preference.PreferenceScreen
import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.dialog.MaterialAlertDialogBuilder
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
@ -189,7 +190,7 @@ class SettingsLibraryController : SettingsController() {
entryValues = arrayOf(DEVICE_ONLY_ON_WIFI, DEVICE_CHARGING) entryValues = arrayOf(DEVICE_ONLY_ON_WIFI, DEVICE_CHARGING)
defaultValue = preferences.libraryUpdateDeviceRestriction().defaultValue defaultValue = preferences.libraryUpdateDeviceRestriction().defaultValue
visibleIf(preferences.libraryUpdateInterval()) { it > 0 } visibleIfGlobalUpdateEnabled()
onChange { onChange {
// Post to event looper to allow the preference to be updated. // Post to event looper to allow the preference to be updated.
@ -227,7 +228,7 @@ class SettingsLibraryController : SettingsController() {
entryValues = arrayOf(MANGA_FULLY_READ, MANGA_ONGOING) entryValues = arrayOf(MANGA_FULLY_READ, MANGA_ONGOING)
defaultValue = preferences.libraryUpdateMangaRestriction().defaultValue defaultValue = preferences.libraryUpdateMangaRestriction().defaultValue
visibleIf(preferences.libraryUpdateInterval()) { it > 0 } visibleIfGlobalUpdateEnabled()
fun updateSummary() { fun updateSummary() {
val restrictions = preferences.libraryUpdateMangaRestriction().get() val restrictions = preferences.libraryUpdateMangaRestriction().get()
@ -255,6 +256,9 @@ class SettingsLibraryController : SettingsController() {
preference { preference {
key = Keys.libraryUpdateCategories key = Keys.libraryUpdateCategories
titleRes = R.string.categories titleRes = R.string.categories
visibleIfGlobalUpdateEnabled()
onClick { onClick {
LibraryGlobalUpdateCategoriesDialog().showDialog(router) LibraryGlobalUpdateCategoriesDialog().showDialog(router)
} }
@ -314,6 +318,8 @@ class SettingsLibraryController : SettingsController() {
key = Keys.libraryUpdatePrioritization key = Keys.libraryUpdatePrioritization
titleRes = R.string.pref_library_update_prioritization titleRes = R.string.pref_library_update_prioritization
visibleIfGlobalUpdateEnabled()
// The following array lines up with the list rankingScheme in: // The following array lines up with the list rankingScheme in:
// ../../data/library/LibraryUpdateRanker.kt // ../../data/library/LibraryUpdateRanker.kt
val priorities = arrayOf( val priorities = arrayOf(
@ -341,6 +347,7 @@ class SettingsLibraryController : SettingsController() {
titleRes = R.string.pref_library_update_refresh_metadata titleRes = R.string.pref_library_update_refresh_metadata
summaryRes = R.string.pref_library_update_refresh_metadata_summary summaryRes = R.string.pref_library_update_refresh_metadata_summary
defaultValue = false defaultValue = false
visibleIfGlobalUpdateEnabled()
} }
if (trackManager.hasLoggedServices()) { if (trackManager.hasLoggedServices()) {
switchPreference { switchPreference {
@ -348,6 +355,7 @@ class SettingsLibraryController : SettingsController() {
titleRes = R.string.pref_library_update_refresh_trackers titleRes = R.string.pref_library_update_refresh_trackers
summaryRes = R.string.pref_library_update_refresh_trackers_summary summaryRes = R.string.pref_library_update_refresh_trackers_summary
defaultValue = false defaultValue = false
visibleIfGlobalUpdateEnabled()
} }
} }
} }
@ -383,6 +391,10 @@ class SettingsLibraryController : SettingsController() {
// SY <-- // SY <--
} }
private inline fun Preference.visibleIfGlobalUpdateEnabled() {
visibleIf(preferences.libraryUpdateInterval()) { it > 0 }
}
class LibraryColumnsDialog : DialogController() { class LibraryColumnsDialog : DialogController() {
private val preferences: PreferencesHelper = Injekt.get() private val preferences: PreferencesHelper = Injekt.get()