diff --git a/android/android/src/de/benibela/videlibri/activities/Options.kt b/android/android/src/de/benibela/videlibri/activities/Options.kt index e76ad80a..ba5e5ef0 100644 --- a/android/android/src/de/benibela/videlibri/activities/Options.kt +++ b/android/android/src/de/benibela/videlibri/activities/Options.kt @@ -114,8 +114,9 @@ class Options : VideLibriBaseActivity() { onChanged(saveOptionsAndroidOnly) } as PreferenceSeekBar seekBarToToggle!!.apply { + //showSeekBarValue = true dynamicSummary = getString(R.string.lay_options_label_autocheckdelay_summary) - safeMax = 120 + safeMax = 1200 unsafeWarning = getString(R.string.lay_options_label_autocheckdelay_too_large) isEnabled = globalOptionsAndroid.notifications.enabled showDynamicSummary() diff --git a/android/android/src/de/benibela/videlibri/components/PreferenceSeekBar.kt b/android/android/src/de/benibela/videlibri/components/PreferenceSeekBar.kt index c0135f98..cd844228 100644 --- a/android/android/src/de/benibela/videlibri/components/PreferenceSeekBar.kt +++ b/android/android/src/de/benibela/videlibri/components/PreferenceSeekBar.kt @@ -19,6 +19,8 @@ class PreferenceSeekBar @JvmOverloads constructor(context: Context, attrs: Attri var safeMax: Int var unsafeWarning: String? + var valueDisplayMapper: ((Int)->Int) = { x -> x } + init { val a = context.obtainStyledAttributes(attrs, R.styleable.PreferenceSeekBar, defStyleAttr, defStyleRes) @@ -56,7 +58,7 @@ class PreferenceSeekBar @JvmOverloads constructor(context: Context, attrs: Attri } fun showDynamicSummary() { - val s = dynamicSummary?.let { String.format(it, value) } ?: "" + val s = dynamicSummary?.let { String.format(it, valueDisplayMapper( value)) } ?: "" //todo: plural https://stackoverflow.com/a/25648349 summary = if (editable) s else s + " " + getString(R.string.lay_options_seekbar_tap_to_change) diff --git a/android/android/src/de/benibela/videlibri/components/PreferencesBuilder.kt b/android/android/src/de/benibela/videlibri/components/PreferencesBuilder.kt index fb9b688d..7674e903 100644 --- a/android/android/src/de/benibela/videlibri/components/PreferencesBuilder.kt +++ b/android/android/src/de/benibela/videlibri/components/PreferencesBuilder.kt @@ -6,6 +6,9 @@ import android.content.Context import androidx.annotation.ArrayRes import androidx.annotation.StringRes import androidx.preference.* +import kotlin.math.log2 +import kotlin.math.pow +import kotlin.math.round import kotlin.reflect.KMutableProperty0 class PreferenceScreenBuilder(val context: Context, val screen: PreferenceScreen, init: PreferenceScreenBuilder.() -> Unit) { @@ -147,6 +150,38 @@ class SeekBarBuilder(ctx: Context, customPreference: SeekBarPreference?): super.property(p) preference.value = p.get() } + //scale the seekbar exponential + //this is kind of a hack, since the seekbar and preference is still linear, the value is scaled before being written to persistent storage + //so all the preference options (max, safeMax, showSeekBarValue) show the wrong value + fun logarithmicProperty(p: KMutableProperty0){ +/* + a good looking mapping: + 180 -> 30 + 360 -> 60 + 540 -> 120 + 720 -> 240 + 900 -> 480 + corresponds to + x -> 15*2**( x/180 ) + reverse: + y -> log2(y/15) *180 + + but use 5, because that is also the minimum since exp(0) = 1 + */ + val propertyTransformer = object { + val actualProperty = p + var fakeProperty: Int + get() = getterTransform( p.get() ) + set(value) { + p.set( setterTransform( value ) ); + // Log.i("videlibriLOG", "$value -> ${setterTransform( value )} -> ${p.get()}") + } + fun setterTransform(x: Int) = round( 5 * (2.0.pow(x/180.0)) ).toInt() + fun getterTransform(y: Int) = round( log2 (y / 5.0) * 180 ).toInt() + } + property(propertyTransformer::fakeProperty) + (preference as? PreferenceSeekBar)?.valueDisplayMapper = propertyTransformer::setterTransform + } } /*