0
0
mirror of https://github.com/ankidroid/Anki-Android.git synced 2024-09-20 20:03:05 +02:00

Make possible to set preferences formatted preferences on the XMLs

This commit is contained in:
Brayan Oliveira 2022-08-11 16:49:13 -03:00 committed by lukstbit
parent 1f2c6e1b6a
commit 55eeafa39f
2 changed files with 26 additions and 14 deletions

View File

@ -33,25 +33,30 @@ import timber.log.Timber
open class NumberRangePreferenceCompat : EditTextPreference {
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int, defStyleRes: Int) : super(context, attrs, defStyleAttr, defStyleRes) {
min = getMinFromAttributes(attrs)
max = getMaxFromAttributes(attrs)
defaultValue = getDefaultValueFromAttributes(attrs)
setup(attrs)
}
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
min = getMinFromAttributes(attrs)
max = getMaxFromAttributes(attrs)
defaultValue = getDefaultValueFromAttributes(attrs)
setup(attrs)
}
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) {
setup(attrs)
}
constructor(context: Context) : super(context)
fun setup(attrs: AttributeSet?) {
min = getMinFromAttributes(attrs)
max = getMaxFromAttributes(attrs)
defaultValue = getDefaultValueFromAttributes(attrs)
}
constructor(context: Context) : super(context) {
defaultValue = null
val formattedSummary = attrs?.getAttributeResourceValue(AnkiDroidApp.XML_CUSTOM_NAMESPACE, "formattedSummary", -1)
if (formattedSummary != null && formattedSummary != -1) {
setSummaryProvider {
context.getString(formattedSummary, text)
}
}
}
val defaultValue: String?
var defaultValue: String? = null
var min = 0
protected set

View File

@ -60,20 +60,20 @@ class SeekBarPreferenceCompat : DialogPreference {
private var mYLabel = 0
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int, defStyleRes: Int) : super(context, attrs, defStyleAttr, defStyleRes) {
setupVariables(attrs)
setupVariables(context, attrs)
}
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
setupVariables(attrs)
setupVariables(context, attrs)
}
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) {
setupVariables(attrs)
setupVariables(context, attrs)
}
constructor(context: Context) : super(context)
private fun setupVariables(attrs: AttributeSet?) {
private fun setupVariables(context: Context, attrs: AttributeSet?) {
mSuffix = attrs?.getAttributeValue(androidns, "text")
mDefault = attrs?.getAttributeIntValue(androidns, "defaultValue", 0) ?: 0
mMax = attrs?.getAttributeIntValue(androidns, "max", 100) ?: 100
@ -85,6 +85,13 @@ class SeekBarPreferenceCompat : DialogPreference {
if (useSimpleSummaryProvider) {
setSummaryProvider { value.toString() }
}
val formattedSummary = attrs?.getAttributeResourceValue(AnkiDroidApp.XML_CUSTOM_NAMESPACE, "formattedSummary", -1)
if (formattedSummary != null && formattedSummary != -1) {
setSummaryProvider {
context.getString(formattedSummary, value)
}
}
}
@Suppress("DEPRECATION")