From 9e31fdd4f15ec65cfd272fb1e814bfe0461f0d4f Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Fri, 23 Jun 2017 17:45:54 -0700 Subject: Add plain text kpref --- .../kotlin/ca/allanwang/kau/kpref/KPrefBinder.kt | 7 +++++- .../ca/allanwang/kau/kpref/items/KPrefPlainText.kt | 27 ++++++++++++++++++++++ .../ca/allanwang/kau/kpref/items/KPrefSubItems.kt | 9 ++++---- .../ca/allanwang/kau/kpref/items/KPrefText.kt | 2 +- library/src/main/res/values/ids.xml | 2 ++ 5 files changed, 40 insertions(+), 7 deletions(-) create mode 100644 library/src/main/kotlin/ca/allanwang/kau/kpref/items/KPrefPlainText.kt (limited to 'library/src/main') diff --git a/library/src/main/kotlin/ca/allanwang/kau/kpref/KPrefBinder.kt b/library/src/main/kotlin/ca/allanwang/kau/kpref/KPrefBinder.kt index 472c538..89afaab 100644 --- a/library/src/main/kotlin/ca/allanwang/kau/kpref/KPrefBinder.kt +++ b/library/src/main/kotlin/ca/allanwang/kau/kpref/KPrefBinder.kt @@ -45,7 +45,7 @@ class CoreAttributeBuilder : CoreAttributeContract { } interface KPrefActivityContract { - fun showNextPrefs(@StringRes toolbarTitleRes:Int, builder: KPrefAdapterBuilder.() -> Unit) + fun showNextPrefs(@StringRes toolbarTitleRes: Int, builder: KPrefAdapterBuilder.() -> Unit) fun showPrevPrefs() fun reloadByTitle(@StringRes vararg title: Int) } @@ -94,5 +94,10 @@ class KPrefAdapterBuilder(internal val globalOptions: GlobalOptions) { = list.add(KPrefSubItems(KPrefSubItems.KPrefSubItemsBuilder(globalOptions, title, itemBuilder) .apply { builder() })) + fun plainText(@StringRes title: Int, + builder: KPrefItemBase.BaseContract.() -> Unit = {}) + = list.add(KPrefPlainText(KPrefPlainText.KPrefPlainTextBuilder(globalOptions, title) + .apply { builder() })) + internal val list: MutableList = mutableListOf() } \ No newline at end of file diff --git a/library/src/main/kotlin/ca/allanwang/kau/kpref/items/KPrefPlainText.kt b/library/src/main/kotlin/ca/allanwang/kau/kpref/items/KPrefPlainText.kt new file mode 100644 index 0000000..9732b98 --- /dev/null +++ b/library/src/main/kotlin/ca/allanwang/kau/kpref/items/KPrefPlainText.kt @@ -0,0 +1,27 @@ +package ca.allanwang.kau.kpref.items + +import android.view.View +import ca.allanwang.kau.R +import ca.allanwang.kau.kpref.GlobalOptions + +/** + * Created by Allan Wang on 2017-06-14. + * + * Just text with the core options. Extends base preference but has an empty getter and setter + * + */ +class KPrefPlainText(val builder: KPrefPlainTextBuilder) : KPrefItemBase(builder) { + + override fun defaultOnClick(itemView: View, innerContent: View?): Boolean { + //nothing + return true + } + + class KPrefPlainTextBuilder( + globalOptions: GlobalOptions, + titleRes: Int + ) : BaseContract by BaseBuilder(globalOptions, titleRes, {}, {}) + + override fun getType(): Int = R.id.kau_item_pref_plain_text + +} \ No newline at end of file diff --git a/library/src/main/kotlin/ca/allanwang/kau/kpref/items/KPrefSubItems.kt b/library/src/main/kotlin/ca/allanwang/kau/kpref/items/KPrefSubItems.kt index 8614cb6..51625ab 100644 --- a/library/src/main/kotlin/ca/allanwang/kau/kpref/items/KPrefSubItems.kt +++ b/library/src/main/kotlin/ca/allanwang/kau/kpref/items/KPrefSubItems.kt @@ -8,12 +8,11 @@ import ca.allanwang.kau.kpref.KPrefAdapterBuilder /** * Created by Allan Wang on 2017-06-14. * - * Text preference - * Holds a textview to display data on the right - * This is still a generic preference + * Sub item preference + * When clicked, will navigate to a new set of preferences and add the old list to a stack * */ -class KPrefSubItems(val builder: KPrefSubItemsBuilder) : KPrefItemCore(builder) { +class KPrefSubItems(val builder: KPrefSubItemsContract) : KPrefItemCore(builder) { override fun onClick(itemView: View, innerContent: View?): Boolean { builder.globalOptions.showNextPrefs(builder.titleRes, builder.itemBuilder) @@ -39,6 +38,6 @@ class KPrefSubItems(val builder: KPrefSubItemsBuilder) : KPrefItemCore(builder) override val itemBuilder: KPrefAdapterBuilder.() -> Unit ) : KPrefSubItemsContract, CoreContract by CoreBuilder(globalOptions, titleRes) - override fun getType(): Int = R.id.kau_item_pref_checkbox + override fun getType(): Int = R.id.kau_item_pref_sub_item } \ No newline at end of file diff --git a/library/src/main/kotlin/ca/allanwang/kau/kpref/items/KPrefText.kt b/library/src/main/kotlin/ca/allanwang/kau/kpref/items/KPrefText.kt index 894f024..8662b6a 100644 --- a/library/src/main/kotlin/ca/allanwang/kau/kpref/items/KPrefText.kt +++ b/library/src/main/kotlin/ca/allanwang/kau/kpref/items/KPrefText.kt @@ -57,6 +57,6 @@ class KPrefText(val builder: KPrefTextContract) : KPrefItemBase(builder override var textGetter: (T) -> String? = { it?.toString() } } - override fun getType(): Int = R.id.kau_item_pref_checkbox + override fun getType(): Int = R.id.kau_item_pref_text } \ No newline at end of file diff --git a/library/src/main/res/values/ids.xml b/library/src/main/res/values/ids.xml index 36be2b2..54f01af 100644 --- a/library/src/main/res/values/ids.xml +++ b/library/src/main/res/values/ids.xml @@ -5,4 +5,6 @@ + + \ No newline at end of file -- cgit v1.2.3