aboutsummaryrefslogtreecommitdiff
path: root/kpref-activity/src/main/kotlin/ca
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2018-12-24 20:05:06 -0500
committerGitHub <noreply@github.com>2018-12-24 20:05:06 -0500
commit8447b1ae8ce89b3f1bbe79dbae8847d901831c12 (patch)
treece516950e452581766e905ead32970d891bb46f6 /kpref-activity/src/main/kotlin/ca
parent701b94ab09ff53aca682fac6c4ef5364566339be (diff)
downloadkau-8447b1ae8ce89b3f1bbe79dbae8847d901831c12.tar.gz
kau-8447b1ae8ce89b3f1bbe79dbae8847d901831c12.tar.bz2
kau-8447b1ae8ce89b3f1bbe79dbae8847d901831c12.zip
Enhancement/coroutines (#180)
* Add coroutine dependency * Add coroutines to kprefactivity * Change base job to supervisor * Update coroutines for faq * Update changelog * Use preloading in media picker core * Make test logging internal * Remove anko
Diffstat (limited to 'kpref-activity/src/main/kotlin/ca')
-rw-r--r--kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/KPrefActivity.kt31
1 files changed, 17 insertions, 14 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 02b6e98..450bc6e 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
@@ -33,8 +33,8 @@ import ca.allanwang.kau.utils.statusBarColor
import ca.allanwang.kau.utils.withLinearAdapter
import com.mikepenz.fastadapter.commons.adapters.FastItemAdapter
import kotlinx.android.synthetic.main.kau_pref_activity.*
-import org.jetbrains.anko.doAsync
-import org.jetbrains.anko.uiThread
+import kotlinx.coroutines.async
+import kotlinx.coroutines.launch
import java.util.Stack
abstract class KPrefActivity : KauBaseActivity(), KPrefActivityContract {
@@ -104,19 +104,24 @@ abstract class KPrefActivity : KauBaseActivity(), KPrefActivityContract {
builder: KPrefAdapterBuilder.() -> Unit,
first: Boolean
) {
- doAsync {
- val items = KPrefAdapterBuilder(globalOptions)
- builder(items)
- kprefStack.push(toolbarTitleRes to items.list)
+ launch {
+ val items = async {
+ val items = KPrefAdapterBuilder(globalOptions)
+ builder(items)
+ kprefStack.push(toolbarTitleRes to items.list)
+ items.list
+ }.await()
kau_recycler.itemAnimator = if (animate && !first) recyclerAnimatorNext else null
- uiThread {
- adapter.clear()
- adapter.add(items.list.filter { it.core.visible() })
- toolbar.setTitle(toolbarTitleRes)
- }
+ show(toolbarTitleRes, items)
}
}
+ private fun show(@StringRes toolbarTitleRes: Int, items: List<KPrefItemCore>) {
+ toolbar.setTitle(toolbarTitleRes)
+ adapter.clear()
+ adapter.add(items.filter { it.core.visible() })
+ }
+
/**
* Pops the stack and loads the next kpref list
* Indices are not checked so ensure that this is possible first
@@ -125,9 +130,7 @@ abstract class KPrefActivity : KauBaseActivity(), KPrefActivityContract {
kprefStack.pop()
val (title, list) = kprefStack.peek()
kau_recycler.itemAnimator = if (animate) recyclerAnimatorPrev else null
- adapter.clear()
- adapter.add(list.filter { it.core.visible() })
- toolbar.setTitle(title)
+ show(title, list)
}
/**