[Android] Prevent actions on video groups in unmounted SDCards

Nicolas Pomepuy git at videolan.org
Wed Sep 1 11:39:51 UTC 2021


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Tue Aug 31 11:11:42 2021 +0200| [b147eb999473413f172db810e13673dfd75a821e] | committer: Nicolas Pomepuy

Prevent actions on video groups in unmounted SDCards

Prevents some crashes and also display the right icon
for SDCard media when they are not present

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

 .../resources/src/main/res/drawable/ic_sd_media_off.xml        |  9 +++++++++
 application/vlc-android/res/layout/video_grid_card.xml         | 10 +++++-----
 application/vlc-android/res/layout/video_list_card.xml         | 10 +++++-----
 .../src/org/videolan/vlc/gui/helpers/ImageLoader.kt            |  6 ++++++
 .../src/org/videolan/vlc/gui/video/VideoGridFragment.kt        |  7 ++++---
 5 files changed, 29 insertions(+), 13 deletions(-)

diff --git a/application/resources/src/main/res/drawable/ic_sd_media_off.xml b/application/resources/src/main/res/drawable/ic_sd_media_off.xml
new file mode 100644
index 000000000..d68f50494
--- /dev/null
+++ b/application/resources/src/main/res/drawable/ic_sd_media_off.xml
@@ -0,0 +1,9 @@
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+        android:width="12dp"
+        android:height="12dp"
+        android:viewportWidth="24"
+        android:viewportHeight="24">
+    <path
+            android:fillColor="#FFFFFF"
+            android:pathData="M21.26,21.21L3.79,3.74 2.38,5.15l2.74,2.74 -0.12,0.12L5,19c0,1.1 0.9,2 2,2h10c0.35,0 0.68,-0.1 0.97,-0.26l1.88,1.88 1.41,-1.41zM7,19L7,9.77L16.23,19L7,19zM10.84,5L17,5v9.11l2,2L19,5c0,-1.1 -0.9,-2 -2,-2h-6.99L7.95,5.06l1.41,1.41L10.84,5z" />
+</vector>
diff --git a/application/vlc-android/res/layout/video_grid_card.xml b/application/vlc-android/res/layout/video_grid_card.xml
index e48a10755..321704feb 100644
--- a/application/vlc-android/res/layout/video_grid_card.xml
+++ b/application/vlc-android/res/layout/video_grid_card.xml
@@ -113,7 +113,7 @@
                         android:id="@+id/network_off_overlay"
                         android:layout_width="0dp"
                         android:layout_height="0dp"
-                        android:visibility="@{!selected && isNetwork && !isPresent ? View.VISIBLE : View.GONE}"
+                        android:visibility="@{!selected && !isPresent ? View.VISIBLE : View.GONE}"
                         android:background="?attr/disabled_overlay_color"
                         vlc:layout_constraintBottom_toBottomOf="@+id/ml_item_thumbnail"
                         vlc:layout_constraintEnd_toEndOf="@+id/ml_item_thumbnail"
@@ -176,11 +176,11 @@
                         android:layout_marginBottom="4dp"
                         android:background="@drawable/rounded_corners_black_more_transparent"
                         android:padding="3dp"
-                        android:visibility="@{isNetwork && !isPresent ? View.VISIBLE : View.GONE}"
+                        android:visibility="@{!isPresent ? View.VISIBLE : View.GONE}"
                         vlc:layout_constraintBottom_toTopOf="@+id/ml_item_progress"
                         vlc:layout_constraintStart_toStartOf="@+id/ml_item_thumbnail"
                         vlc:layout_goneMarginBottom="4dp"
-                        vlc:srcCompat="@drawable/ic_network_media_off" />
+                        vlc:missingMedia="@{media}"/>
 
 
                 <ImageView
@@ -263,7 +263,7 @@
                 android:textSize="16sp"
                 tools:targetApi="jelly_bean"
                 tools:text="Star wars Episode 1"
-                android:enabled="@{!isNetwork || isPresent}"
+                android:enabled="@{isPresent}"
                 vlc:layout_constraintEnd_toEndOf="@+id/container"
                 vlc:layout_constraintStart_toStartOf="parent"
                 vlc:layout_constraintTop_toBottomOf="@+id/container" />
@@ -277,7 +277,7 @@
                 android:ellipsize="end"
                 android:gravity="start"
                 vlc:presenceDescription="@{time}"
-                android:enabled="@{!isNetwork || isPresent}"
+                android:enabled="@{isPresent}"
                 android:textSize="12sp"
                 android:visibility="@{TextUtils.isEmpty(time) ? View.GONE : View.VISIBLE}"
                 tools:text="32:55"
diff --git a/application/vlc-android/res/layout/video_list_card.xml b/application/vlc-android/res/layout/video_list_card.xml
index 22cc3b377..0f1b525d0 100644
--- a/application/vlc-android/res/layout/video_list_card.xml
+++ b/application/vlc-android/res/layout/video_list_card.xml
@@ -107,7 +107,7 @@
                         android:layout_width="0dp"
                         android:layout_height="0dp"
                         android:background="?attr/disabled_overlay_color"
-                        android:visibility="@{!selected && isNetwork && !isPresent ? View.VISIBLE : View.GONE}"
+                        android:visibility="@{!selected && !isPresent ? View.VISIBLE : View.GONE}"
                         vlc:layout_constraintBottom_toBottomOf="@+id/ml_item_thumbnail"
                         vlc:layout_constraintEnd_toEndOf="@+id/ml_item_thumbnail"
                         vlc:layout_constraintStart_toStartOf="@+id/ml_item_thumbnail"
@@ -134,10 +134,10 @@
                         android:layout_marginTop="4dp"
                         android:background="@drawable/rounded_corners_black_more_transparent"
                         android:padding="3dp"
-                        android:visibility="@{isNetwork && !isPresent ? View.VISIBLE : View.GONE}"
+                        android:visibility="@{!isPresent ? View.VISIBLE : View.GONE}"
                         vlc:layout_constraintStart_toStartOf="@+id/ml_item_thumbnail"
                         vlc:layout_constraintTop_toTopOf="@+id/ml_item_thumbnail"
-                        vlc:srcCompat="@drawable/ic_network_media_off" />
+                        vlc:missingMedia="@{media}"/>
 
                 <ImageView
                         android:id="@+id/ml_item_seen"
@@ -195,7 +195,7 @@
                 android:gravity="center_vertical"
                 android:lineSpacingMultiplier="1"
                 android:text="@{media.title}"
-                android:enabled="@{!isNetwork || isPresent}"
+                android:enabled="@{isPresent}"
                 android:textSize="16sp"
                 tools:text="Star wars Episode 1"
                 vlc:layout_constraintBottom_toTopOf="@+id/ml_item_time"
@@ -228,7 +228,7 @@
                 android:layout_marginStart="16dp"
                 android:layout_marginEnd="4dp"
                 android:gravity="start"
-                android:text="@{time}"
+                vlc:presenceDescription="@{time}"
                 android:textSize="12sp"
                 android:enabled="@{!isNetwork || isPresent}"
                 android:visibility="@{TextUtils.isEmpty(time) ? View.GONE : View.VISIBLE}"
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/helpers/ImageLoader.kt b/application/vlc-android/src/org/videolan/vlc/gui/helpers/ImageLoader.kt
index ee97fae3b..0d34b17d5 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/helpers/ImageLoader.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/helpers/ImageLoader.kt
@@ -28,6 +28,7 @@ import kotlinx.coroutines.*
 import org.videolan.medialibrary.interfaces.Medialibrary
 import org.videolan.medialibrary.interfaces.media.Folder
 import org.videolan.medialibrary.interfaces.media.MediaWrapper
+import org.videolan.medialibrary.interfaces.media.VideoGroup
 import org.videolan.medialibrary.media.DummyItem
 import org.videolan.medialibrary.media.MediaLibraryItem
 import org.videolan.resources.AppContextProvider
@@ -206,6 +207,11 @@ fun downloadIcon(v: View, imageUrl: String?, tv: Boolean = true) {
     }
 }
 
+ at BindingAdapter("missingMedia")
+fun missingMedia(imageView: ImageView, media: MediaLibraryItem) {
+    if (media is VideoGroup && !media.isNetwork()) imageView.setImageResource(R.drawable.ic_sd_media_off) else imageView.setImageResource(R.drawable.ic_network_media_off)
+}
+
 private suspend fun getImage(v: View, item: MediaLibraryItem, binding: ViewDataBinding?, imageWidth: Int = 0, tv: Boolean = false, card: Boolean = false) {
     var bindChanged = false
     val rebindCallbacks = if (binding !== null) object : OnRebindCallback<ViewDataBinding>() {
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.kt b/application/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.kt
index 12c3e941b..940f0aefa 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.kt
@@ -521,12 +521,12 @@ class VideoGridFragment : MediaBrowserFragment<VideosViewModel>(), SwipeRefreshL
                 onClick(position, item)
             }
             is VideoLongClick -> {
-                onLongClick(position)
+                if ((item is VideoGroup && item.presentCount == 0)) UiTools.snackerMissing(requireActivity()) else onLongClick(position)
             }
             is VideoCtxClick -> {
                 when (item) {
                     is Folder -> showContext(requireActivity(), this at VideoGridFragment, position, item.title, CTX_FOLDER_FLAGS)
-                    is VideoGroup -> showContext(requireActivity(), this at VideoGridFragment, position, item.title, CTX_FOLDER_FLAGS or CTX_RENAME_GROUP or CTX_UNGROUP or CTX_PLAY_ALL and CTX_PLAY.inv() or CTX_ADD_GROUP)
+                    is VideoGroup -> if (item.presentCount == 0) UiTools.snackerMissing(requireActivity()) else showContext(requireActivity(), this at VideoGridFragment, position, item.title, CTX_FOLDER_FLAGS or CTX_RENAME_GROUP or CTX_UNGROUP or CTX_PLAY_ALL and CTX_PLAY.inv() or CTX_ADD_GROUP)
                     is MediaWrapper -> {
                         val group = item.type == MediaWrapper.TYPE_GROUP
                         var flags = if (group) CTX_VIDEO_GROUP_FLAGS else CTX_VIDEO_FLAGS
@@ -575,7 +575,8 @@ class VideoGridFragment : MediaBrowserFragment<VideosViewModel>(), SwipeRefreshL
                     multiSelectHelper.toggleSelection(position)
                     invalidateActionMode()
                 }
-                item.mediaCount() == 1 -> viewModel.play(position)
+                item.presentCount == 0 -> UiTools.snackerMissing(requireActivity())
+                item.presentCount == 1 -> viewModel.play(position)
                 else -> activity?.open(item)
             }
         }



More information about the Android mailing list