diff options
author | Allan Wang <me@allanwang.ca> | 2019-06-07 12:41:13 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-06-07 12:41:13 -0400 |
commit | 1e3cb74579a3297460cd4085c57942138c5805a2 (patch) | |
tree | ba1ab2f42d3d4407c50c215ba85674700c047db7 /kpref-activity | |
parent | b9feba20d45505a22162c386e18dfc1a4f117d3f (diff) | |
parent | 879ac366074697dd0a7fbb2c3d99a48d7aeeb22d (diff) | |
download | kau-1e3cb74579a3297460cd4085c57942138c5805a2.tar.gz kau-1e3cb74579a3297460cd4085c57942138c5805a2.tar.bz2 kau-1e3cb74579a3297460cd4085c57942138c5805a2.zip |
Merge pull request #200 from AllanWang/material-dialogs-3
Material Dialogs 3
Diffstat (limited to 'kpref-activity')
-rw-r--r-- | kpref-activity/build.gradle | 2 | ||||
-rw-r--r-- | kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefColorPicker.kt | 35 |
2 files changed, 20 insertions, 17 deletions
diff --git a/kpref-activity/build.gradle b/kpref-activity/build.gradle index 8b2d12d..ef91e2b 100644 --- a/kpref-activity/build.gradle +++ b/kpref-activity/build.gradle @@ -6,8 +6,8 @@ apply from: '../android-lib.gradle' dependencies { implementation project(':core') - implementation project(':adapter') implementation project(':colorpicker') + implementation project(':adapter') } apply from: '../artifacts.gradle' 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 |