aboutsummaryrefslogtreecommitdiff
path: root/kpref-activity/src
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2017-08-07 22:20:57 -0700
committerGitHub <noreply@github.com>2017-08-07 22:20:57 -0700
commit02e1dbc84425b0ac7f771c82f70444f742397452 (patch)
tree05e978e7588e30ce653428671f3d9f5df5397385 /kpref-activity/src
parent187d8e64dc7189f63707d154166867084662dbe3 (diff)
downloadkau-02e1dbc84425b0ac7f771c82f70444f742397452.tar.gz
kau-02e1dbc84425b0ac7f771c82f70444f742397452.tar.bz2
kau-02e1dbc84425b0ac7f771c82f70444f742397452.zip
Release 3.3.0 (#32)3.3.0
* Rewrite Logger (#29) * Remove dependency on timber * Update logger * Reorder throwabl * Fix lint * Update readme * Blank target * Create Zip (#30) * Finish zips with tests * Finalize * Update changelog * Add log hooks * Open most logging functions * Remap kpref items (#31) * Update readme * Generate files and prepare release * Kpref -
Diffstat (limited to 'kpref-activity/src')
-rw-r--r--kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/KPrefActivity.kt98
-rw-r--r--kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/KPrefBinder.kt29
-rw-r--r--kpref-activity/src/main/res/layout/kau_pref_activity.xml16
3 files changed, 51 insertions, 92 deletions
diff --git a/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/KPrefActivity.kt b/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/KPrefActivity.kt
index 3e1596f..900b004 100644
--- a/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/KPrefActivity.kt
+++ b/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/KPrefActivity.kt
@@ -3,49 +3,43 @@ package ca.allanwang.kau.kpref.activity
import android.annotation.SuppressLint
import android.os.Bundle
import android.support.annotation.StringRes
-import android.support.constraint.ConstraintLayout
-import android.support.v7.app.AppCompatActivity
import android.support.v7.widget.RecyclerView
import android.support.v7.widget.Toolbar
import android.view.View
-import android.view.animation.Animation
-import android.view.animation.AnimationUtils
-import android.widget.FrameLayout
-import android.widget.ViewAnimator
+import ca.allanwang.kau.animators.KauAnimator
+import ca.allanwang.kau.animators.SlideAnimatorAdd
+import ca.allanwang.kau.animators.SlideAnimatorRemove
import ca.allanwang.kau.internal.KauBaseActivity
import ca.allanwang.kau.kpref.activity.items.KPrefItemCore
import ca.allanwang.kau.ui.views.RippleCanvas
-import ca.allanwang.kau.ui.widgets.TextSlider
-import ca.allanwang.kau.utils.bindView
-import ca.allanwang.kau.utils.resolveColor
-import ca.allanwang.kau.utils.statusBarColor
-import ca.allanwang.kau.utils.string
+import ca.allanwang.kau.utils.*
import com.mikepenz.fastadapter.commons.adapters.FastItemAdapter
+import org.jetbrains.anko.doAsync
+import org.jetbrains.anko.uiThread
+import java.util.*
abstract class KPrefActivity : KauBaseActivity(), KPrefActivityContract {
- val adapter: FastItemAdapter<KPrefItemCore>
- @Suppress("UNCHECKED_CAST")
- get() = recycler.adapter as FastItemAdapter<KPrefItemCore>
- val recycler: RecyclerView
- get() = prefHolder.currentView as RecyclerView
- val container: ConstraintLayout by bindView(R.id.kau_container)
+ private val adapter: FastItemAdapter<KPrefItemCore> = FastItemAdapter()
+ private val recycler: RecyclerView by bindView(R.id.kau_recycler)
val bgCanvas: RippleCanvas by bindView(R.id.kau_ripple)
val toolbarCanvas: RippleCanvas by bindView(R.id.kau_toolbar_ripple)
val toolbar: Toolbar by bindView(R.id.kau_toolbar)
- val toolbarTitle: TextSlider by bindView(R.id.kau_toolbar_text)
- val prefHolder: ViewAnimator by bindView(R.id.kau_holder)
private lateinit var globalOptions: GlobalOptions
+ private val kprefStack = Stack<Pair<Int, List<KPrefItemCore>>>()
+ /**
+ * Toggle sliding animations for the kpref items
+ */
var animate: Boolean = true
- set(value) {
- field = value
- toolbarTitle.animationType = if (value) TextSlider.ANIMATION_SLIDE_HORIZONTAL else TextSlider.ANIMATION_NONE
- }
- private val SLIDE_IN_LEFT_ITEMS: Animation by lazy { AnimationUtils.loadAnimation(this, R.anim.kau_slide_in_left) }
- private val SLIDE_IN_RIGHT_ITEMS: Animation by lazy { AnimationUtils.loadAnimation(this, R.anim.kau_slide_in_right) }
- private val SLIDE_OUT_LEFT_ITEMS: Animation by lazy { AnimationUtils.loadAnimation(this, R.anim.kau_slide_out_left) }
- private val SLIDE_OUT_RIGHT_ITEMS: Animation by lazy { AnimationUtils.loadAnimation(this, R.anim.kau_slide_out_right) }
+ private val recyclerAnimatorNext: KauAnimator by lazy {
+ KauAnimator(SlideAnimatorAdd(KAU_RIGHT, itemDelayFactor = 0f),
+ SlideAnimatorRemove(KAU_LEFT, itemDelayFactor = 0f))
+ }
+ private val recyclerAnimatorPrev: KauAnimator by lazy {
+ KauAnimator(SlideAnimatorAdd(KAU_LEFT, itemDelayFactor = 0f),
+ SlideAnimatorRemove(KAU_RIGHT, itemDelayFactor = 0f))
+ }
/**
* Core attribute builder that is consistent throughout all items
@@ -69,43 +63,41 @@ abstract class KPrefActivity : KauBaseActivity(), KPrefActivityContract {
statusBarColor = 0x30000000
toolbarCanvas.set(resolveColor(R.attr.colorPrimary))
bgCanvas.set(resolveColor(android.R.attr.colorBackground))
- prefHolder.animateFirstView = false
//setup prefs
val core = CoreAttributeBuilder()
val builder = kPrefCoreAttributes()
core.builder()
globalOptions = GlobalOptions(core, this)
- showNextPrefs(R.string.kau_settings, onCreateKPrefs(savedInstanceState))
+ recycler.withLinearAdapter(adapter)
+ adapter.withSelectable(false)
+ .withOnClickListener { v, _, item, _ -> item.onClick(v, v.findViewById(R.id.kau_pref_inner_content)) }
+ showNextPrefs(R.string.kau_settings, onCreateKPrefs(savedInstanceState), true)
}
- override fun onPostCreate(savedInstanceState: Bundle?) {
- super.onPostCreate(savedInstanceState)
- }
+ override fun showNextPrefs(@StringRes toolbarTitleRes: Int, builder: KPrefAdapterBuilder.() -> Unit)
+ = showNextPrefs(toolbarTitleRes, builder, false)
- override fun showNextPrefs(@StringRes toolbarTitleRes: Int, builder: KPrefAdapterBuilder.() -> Unit) {
- val rv = RecyclerView(this).apply {
- layoutParams = FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT)
- setKPrefAdapter(globalOptions, builder)
+ private fun showNextPrefs(@StringRes toolbarTitleRes: Int, builder: KPrefAdapterBuilder.() -> Unit, first: Boolean) {
+ doAsync {
+ val items = KPrefAdapterBuilder(globalOptions)
+ builder(items)
+ kprefStack.push(toolbarTitleRes to items.list)
+ recycler.itemAnimator = if (animate && !first) recyclerAnimatorNext else null
+ uiThread {
+ adapter.clear()
+ adapter.add(items.list)
+ toolbar.setTitle(toolbarTitleRes)
+ }
}
- with(prefHolder) {
- inAnimation = if (animate) SLIDE_IN_RIGHT_ITEMS else null
- outAnimation = if (animate) SLIDE_OUT_LEFT_ITEMS else null
- addView(rv)
- showNext()
- }
- toolbarTitle.setNextText(string(toolbarTitleRes))
}
override fun showPrevPrefs() {
- val current = prefHolder.currentView
- with(prefHolder) {
- inAnimation = if (animate) SLIDE_IN_LEFT_ITEMS else null
- outAnimation = if (animate) SLIDE_OUT_RIGHT_ITEMS else null
- showPrevious()
- removeView(current)
- adapter.notifyAdapterDataSetChanged()
- }
- toolbarTitle.setPrevText()
+ kprefStack.pop()
+ val (title, list) = kprefStack.peek()
+ recycler.itemAnimator = if (animate) recyclerAnimatorPrev else null
+ adapter.clear()
+ adapter.add(list)
+ toolbar.setTitle(title)
}
fun reload(vararg index: Int) {
@@ -128,7 +120,7 @@ abstract class KPrefActivity : KauBaseActivity(), KPrefActivityContract {
}
fun backPress(): Boolean {
- if (!toolbarTitle.isRoot) {
+ if (kprefStack.size > 1) {
showPrevPrefs()
return true
}
diff --git a/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/KPrefBinder.kt b/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/KPrefBinder.kt
index 6048c1a..b45e406 100644
--- a/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/KPrefBinder.kt
+++ b/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/KPrefBinder.kt
@@ -1,39 +1,13 @@
package ca.allanwang.kau.kpref.activity
import android.support.annotation.StringRes
-import android.support.v7.widget.LinearLayoutManager
-import android.support.v7.widget.RecyclerView
-import ca.allanwang.kau.R
import ca.allanwang.kau.kpref.activity.items.*
-import com.mikepenz.fastadapter.commons.adapters.FastItemAdapter
-import org.jetbrains.anko.doAsync
-import org.jetbrains.anko.uiThread
/**
* Created by Allan Wang on 2017-06-08.
*
* Houses all the components that can be called externally to setup the kpref mainAdapter
*/
-
-/**
- * Base extension that will register the layout manager and mainAdapter with the given items
- * Returns FastAdapter
- */
-fun RecyclerView.setKPrefAdapter(globalOptions: GlobalOptions, builder: KPrefAdapterBuilder.() -> Unit): FastItemAdapter<KPrefItemCore> {
- layoutManager = LinearLayoutManager(context)
- val adapter = FastItemAdapter<KPrefItemCore>()
- adapter.withOnClickListener { v, _, item, _ -> item.onClick(v, v.findViewById(R.id.kau_pref_inner_content)) }
- this.adapter = adapter
- doAsync {
- val items = KPrefAdapterBuilder(globalOptions)
- builder.invoke(items)
- uiThread {
- adapter.add(items.list)
- }
- }
- return adapter
-}
-
@DslMarker
annotation class KPrefMarker
@@ -70,6 +44,9 @@ class GlobalOptions(core: CoreAttributeContract, activity: KPrefActivityContract
* Contains DSLs for every possible item
* The arguments are all the mandatory values plus an optional builder housing all the possible configurations
* The mandatory values are final so they cannot be edited in the builder
+ *
+ * This function will be called asynchronously, so don't worry about blocking the thread
+ * The recycler will only animate once this is completed though
*/
@KPrefMarker
class KPrefAdapterBuilder(val globalOptions: GlobalOptions) {
diff --git a/kpref-activity/src/main/res/layout/kau_pref_activity.xml b/kpref-activity/src/main/res/layout/kau_pref_activity.xml
index 19320b8..7651e5a 100644
--- a/kpref-activity/src/main/res/layout/kau_pref_activity.xml
+++ b/kpref-activity/src/main/res/layout/kau_pref_activity.xml
@@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
- android:id="@+id/kau_container"
android:layout_width="match_parent"
android:layout_height="match_parent">
@@ -22,16 +21,7 @@
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
- app:layout_constraintTop_toTopOf="parent">
-
- <ca.allanwang.kau.ui.widgets.TextSlider
- android:id="@+id/kau_toolbar_text"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:gravity="center"
- app:animation_type="slide_horizontal" />
-
- </android.support.v7.widget.Toolbar>
+ app:layout_constraintTop_toTopOf="parent" />
<ca.allanwang.kau.ui.views.RippleCanvas
android:id="@+id/kau_ripple"
@@ -42,8 +32,8 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/kau_toolbar" />
- <ViewAnimator
- android:id="@+id/kau_holder"
+ <android.support.v7.widget.RecyclerView
+ android:id="@+id/kau_recycler"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"