aboutsummaryrefslogtreecommitdiff
path: root/sample/src/main/kotlin/ca
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2017-06-10 23:46:02 -0700
committerAllan Wang <me@allanwang.ca>2017-06-10 23:46:02 -0700
commitc00f9e2674f5109a64f1f50873ce08089a2fce33 (patch)
treef12b43da762a34b9e803c48c9d53be473cff9c54 /sample/src/main/kotlin/ca
parent93846b3df8fd838a3277f5bacaa99e4ffb59012a (diff)
downloadkau-c00f9e2674f5109a64f1f50873ce08089a2fce33.tar.gz
kau-c00f9e2674f5109a64f1f50873ce08089a2fce33.tar.bz2
kau-c00f9e2674f5109a64f1f50873ce08089a2fce33.zip
Create kpref activity base
Diffstat (limited to 'sample/src/main/kotlin/ca')
-rw-r--r--sample/src/main/kotlin/ca/allanwang/kau/sample/KPrefSample.kt1
-rw-r--r--sample/src/main/kotlin/ca/allanwang/kau/sample/MainActivity.kt83
2 files changed, 45 insertions, 39 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 a752ea2..96c7c71 100644
--- a/sample/src/main/kotlin/ca/allanwang/kau/sample/KPrefSample.kt
+++ b/sample/src/main/kotlin/ca/allanwang/kau/sample/KPrefSample.kt
@@ -9,6 +9,7 @@ import ca.allanwang.kau.kpref.kpref
*/
object KPrefSample : KPref() {
var textColor: Int by kpref("TEXT_COLOR", Color.WHITE)
+ var accentColor: Int by kpref("ACCENT_COLOR", 0xffff4081.toInt())
var bgColor: Int by kpref("BG_COLOR", 0xff303030.toInt())
var check1: Boolean by kpref("check1", true)
var check2: Boolean by kpref("check2", false)
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 6c36626..db42f9b 100644
--- a/sample/src/main/kotlin/ca/allanwang/kau/sample/MainActivity.kt
+++ b/sample/src/main/kotlin/ca/allanwang/kau/sample/MainActivity.kt
@@ -1,56 +1,61 @@
package ca.allanwang.kau.sample
import android.os.Bundle
-import android.support.v7.app.AppCompatActivity
-import android.support.v7.widget.RecyclerView
import android.view.Menu
import android.view.MenuItem
-import android.view.ViewGroup
+import ca.allanwang.kau.kpref.KPrefActivity
import ca.allanwang.kau.kpref.KPrefAdapterBuilder
-import ca.allanwang.kau.kpref.items.KPrefItemCore
-import ca.allanwang.kau.kpref.setKPrefAdapter
+import ca.allanwang.kau.utils.darken
+import ca.allanwang.kau.utils.navigationBarColor
import ca.allanwang.kau.utils.showChangelog
import ca.allanwang.kau.views.RippleCanvas
-import com.mikepenz.fastadapter.commons.adapters.FastItemAdapter
-class MainActivity : AppCompatActivity() {
- lateinit var adapter: FastItemAdapter<KPrefItemCore>
- lateinit var builder: KPrefAdapterBuilder
+class MainActivity : KPrefActivity() {
+
+ override fun onCreateKPrefs(savedInstanceState: android.os.Bundle?): KPrefAdapterBuilder.() -> Unit = {
+ textColorGetter = { KPrefSample.textColor }
+ accentColorGetter = { KPrefSample.accentColor }
+ header(R.string.header)
+ checkbox(title = R.string.checkbox_1, description = R.string.desc,
+ getter = { KPrefSample.check1 }, setter = { KPrefSample.check1 = it })
+ checkbox(title = R.string.checkbox_2,
+ getter = { KPrefSample.check2 }, setter = { KPrefSample.check2 = it })
+ checkbox(title = R.string.checkbox_3, description = R.string.desc_disabled, enabled = false,
+ getter = { KPrefSample.check3 }, setter = { KPrefSample.check3 = it })
+ colorPicker(title = R.string.text_color, description = R.string.color_custom,
+ getter = { KPrefSample.textColor }, setter = {
+ KPrefSample.textColor = it
+ adapter.notifyAdapterDataSetChanged()
+ },
+ configs = {
+ allowCustom = true
+ })
+ colorPicker(title = R.string.accent_color, description = R.string.color_no_custom,
+ getter = { KPrefSample.accentColor }, setter = {
+ KPrefSample.accentColor = it
+ adapter.notifyAdapterDataSetChanged()
+ val darkerColor = it.darken()
+ this@MainActivity.navigationBarColor = darkerColor
+ toolbarCanvas.ripple(darkerColor, RippleCanvas.MIDDLE, RippleCanvas.END, duration = 500)
+ },
+ configs = {
+ allowCustom = false
+ })
+ colorPicker(title = R.string.background_color, description = R.string.color_custom_alpha,
+ getter = { KPrefSample.bgColor }, setter = { KPrefSample.bgColor = it; bgCanvas.ripple(it, duration = 500) },
+ configs = {
+ allowCustomAlpha = true
+ allowCustom = true
+ })
+ }
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
- val recycler = RecyclerView(this)
- val bgCanvas = RippleCanvas(this)
- setContentView(bgCanvas)
- addContentView(recycler, ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT))
bgCanvas.set(KPrefSample.bgColor)
- adapter = recycler.setKPrefAdapter {
- builder = this
- textColor = KPrefSample.textColor
- header(R.string.header)
- checkbox(title = R.string.checkbox_1, description = R.string.desc,
- getter = { KPrefSample.check1 }, setter = { KPrefSample.check1 = it })
- checkbox(title = R.string.checkbox_2,
- getter = { KPrefSample.check2 }, setter = { KPrefSample.check2 = it })
- checkbox(title = R.string.checkbox_3, description = R.string.desc_disabled, enabled = false,
- getter = { KPrefSample.check3 }, setter = { KPrefSample.check3 = it })
- colorPicker(title = R.string.text_color,
- getter = { KPrefSample.textColor }, setter = { KPrefSample.textColor = it; builder.textColor = it; refresh() },
- configs = {
- allowCustom = false
- })
- colorPicker(title = R.string.background_color,
- getter = { KPrefSample.bgColor }, setter = { KPrefSample.bgColor = it; bgCanvas.ripple(it, duration = 500) },
- configs = {
- allowCustomAlpha = true
- allowCustom = true
- })
- }
- }
-
- fun refresh() {
- adapter.notifyAdapterDataSetChanged()
+ val darkAccent = KPrefSample.accentColor.darken()
+ toolbarCanvas.set(darkAccent)
+ this.navigationBarColor = darkAccent
}
override fun onCreateOptionsMenu(menu: Menu): Boolean {