aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2018-12-25 21:45:26 -0500
committerAllan Wang <me@allanwang.ca>2018-12-25 21:45:26 -0500
commitf931e55d534e6162748f9fa888e7313cc2f0b619 (patch)
tree34ee7c82f49420d83ee44d77cace56cd8fbd3582
parentd850474b0a82ee00d094990d9bd3392ae8cd9575 (diff)
downloadkau-f931e55d534e6162748f9fa888e7313cc2f0b619.tar.gz
kau-f931e55d534e6162748f9fa888e7313cc2f0b619.tar.bz2
kau-f931e55d534e6162748f9fa888e7313cc2f0b619.zip
Use withContext instead of async
-rw-r--r--about/src/main/kotlin/ca/allanwang/kau/about/AboutPanelDelegate.kt13
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/internal/KauBaseActivity.kt2
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/logging/KL.kt8
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/utils/BundleUtils.kt2
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt3
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/xml/Changelog.kt5
-rw-r--r--kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/KPrefActivity.kt7
7 files changed, 24 insertions, 16 deletions
diff --git a/about/src/main/kotlin/ca/allanwang/kau/about/AboutPanelDelegate.kt b/about/src/main/kotlin/ca/allanwang/kau/about/AboutPanelDelegate.kt
index f77bcf2..924a771 100644
--- a/about/src/main/kotlin/ca/allanwang/kau/about/AboutPanelDelegate.kt
+++ b/about/src/main/kotlin/ca/allanwang/kau/about/AboutPanelDelegate.kt
@@ -36,8 +36,8 @@ import ca.allanwang.kau.xml.kauParseFaq
import com.mikepenz.aboutlibraries.Libs
import com.mikepenz.fastadapter.IItem
import kotlinx.coroutines.Dispatchers
-import kotlinx.coroutines.async
import kotlinx.coroutines.launch
+import kotlinx.coroutines.withContext
/**
* Created by Allan Wang on 2017-08-02.
@@ -177,12 +177,12 @@ open class AboutPanelLibs : AboutPanelRecycler() {
override fun loadItems(activity: AboutActivityBase, position: Int) {
with(activity) {
launch {
- items = async {
+ items = withContext(Dispatchers.Default) {
getLibraries(
if (rClass == null) Libs(activity)
else Libs(activity, Libs.toStringArray(rClass.fields))
).map(::LibraryIItem)
- }.await()
+ }
if (pageStatus[position] == 1)
addItems(activity, position)
}
@@ -207,7 +207,12 @@ open class AboutPanelFaqs : AboutPanelRecycler() {
override fun loadItems(activity: AboutActivityBase, position: Int) {
with(activity) {
launch {
- items = async { kauParseFaq(configs.faqXmlRes, configs.faqParseNewLine) }.await().map(::FaqIItem)
+ items = withContext(Dispatchers.IO) {
+ kauParseFaq(
+ configs.faqXmlRes,
+ configs.faqParseNewLine
+ )
+ }.map(::FaqIItem)
if (pageStatus[position] == 1)
addItems(activity, position)
}
diff --git a/core/src/main/kotlin/ca/allanwang/kau/internal/KauBaseActivity.kt b/core/src/main/kotlin/ca/allanwang/kau/internal/KauBaseActivity.kt
index bf977f2..e192ff2 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/internal/KauBaseActivity.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/internal/KauBaseActivity.kt
@@ -59,4 +59,4 @@ abstract class KauBaseActivity : AppCompatActivity(), CoroutineScope {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
kauOnRequestPermissionsResult(permissions, grantResults)
}
-} \ No newline at end of file
+}
diff --git a/core/src/main/kotlin/ca/allanwang/kau/logging/KL.kt b/core/src/main/kotlin/ca/allanwang/kau/logging/KL.kt
index 52e5415..9fbc070 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/logging/KL.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/logging/KL.kt
@@ -23,8 +23,12 @@ import ca.allanwang.kau.BuildConfig
* Internal KAU logger
*/
object KL : KauLogger("KAU", { BuildConfig.DEBUG }) {
- internal inline fun test(message: () -> Any?) {
+
+ /**
+ * Logger with searchable tag and thread info
+ */
+ inline fun test(message: () -> Any?) {
if (BuildConfig.DEBUG)
- d { "Test1234 ${message()}" }
+ d { "Test1234 ${Thread.currentThread().name} ${message()}" }
}
}
diff --git a/core/src/main/kotlin/ca/allanwang/kau/utils/BundleUtils.kt b/core/src/main/kotlin/ca/allanwang/kau/utils/BundleUtils.kt
index 8dcd856..40c1c72 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/utils/BundleUtils.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/utils/BundleUtils.kt
@@ -23,8 +23,6 @@ import android.os.Bundle
import android.os.Parcelable
import android.util.Pair
import android.view.View
-import android.widget.ImageView
-import android.widget.TextView
import androidx.annotation.AnimRes
import ca.allanwang.kau.R
import java.io.Serializable
diff --git a/core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt b/core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt
index 60ef236..6867b49 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt
@@ -49,13 +49,12 @@ import ca.allanwang.kau.logging.KL
import com.afollestad.materialdialogs.MaterialDialog
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
-import kotlinx.coroutines.GlobalScope
import kotlin.coroutines.CoroutineContext
/**
* Created by Allan Wang on 2017-06-03.
*/
-private object ContextHelper: CoroutineScope {
+private object ContextHelper : CoroutineScope {
val handler = Handler(Looper.getMainLooper())
diff --git a/core/src/main/kotlin/ca/allanwang/kau/xml/Changelog.kt b/core/src/main/kotlin/ca/allanwang/kau/xml/Changelog.kt
index 51e63f9..22e8e76 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/xml/Changelog.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/xml/Changelog.kt
@@ -30,8 +30,9 @@ import ca.allanwang.kau.utils.ctxCoroutine
import ca.allanwang.kau.utils.materialDialog
import ca.allanwang.kau.utils.use
import com.afollestad.materialdialogs.MaterialDialog
-import kotlinx.coroutines.async
+import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
+import kotlinx.coroutines.withContext
import org.xmlpull.v1.XmlPullParser
/**
@@ -41,7 +42,7 @@ import org.xmlpull.v1.XmlPullParser
*/
fun Context.showChangelog(@XmlRes xmlRes: Int, @ColorInt textColor: Int? = null, customize: MaterialDialog.Builder.() -> Unit = {}) {
ctxCoroutine.launch {
- val items = async { parse(this@showChangelog, xmlRes) }.await()
+ val items = withContext(Dispatchers.Default) { parse(this@showChangelog, xmlRes) }
materialDialog {
title(R.string.kau_changelog)
positiveText(R.string.kau_great)
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 450bc6e..edaf347 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,9 @@ 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 kotlinx.coroutines.async
+import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
+import kotlinx.coroutines.withContext
import java.util.Stack
abstract class KPrefActivity : KauBaseActivity(), KPrefActivityContract {
@@ -105,12 +106,12 @@ abstract class KPrefActivity : KauBaseActivity(), KPrefActivityContract {
first: Boolean
) {
launch {
- val items = async {
+ val items = withContext(Dispatchers.Default) {
val items = KPrefAdapterBuilder(globalOptions)
builder(items)
kprefStack.push(toolbarTitleRes to items.list)
items.list
- }.await()
+ }
kau_recycler.itemAnimator = if (animate && !first) recyclerAnimatorNext else null
show(toolbarTitleRes, items)
}