From 90e61e0fef26b7134cdda1b97f1a358d7496c4ec Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Wed, 14 Jun 2017 16:09:43 -0700 Subject: Add text pref with example --- .../kotlin/ca/allanwang/kau/sample/KPrefSample.kt | 1 + .../kotlin/ca/allanwang/kau/sample/MainActivity.kt | 28 ++++++++++++++++++---- sample/src/main/res/values/strings.xml | 2 ++ 3 files changed, 26 insertions(+), 5 deletions(-) (limited to 'sample') diff --git a/sample/src/main/kotlin/ca/allanwang/kau/sample/KPrefSample.kt b/sample/src/main/kotlin/ca/allanwang/kau/sample/KPrefSample.kt index 96c7c71..a0fbc59 100644 --- a/sample/src/main/kotlin/ca/allanwang/kau/sample/KPrefSample.kt +++ b/sample/src/main/kotlin/ca/allanwang/kau/sample/KPrefSample.kt @@ -14,4 +14,5 @@ object KPrefSample : KPref() { var check1: Boolean by kpref("check1", true) var check2: Boolean by kpref("check2", false) var check3: Boolean by kpref("check3", false) + var text: String by kpref("text", "empty") } \ 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 4efd9f1..b8ba393 100644 --- a/sample/src/main/kotlin/ca/allanwang/kau/sample/MainActivity.kt +++ b/sample/src/main/kotlin/ca/allanwang/kau/sample/MainActivity.kt @@ -5,10 +5,7 @@ import android.view.Menu import android.view.MenuItem import ca.allanwang.kau.kpref.KPrefActivity import ca.allanwang.kau.kpref.KPrefAdapterBuilder -import ca.allanwang.kau.utils.darken -import ca.allanwang.kau.utils.navigationBarColor -import ca.allanwang.kau.utils.startActivitySlideIn -import ca.allanwang.kau.utils.toast +import ca.allanwang.kau.utils.* import ca.allanwang.kau.views.RippleCanvas import com.mikepenz.google_material_typeface_library.GoogleMaterial @@ -30,7 +27,7 @@ class MainActivity : KPrefActivity() { checkbox(title = R.string.checkbox_2, itemBuilder = { getter = { KPrefSample.check2 } - setter = { KPrefSample.check2 = it; reload(3) } + setter = { KPrefSample.check2 = it; reloadByTitle(R.string.checkbox_3) } }) checkbox(title = R.string.checkbox_3, coreBuilder = { @@ -80,6 +77,27 @@ class MainActivity : KPrefActivity() { allowCustomAlpha = true allowCustom = true }) + + text(title = R.string.text, coreBuilder = { + description = R.string.text_desc + }, itemBuilder = { + getter = { KPrefSample.text } + setter = { KPrefSample.text = it } + onClick = { + itemView, _, item -> + itemView.context.materialDialog { + title("Type Text") + input("Type here", item.pref, { + _, input -> + item.pref = input.toString() + reloadByTitle(R.string.text) + }) + inputRange(0, 20) + build() + }.show() + true + } + }) } override fun onCreate(savedInstanceState: Bundle?) { diff --git a/sample/src/main/res/values/strings.xml b/sample/src/main/res/values/strings.xml index 56addfd..7399593 100644 --- a/sample/src/main/res/values/strings.xml +++ b/sample/src/main/res/values/strings.xml @@ -13,4 +13,6 @@ This selector allows custom colors This selector does not allow custom colors This selector allows for custom colors with alpha values + Text Pref + Saves the text -- cgit v1.2.3