diff options
author | Allan Wang <me@allanwang.ca> | 2019-02-06 12:12:10 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-02-06 12:12:10 -0500 |
commit | 91b7d53fb37b9939943c16b0bfd7a947d9f2363e (patch) | |
tree | 01d8feffb8e467bb19bc405c91e0cd4f66f8fe06 /app/src/main/kotlin/com/pitchedapps/frost/views/FrostContentView.kt | |
parent | a75555f3464607b93d523478999b9c8a7dc224a0 (diff) | |
download | frost-91b7d53fb37b9939943c16b0bfd7a947d9f2363e.tar.gz frost-91b7d53fb37b9939943c16b0bfd7a947d9f2363e.tar.bz2 frost-91b7d53fb37b9939943c16b0bfd7a947d9f2363e.zip |
Fix/open broadcast (#1345)
* Convert jsi related channels to broadcasts
* Close channel in debug activity
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/views/FrostContentView.kt')
-rw-r--r-- | app/src/main/kotlin/com/pitchedapps/frost/views/FrostContentView.kt | 38 |
1 files changed, 14 insertions, 24 deletions
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 575e5a4d..baf9421f 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/views/FrostContentView.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/views/FrostContentView.kt @@ -23,6 +23,7 @@ import android.view.View import android.widget.FrameLayout import android.widget.ProgressBar import androidx.swiperefreshlayout.widget.SwipeRefreshLayout +import ca.allanwang.kau.utils.ContextHelper import ca.allanwang.kau.utils.bindView import ca.allanwang.kau.utils.circularReveal import ca.allanwang.kau.utils.fadeIn @@ -38,6 +39,7 @@ import com.pitchedapps.frost.contracts.FrostContentCore import com.pitchedapps.frost.contracts.FrostContentParent import com.pitchedapps.frost.facebook.FbItem import com.pitchedapps.frost.facebook.WEB_LOAD_DELAY +import com.pitchedapps.frost.kotlin.subscribeDuringJob import com.pitchedapps.frost.utils.L import com.pitchedapps.frost.utils.Prefs import kotlinx.coroutines.CoroutineScope @@ -45,7 +47,6 @@ import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.channels.BroadcastChannel import kotlinx.coroutines.channels.ConflatedBroadcastChannel import kotlinx.coroutines.channels.ReceiveChannel -import kotlinx.coroutines.launch class FrostContentWeb @JvmOverloads constructor( context: Context, @@ -127,26 +128,18 @@ abstract class FrostContentView<out T> @JvmOverloads constructor( reload(true) } } - // Begin subscription in the main thread - val refreshReceiver = refreshChannel.openSubscription() - val progressReceiver = progressChannel.openSubscription() - - scope.launchMain { - launch { - for (r in refreshReceiver) { - refresh.isRefreshing = r - refresh.isEnabled = true - } - } - launch { - for (p in progressReceiver) { - progress.invisibleIf(p == 100) - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) - progress.setProgress(p, true) - else - progress.progress = p - } - } + + refreshChannel.subscribeDuringJob(scope, ContextHelper.coroutineContext) { r -> + refresh.isRefreshing = r + refresh.isEnabled = true + } + + progressChannel.subscribeDuringJob(scope, ContextHelper.coroutineContext) { p -> + progress.invisibleIf(p == 100) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) + progress.setProgress(p, true) + else + progress.progress = p } } @@ -170,9 +163,6 @@ abstract class FrostContentView<out T> @JvmOverloads constructor( } override fun destroy() { - titleChannel.close() - progressChannel.close() - refreshChannel.close() core.destroy() } |