[Android] Display settings: consume the flow to avoid changing the settings in previously loaded fragments

Nicolas Pomepuy git at videolan.org
Thu Feb 9 09:08:58 UTC 2023


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Wed Feb  8 14:21:42 2023 +0100| [462a9c9a2ae175d890af6fd60aef1f44468d24cd] | committer: Nicolas Pomepuy

Display settings: consume the flow to avoid changing the settings in previously loaded fragments

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

 .../src/org/videolan/vlc/gui/browser/MediaBrowserFragment.kt      | 6 ++++--
 .../src/org/videolan/vlc/viewmodels/DisplaySettingsViewModel.kt   | 8 ++++++++
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/application/vlc-android/src/org/videolan/vlc/gui/browser/MediaBrowserFragment.kt b/application/vlc-android/src/org/videolan/vlc/gui/browser/MediaBrowserFragment.kt
index 680861b451..6534ab83df 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/browser/MediaBrowserFragment.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/browser/MediaBrowserFragment.kt
@@ -92,8 +92,10 @@ abstract class MediaBrowserFragment<T : SortableModel> : BaseFragment(), Filtera
             displaySettingsViewModel.settingChangeFlow
                     .flowWithLifecycle(viewLifecycleOwner.lifecycle, Lifecycle.State.STARTED)
                     .collect {
-                        //we only dispatch the event if the fragment is resumed to avoid triggering non current fragment of a view pager
-                        if (isResumed) onDisplaySettingChanged(it.key, it.value)
+                        if (isResumed) {
+                            onDisplaySettingChanged(it.key, it.value)
+                            displaySettingsViewModel.consume()
+                        }
                     }
         }
 
diff --git a/application/vlc-android/src/org/videolan/vlc/viewmodels/DisplaySettingsViewModel.kt b/application/vlc-android/src/org/videolan/vlc/viewmodels/DisplaySettingsViewModel.kt
index a292ff2bc7..8ba633ba14 100644
--- a/application/vlc-android/src/org/videolan/vlc/viewmodels/DisplaySettingsViewModel.kt
+++ b/application/vlc-android/src/org/videolan/vlc/viewmodels/DisplaySettingsViewModel.kt
@@ -59,4 +59,12 @@ class DisplaySettingsViewModel: ViewModel() {
         _settingChangeFlow.emit(SettingChange(key, value))
     }
 
+    /**
+     * When the flow value is consumed, revert to "init" state
+     *
+     */
+    suspend fun consume() {
+        _settingChangeFlow.emit(SettingChange())
+    }
+
 }
\ No newline at end of file



More information about the Android mailing list