[Android] Prevent showing an edit favorite ctx to non supported schemes

Nicolas Pomepuy git at videolan.org
Wed Oct 5 07:46:11 UTC 2022


vlc-android | branch: 3.5.x | Nicolas Pomepuy <nicolas at videolabs.io> | Mon Oct  3 07:58:57 2022 +0200| [ef489711bd4c45e5c59a06a920b2bd1353b47c6c] | committer: Duncan McNamara

Prevent showing an edit favorite ctx to non supported schemes

Fixes #2703

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

 .../src/org/videolan/vlc/gui/browser/BaseBrowserFragment.kt            | 3 ++-
 .../src/org/videolan/vlc/gui/browser/MainBrowserFragment.kt            | 3 ++-
 application/vlc-android/src/org/videolan/vlc/util/Browserutils.kt      | 2 ++
 3 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/application/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.kt b/application/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.kt
index f5e30a3db..df02f8346 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.kt
@@ -74,6 +74,7 @@ import org.videolan.vlc.media.MediaUtils
 import org.videolan.vlc.media.PlaylistManager
 import org.videolan.vlc.repository.BrowserFavRepository
 import org.videolan.vlc.util.Permissions
+import org.videolan.vlc.util.isSchemeFavoriteEditable
 import org.videolan.vlc.util.isSchemeSupported
 import org.videolan.vlc.util.isTalkbackIsEnabled
 import org.videolan.vlc.viewmodels.browser.BrowserModel
@@ -568,7 +569,7 @@ abstract class BaseBrowserFragment : MediaBrowserFragment<BrowserModel>(), IRefr
                 if (isFileBrowser || isNetworkBrowser) {
                     val favExists = browserFavRepository.browserFavExists(mw.uri)
                     flags = if (favExists) {
-                        if (isNetworkBrowser) flags or CTX_FAV_EDIT or CTX_FAV_REMOVE
+                        if (mw.uri.scheme.isSchemeFavoriteEditable() && isNetworkBrowser) flags or CTX_FAV_EDIT or CTX_FAV_REMOVE
                         else flags or CTX_FAV_REMOVE
                     } else flags or CTX_FAV_ADD
                 }
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/browser/MainBrowserFragment.kt b/application/vlc-android/src/org/videolan/vlc/gui/browser/MainBrowserFragment.kt
index 417a7ef76..f018b3904 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/browser/MainBrowserFragment.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/browser/MainBrowserFragment.kt
@@ -57,6 +57,7 @@ import org.videolan.vlc.gui.view.TitleListView
 import org.videolan.vlc.media.MediaUtils
 import org.videolan.vlc.repository.BrowserFavRepository
 import org.videolan.vlc.util.Permissions
+import org.videolan.vlc.util.isSchemeFavoriteEditable
 import org.videolan.vlc.viewmodels.browser.*
 
 class MainBrowserFragment : BaseFragment(), View.OnClickListener, CtxActionReceiver {
@@ -380,7 +381,7 @@ class MainBrowserFragment : BaseFragment(), View.OnClickListener, CtxActionRecei
                 val isFileBrowser = isFile && item.uri.scheme == "file"
                 val favExists = withContext(Dispatchers.IO) { browserFavRepository.browserFavExists(mw.uri) }
                 flags = if (favExists) {
-                    if (withContext(Dispatchers.IO) { browserFavRepository.isFavNetwork(mw.uri) }) flags or CTX_FAV_EDIT or CTX_FAV_REMOVE
+                    if (mw.uri.scheme.isSchemeFavoriteEditable() && withContext(Dispatchers.IO) { browserFavRepository.isFavNetwork(mw.uri) }) flags or CTX_FAV_EDIT or CTX_FAV_REMOVE
                     else flags or CTX_FAV_REMOVE
                 } else flags or CTX_FAV_ADD
                 if (isFileBrowser) {
diff --git a/application/vlc-android/src/org/videolan/vlc/util/Browserutils.kt b/application/vlc-android/src/org/videolan/vlc/util/Browserutils.kt
index 0eb6bb11c..066573abf 100644
--- a/application/vlc-android/src/org/videolan/vlc/util/Browserutils.kt
+++ b/application/vlc-android/src/org/videolan/vlc/util/Browserutils.kt
@@ -47,6 +47,8 @@ fun String?.isSchemeNetwork() = when(this) {
     else -> false
 }
 
+fun String?.isSchemeFavoriteEditable() = this in arrayOf("ftp", "ftps", "sftp", "smb", "nfs")
+
 fun String?.isSchemeFile() = when(this) {
     "file", null -> true
     else -> false



More information about the Android mailing list