aboutsummaryrefslogtreecommitdiff
path: root/kpref-activity/src
diff options
context:
space:
mode:
Diffstat (limited to 'kpref-activity/src')
-rw-r--r--kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefColorPicker.kt35
1 files changed, 19 insertions, 16 deletions
diff --git a/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefColorPicker.kt b/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefColorPicker.kt
index 0b53797..8b051c5 100644
--- a/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefColorPicker.kt
+++ b/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefColorPicker.kt
@@ -18,11 +18,12 @@ package ca.allanwang.kau.kpref.activity.items
import ca.allanwang.kau.colorpicker.CircleView
import ca.allanwang.kau.colorpicker.ColorBuilder
import ca.allanwang.kau.colorpicker.ColorContract
-import ca.allanwang.kau.colorpicker.colorPickerDialog
+import ca.allanwang.kau.colorpicker.kauColorChooser
import ca.allanwang.kau.kpref.activity.GlobalOptions
import ca.allanwang.kau.kpref.activity.KClick
import ca.allanwang.kau.kpref.activity.KPrefItemActions
import ca.allanwang.kau.kpref.activity.R
+import com.afollestad.materialdialogs.MaterialDialog
/**
* Created by Allan Wang on 2017-06-07.
@@ -34,36 +35,37 @@ open class KPrefColorPicker(open val builder: KPrefColorContract) : KPrefItemBas
override fun bindView(holder: ViewHolder, payloads: List<Any>) {
super.bindView(holder, payloads)
- builder.apply {
- titleRes = core.titleFun()
- colorCallback = { pref = it }
- }
if (builder.showPreview) {
val preview = holder.bindInnerView<CircleView>(R.layout.kau_pref_color)
preview.setBackgroundColor(pref)
preview.withBorder = true
- builder.apply {
- colorCallback = {
- pref = it
- if (builder.showPreview)
- preview.setBackgroundColor(it)
- holder.updateTitle()
- holder.updateDesc()
- }
+ builder.callback = { _, color ->
+ pref = color
+ if (builder.showPreview)
+ preview.setBackgroundColor(color)
+ holder.updateTitle()
+ holder.updateDesc()
}
+ } else {
+ builder.callback = { _, color -> pref = color }
}
}
override fun KClick<Int>.defaultOnClick() {
builder.defaultColor = pref
- context.colorPickerDialog(builder).show()
+ MaterialDialog(context).show {
+ kauColorChooser(builder)
+ builder.dialogBuilder(this)
+ title(core.titleFun())
+ }
}
/**
* Extension of the base contract and [ColorContract] along with a showPreview option
*/
- interface KPrefColorContract : BaseContract<Int>, ColorContract {
+ interface KPrefColorContract : KPrefItemBase.BaseContract<Int>, ColorContract {
var showPreview: Boolean
+ var dialogBuilder: MaterialDialog.() -> Unit
}
/**
@@ -74,9 +76,10 @@ open class KPrefColorPicker(open val builder: KPrefColorContract) : KPrefItemBas
titleId: Int,
getter: () -> Int,
setter: KPrefItemActions.(value: Int) -> Unit
- ) : KPrefColorContract, BaseContract<Int> by BaseBuilder(globalOptions, titleId, getter, setter),
+ ) : KPrefColorContract, KPrefItemBase.BaseContract<Int> by BaseBuilder(globalOptions, titleId, getter, setter),
ColorContract by ColorBuilder() {
override var showPreview: Boolean = true
+ override var dialogBuilder: MaterialDialog.() -> Unit = {}
}
override fun getType(): Int = R.id.kau_item_pref_color_picker