aboutsummaryrefslogtreecommitdiff
path: root/library/src/main
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2017-06-23 17:45:54 -0700
committerAllan Wang <me@allanwang.ca>2017-06-23 17:45:54 -0700
commit9e31fdd4f15ec65cfd272fb1e814bfe0461f0d4f (patch)
tree2427336ce786a745321865be1e30de629007656a /library/src/main
parent0df43d971f1eb18a0e6ce7fa56fab11dfba154b8 (diff)
downloadkau-9e31fdd4f15ec65cfd272fb1e814bfe0461f0d4f.tar.gz
kau-9e31fdd4f15ec65cfd272fb1e814bfe0461f0d4f.tar.bz2
kau-9e31fdd4f15ec65cfd272fb1e814bfe0461f0d4f.zip
Add plain text kpref
Diffstat (limited to 'library/src/main')
-rw-r--r--library/src/main/kotlin/ca/allanwang/kau/kpref/KPrefBinder.kt7
-rw-r--r--library/src/main/kotlin/ca/allanwang/kau/kpref/items/KPrefPlainText.kt27
-rw-r--r--library/src/main/kotlin/ca/allanwang/kau/kpref/items/KPrefSubItems.kt9
-rw-r--r--library/src/main/kotlin/ca/allanwang/kau/kpref/items/KPrefText.kt2
-rw-r--r--library/src/main/res/values/ids.xml2
5 files changed, 40 insertions, 7 deletions
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>.() -> Unit = {})
+ = list.add(KPrefPlainText(KPrefPlainText.KPrefPlainTextBuilder(globalOptions, title)
+ .apply { builder() }))
+
internal val list: MutableList<KPrefItemCore> = 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<Unit>(builder) {
+
+ override fun defaultOnClick(itemView: View, innerContent: View?): Boolean {
+ //nothing
+ return true
+ }
+
+ class KPrefPlainTextBuilder(
+ globalOptions: GlobalOptions,
+ titleRes: Int
+ ) : BaseContract<Unit> 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<T>(val builder: KPrefTextContract<T>) : KPrefItemBase<T>(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 @@
<item name="kau_item_pref_text" type="id" />
<item name="kau_item_pref_checkbox" type="id" />
<item name="kau_item_pref_color_picker" type="id" />
+ <item name="kau_item_pref_sub_item" type="id" />
+ <item name="kau_item_pref_plain_text" type="id" />
</resources> \ No newline at end of file