Fixed scrollbar in preference popup

This commit is contained in:
Jay 2020-01-19 17:42:11 -08:00
parent aa00a1bed8
commit a94d455e79
11 changed files with 145 additions and 106 deletions

View File

@ -181,7 +181,7 @@ class ExtensionDetailsController(bundle: Bundle? = null) :
} }
if (preference is ListPreference) { if (preference is ListPreference) {
ListMatPreference(preference.context).apply { ListMatPreference(activity, preference.context).apply {
key = preference.key key = preference.key
sharedPref = preference.fragment sharedPref = preference.fragment
otherPref = preference otherPref = preference

View File

@ -1,5 +1,6 @@
package eu.kanade.tachiyomi.ui.setting package eu.kanade.tachiyomi.ui.setting
import android.app.Activity
import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat
import androidx.core.graphics.drawable.DrawableCompat import androidx.core.graphics.drawable.DrawableCompat
import androidx.preference.* import androidx.preference.*
@ -40,19 +41,22 @@ inline fun PreferenceGroup.editTextPreference(block: (@DSL EditTextPreference).(
return initThenAdd(EditTextPreference(context), block).also(::initDialog) return initThenAdd(EditTextPreference(context), block).also(::initDialog)
} }
inline fun PreferenceGroup.listPreference(block: (@DSL ListMatPreference).() -> Unit): inline fun PreferenceGroup.listPreference(activity: Activity?, block: (@DSL ListMatPreference).()
-> Unit):
ListMatPreference { ListMatPreference {
return initThenAdd(ListMatPreference(context), block) return initThenAdd(ListMatPreference(activity, context), block)
} }
inline fun PreferenceGroup.intListPreference(block: (@DSL IntListMatPreference).() -> Unit): inline fun PreferenceGroup.intListPreference(activity: Activity?, block: (@DSL
IntListMatPreference).() -> Unit):
IntListMatPreference { IntListMatPreference {
return initThenAdd(IntListMatPreference(context), block) return initThenAdd(IntListMatPreference(activity, context), block)
} }
inline fun PreferenceGroup.multiSelectListPreferenceMat(block: (@DSL MultiListMatPreference).() inline fun PreferenceGroup.multiSelectListPreferenceMat(activity: Activity?, block: (@DSL
MultiListMatPreference).()
-> Unit): MultiListMatPreference { -> Unit): MultiListMatPreference {
return initThenAdd(MultiListMatPreference(context), block) return initThenAdd(MultiListMatPreference(activity, context), block)
} }
inline fun PreferenceScreen.preferenceCategory(block: (@DSL PreferenceCategory).() -> Unit): PreferenceCategory { inline fun PreferenceScreen.preferenceCategory(block: (@DSL PreferenceCategory).() -> Unit): PreferenceCategory {

View File

@ -76,7 +76,7 @@ class SettingsBackupController : SettingsController() {
preferenceCategory { preferenceCategory {
titleRes = R.string.pref_backup_service_category titleRes = R.string.pref_backup_service_category
intListPreference { intListPreference(activity) {
key = Keys.backupInterval key = Keys.backupInterval
titleRes = R.string.pref_backup_interval titleRes = R.string.pref_backup_interval
entriesRes = arrayOf(R.string.update_never, R.string.update_6hour, entriesRes = arrayOf(R.string.update_never, R.string.update_6hour,
@ -117,7 +117,7 @@ class SettingsBackupController : SettingsController() {
summary = dir.filePath + "/automatic" summary = dir.filePath + "/automatic"
} }
} }
val backupNumber = intListPreference { val backupNumber = intListPreference(activity) {
key = Keys.numberOfBackups key = Keys.numberOfBackups
titleRes = R.string.pref_backup_slots titleRes = R.string.pref_backup_slots
entries = listOf("1", "2", "3", "4", "5") entries = listOf("1", "2", "3", "4", "5")

View File

@ -59,7 +59,7 @@ class SettingsDownloadController : SettingsController() {
titleRes = R.string.pref_remove_after_marked_as_read titleRes = R.string.pref_remove_after_marked_as_read
defaultValue = false defaultValue = false
} }
intListPreference { intListPreference(activity) {
key = Keys.removeAfterReadSlots key = Keys.removeAfterReadSlots
titleRes = R.string.pref_remove_after_read titleRes = R.string.pref_remove_after_read
entriesRes = arrayOf(R.string.disabled, R.string.last_read_chapter, entriesRes = arrayOf(R.string.disabled, R.string.last_read_chapter,
@ -80,7 +80,7 @@ class SettingsDownloadController : SettingsController() {
titleRes = R.string.pref_download_new titleRes = R.string.pref_download_new
defaultValue = false defaultValue = false
} }
multiSelectListPreferenceMat { multiSelectListPreferenceMat(activity) {
key = Keys.downloadNewCategories key = Keys.downloadNewCategories
titleRes = R.string.pref_download_new_categories titleRes = R.string.pref_download_new_categories
entries = dbCategories.map { it.name } entries = dbCategories.map { it.name }

View File

@ -17,7 +17,7 @@ class SettingsGeneralController : SettingsController() {
override fun setupPreferenceScreen(screen: PreferenceScreen) = with(screen) { override fun setupPreferenceScreen(screen: PreferenceScreen) = with(screen) {
titleRes = R.string.pref_category_general titleRes = R.string.pref_category_general
listPreference { listPreference(activity) {
key = Keys.lang key = Keys.lang
titleRes = R.string.pref_language titleRes = R.string.pref_language
entryValues = listOf("", "ar", "bg", "bn", "ca", "cs", "de", "el", "en-US", "en-GB", entryValues = listOf("", "ar", "bg", "bn", "ca", "cs", "de", "el", "en-US", "en-GB",
@ -40,7 +40,7 @@ class SettingsGeneralController : SettingsController() {
true true
} }
} }
intListPreference { intListPreference(activity) {
key = Keys.theme key = Keys.theme
titleRes = R.string.pref_theme titleRes = R.string.pref_theme
entriesRes = arrayOf(R.string.light_theme, R.string.dark_theme, entriesRes = arrayOf(R.string.light_theme, R.string.dark_theme,
@ -54,7 +54,7 @@ class SettingsGeneralController : SettingsController() {
true true
} }
} }
intListPreference { intListPreference(activity) {
key = Keys.startScreen key = Keys.startScreen
titleRes = R.string.pref_start_screen titleRes = R.string.pref_start_screen
entriesRes = arrayOf(R.string.label_library, R.string.label_recent_manga, entriesRes = arrayOf(R.string.label_library, R.string.label_recent_manga,
@ -96,7 +96,7 @@ class SettingsGeneralController : SettingsController() {
true true
} }
} }
preference = intListPreference { preference = intListPreference(activity) {
key = Keys.lockAfter key = Keys.lockAfter
titleRes = R.string.lock_when_idle titleRes = R.string.lock_when_idle
isVisible = preferences.useBiometrics().getOrDefault() isVisible = preferences.useBiometrics().getOrDefault()

View File

@ -51,7 +51,7 @@ class SettingsLibraryController : SettingsController() {
"${context.getString(R.string.landscape)}: $landscape" "${context.getString(R.string.landscape)}: $landscape"
} }
} }
intListPreference { intListPreference(activity) {
key = Keys.libraryUpdateInterval key = Keys.libraryUpdateInterval
titleRes = R.string.pref_library_update_interval titleRes = R.string.pref_library_update_interval
entriesRes = arrayOf(R.string.update_never, R.string.update_1hour, entriesRes = arrayOf(R.string.update_never, R.string.update_1hour,
@ -71,7 +71,7 @@ class SettingsLibraryController : SettingsController() {
true true
} }
} }
multiSelectListPreferenceMat { multiSelectListPreferenceMat(activity) {
key = Keys.libraryUpdateRestriction key = Keys.libraryUpdateRestriction
titleRes = R.string.pref_library_update_restriction titleRes = R.string.pref_library_update_restriction
entriesRes = arrayOf(R.string.wifi, R.string.charging) entriesRes = arrayOf(R.string.wifi, R.string.charging)
@ -95,7 +95,7 @@ class SettingsLibraryController : SettingsController() {
val dbCategories = db.getCategories().executeAsBlocking() val dbCategories = db.getCategories().executeAsBlocking()
multiSelectListPreferenceMat { multiSelectListPreferenceMat(activity) {
key = Keys.libraryUpdateCategories key = Keys.libraryUpdateCategories
titleRes = R.string.pref_library_update_categories titleRes = R.string.pref_library_update_categories
entries = dbCategories.map { it.name } entries = dbCategories.map { it.name }
@ -114,7 +114,7 @@ class SettingsLibraryController : SettingsController() {
selectedCategories.joinToString { it.name } selectedCategories.joinToString { it.name }
} }
} }
intListPreference { intListPreference(activity) {
key = Keys.libraryUpdatePrioritization key = Keys.libraryUpdatePrioritization
titleRes = R.string.pref_library_update_prioritization titleRes = R.string.pref_library_update_prioritization
@ -128,7 +128,7 @@ class SettingsLibraryController : SettingsController() {
defaultValue = 0 defaultValue = 0
summaryRes = R.string.pref_library_update_prioritization_summary summaryRes = R.string.pref_library_update_prioritization_summary
} }
intListPreference { intListPreference(activity) {
key = Keys.defaultCategory key = Keys.defaultCategory
titleRes = R.string.default_category titleRes = R.string.default_category

View File

@ -10,7 +10,7 @@ class SettingsReaderController : SettingsController() {
override fun setupPreferenceScreen(screen: PreferenceScreen) = with(screen) { override fun setupPreferenceScreen(screen: PreferenceScreen) = with(screen) {
titleRes = R.string.pref_category_reader titleRes = R.string.pref_category_reader
intListPreference { intListPreference(activity) {
key = Keys.defaultViewer key = Keys.defaultViewer
titleRes = R.string.pref_viewer_type titleRes = R.string.pref_viewer_type
entriesRes = arrayOf(R.string.left_to_right_viewer, R.string.right_to_left_viewer, entriesRes = arrayOf(R.string.left_to_right_viewer, R.string.right_to_left_viewer,
@ -18,7 +18,7 @@ class SettingsReaderController : SettingsController() {
entryRange = 1..4 entryRange = 1..4
defaultValue = 1 defaultValue = 1
} }
intListPreference { intListPreference(activity) {
key = Keys.imageScaleType key = Keys.imageScaleType
titleRes = R.string.pref_image_scale_type titleRes = R.string.pref_image_scale_type
entriesRes = arrayOf(R.string.scale_type_fit_screen, R.string.scale_type_stretch, entriesRes = arrayOf(R.string.scale_type_fit_screen, R.string.scale_type_stretch,
@ -27,7 +27,7 @@ class SettingsReaderController : SettingsController() {
entryRange = 1..6 entryRange = 1..6
defaultValue = 1 defaultValue = 1
} }
intListPreference { intListPreference(activity) {
key = Keys.zoomStart key = Keys.zoomStart
titleRes = R.string.pref_zoom_start titleRes = R.string.pref_zoom_start
entriesRes = arrayOf(R.string.zoom_start_automatic, R.string.zoom_start_left, entriesRes = arrayOf(R.string.zoom_start_automatic, R.string.zoom_start_left,
@ -35,7 +35,7 @@ class SettingsReaderController : SettingsController() {
entryRange = 1..4 entryRange = 1..4
defaultValue = 1 defaultValue = 1
} }
intListPreference { intListPreference(activity) {
key = Keys.rotation key = Keys.rotation
titleRes = R.string.pref_rotation_type titleRes = R.string.pref_rotation_type
entriesRes = arrayOf(R.string.rotation_free, R.string.rotation_lock, entriesRes = arrayOf(R.string.rotation_free, R.string.rotation_lock,
@ -43,7 +43,7 @@ class SettingsReaderController : SettingsController() {
entryRange = 1..4 entryRange = 1..4
defaultValue = 1 defaultValue = 1
} }
intListPreference { intListPreference(activity) {
key = Keys.readerTheme key = Keys.readerTheme
titleRes = R.string.pref_reader_theme titleRes = R.string.pref_reader_theme
entriesRes = arrayOf(R.string.white_background, R.string.black_background, R.string entriesRes = arrayOf(R.string.white_background, R.string.black_background, R.string
@ -51,7 +51,7 @@ class SettingsReaderController : SettingsController() {
entryRange = 0..3 entryRange = 0..3
defaultValue = 2 defaultValue = 2
} }
intListPreference { intListPreference(activity) {
key = Keys.doubleTapAnimationSpeed key = Keys.doubleTapAnimationSpeed
titleRes = R.string.pref_double_tap_anim_speed titleRes = R.string.pref_double_tap_anim_speed
entries = listOf(context.getString(R.string.double_tap_anim_speed_0), context.getString(R entries = listOf(context.getString(R.string.double_tap_anim_speed_0), context.getString(R

View File

@ -1,9 +1,11 @@
package eu.kanade.tachiyomi.widget.preference package eu.kanade.tachiyomi.widget.preference
import android.app.Activity
import android.content.Context import android.content.Context
import android.util.AttributeSet import android.util.AttributeSet
import androidx.preference.Preference import androidx.preference.Preference
import com.afollestad.materialdialogs.MaterialDialog import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.callbacks.onDismiss
import com.afollestad.materialdialogs.list.listItemsSingleChoice import com.afollestad.materialdialogs.list.listItemsSingleChoice
import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.data.preference.getOrDefault import eu.kanade.tachiyomi.data.preference.getOrDefault
@ -11,11 +13,11 @@ import eu.kanade.tachiyomi.ui.setting.defaultValue
import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get import uy.kohesive.injekt.api.get
class IntListMatPreference @JvmOverloads constructor(context: Context, attrs: AttributeSet? = class IntListMatPreference @JvmOverloads constructor(activity: Activity?, context: Context,
attrs:
AttributeSet? =
null) : null) :
Preference(context, attrs) { MatPreference(activity, context, attrs) {
private val prefs: PreferencesHelper = Injekt.get()
var entryValues:List<Int> = emptyList() var entryValues:List<Int> = emptyList()
var entryRange:IntRange var entryRange:IntRange
get() = 0..0 get() = 0..0
@ -36,14 +38,8 @@ class IntListMatPreference @JvmOverloads constructor(context: Context, attrs: At
else entries[index] else entries[index]
} }
override fun onClick() { override fun dialog(): MaterialDialog {
dialog().show() return super.dialog().apply {
}
fun dialog(): MaterialDialog {
return MaterialDialog(context).apply {
title(text = title.toString())
negativeButton(android.R.string.cancel)
val default = entryValues.indexOf(prefs.getInt(key, defValue).getOrDefault()) val default = entryValues.indexOf(prefs.getInt(key, defValue).getOrDefault())
listItemsSingleChoice(items = entries, listItemsSingleChoice(items = entries,
waitForPositiveButton = false, waitForPositiveButton = false,

View File

@ -1,5 +1,7 @@
package eu.kanade.tachiyomi.widget.preference package eu.kanade.tachiyomi.widget.preference
import android.annotation.SuppressLint
import android.app.Activity
import android.content.Context import android.content.Context
import android.content.SharedPreferences import android.content.SharedPreferences
import android.util.AttributeSet import android.util.AttributeSet
@ -13,10 +15,10 @@ import eu.kanade.tachiyomi.ui.setting.defaultValue
import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get import uy.kohesive.injekt.api.get
open class ListMatPreference @JvmOverloads constructor(context: Context, attrs: AttributeSet? = open class ListMatPreference @JvmOverloads constructor(activity: Activity?, context: Context,
attrs: AttributeSet? =
null) : null) :
Preference(context, attrs) { MatPreference(activity, context, attrs) {
protected val prefs: PreferencesHelper = Injekt.get()
var sharedPref:String? = null var sharedPref:String? = null
var otherPref:Preference? = null var otherPref:Preference? = null
@ -37,15 +39,14 @@ open class ListMatPreference @JvmOverloads constructor(context: Context, attrs:
else entries[index] else entries[index]
} }
override fun onClick() { override fun dialog(): MaterialDialog {
dialog().show() return super.dialog().apply {
setItems()
}
} }
open fun dialog(): MaterialDialog { @SuppressLint("CheckResult")
return MaterialDialog(context).apply { open fun MaterialDialog.setItems() {
if (this@ListMatPreference.title != null)
title(text = this@ListMatPreference.title.toString())
negativeButton(android.R.string.cancel)
val default = entryValues.indexOf(if (sharedPref != null) { val default = entryValues.indexOf(if (sharedPref != null) {
val settings = context.getSharedPreferences(sharedPref, Context.MODE_PRIVATE) val settings = context.getSharedPreferences(sharedPref, Context.MODE_PRIVATE)
settings.getString(key, "") settings.getString(key, "")
@ -76,5 +77,4 @@ open class ListMatPreference @JvmOverloads constructor(context: Context, attrs:
dismiss() dismiss()
} }
} }
}
} }

View File

@ -0,0 +1,39 @@
package eu.kanade.tachiyomi.widget.preference
import android.app.Activity
import android.content.Context
import android.util.AttributeSet
import androidx.preference.Preference
import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.callbacks.onDismiss
import com.afollestad.materialdialogs.list.listItemsSingleChoice
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.data.preference.getOrDefault
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
open class MatPreference @JvmOverloads constructor(val activity: Activity?, context: Context,
attrs:
AttributeSet? =
null) :
Preference(context, attrs) {
protected val prefs: PreferencesHelper = Injekt.get()
private var isShowing = false
override fun onClick() {
if (!isShowing)
dialog().apply {
onDismiss { this@MatPreference.isShowing = false }
}.show()
isShowing = true
}
open fun dialog(): MaterialDialog {
return MaterialDialog(activity ?: context).apply {
if (title != null)
title(text = title.toString())
negativeButton(android.R.string.cancel)
}
}
}

View File

@ -1,5 +1,7 @@
package eu.kanade.tachiyomi.widget.preference package eu.kanade.tachiyomi.widget.preference
import android.annotation.SuppressLint
import android.app.Activity
import android.content.Context import android.content.Context
import android.util.AttributeSet import android.util.AttributeSet
import com.afollestad.materialdialogs.MaterialDialog import com.afollestad.materialdialogs.MaterialDialog
@ -9,9 +11,10 @@ import com.afollestad.materialdialogs.list.listItemsMultiChoice
import com.afollestad.materialdialogs.list.uncheckItem import com.afollestad.materialdialogs.list.uncheckItem
import eu.kanade.tachiyomi.data.preference.getOrDefault import eu.kanade.tachiyomi.data.preference.getOrDefault
class MultiListMatPreference @JvmOverloads constructor(context: Context, attrs: AttributeSet? = class MultiListMatPreference @JvmOverloads constructor(activity: Activity?, context: Context,
attrs: AttributeSet? =
null) : null) :
ListMatPreference(context, attrs) { ListMatPreference(activity, context, attrs) {
var allSelectionRes:Int? = null var allSelectionRes:Int? = null
var customSummaryRes:Int var customSummaryRes:Int
@ -24,10 +27,8 @@ class MultiListMatPreference @JvmOverloads constructor(context: Context, attrs:
return customSummary ?: super.getSummary() return customSummary ?: super.getSummary()
} }
override fun dialog():MaterialDialog { @SuppressLint("CheckResult")
return MaterialDialog(context).apply { override fun MaterialDialog.setItems() {
title(text = title.toString())
negativeButton(android.R.string.cancel)
positiveButton(android.R.string.ok) { positiveButton(android.R.string.ok) {
var value = positions?.map { var value = positions?.map {
entryValues[it - if (allSelectionRes != null) 1 else 0] }?.toSet() ?: emptySet() entryValues[it - if (allSelectionRes != null) 1 else 0] }?.toSet() ?: emptySet()
@ -56,5 +57,4 @@ class MultiListMatPreference @JvmOverloads constructor(context: Context, attrs:
callChangeListener(positions) callChangeListener(positions)
} }
} }
}
} }