aboutsummaryrefslogtreecommitdiff
path: root/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/KPrefActivity.kt
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2017-08-12 19:31:55 -0700
committerAllan Wang <me@allanwang.ca>2017-08-30 12:24:19 -0400
commitfba4ac38a8e2dff6e53ba8ecccc95dac2550a3fa (patch)
tree7747f8f1c396cbe397f0e471ee7204e8106ac30a /kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/KPrefActivity.kt
parent27f38ffe00bc27b76020072a591ce63d20ddd86a (diff)
downloadkau-fba4ac38a8e2dff6e53ba8ecccc95dac2550a3fa.tar.gz
kau-fba4ac38a8e2dff6e53ba8ecccc95dac2550a3fa.tar.bz2
kau-fba4ac38a8e2dff6e53ba8ecccc95dac2550a3fa.zip
Feature/kpref activity visibility (#38)
* Add visibility toggle * Update docs
Diffstat (limited to 'kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/KPrefActivity.kt')
-rw-r--r--kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/KPrefActivity.kt37
1 files changed, 34 insertions, 3 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 900b004..4377631 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
@@ -85,26 +85,57 @@ abstract class KPrefActivity : KauBaseActivity(), KPrefActivityContract {
recycler.itemAnimator = if (animate && !first) recyclerAnimatorNext else null
uiThread {
adapter.clear()
- adapter.add(items.list)
+ adapter.add(items.list.filter { it.core.visible() })
toolbar.setTitle(toolbarTitleRes)
}
}
}
+ /**
+ * Pops the stack and loads the next kpref list
+ * Indices are not checked so ensure that this is possible first
+ */
override fun showPrevPrefs() {
kprefStack.pop()
val (title, list) = kprefStack.peek()
recycler.itemAnimator = if (animate) recyclerAnimatorPrev else null
adapter.clear()
- adapter.add(list)
+ adapter.add(list.filter { it.core.visible() })
toolbar.setTitle(title)
}
+ /**
+ * Check if it's possible to go back a stack
+ */
+ override val hasPrevPrefs
+ get() = kprefStack.size > 1
+
+ /**
+ * Reload the current pref list from the stack.
+ * This will adjust the list of items change in visibility
+ */
+ fun reloadList() {
+ recycler.itemAnimator = null
+ val list = kprefStack.peek().second
+ adapter.setNewList(list.filter { it.core.visible() })
+ }
+
+ /**
+ * Selectively reload an item based on its index.
+ * Note that this might not behave as expected if certain items are not visible,
+ * as those items aren't sent to the adapter.
+ *
+ * For those cases, consider using [reloadByTitle]
+ */
fun reload(vararg index: Int) {
if (index.isEmpty()) adapter.notifyAdapterDataSetChanged()
else index.forEach { adapter.notifyItemChanged(it) }
}
+ /**
+ * Iterate through all items and reload if it matches any of the titles
+ * If multiple items have the same title, they will all be reloaded
+ */
override fun reloadByTitle(@StringRes vararg title: Int) {
if (title.isEmpty()) return
adapter.adapterItems.forEachIndexed { index, item ->
@@ -120,7 +151,7 @@ abstract class KPrefActivity : KauBaseActivity(), KPrefActivityContract {
}
fun backPress(): Boolean {
- if (kprefStack.size > 1) {
+ if (hasPrevPrefs) {
showPrevPrefs()
return true
}