aboutsummaryrefslogtreecommitdiff
path: root/sample/src/main
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
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')
-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
-rw-r--r--sample/src/main/res/values/strings.xml3
-rw-r--r--sample/src/main/res/xml/kau_changelog.xml8
4 files changed, 28 insertions, 17 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()
}
diff --git a/sample/src/main/res/values/strings.xml b/sample/src/main/res/values/strings.xml
index a887ad3..1e3361e 100644
--- a/sample/src/main/res/values/strings.xml
+++ b/sample/src/main/res/values/strings.xml
@@ -15,6 +15,9 @@
<string name="text">Text Pref</string>
<string name="text_desc">Saves the text</string>
<string name="seekbar">Seekbar</string>
+ <string name="time">Time Pref</string>
+ <string name="time_desc_12">AM PM version</string>
+ <string name="time_desc_24">24h version</string>
<string name="sub_item">Sub Item Pref</string>
<string name="sub_item_desc">Press this to view the next subset of preferences</string>
<string name="your_email">your.email@here.com</string>
diff --git a/sample/src/main/res/xml/kau_changelog.xml b/sample/src/main/res/xml/kau_changelog.xml
index 53dfe99..a33edbd 100644
--- a/sample/src/main/res/xml/kau_changelog.xml
+++ b/sample/src/main/res/xml/kau_changelog.xml
@@ -7,9 +7,11 @@
-->
<version title="v3.4.1"/>
- <item text="Validate context before showing dialogs" />
- <item text="Add intent resolver checks prior to all executions." />
- <item text="Fix bundle NPE when starting activity" />
+ <item text=":core: Validate context before showing dialogs" />
+ <item text=":core: Add intent resolver checks prior to all executions." />
+ <item text=":core: Fix bundle NPE when starting activity" />
+ <item text=":kpref-activity: Create timePicker" />
+ <item text="" />
<item text="" />
<item text="" />