aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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
-rw-r--r--sample/src/main/kotlin/ca/allanwang/kau/sample/MainActivity.kt13
6 files changed, 46 insertions, 14 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
diff --git a/sample/src/main/kotlin/ca/allanwang/kau/sample/MainActivity.kt b/sample/src/main/kotlin/ca/allanwang/kau/sample/MainActivity.kt
index 460d993..2914824 100644
--- a/sample/src/main/kotlin/ca/allanwang/kau/sample/MainActivity.kt
+++ b/sample/src/main/kotlin/ca/allanwang/kau/sample/MainActivity.kt
@@ -7,7 +7,10 @@ import ca.allanwang.kau.email.sendEmail
import ca.allanwang.kau.kpref.CoreAttributeContract
import ca.allanwang.kau.kpref.KPrefActivity
import ca.allanwang.kau.kpref.KPrefAdapterBuilder
-import ca.allanwang.kau.utils.*
+import ca.allanwang.kau.utils.materialDialog
+import ca.allanwang.kau.utils.navigationBarColor
+import ca.allanwang.kau.utils.startActivity
+import ca.allanwang.kau.utils.toast
import ca.allanwang.kau.views.RippleCanvas
import com.mikepenz.google_material_typeface_library.GoogleMaterial
@@ -73,17 +76,13 @@ class MainActivity : KPrefActivity() {
allowCustom = true
}
- text<String>(R.string.text, { KPrefSample.text }, { KPrefSample.text = it }) {
+ text(R.string.text, { KPrefSample.text }, { KPrefSample.text = it }) {
descRes = R.string.text_desc
onClick = {
itemView, _, item ->
itemView.context.materialDialog {
title("Type Text")
- input("Type here", item.pref, {
- _, input ->
- item.pref = input.toString()
- reloadSelf()
- })
+ input("Type here", item.pref, { _, input -> item.pref = input.toString() })
inputRange(0, 20)
}
true