diff options
4 files changed, 23 insertions, 7 deletions
diff --git a/buildSrc/src/main/groovy/ca/allanwang/kau/Versions.groovy b/buildSrc/src/main/groovy/ca/allanwang/kau/Versions.groovy index 0e4c29a..448a049 100644 --- a/buildSrc/src/main/groovy/ca/allanwang/kau/Versions.groovy +++ b/buildSrc/src/main/groovy/ca/allanwang/kau/Versions.groovy @@ -15,7 +15,7 @@ class Versions { static def blurry = '2.1.1' // https://dl.google.com/dl/android/maven2/com/android/support/constraint/group-index.xml - static def constraintLayout = '1.1.0-beta6' + static def constraintLayout = '1.1.0' static def fastAdapter = '3.2.5' static def fastAdapterCommons = fastAdapter static def glide = '4.6.1' @@ -31,7 +31,7 @@ class Versions { static def junit = '4.12' static def testRunner = '1.0.1' - static def gradlePlugin = '3.1.0' + static def gradlePlugin = '3.1.1' static def mavenPlugin = '2.0' static def playPublishPlugin = '1.2.0' static def dexCountPlugin = '0.8.2' diff --git a/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefSeekbar.kt b/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefSeekbar.kt index a580e83..78f4f80 100644 --- a/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefSeekbar.kt +++ b/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefSeekbar.kt @@ -15,6 +15,15 @@ import ca.allanwang.kau.utils.tint */ open class KPrefSeekbar(val builder: KPrefSeekbarContract) : KPrefItemBase<Int>(builder) { + protected val min = builder.min + protected val max = builder.max + protected val increment = builder.increments + + init { + if (increment <= 0) + throw IllegalArgumentException("Seekbar must increment by at least 1") + } + override fun KClick<Int>.defaultOnClick() = Unit override fun bindView(holder: ViewHolder, payloads: List<Any>) { @@ -26,8 +35,7 @@ open class KPrefSeekbar(val builder: KPrefSeekbarContract) : KPrefItemBase<Int>( text.tvc() val seekbar = holder.bindLowerView<SeekBar>(R.layout.kau_pref_seekbar) { - it.max = builder.max - builder.min - it.incrementProgressBy(builder.increments) + it.max = (max - min) / increment it.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener { override fun onProgressChanged(sb: SeekBar, progress: Int, fromUser: Boolean) { text.text = builder.toText(progress.fromProgress) @@ -81,11 +89,18 @@ open class KPrefSeekbar(val builder: KPrefSeekbarContract) : KPrefItemBase<Int>( override var textViewConfigs: TextView.() -> Unit = {} } + /** + * Helper to convert true value to progress value + * Progress values start at 0 and increment by 1 + */ protected inline val Int.toProgress: Int - get() = this - builder.min + get() = (this - min) / increment + /** + * Inverse of [Int.toProgress] to find the true value from the seekbar + */ protected inline val Int.fromProgress: Int - get() = this + builder.min + get() = this * increment + min override fun getType(): Int = R.id.kau_item_pref_seekbar diff --git a/sample/src/main/kotlin/ca/allanwang/kau/sample/MainActivity.kt b/sample/src/main/kotlin/ca/allanwang/kau/sample/MainActivity.kt index b424e91..6cd9776 100644 --- a/sample/src/main/kotlin/ca/allanwang/kau/sample/MainActivity.kt +++ b/sample/src/main/kotlin/ca/allanwang/kau/sample/MainActivity.kt @@ -149,6 +149,7 @@ class MainActivity : KPrefActivity() { seekbar(R.string.seekbar, KPrefSample::seekbar, { KPrefSample.seekbar = it }) { descRes = R.string.kau_lorem_ipsum + increments = 5 textViewConfigs = { minEms = 2 } diff --git a/sample/src/main/res/xml/kau_changelog.xml b/sample/src/main/res/xml/kau_changelog.xml index 636525f..a5d0ea9 100644 --- a/sample/src/main/res/xml/kau_changelog.xml +++ b/sample/src/main/res/xml/kau_changelog.xml @@ -11,7 +11,7 @@ <item text="Fix new lint issues (see Migration for resource related methods)" /> <item text=":adapter: Add more IAdapter functions to help retrieve selections" /> <item text=":core: Add deprecation warning to bindView for fragment based extensions; use bindViewResettable instead" /> - <item text="" /> + <item text=":kpref-activity: Fix seekbar increment" /> <item text="" /> <item text="" /> |