mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-12-23 20:01:53 +01: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) {
|
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
|
||||||
|
@ -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 {
|
||||||
|
@ -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")
|
||||||
|
@ -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 }
|
||||||
|
@ -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()
|
||||||
|
@ -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
|
||||||
|
|
||||||
|
@ -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
|
||||||
|
@ -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,
|
||||||
|
@ -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,44 +39,42 @@ 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)
|
val default = entryValues.indexOf(if (sharedPref != null) {
|
||||||
title(text = this@ListMatPreference.title.toString())
|
val settings = context.getSharedPreferences(sharedPref, Context.MODE_PRIVATE)
|
||||||
negativeButton(android.R.string.cancel)
|
settings.getString(key, "")
|
||||||
val default = entryValues.indexOf(if (sharedPref != null) {
|
}
|
||||||
|
else prefs.getStringPref(key, defValue).getOrDefault())
|
||||||
|
listItemsSingleChoice(items = entries,
|
||||||
|
waitForPositiveButton = false,
|
||||||
|
initialSelection = default) { _, pos, _ ->
|
||||||
|
val value = entryValues[pos]
|
||||||
|
if (sharedPref != null) {
|
||||||
|
val oldDef = if (default > -1) entries[default] else ""
|
||||||
val settings = context.getSharedPreferences(sharedPref, Context.MODE_PRIVATE)
|
val settings = context.getSharedPreferences(sharedPref, Context.MODE_PRIVATE)
|
||||||
settings.getString(key, "")
|
val edit = settings.edit()
|
||||||
|
edit.putString(key, value)
|
||||||
|
edit.apply()
|
||||||
|
otherPref?.callChangeListener(value)
|
||||||
|
if (oldDef == otherPref?.summary || otherPref?.summary.isNullOrEmpty()) otherPref?.summary =
|
||||||
|
entries[pos]
|
||||||
|
else otherPref?.summary = otherPref?.summary?.toString()?.replace(oldDef,
|
||||||
|
entries[pos]
|
||||||
|
) ?: entries[pos]
|
||||||
}
|
}
|
||||||
else prefs.getStringPref(key, defValue).getOrDefault())
|
else {
|
||||||
listItemsSingleChoice(items = entries,
|
prefs.getStringPref(key, defValue).set(value)
|
||||||
waitForPositiveButton = false,
|
this@ListMatPreference.summary = this@ListMatPreference.summary
|
||||||
initialSelection = default) { _, pos, _ ->
|
callChangeListener(value)
|
||||||
val value = entryValues[pos]
|
|
||||||
if (sharedPref != null) {
|
|
||||||
val oldDef = if (default > -1) entries[default] else ""
|
|
||||||
val settings = context.getSharedPreferences(sharedPref, Context.MODE_PRIVATE)
|
|
||||||
val edit = settings.edit()
|
|
||||||
edit.putString(key, value)
|
|
||||||
edit.apply()
|
|
||||||
otherPref?.callChangeListener(value)
|
|
||||||
if (oldDef == otherPref?.summary || otherPref?.summary.isNullOrEmpty()) otherPref?.summary =
|
|
||||||
entries[pos]
|
|
||||||
else otherPref?.summary = otherPref?.summary?.toString()?.replace(oldDef,
|
|
||||||
entries[pos]
|
|
||||||
) ?: entries[pos]
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
prefs.getStringPref(key, defValue).set(value)
|
|
||||||
this@ListMatPreference.summary = this@ListMatPreference.summary
|
|
||||||
callChangeListener(value)
|
|
||||||
}
|
|
||||||
dismiss()
|
|
||||||
}
|
}
|
||||||
|
dismiss()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -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
|
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,37 +27,34 @@ 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())
|
positiveButton(android.R.string.ok) {
|
||||||
negativeButton(android.R.string.cancel)
|
var value = positions?.map {
|
||||||
positiveButton(android.R.string.ok) {
|
entryValues[it - if (allSelectionRes != null) 1 else 0] }?.toSet() ?: emptySet()
|
||||||
var value = positions?.map {
|
if (allSelectionRes != null && isItemChecked(0)) value = emptySet()
|
||||||
entryValues[it - if (allSelectionRes != null) 1 else 0] }?.toSet() ?: emptySet()
|
prefs.getStringSet(key, emptySet()).set(value)
|
||||||
if (allSelectionRes != null && isItemChecked(0)) value = emptySet()
|
callChangeListener(value)
|
||||||
prefs.getStringSet(key, emptySet()).set(value)
|
this@MultiListMatPreference.summary = this@MultiListMatPreference.summary
|
||||||
callChangeListener(value)
|
}
|
||||||
this@MultiListMatPreference.summary = this@MultiListMatPreference.summary
|
val set = prefs.getStringSet(key, emptySet()).getOrDefault()
|
||||||
}
|
var default = set.map {
|
||||||
val set = prefs.getStringSet(key, emptySet()).getOrDefault()
|
entryValues.indexOf(it) + if (allSelectionRes != null) 1 else 0 }
|
||||||
var default = set.map {
|
.toIntArray()
|
||||||
entryValues.indexOf(it) + if (allSelectionRes != null) 1 else 0 }
|
if (allSelectionRes != null && default.isEmpty()) default = intArrayOf(0)
|
||||||
.toIntArray()
|
val items = if (allSelectionRes != null)
|
||||||
if (allSelectionRes != null && default.isEmpty()) default = intArrayOf(0)
|
(listOf(context.getString(allSelectionRes!!)) + entries) else entries
|
||||||
val items = if (allSelectionRes != null)
|
listItemsMultiChoice(items = items,
|
||||||
(listOf(context.getString(allSelectionRes!!)) + entries) else entries
|
allowEmptySelection = true,
|
||||||
listItemsMultiChoice(items = items,
|
disabledIndices = if (allSelectionRes != null) intArrayOf(0) else null,
|
||||||
allowEmptySelection = true,
|
waitForPositiveButton = false,
|
||||||
disabledIndices = if (allSelectionRes != null) intArrayOf(0) else null,
|
initialSelection = default) { _, pos, _ ->
|
||||||
waitForPositiveButton = false,
|
positions = pos
|
||||||
initialSelection = default) { _, pos, _ ->
|
if (allSelectionRes != null) {
|
||||||
positions = pos
|
if (pos.isEmpty()) checkItem(0)
|
||||||
if (allSelectionRes != null) {
|
else uncheckItem(0)
|
||||||
if (pos.isEmpty()) checkItem(0)
|
|
||||||
else uncheckItem(0)
|
|
||||||
}
|
|
||||||
callChangeListener(positions)
|
|
||||||
}
|
}
|
||||||
|
callChangeListener(positions)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user