[Android] Prevent the refresh action to be displayed / used when the permission is not given

Nicolas Pomepuy git at videolan.org
Mon Jul 5 11:12:29 UTC 2021


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Thu Jun 24 09:22:27 2021 +0200| [432d5fa1c52f254e0727fc392cf3149af3920f87] | committer: Nicolas Pomepuy

Prevent the refresh action to be displayed / used when the permission is not given

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

 .../main/java/org/videolan/television/ui/MainTvFragment.kt  |  3 ++-
 .../vlc-android/src/org/videolan/vlc/gui/MainActivity.kt    |  8 +++++++-
 .../src/org/videolan/vlc/gui/SecondaryActivity.kt           | 13 +++++++++++--
 3 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/application/television/src/main/java/org/videolan/television/ui/MainTvFragment.kt b/application/television/src/main/java/org/videolan/television/ui/MainTvFragment.kt
index ce252233b..dccddc029 100644
--- a/application/television/src/main/java/org/videolan/television/ui/MainTvFragment.kt
+++ b/application/television/src/main/java/org/videolan/television/ui/MainTvFragment.kt
@@ -52,6 +52,7 @@ import org.videolan.vlc.donations.VLCBilling
 import org.videolan.vlc.gui.helpers.UiTools.showDonations
 import org.videolan.vlc.gui.video.VideoPlayerActivity
 import org.videolan.vlc.reloadLibrary
+import org.videolan.vlc.util.Permissions
 
 private const val TAG = "VLC/MainTvFragment"
 
@@ -160,7 +161,7 @@ class MainTvFragment : BrowseSupportFragment(), OnItemViewSelectedListener, OnIt
         val miscHeader = HeaderItem(HEADER_MISC, getString(R.string.other))
 
         otherAdapter.add(GenericCardItem(ID_SETTINGS, getString(R.string.preferences), "", R.drawable.ic_menu_preferences_big, R.color.tv_card_content_dark))
-        otherAdapter.add(GenericCardItem(ID_REFRESH, getString(R.string.refresh), "", R.drawable.ic_menu_tv_scan, R.color.tv_card_content_dark))
+        if (Permissions.canReadStorage(requireActivity())) otherAdapter.add(GenericCardItem(ID_REFRESH, getString(R.string.refresh), "", R.drawable.ic_menu_tv_scan, R.color.tv_card_content_dark))
         otherAdapter.add(GenericCardItem(ID_ABOUT_TV, getString(R.string.about), "${getString(R.string.app_name_full)} ${BuildConfig.VLC_VERSION_NAME}", R.drawable.ic_menu_info_big, R.color.tv_card_content_dark))
         otherAdapter.add(GenericCardItem(ID_LICENCE, getString(R.string.licence), "", R.drawable.ic_menu_open_source, R.color.tv_card_content_dark))
         val donateCard = GenericCardItem(ID_SPONSOR, getString(R.string.tip_jar), "", R.drawable.ic_donate_big, R.color.tv_card_content_dark)
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/MainActivity.kt b/application/vlc-android/src/org/videolan/vlc/gui/MainActivity.kt
index a9c02b988..06a7cbd7e 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/MainActivity.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/MainActivity.kt
@@ -29,6 +29,7 @@ import android.os.Bundle
 import android.util.Log
 import android.util.TypedValue
 import android.view.KeyEvent
+import android.view.Menu
 import android.view.MenuItem
 import android.view.View
 import androidx.appcompat.view.ActionMode
@@ -163,6 +164,11 @@ class MainActivity : ContentActivity(),
         return super.startSupportActionMode(callback)
     }
 
+    override fun onPrepareOptionsMenu(menu: Menu?): Boolean {
+        menu?.findItem(R.id.ml_menu_refresh)?.isVisible = Permissions.canReadStorage(this)
+        return super.onPrepareOptionsMenu(menu)
+    }
+
     /**
      * Handle onClick form menu buttons
      */
@@ -173,7 +179,7 @@ class MainActivity : ContentActivity(),
         return when (item.itemId) {
             // Refresh
             R.id.ml_menu_refresh -> {
-                forceRefresh()
+                if (Permissions.canReadStorage(this)) forceRefresh()
                 true
             }
             android.R.id.home ->
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/SecondaryActivity.kt b/application/vlc-android/src/org/videolan/vlc/gui/SecondaryActivity.kt
index 010e3f5a2..04dc0a415 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/SecondaryActivity.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/SecondaryActivity.kt
@@ -25,6 +25,7 @@ package org.videolan.vlc.gui
 
 import android.content.Intent
 import android.os.Bundle
+import android.view.Menu
 import android.view.MenuItem
 import android.view.View
 import androidx.coordinatorlayout.widget.CoordinatorLayout
@@ -53,6 +54,7 @@ import org.videolan.vlc.gui.video.VideoGridFragment
 import org.videolan.vlc.reloadLibrary
 import org.videolan.vlc.util.DialogDelegate
 import org.videolan.vlc.util.IDialogManager
+import org.videolan.vlc.util.Permissions
 import org.videolan.vlc.util.isSchemeNetwork
 
 @ExperimentalCoroutinesApi
@@ -132,12 +134,19 @@ class SecondaryActivity : ContentActivity(), IDialogManager {
         }
     }
 
+    override fun onPrepareOptionsMenu(menu: Menu?): Boolean {
+        menu?.findItem(R.id.ml_menu_refresh)?.isVisible = Permissions.canReadStorage(this)
+        return super.onPrepareOptionsMenu(menu)
+    }
+
     override fun onOptionsItemSelected(item: MenuItem): Boolean {
         // Handle item selection
         when (item.itemId) {
             R.id.ml_menu_refresh -> {
-                val ml = Medialibrary.getInstance()
-                if (!ml.isWorking) reloadLibrary()
+                if (Permissions.canReadStorage(this)) {
+                    val ml = Medialibrary.getInstance()
+                    if (!ml.isWorking) reloadLibrary()
+                }
                 return true
             }
         }



More information about the Android mailing list