diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralController.kt index 4dfd468117..84fe9abcd6 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralController.kt @@ -21,6 +21,12 @@ class SettingsGeneralController : SettingsController() { intListPreference(activity) { key = Keys.startingTab titleRes = R.string.starting_screen + summaryRes = when (preferences.startingTab().get()) { + -1 -> R.string.library + -2 -> R.string.recents + -3 -> R.string.browse + else -> R.string.last_used_library_recents + } entriesRes = arrayOf( R.string.last_used_library_recents, R.string.library, @@ -29,6 +35,25 @@ class SettingsGeneralController : SettingsController() { ) entryValues = (0 downTo -3).toList() defaultValue = 0 + customSelectedValue = when (val value = preferences.startingTab().get()) { + in -3..-1 -> value + else -> 0 + } + + onChange { newValue -> + summaryRes = when (newValue) { + 0, 1 -> R.string.last_used_library_recents + -1 -> R.string.library + -2 -> R.string.recents + -3 -> R.string.browse + else -> R.string.last_used_library_recents + } + customSelectedValue = when (newValue) { + in -3..-1 -> newValue as Int + else -> 0 + } + true + } } switchPreference { diff --git a/app/src/main/java/eu/kanade/tachiyomi/widget/preference/IntListMatPreference.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/preference/IntListMatPreference.kt index 139c4ddb56..eae0e21900 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/widget/preference/IntListMatPreference.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/widget/preference/IntListMatPreference.kt @@ -24,6 +24,7 @@ class IntListMatPreference @JvmOverloads constructor( set(value) { entries = value.map { context.getString(it) } } private var defValue: Int = 0 var entries: List = emptyList() + var customSelectedValue: Int? = null override fun onSetInitialValue(defaultValue: Any?) { super.onSetInitialValue(defaultValue) @@ -37,9 +38,19 @@ class IntListMatPreference @JvmOverloads constructor( else entries[index] } + override fun setSummary(summaryResId: Int) { + super.setSummary(summaryResId) + customSummary = summary.toString() + } + + override fun setSummary(summary: CharSequence?) { + super.setSummary(summary) + customSummary = summary?.toString() + } + override fun dialog(): MaterialDialog { return super.dialog().apply { - val default = entryValues.indexOf(prefs.getInt(key, defValue).getOrDefault()) + val default = entryValues.indexOf(customSelectedValue ?: prefs.getInt(key, defValue).getOrDefault()) listItemsSingleChoice( items = entries, waitForPositiveButton = false,