aboutsummaryrefslogtreecommitdiff
path: root/sample/src/main
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2017-06-16 23:35:22 -0700
committerAllan Wang <me@allanwang.ca>2017-06-16 23:35:22 -0700
commite6c13788e94d10832116fc08e4c71d5f0d38511b (patch)
treec1048b24f7ddc02016013819ffe80f0b71b72c63 /sample/src/main
parentfbbea20e78f196ffccda5a3a844a265772c68ea4 (diff)
downloadkau-e6c13788e94d10832116fc08e4c71d5f0d38511b.tar.gz
kau-e6c13788e94d10832116fc08e4c71d5f0d38511b.tar.bz2
kau-e6c13788e94d10832116fc08e4c71d5f0d38511b.zip
Embed color attributes and clean up sample
Diffstat (limited to 'sample/src/main')
-rw-r--r--sample/src/main/kotlin/ca/allanwang/kau/sample/MainActivity.kt130
-rw-r--r--sample/src/main/kotlin/ca/allanwang/kau/sample/SL.kt8
2 files changed, 68 insertions, 70 deletions
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 7c6412a..cb7c082 100644
--- a/sample/src/main/kotlin/ca/allanwang/kau/sample/MainActivity.kt
+++ b/sample/src/main/kotlin/ca/allanwang/kau/sample/MainActivity.kt
@@ -18,81 +18,73 @@ class MainActivity : KPrefActivity() {
header(R.string.header)
- checkbox(title = R.string.checkbox_1,
- getter = { KPrefSample.check1 },
- setter = { KPrefSample.check1 = it },
+ /**
+ * This is how the setup looks like with all the proper tags
+ */
+ checkbox(title = R.string.checkbox_1, getter = { KPrefSample.check1 }, setter = { KPrefSample.check1 = it },
builder = {
descRes = R.string.desc
})
- checkbox(title = R.string.checkbox_2,
- getter = { KPrefSample.check2 },
- setter = { KPrefSample.check2 = it; reloadByTitle(R.string.checkbox_3) })
-
- checkbox(title = R.string.checkbox_3,
- getter = { KPrefSample.check3 },
- setter = { KPrefSample.check3 = it },
- builder = {
- descRes = R.string.desc_dependent
- enabler = { KPrefSample.check2 }
- onDisabledClick = {
- itemView, _, _ ->
- itemView.context.toast("I am still disabled")
- true
- }
- })
+ /**
+ * Since we know the order, we may omit the tags
+ */
+ checkbox(R.string.checkbox_2, { KPrefSample.check2 }, { KPrefSample.check2 = it; reloadByTitle(R.string.checkbox_3) })
+
+ /**
+ * Since the builder is the last argument and is a lambda, we may write the setup cleanly like so:
+ */
+ checkbox(R.string.checkbox_3, { KPrefSample.check3 }, { KPrefSample.check3 = it }) {
+ descRes = R.string.desc_dependent
+ enabler = { KPrefSample.check2 }
+ onDisabledClick = {
+ itemView, _, _ ->
+ itemView.context.toast("I am still disabled")
+ true
+ }
+ }
- colorPicker(title = R.string.text_color,
- getter = { KPrefSample.textColor },
- setter = { KPrefSample.textColor = it; reload() },
- builder = {
- descRes = R.string.color_custom
- allowCustom = true
- })
+ colorPicker(R.string.text_color, { KPrefSample.textColor }, { KPrefSample.textColor = it; reload() }) {
+ descRes = R.string.color_custom
+ allowCustom = true
+ }
- colorPicker(title = R.string.accent_color,
- getter = { KPrefSample.accentColor },
- setter = {
- KPrefSample.accentColor = it
- reload()
- val darkerColor = it.darken()
- this@MainActivity.navigationBarColor = darkerColor
- toolbarCanvas.ripple(darkerColor, RippleCanvas.MIDDLE, RippleCanvas.END, duration = 500L)
- },
- builder = {
- descRes = R.string.color_no_custom
- allowCustom = false
- })
+ colorPicker(R.string.accent_color, { KPrefSample.accentColor }, {
+ KPrefSample.accentColor = it
+ reload()
+ val darkerColor = it.darken()
+ this@MainActivity.navigationBarColor = darkerColor
+ toolbarCanvas.ripple(darkerColor, RippleCanvas.MIDDLE, RippleCanvas.END, duration = 500L)
+ }) {
+ descRes = R.string.color_no_custom
+ allowCustom = false
+ }
- colorPicker(title = R.string.background_color,
- getter = { KPrefSample.bgColor },
- setter = { KPrefSample.bgColor = it; bgCanvas.ripple(it, duration = 500L) },
- builder = {
- iicon = GoogleMaterial.Icon.gmd_colorize
- descRes = R.string.color_custom_alpha
- allowCustomAlpha = true
- allowCustom = true
- })
+ colorPicker(R.string.background_color, { KPrefSample.bgColor }, {
+ KPrefSample.bgColor = it; bgCanvas.ripple(it, duration = 500L)
+ }) {
+ iicon = GoogleMaterial.Icon.gmd_colorize
+ descRes = R.string.color_custom_alpha
+ allowCustomAlpha = true
+ allowCustom = true
+ }
- text<String>(title = R.string.text,
- getter = { KPrefSample.text },
- setter = { KPrefSample.text = it },
- builder = {
- descRes = R.string.text_desc
- 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)
- }
- true
- }
- })
+ text<String>(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()
+ reloadByTitle(R.string.text)
+ })
+ inputRange(0, 20)
+ }
+ true
+ }
+ }
}
override fun onCreate(savedInstanceState: Bundle?) {
@@ -110,9 +102,7 @@ class MainActivity : KPrefActivity() {
override fun onOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
- R.id.action_settings -> {
- startActivitySlideIn(AnimActivity::class.java, clearStack = true)
- }
+ R.id.action_settings -> startActivitySlideIn(AnimActivity::class.java, clearStack = true)
else -> return super.onOptionsItemSelected(item)
}
return true
diff --git a/sample/src/main/kotlin/ca/allanwang/kau/sample/SL.kt b/sample/src/main/kotlin/ca/allanwang/kau/sample/SL.kt
new file mode 100644
index 0000000..a77ffe8
--- /dev/null
+++ b/sample/src/main/kotlin/ca/allanwang/kau/sample/SL.kt
@@ -0,0 +1,8 @@
+package ca.allanwang.kau.sample
+
+import ca.allanwang.kau.logging.TimberLogger
+
+/**
+ * Created by Allan Wang on 2017-06-08.
+ */
+object SL: TimberLogger("KAU Sample") \ No newline at end of file