From 149c6be1bfd4bd84381757940fece1be7b9801aa Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Mon, 31 Dec 2018 18:57:28 -0500 Subject: Enhancement/coroutines (#1273) * Convert rest of fbcookie to suspended methods * Replace active checks with yield * Apply spotless * Switch cookie domain to exact url * Optimize imports and enable travis tests again * Update proguard rules * Remove unnecessary yield * Remove unused flyweight * Remove unused disposable and method * Use contexthelper instead of dispatcher main * Convert login activity to coroutines * Use kau helper methods for coroutines * Enhancement/offline site (#1288) * Begin conversion of offline site logic * Fix offline tests and add validation tests * Ignore cookie in jsoup if it is blank * Force load and zip to be in io * Use different zip files to fix tests * Log all test output * Do not log stdout * Allow test skip for fb offline --- .../pitchedapps/frost/views/FrostContentView.kt | 27 ++++++++-------------- .../pitchedapps/frost/views/FrostRecyclerView.kt | 2 ++ 2 files changed, 12 insertions(+), 17 deletions(-) (limited to 'app/src/main/kotlin/com/pitchedapps/frost/views') diff --git a/app/src/main/kotlin/com/pitchedapps/frost/views/FrostContentView.kt b/app/src/main/kotlin/com/pitchedapps/frost/views/FrostContentView.kt index 9619eecc..72d8803c 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/views/FrostContentView.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/views/FrostContentView.kt @@ -29,6 +29,7 @@ import ca.allanwang.kau.utils.fadeIn import ca.allanwang.kau.utils.fadeOut import ca.allanwang.kau.utils.invisibleIf import ca.allanwang.kau.utils.isVisible +import ca.allanwang.kau.utils.launchMain import ca.allanwang.kau.utils.tint import ca.allanwang.kau.utils.withAlpha import com.pitchedapps.frost.R @@ -39,14 +40,11 @@ import com.pitchedapps.frost.facebook.FbItem import com.pitchedapps.frost.facebook.WEB_LOAD_DELAY import com.pitchedapps.frost.utils.L import com.pitchedapps.frost.utils.Prefs -import io.reactivex.disposables.Disposable import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.channels.BroadcastChannel import kotlinx.coroutines.channels.ReceiveChannel import kotlinx.coroutines.launch -import kotlinx.coroutines.withContext class FrostContentWeb @JvmOverloads constructor( context: Context, @@ -128,24 +126,20 @@ abstract class FrostContentView @JvmOverloads constructor( val refreshReceiver = refreshChannel.openSubscription() val progressReceiver = progressChannel.openSubscription() - scope.launch(Dispatchers.Default) { + scope.launchMain { launch { for (r in refreshReceiver) { - withContext(Dispatchers.Main) { - refresh.isRefreshing = r - refresh.isEnabled = true - } + refresh.isRefreshing = r + refresh.isEnabled = true } } launch { for (p in progressReceiver) { - withContext(Dispatchers.Main) { - progress.invisibleIf(p == 100) - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) - progress.setProgress(p, true) - else - progress.progress = p - } + progress.invisibleIf(p == 100) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) + progress.setProgress(p, true) + else + progress.progress = p } } } @@ -177,7 +171,6 @@ abstract class FrostContentView @JvmOverloads constructor( core.destroy() } - private var dispose: Disposable? = null private var transitionStart: Long = -1 private var refreshReceiver: ReceiveChannel? = null @@ -194,7 +187,7 @@ abstract class FrostContentView @JvmOverloads constructor( L.v { "Registered transition" } with(coreView) { refreshReceiver = refreshChannel.openSubscription().also { receiver -> - scope.launch(Dispatchers.Main) { + scope.launchMain { var loading = false for (r in receiver) { if (r) { diff --git a/app/src/main/kotlin/com/pitchedapps/frost/views/FrostRecyclerView.kt b/app/src/main/kotlin/com/pitchedapps/frost/views/FrostRecyclerView.kt index f7cb2214..860bf36c 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/views/FrostRecyclerView.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/views/FrostRecyclerView.kt @@ -28,12 +28,14 @@ import com.pitchedapps.frost.contracts.FrostContentCore import com.pitchedapps.frost.contracts.FrostContentParent import com.pitchedapps.frost.fragments.RecyclerContentContract import com.pitchedapps.frost.utils.Prefs +import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.launch /** * Created by Allan Wang on 2017-05-29. * */ +@UseExperimental(ExperimentalCoroutinesApi::class) class FrostRecyclerView @JvmOverloads constructor( context: Context, attrs: AttributeSet? = null, -- cgit v1.2.3