[Android] Comsume Flows when started

Geoffrey Métais git at videolan.org
Fri Feb 21 14:34:19 CET 2020


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Wed Feb 19 15:24:52 2020 +0100| [d650c5d94b6c0fecd55db638c194f9e40f11375f] | committer: Geoffrey Métais

Comsume Flows when started

> https://code.videolan.org/videolan/vlc-android/commit/d650c5d94b6c0fecd55db638c194f9e40f11375f
---

 .../src/main/java/org/videolan/television/ui/MoviepediaTvFragment.kt  | 2 +-
 .../vlc-android/src/org/videolan/vlc/gui/dialogs/PickTimeFragment.kt  | 4 ++--
 .../src/org/videolan/vlc/gui/dialogs/PlaybackSpeedDialog.kt           | 4 ++--
 .../src/org/videolan/vlc/gui/dialogs/SelectChapterDialog.kt           | 3 ++-
 4 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/application/television/src/main/java/org/videolan/television/ui/MoviepediaTvFragment.kt b/application/television/src/main/java/org/videolan/television/ui/MoviepediaTvFragment.kt
index 63f705f01..98edc95a0 100644
--- a/application/television/src/main/java/org/videolan/television/ui/MoviepediaTvFragment.kt
+++ b/application/television/src/main/java/org/videolan/television/ui/MoviepediaTvFragment.kt
@@ -122,7 +122,7 @@ class MoviepediaTvFragment : SearchSupportFragment(), SearchSupportFragment.Sear
         viewModel.exceptionLiveData.observe(this, Observer { e ->
             e?.let {
                 requireActivity().manageHttpException(it)
-                lifecycleScope.launch {
+                lifecycleScope.launchWhenStarted {
                     NetworkMonitor.getInstance(requireContext()).connectionFlow.first { it.connected }
                     refresh()
                 }
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/dialogs/PickTimeFragment.kt b/application/vlc-android/src/org/videolan/vlc/gui/dialogs/PickTimeFragment.kt
index a7874536c..38b0131dc 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/dialogs/PickTimeFragment.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/dialogs/PickTimeFragment.kt
@@ -33,10 +33,10 @@ import com.google.android.material.bottomsheet.BottomSheetBehavior.STATE_EXPANDE
 import kotlinx.coroutines.ExperimentalCoroutinesApi
 import kotlinx.coroutines.ObsoleteCoroutinesApi
 import kotlinx.coroutines.flow.filterNotNull
-import kotlinx.coroutines.flow.launchIn
 import kotlinx.coroutines.flow.onEach
 import org.videolan.vlc.PlaybackService
 import org.videolan.vlc.R
+import org.videolan.vlc.util.launchWhenStarted
 
 @ObsoleteCoroutinesApi
 @ExperimentalCoroutinesApi
@@ -115,7 +115,7 @@ abstract class PickTimeFragment : VLCBottomSheetDialogFragment(), View.OnClickLi
     }
 
     override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
-        PlaybackService.serviceFlow.filterNotNull().onEach { playbackService = it }.launchIn(lifecycleScope)
+        PlaybackService.serviceFlow.filterNotNull().onEach { playbackService = it }.launchWhenStarted(lifecycleScope)
         super.onViewCreated(view, savedInstanceState)
     }
 
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/dialogs/PlaybackSpeedDialog.kt b/application/vlc-android/src/org/videolan/vlc/gui/dialogs/PlaybackSpeedDialog.kt
index 3cec0737d..a880bf56e 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/dialogs/PlaybackSpeedDialog.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/dialogs/PlaybackSpeedDialog.kt
@@ -33,12 +33,12 @@ import androidx.core.content.ContextCompat
 import androidx.lifecycle.lifecycleScope
 import kotlinx.coroutines.ExperimentalCoroutinesApi
 import kotlinx.coroutines.ObsoleteCoroutinesApi
-import kotlinx.coroutines.flow.launchIn
 import kotlinx.coroutines.flow.onEach
 import org.videolan.tools.formatRateString
 import org.videolan.vlc.PlaybackService
 import org.videolan.vlc.R
 import org.videolan.vlc.gui.helpers.OnRepeatListener
+import org.videolan.vlc.util.launchWhenStarted
 
 @ObsoleteCoroutinesApi
 @ExperimentalCoroutinesApi
@@ -118,7 +118,7 @@ class PlaybackSpeedDialog : VLCBottomSheetDialogFragment() {
 
     override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
         super.onViewCreated(view, savedInstanceState)
-        PlaybackService.serviceFlow.onEach { onServiceChanged(it) }.launchIn(lifecycleScope)
+        PlaybackService.serviceFlow.onEach { onServiceChanged(it) }.launchWhenStarted(lifecycleScope)
     }
 
     private fun setRateProgress() {
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/dialogs/SelectChapterDialog.kt b/application/vlc-android/src/org/videolan/vlc/gui/dialogs/SelectChapterDialog.kt
index 96f0b162a..dafe83820 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/dialogs/SelectChapterDialog.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/dialogs/SelectChapterDialog.kt
@@ -38,6 +38,7 @@ import org.videolan.medialibrary.Tools
 import org.videolan.vlc.PlaybackService
 import org.videolan.vlc.R
 import org.videolan.vlc.databinding.ChapterListItemBinding
+import org.videolan.vlc.util.launchWhenStarted
 import java.util.*
 
 @ObsoleteCoroutinesApi
@@ -68,7 +69,7 @@ class SelectChapterDialog : VLCBottomSheetDialogFragment(), IOnChapterSelectedLi
 
     override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
         super.onViewCreated(view, savedInstanceState)
-        PlaybackService.serviceFlow.onEach { onServiceChanged(it) }.launchIn(lifecycleScope)
+        PlaybackService.serviceFlow.onEach { onServiceChanged(it) }.launchWhenStarted(lifecycleScope)
     }
 
     private fun initChapterList() {



More information about the Android mailing list