[Android] Fix add to group dialog empty state and text

Nicolas Pomepuy git at videolan.org
Wed May 18 05:36:45 UTC 2022


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Mon May 16 08:51:21 2022 +0200| [3e7b97009e3b45311925fb1cd7956c860cd40f05] | committer: Nicolas Pomepuy

Fix add to group dialog empty state and text

Fixes #2521

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

 application/resources/src/main/res/values/strings.xml    |  1 +
 .../vlc-android/res/layout/dialog_add_to_group.xml       |  6 +++---
 .../src/org/videolan/vlc/gui/dialogs/AddToGroupDialog.kt | 16 +++++++++-------
 3 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/application/resources/src/main/res/values/strings.xml b/application/resources/src/main/res/values/strings.xml
index 4cbd2b3b5..f8dc2e141 100644
--- a/application/resources/src/main/res/values/strings.xml
+++ b/application/resources/src/main/res/values/strings.xml
@@ -816,6 +816,7 @@
     <string name="rename_group">Rename video group</string>
     <string name="ungroup">Ungroup</string>
     <string name="group_similar">Regroup automatically</string>
+    <string name="no_group_found">No video group found</string>
     <string name="no_favorite">No favorite</string>
     <string name="empty_directory">Empty</string>
     <string name="no_track">No track</string>
diff --git a/application/vlc-android/res/layout/dialog_add_to_group.xml b/application/vlc-android/res/layout/dialog_add_to_group.xml
index 5b1e18d0b..d55c0d9c5 100644
--- a/application/vlc-android/res/layout/dialog_add_to_group.xml
+++ b/application/vlc-android/res/layout/dialog_add_to_group.xml
@@ -23,8 +23,7 @@
   -->
 
 <layout xmlns:android="http://schemas.android.com/apk/res/android"
-        xmlns:app="http://schemas.android.com/apk/res-auto"
-        xmlns:tools="http://schemas.android.com/tools">
+        xmlns:app="http://schemas.android.com/apk/res-auto">
 
     <data>
 
@@ -85,7 +84,8 @@
                         android:layout_width="match_parent"
                         android:layout_height="wrap_content"
                         android:gravity="center_horizontal"
-                        android:text="@string/noplaylist" />
+                        android:layout_marginBottom="16dp"
+                        android:text="@string/no_group_found" />
             </FrameLayout>
 
         </androidx.constraintlayout.widget.ConstraintLayout>
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/dialogs/AddToGroupDialog.kt b/application/vlc-android/src/org/videolan/vlc/gui/dialogs/AddToGroupDialog.kt
index 3d4a0d64e..24289b069 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/dialogs/AddToGroupDialog.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/dialogs/AddToGroupDialog.kt
@@ -52,6 +52,7 @@ class AddToGroupDialog : VLCBottomSheetDialogFragment(), SimpleAdapter.ClickHand
 
     override fun needToManageOrientation(): Boolean = false
 
+    private lateinit var viewModel: VideosViewModel
     private var forbidNewGroup: Boolean = true
     lateinit var newGroupListener: () -> Unit
     private var isLoading: Boolean = false
@@ -105,23 +106,24 @@ class AddToGroupDialog : VLCBottomSheetDialogFragment(), SimpleAdapter.ClickHand
         binding.list.layoutManager = LinearLayoutManager(view.context)
         binding.list.adapter = adapter
         //we have to create the viewmodel that way to avoid the cache from ViewModelProvider which will send the model from the calling activity that may have a different groupingType
-        val viewModel = VideosViewModel.Factory(requireContext(), VideoGroupingType.NAME, null, null).create(VideosViewModel::class.java)
+        viewModel = VideosViewModel.Factory(requireContext(), VideoGroupingType.NAME, null, null).create(VideosViewModel::class.java)
+        updateEmptyView()
         viewModel.provider.pagedList.observe(viewLifecycleOwner) {
 
-            adapter.submitList(it.filter { group -> group is VideoGroup && group.mediaCount() > 1 }.apply {
+            val groupList = it.filter { group -> group is VideoGroup && group.mediaCount() > 1 }.apply {
                 forEach { mediaLibraryItem -> mediaLibraryItem.description = resources.getQuantityString(R.plurals.media_quantity, mediaLibraryItem.tracksCount, mediaLibraryItem.tracksCount) }
             }.toMutableList().apply {
                 if (newTrack.size > 1 && !forbidNewGroup) {
                     this.add(0, DummyItem(DUMMY_NEW_GROUP, getString(R.string.new_group), getString(R.string.new_group_desc)))
                 }
-            })
-            updateEmptyView()
+            }
+            adapter.submitList(groupList)
+            updateEmptyView(groupList.isEmpty())
         }
-        updateEmptyView()
     }
 
-    private fun updateEmptyView() {
-        binding.empty.visibility = if (adapter.isEmpty()) View.VISIBLE else View.GONE
+    private fun updateEmptyView(empty:Boolean = true) {
+        binding.empty.visibility = if (empty) View.VISIBLE else View.GONE
     }
 
     private fun addToGroup(videoGroup: VideoGroup) {



More information about the Android mailing list