aboutsummaryrefslogtreecommitdiff
path: root/sample/src/main/kotlin
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2017-09-24 16:41:13 -0400
committerAllan Wang <me@allanwang.ca>2017-09-24 16:43:15 -0400
commit1a509b896aa670da4ab3e2f039140ad7608387e9 (patch)
treeedc1bd60d79715a76f1129882f7b8297f27d746f /sample/src/main/kotlin
parentcd41bb2917425599fca5d786ea62a2c3253dda70 (diff)
downloadkau-1a509b896aa670da4ab3e2f039140ad7608387e9.tar.gz
kau-1a509b896aa670da4ab3e2f039140ad7608387e9.tar.bz2
kau-1a509b896aa670da4ab3e2f039140ad7608387e9.zip
Feature/kpref time picker (#64)
* Init kpref time builder and open up other builders * Enable self refresh * Add readme * Update changelog * Update readme
Diffstat (limited to 'sample/src/main/kotlin')
-rw-r--r--sample/src/main/kotlin/ca/allanwang/kau/sample/KPrefSample.kt3
-rw-r--r--sample/src/main/kotlin/ca/allanwang/kau/sample/MainActivity.kt31
2 files changed, 20 insertions, 14 deletions
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 9adabed..0c243e4 100644
--- a/sample/src/main/kotlin/ca/allanwang/kau/sample/KPrefSample.kt
+++ b/sample/src/main/kotlin/ca/allanwang/kau/sample/KPrefSample.kt
@@ -17,4 +17,7 @@ object KPrefSample : KPref() {
var check3: Boolean by kpref("check3", false)
var text: String by kpref("text", "empty")
var seekbar: Int by kpref("seekbar", 20)
+ var time12: Int by kpref("time_12", 315)
+ var time24: Int by kpref("time_24", 2220)
+
} \ 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 1528970..ca75ebb 100644
--- a/sample/src/main/kotlin/ca/allanwang/kau/sample/MainActivity.kt
+++ b/sample/src/main/kotlin/ca/allanwang/kau/sample/MainActivity.kt
@@ -107,8 +107,7 @@ class MainActivity : KPrefActivity() {
checkbox(R.string.checkbox_3, { KPrefSample.check3 }, { KPrefSample.check3 = it }) {
descRes = R.string.desc_dependent
enabler = { KPrefSample.check2 }
- onDisabledClick = {
- itemView, _, _ ->
+ onDisabledClick = { itemView, _, _ ->
itemView.context.toast("I am still disabled")
true
}
@@ -140,8 +139,7 @@ class MainActivity : KPrefActivity() {
text(R.string.text, { KPrefSample.text }, { KPrefSample.text = it }) {
descRes = R.string.text_desc
- onClick = {
- itemView, _, item ->
+ onClick = { itemView, _, item ->
itemView.context.materialDialog {
title("Type Text")
input("Type here", item.pref, { _, input -> item.pref = input.toString() })
@@ -193,17 +191,25 @@ class MainActivity : KPrefActivity() {
textGetter = { string(R.string.kau_lorem_ipsum) }
}
+ timePicker(R.string.time, { KPrefSample.time12 }, { KPrefSample.time12 = it }) {
+ descRes = R.string.time_desc_12
+ use24HourFormat = false
+ }
+
+ timePicker(R.string.time, { KPrefSample.time24 }, { KPrefSample.time24 = it }) {
+ descRes = R.string.time_desc_24
+ use24HourFormat = true
+ }
+
}
fun subPrefs(): KPrefAdapterBuilder.() -> Unit = {
text(R.string.text, { KPrefSample.text }, { KPrefSample.text = it }) {
descRes = R.string.text_desc
- onClick = {
- itemView, _, item ->
+ onClick = { itemView, _, item ->
itemView.context.materialDialog {
title("Type Text")
- input("Type here", item.pref, {
- _, input ->
+ input("Type here", item.pref, { _, input ->
item.pref = input.toString()
reloadSelf()
})
@@ -237,21 +243,18 @@ class MainActivity : KPrefActivity() {
menuInflater.inflate(R.menu.menu_main, menu)
if (searchView == null) searchView = bindSearchView(menu, R.id.action_search) {
- textCallback = {
- query, searchView ->
+ textCallback = { query, searchView ->
val items = wordBank.filter { it.contains(query) }.sorted().map { SearchItem(it) }
searchView.results = items
}
- searchCallback = {
- query, _ ->
+ searchCallback = { query, _ ->
toast("Enter pressed for $query")
true
}
textDebounceInterval = 0
noResultsFound = R.string.kau_no_results_found
shouldClearOnClose = false
- onItemClick = {
- _, _, content, searchView ->
+ onItemClick = { _, _, content, searchView ->
toast(content)
searchView.revealClose()
}