[Android] Prevent the action mode to display an invalid title upon orientation change

Nicolas Pomepuy git at videolan.org
Thu Feb 24 13:18:01 UTC 2022


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Thu Feb 24 08:30:52 2022 +0100| [88c73089a49c608057b96f90bce3013194602b43] | committer: Nicolas Pomepuy

Prevent the action mode to display an invalid title upon orientation change

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

 .../src/org/videolan/vlc/gui/helpers/UiTools.kt     | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/application/vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.kt b/application/vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.kt
index 8fea32592..616dea25b 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.kt
@@ -76,14 +76,8 @@ import org.videolan.vlc.BuildConfig.VLC_VERSION_NAME
 import org.videolan.vlc.MediaParsingService
 import org.videolan.vlc.R
 import org.videolan.vlc.gui.*
-import org.videolan.vlc.gui.BaseActivity
-import org.videolan.vlc.gui.InfoActivity
-import org.videolan.vlc.gui.LibrariesActivity
 import org.videolan.vlc.gui.browser.MediaBrowserFragment
 import org.videolan.vlc.gui.dialogs.*
-import org.videolan.vlc.gui.dialogs.AddToGroupDialog
-import org.videolan.vlc.gui.dialogs.SavePlaylistDialog
-import org.videolan.vlc.gui.dialogs.VideoTracksDialog
 import org.videolan.vlc.gui.preferences.PreferencesActivity
 import org.videolan.vlc.media.MediaUtils
 import org.videolan.vlc.media.getAll
@@ -842,8 +836,13 @@ fun getTvIconRes(mediaLibraryItem: MediaLibraryItem) = when (mediaLibraryItem.it
 suspend fun fillActionMode(context: Context, mode: ActionMode, multiSelectHelper: MultiSelectHelper<MediaLibraryItem>) {
     var realCount = 0
     var length = 0L
+    //checks if the selection can be retrieved (if the adapter is populated).
+    // If not, we want to prevent changing the title to avoid flashing an invalid empty title
+    var ready: Boolean
     withContext(Dispatchers.IO) {
-        multiSelectHelper.getSelection().forEach { mediaItem ->
+        val selection = multiSelectHelper.getSelection()
+        ready = selection.size == multiSelectHelper.getSelectionCount()
+        selection.forEach { mediaItem ->
             when (mediaItem) {
                 is MediaWrapper -> realCount += 1
                 is Album -> realCount += mediaItem.realTracksCount
@@ -853,7 +852,7 @@ suspend fun fillActionMode(context: Context, mode: ActionMode, multiSelectHelper
             }
         }
 
-        multiSelectHelper.getSelection().forEach { mediaItem ->
+        selection.forEach { mediaItem ->
             when (mediaItem) {
                 is MediaWrapper -> length += mediaItem.length
                 is Album -> mediaItem.getAll().forEach { length += it.length }
@@ -863,6 +862,8 @@ suspend fun fillActionMode(context: Context, mode: ActionMode, multiSelectHelper
             }
         }
     }
-    mode.title = context.getString(R.string.selection_count, realCount)
-    mode.subtitle = "${ Tools.millisToString(length)}"
+    if (ready) {
+        mode.title = context.getString(R.string.selection_count, realCount)
+        mode.subtitle = "${ Tools.millisToString(length)}"
+    }
 }
\ No newline at end of file



More information about the Android mailing list