[Android] Missing media: snackbar and settings shortcut

Nicolas Pomepuy git at videolan.org
Thu Jun 10 09:42:19 UTC 2021


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Tue Feb 23 07:40:59 2021 +0100| [dedb1d91dd16f55111e277b83b18856ba96cd267] | committer: Nicolas Pomepuy

Missing media: snackbar and settings shortcut

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

 application/resources/src/main/res/values/strings.xml    |  3 +++
 application/vlc-android/res/xml/preferences_ui.xml       |  7 +++++++
 .../org/videolan/vlc/gui/audio/AudioBrowserFragment.kt   |  5 +++++
 .../src/org/videolan/vlc/gui/helpers/UiTools.kt          | 16 ++++++++++++++++
 .../videolan/vlc/gui/preferences/PreferencesFragment.kt  |  4 +++-
 .../org/videolan/vlc/gui/preferences/PreferencesUi.kt    |  1 +
 .../videolan/vlc/viewmodels/mobile/VideosViewModel.kt    |  5 +++++
 7 files changed, 40 insertions(+), 1 deletion(-)

diff --git a/application/resources/src/main/res/values/strings.xml b/application/resources/src/main/res/values/strings.xml
index 3a5a26472..37d441445 100644
--- a/application/resources/src/main/res/values/strings.xml
+++ b/application/resources/src/main/res/values/strings.xml
@@ -800,6 +800,9 @@
     <string name="enqueuing">Loading your medias</string>
     <string name="soundfont">MIDI SoundFont</string>
     <string name="soundfont_summary">Pick a SoundFont file to play midi audio tracks</string>
+    <string name="missing_media_snack">Media is missing. Hide all missing media?</string>
+    <string name="browser_show_missing_media">Show missing medias</string>
+    <string name="browser_show_missing_media_summary">Show distant medias event if they are not present</string>
     <string name="search_prefs">Search settings</string>
     <string name="preferred_resolution">Preferred video resolution</string>
     <string name="preferred_resolution_summary">Maximum video quality for streams, when applicable, will be: %s</string>
diff --git a/application/vlc-android/res/xml/preferences_ui.xml b/application/vlc-android/res/xml/preferences_ui.xml
index 06a5549c8..c5b68b5d3 100644
--- a/application/vlc-android/res/xml/preferences_ui.xml
+++ b/application/vlc-android/res/xml/preferences_ui.xml
@@ -41,6 +41,13 @@
             android:summary="@string/show_headers_summary"
             android:title="@string/show_headers"/>
 
+    <CheckBoxPreference
+            app:singleLineTitle="false"
+            android:key="include_missing"
+            android:defaultValue="true"
+            android:summary="@string/browser_show_missing_media_summary"
+            android:title="@string/browser_show_missing_media"/>
+
     <PreferenceCategory
             android:title="@string/video"
             android:key="ui_video_category">
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.kt b/application/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.kt
index 477ec52d5..d01a5d206 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.kt
@@ -53,6 +53,7 @@ import org.videolan.vlc.gui.AudioPlayerContainerActivity
 import org.videolan.vlc.gui.ContentActivity
 import org.videolan.vlc.gui.PlaylistActivity
 import org.videolan.vlc.gui.SecondaryActivity
+import org.videolan.vlc.gui.helpers.UiTools
 import org.videolan.vlc.gui.view.EmptyLoadingState
 import org.videolan.vlc.gui.view.RecyclerSectionItemGridDecoration
 import org.videolan.vlc.media.MediaUtils
@@ -324,6 +325,10 @@ class AudioBrowserFragment : BaseAudioBrowser<AudioBrowserViewModel>() {
             return
         }
         if (item.itemType == MediaLibraryItem.TYPE_MEDIA) {
+            if (item is MediaWrapper && !item.isPresent) {
+                UiTools.snackerMissing(requireActivity())
+                return
+            }
             MediaUtils.openMedia(activity, item as MediaWrapper)
             return
         }
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 7951cf92c..4c6d65194 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
@@ -83,6 +83,8 @@ import org.videolan.vlc.gui.dialogs.AddToGroupDialog
 import org.videolan.vlc.gui.dialogs.SavePlaylistDialog
 import org.videolan.vlc.gui.dialogs.VLCBillingDialog
 import org.videolan.vlc.gui.dialogs.VideoTracksDialog
+import org.videolan.vlc.gui.preferences.EXTRA_PREF_END_POINT
+import org.videolan.vlc.gui.preferences.PreferencesActivity
 import org.videolan.vlc.media.MediaUtils
 import org.videolan.vlc.providers.medialibrary.MedialibraryProvider
 import org.videolan.vlc.util.FileUtils
@@ -289,6 +291,20 @@ object UiTools {
         return Snackbar.make(view, message, Snackbar.LENGTH_INDEFINITE)
     }
 
+        @TargetApi(Build.VERSION_CODES.LOLLIPOP)
+    fun snackerMissing(activity: Activity) {
+        val view = getSnackAnchorView(activity) ?: return
+        val snack = Snackbar.make(view, activity.getString(R.string.missing_media_snack), Snackbar.LENGTH_LONG)
+                .setAction(R.string.ok) {
+                    val intent = Intent(activity, PreferencesActivity::class.java)
+                    intent.putExtra(EXTRA_PREF_END_POINT, "include_missing")
+                    activity.startActivityForResult(intent, ACTIVITY_RESULT_PREFERENCES)
+                }
+        if (AndroidUtil.isLolliPopOrLater)
+            snack.view.elevation = view.resources.getDimensionPixelSize(R.dimen.audio_player_elevation).toFloat()
+        snack.show()
+    }
+
     /**
      * Get a resource id from an attribute id.
      *
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesFragment.kt b/application/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesFragment.kt
index 0517f33e5..16cb92ac9 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesFragment.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesFragment.kt
@@ -60,7 +60,9 @@ class PreferencesFragment : BasePreferenceFragment(), SharedPreferences.OnShared
         preferenceScreen.sharedPreferences.unregisterOnSharedPreferenceChangeListener(this)
     }
 
-
+    override fun onCreate(savedInstanceState: Bundle?) {
+        super.onCreate(savedInstanceState)
+    }
     override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
         super.onViewCreated(view, savedInstanceState)
         findPreference<Preference>("extensions_category")?.isVisible = BuildConfig.DEBUG
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesUi.kt b/application/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesUi.kt
index 8623aff7d..348ee4a89 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesUi.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesUi.kt
@@ -26,6 +26,7 @@ package org.videolan.vlc.gui.preferences
 import android.content.SharedPreferences
 import android.os.Bundle
 import android.text.InputType
+import android.view.View
 import androidx.appcompat.app.AppCompatDelegate
 import androidx.preference.EditTextPreference
 import androidx.preference.ListPreference
diff --git a/application/vlc-android/src/org/videolan/vlc/viewmodels/mobile/VideosViewModel.kt b/application/vlc-android/src/org/videolan/vlc/viewmodels/mobile/VideosViewModel.kt
index e55f8693b..4020b3e2d 100644
--- a/application/vlc-android/src/org/videolan/vlc/viewmodels/mobile/VideosViewModel.kt
+++ b/application/vlc-android/src/org/videolan/vlc/viewmodels/mobile/VideosViewModel.kt
@@ -34,6 +34,7 @@ import org.videolan.medialibrary.media.MediaLibraryItem
 import org.videolan.tools.FORCE_PLAY_ALL
 import org.videolan.tools.Settings
 import org.videolan.tools.isStarted
+import org.videolan.vlc.gui.helpers.UiTools
 import org.videolan.vlc.gui.helpers.UiTools.addToPlaylist
 import org.videolan.vlc.gui.video.VideoGridFragment
 import org.videolan.vlc.media.MediaUtils
@@ -128,6 +129,10 @@ class VideosViewModel(context: Context, type: VideoGroupingType, val folder: Fol
 
     internal fun playVideo(context: Activity?, mw: MediaWrapper, position: Int, fromStart: Boolean = false, forceAll:Boolean = false) {
         if (context === null) return
+        if (!mw.isPresent) {
+            UiTools.snackerMissing(context)
+            return
+        }
         mw.removeFlags(MediaWrapper.MEDIA_FORCE_AUDIO)
         val settings = Settings.getInstance(context)
         if (!fromStart && (settings.getBoolean(FORCE_PLAY_ALL, false) || forceAll)) {



More information about the Android mailing list