diff options
author | Allan Wang <me@allanwang.ca> | 2019-06-07 09:39:33 -0400 |
---|---|---|
committer | Allan Wang <me@allanwang.ca> | 2019-06-07 09:39:33 -0400 |
commit | d6a61d5b2601b3849bf402e48fcf1c50a32cfcab (patch) | |
tree | 745ed921423e572c8bff8da6dc08db5ec115115b /kpref-activity/src/main | |
parent | b9feba20d45505a22162c386e18dfc1a4f117d3f (diff) | |
download | kau-d6a61d5b2601b3849bf402e48fcf1c50a32cfcab.tar.gz kau-d6a61d5b2601b3849bf402e48fcf1c50a32cfcab.tar.bz2 kau-d6a61d5b2601b3849bf402e48fcf1c50a32cfcab.zip |
Begin initial md port
Diffstat (limited to 'kpref-activity/src/main')
-rw-r--r-- | kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefColorPicker.kt | 35 |
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 |