mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-09-10 21:13:24 +02:00
Fixed scrollbar in preference popup
This commit is contained in:
parent
aa00a1bed8
commit
a94d455e79
@ -181,7 +181,7 @@ class ExtensionDetailsController(bundle: Bundle? = null) :
|
||||
}
|
||||
|
||||
if (preference is ListPreference) {
|
||||
ListMatPreference(preference.context).apply {
|
||||
ListMatPreference(activity, preference.context).apply {
|
||||
key = preference.key
|
||||
sharedPref = preference.fragment
|
||||
otherPref = preference
|
||||
|
@ -1,5 +1,6 @@
|
||||
package eu.kanade.tachiyomi.ui.setting
|
||||
|
||||
import android.app.Activity
|
||||
import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat
|
||||
import androidx.core.graphics.drawable.DrawableCompat
|
||||
import androidx.preference.*
|
||||
@ -40,19 +41,22 @@ inline fun PreferenceGroup.editTextPreference(block: (@DSL EditTextPreference).(
|
||||
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 {
|
||||
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 {
|
||||
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 {
|
||||
return initThenAdd(MultiListMatPreference(context), block)
|
||||
return initThenAdd(MultiListMatPreference(activity, context), block)
|
||||
}
|
||||
|
||||
inline fun PreferenceScreen.preferenceCategory(block: (@DSL PreferenceCategory).() -> Unit): PreferenceCategory {
|
||||
|
@ -76,7 +76,7 @@ class SettingsBackupController : SettingsController() {
|
||||
preferenceCategory {
|
||||
titleRes = R.string.pref_backup_service_category
|
||||
|
||||
intListPreference {
|
||||
intListPreference(activity) {
|
||||
key = Keys.backupInterval
|
||||
titleRes = R.string.pref_backup_interval
|
||||
entriesRes = arrayOf(R.string.update_never, R.string.update_6hour,
|
||||
@ -117,7 +117,7 @@ class SettingsBackupController : SettingsController() {
|
||||
summary = dir.filePath + "/automatic"
|
||||
}
|
||||
}
|
||||
val backupNumber = intListPreference {
|
||||
val backupNumber = intListPreference(activity) {
|
||||
key = Keys.numberOfBackups
|
||||
titleRes = R.string.pref_backup_slots
|
||||
entries = listOf("1", "2", "3", "4", "5")
|
||||
|
@ -59,7 +59,7 @@ class SettingsDownloadController : SettingsController() {
|
||||
titleRes = R.string.pref_remove_after_marked_as_read
|
||||
defaultValue = false
|
||||
}
|
||||
intListPreference {
|
||||
intListPreference(activity) {
|
||||
key = Keys.removeAfterReadSlots
|
||||
titleRes = R.string.pref_remove_after_read
|
||||
entriesRes = arrayOf(R.string.disabled, R.string.last_read_chapter,
|
||||
@ -80,7 +80,7 @@ class SettingsDownloadController : SettingsController() {
|
||||
titleRes = R.string.pref_download_new
|
||||
defaultValue = false
|
||||
}
|
||||
multiSelectListPreferenceMat {
|
||||
multiSelectListPreferenceMat(activity) {
|
||||
key = Keys.downloadNewCategories
|
||||
titleRes = R.string.pref_download_new_categories
|
||||
entries = dbCategories.map { it.name }
|
||||
|
@ -17,7 +17,7 @@ class SettingsGeneralController : SettingsController() {
|
||||
override fun setupPreferenceScreen(screen: PreferenceScreen) = with(screen) {
|
||||
titleRes = R.string.pref_category_general
|
||||
|
||||
listPreference {
|
||||
listPreference(activity) {
|
||||
key = Keys.lang
|
||||
titleRes = R.string.pref_language
|
||||
entryValues = listOf("", "ar", "bg", "bn", "ca", "cs", "de", "el", "en-US", "en-GB",
|
||||
@ -40,7 +40,7 @@ class SettingsGeneralController : SettingsController() {
|
||||
true
|
||||
}
|
||||
}
|
||||
intListPreference {
|
||||
intListPreference(activity) {
|
||||
key = Keys.theme
|
||||
titleRes = R.string.pref_theme
|
||||
entriesRes = arrayOf(R.string.light_theme, R.string.dark_theme,
|
||||
@ -54,7 +54,7 @@ class SettingsGeneralController : SettingsController() {
|
||||
true
|
||||
}
|
||||
}
|
||||
intListPreference {
|
||||
intListPreference(activity) {
|
||||
key = Keys.startScreen
|
||||
titleRes = R.string.pref_start_screen
|
||||
entriesRes = arrayOf(R.string.label_library, R.string.label_recent_manga,
|
||||
@ -96,7 +96,7 @@ class SettingsGeneralController : SettingsController() {
|
||||
true
|
||||
}
|
||||
}
|
||||
preference = intListPreference {
|
||||
preference = intListPreference(activity) {
|
||||
key = Keys.lockAfter
|
||||
titleRes = R.string.lock_when_idle
|
||||
isVisible = preferences.useBiometrics().getOrDefault()
|
||||
|
@ -51,7 +51,7 @@ class SettingsLibraryController : SettingsController() {
|
||||
"${context.getString(R.string.landscape)}: $landscape"
|
||||
}
|
||||
}
|
||||
intListPreference {
|
||||
intListPreference(activity) {
|
||||
key = Keys.libraryUpdateInterval
|
||||
titleRes = R.string.pref_library_update_interval
|
||||
entriesRes = arrayOf(R.string.update_never, R.string.update_1hour,
|
||||
@ -71,7 +71,7 @@ class SettingsLibraryController : SettingsController() {
|
||||
true
|
||||
}
|
||||
}
|
||||
multiSelectListPreferenceMat {
|
||||
multiSelectListPreferenceMat(activity) {
|
||||
key = Keys.libraryUpdateRestriction
|
||||
titleRes = R.string.pref_library_update_restriction
|
||||
entriesRes = arrayOf(R.string.wifi, R.string.charging)
|
||||
@ -95,7 +95,7 @@ class SettingsLibraryController : SettingsController() {
|
||||
|
||||
val dbCategories = db.getCategories().executeAsBlocking()
|
||||
|
||||
multiSelectListPreferenceMat {
|
||||
multiSelectListPreferenceMat(activity) {
|
||||
key = Keys.libraryUpdateCategories
|
||||
titleRes = R.string.pref_library_update_categories
|
||||
entries = dbCategories.map { it.name }
|
||||
@ -114,7 +114,7 @@ class SettingsLibraryController : SettingsController() {
|
||||
selectedCategories.joinToString { it.name }
|
||||
}
|
||||
}
|
||||
intListPreference {
|
||||
intListPreference(activity) {
|
||||
key = Keys.libraryUpdatePrioritization
|
||||
titleRes = R.string.pref_library_update_prioritization
|
||||
|
||||
@ -128,7 +128,7 @@ class SettingsLibraryController : SettingsController() {
|
||||
defaultValue = 0
|
||||
summaryRes = R.string.pref_library_update_prioritization_summary
|
||||
}
|
||||
intListPreference {
|
||||
intListPreference(activity) {
|
||||
key = Keys.defaultCategory
|
||||
titleRes = R.string.default_category
|
||||
|
||||
|
@ -10,7 +10,7 @@ class SettingsReaderController : SettingsController() {
|
||||
override fun setupPreferenceScreen(screen: PreferenceScreen) = with(screen) {
|
||||
titleRes = R.string.pref_category_reader
|
||||
|
||||
intListPreference {
|
||||
intListPreference(activity) {
|
||||
key = Keys.defaultViewer
|
||||
titleRes = R.string.pref_viewer_type
|
||||
entriesRes = arrayOf(R.string.left_to_right_viewer, R.string.right_to_left_viewer,
|
||||
@ -18,7 +18,7 @@ class SettingsReaderController : SettingsController() {
|
||||
entryRange = 1..4
|
||||
defaultValue = 1
|
||||
}
|
||||
intListPreference {
|
||||
intListPreference(activity) {
|
||||
key = Keys.imageScaleType
|
||||
titleRes = R.string.pref_image_scale_type
|
||||
entriesRes = arrayOf(R.string.scale_type_fit_screen, R.string.scale_type_stretch,
|
||||
@ -27,7 +27,7 @@ class SettingsReaderController : SettingsController() {
|
||||
entryRange = 1..6
|
||||
defaultValue = 1
|
||||
}
|
||||
intListPreference {
|
||||
intListPreference(activity) {
|
||||
key = Keys.zoomStart
|
||||
titleRes = R.string.pref_zoom_start
|
||||
entriesRes = arrayOf(R.string.zoom_start_automatic, R.string.zoom_start_left,
|
||||
@ -35,7 +35,7 @@ class SettingsReaderController : SettingsController() {
|
||||
entryRange = 1..4
|
||||
defaultValue = 1
|
||||
}
|
||||
intListPreference {
|
||||
intListPreference(activity) {
|
||||
key = Keys.rotation
|
||||
titleRes = R.string.pref_rotation_type
|
||||
entriesRes = arrayOf(R.string.rotation_free, R.string.rotation_lock,
|
||||
@ -43,7 +43,7 @@ class SettingsReaderController : SettingsController() {
|
||||
entryRange = 1..4
|
||||
defaultValue = 1
|
||||
}
|
||||
intListPreference {
|
||||
intListPreference(activity) {
|
||||
key = Keys.readerTheme
|
||||
titleRes = R.string.pref_reader_theme
|
||||
entriesRes = arrayOf(R.string.white_background, R.string.black_background, R.string
|
||||
@ -51,7 +51,7 @@ class SettingsReaderController : SettingsController() {
|
||||
entryRange = 0..3
|
||||
defaultValue = 2
|
||||
}
|
||||
intListPreference {
|
||||
intListPreference(activity) {
|
||||
key = Keys.doubleTapAnimationSpeed
|
||||
titleRes = R.string.pref_double_tap_anim_speed
|
||||
entries = listOf(context.getString(R.string.double_tap_anim_speed_0), context.getString(R
|
||||
|
@ -1,9 +1,11 @@
|
||||
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
|
||||
@ -11,11 +13,11 @@ import eu.kanade.tachiyomi.ui.setting.defaultValue
|
||||
import uy.kohesive.injekt.Injekt
|
||||
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) :
|
||||
Preference(context, attrs) {
|
||||
private val prefs: PreferencesHelper = Injekt.get()
|
||||
|
||||
MatPreference(activity, context, attrs) {
|
||||
var entryValues:List<Int> = emptyList()
|
||||
var entryRange:IntRange
|
||||
get() = 0..0
|
||||
@ -36,14 +38,8 @@ class IntListMatPreference @JvmOverloads constructor(context: Context, attrs: At
|
||||
else entries[index]
|
||||
}
|
||||
|
||||
override fun onClick() {
|
||||
dialog().show()
|
||||
}
|
||||
|
||||
fun dialog(): MaterialDialog {
|
||||
return MaterialDialog(context).apply {
|
||||
title(text = title.toString())
|
||||
negativeButton(android.R.string.cancel)
|
||||
override fun dialog(): MaterialDialog {
|
||||
return super.dialog().apply {
|
||||
val default = entryValues.indexOf(prefs.getInt(key, defValue).getOrDefault())
|
||||
listItemsSingleChoice(items = entries,
|
||||
waitForPositiveButton = false,
|
||||
|
@ -1,5 +1,7 @@
|
||||
package eu.kanade.tachiyomi.widget.preference
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import android.util.AttributeSet
|
||||
@ -13,10 +15,10 @@ import eu.kanade.tachiyomi.ui.setting.defaultValue
|
||||
import uy.kohesive.injekt.Injekt
|
||||
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) :
|
||||
Preference(context, attrs) {
|
||||
protected val prefs: PreferencesHelper = Injekt.get()
|
||||
MatPreference(activity, context, attrs) {
|
||||
|
||||
var sharedPref:String? = null
|
||||
var otherPref:Preference? = null
|
||||
@ -37,15 +39,14 @@ open class ListMatPreference @JvmOverloads constructor(context: Context, attrs:
|
||||
else entries[index]
|
||||
}
|
||||
|
||||
override fun onClick() {
|
||||
dialog().show()
|
||||
override fun dialog(): MaterialDialog {
|
||||
return super.dialog().apply {
|
||||
setItems()
|
||||
}
|
||||
}
|
||||
|
||||
open fun dialog(): MaterialDialog {
|
||||
return MaterialDialog(context).apply {
|
||||
if (this@ListMatPreference.title != null)
|
||||
title(text = this@ListMatPreference.title.toString())
|
||||
negativeButton(android.R.string.cancel)
|
||||
@SuppressLint("CheckResult")
|
||||
open fun MaterialDialog.setItems() {
|
||||
val default = entryValues.indexOf(if (sharedPref != null) {
|
||||
val settings = context.getSharedPreferences(sharedPref, Context.MODE_PRIVATE)
|
||||
settings.getString(key, "")
|
||||
@ -77,4 +78,3 @@ open class ListMatPreference @JvmOverloads constructor(context: Context, attrs:
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +1,7 @@
|
||||
package eu.kanade.tachiyomi.widget.preference
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import com.afollestad.materialdialogs.MaterialDialog
|
||||
@ -9,9 +11,10 @@ import com.afollestad.materialdialogs.list.listItemsMultiChoice
|
||||
import com.afollestad.materialdialogs.list.uncheckItem
|
||||
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) :
|
||||
ListMatPreference(context, attrs) {
|
||||
ListMatPreference(activity, context, attrs) {
|
||||
|
||||
var allSelectionRes:Int? = null
|
||||
var customSummaryRes:Int
|
||||
@ -24,10 +27,8 @@ class MultiListMatPreference @JvmOverloads constructor(context: Context, attrs:
|
||||
return customSummary ?: super.getSummary()
|
||||
}
|
||||
|
||||
override fun dialog():MaterialDialog {
|
||||
return MaterialDialog(context).apply {
|
||||
title(text = title.toString())
|
||||
negativeButton(android.R.string.cancel)
|
||||
@SuppressLint("CheckResult")
|
||||
override fun MaterialDialog.setItems() {
|
||||
positiveButton(android.R.string.ok) {
|
||||
var value = positions?.map {
|
||||
entryValues[it - if (allSelectionRes != null) 1 else 0] }?.toSet() ?: emptySet()
|
||||
@ -57,4 +58,3 @@ class MultiListMatPreference @JvmOverloads constructor(context: Context, attrs:
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user