[Android] Prevent the permission snackbar to be shown more than once every 2 days

Nicolas Pomepuy git at videolan.org
Mon Jun 20 12:17:09 UTC 2022


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Mon Jun 20 13:51:14 2022 +0200| [49e208d6bc7ca8ed9741842f8be2ea1da013b23f] | committer: Duncan McNamara

Prevent the permission snackbar to be shown more than once every 2 days

Fixes #2575

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

 application/tools/src/main/java/org/videolan/tools/Settings.kt   | 1 +
 application/vlc-android/src/org/videolan/vlc/gui/MainActivity.kt | 4 +++-
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/application/tools/src/main/java/org/videolan/tools/Settings.kt b/application/tools/src/main/java/org/videolan/tools/Settings.kt
index be6d7251e..77148501d 100644
--- a/application/tools/src/main/java/org/videolan/tools/Settings.kt
+++ b/application/tools/src/main/java/org/videolan/tools/Settings.kt
@@ -163,6 +163,7 @@ const val SUBTITLE_PREFERRED_LANGUAGE = "subtitle_preferred_language"
 const val LAST_LOCK_ORIENTATION = "last_lock_orientation"
 const val INITIAL_PERMISSION_ASKED = "initial_permission_asked"
 const val PERMISSION_NEVER_ASK = "permission_never_ask"
+const val PERMISSION_NEXT_ASK = "permission_next_ask"
 
 const val WIDGETS_BACKGROUND_LAST_COLORS = "widgets_background_last_colors"
 const val WIDGETS_FOREGROUND_LAST_COLORS = "widgets_foreground_last_colors"
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 5f8131afb..f651e4bc5 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/MainActivity.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/MainActivity.kt
@@ -61,6 +61,7 @@ import org.videolan.vlc.util.Permissions
 import org.videolan.vlc.util.Util
 import org.videolan.vlc.util.WidgetMigration
 import org.videolan.vlc.util.getScreenWidth
+import java.util.concurrent.TimeUnit
 
 private const val TAG = "VLC/MainActivity"
 
@@ -103,10 +104,11 @@ class MainActivity : ContentActivity(),
     override fun onResume() {
         super.onResume()
         //Only the partial permission is granted for Android 11+
-        if (!settings.getBoolean(PERMISSION_NEVER_ASK, false) && Permissions.canReadStorage(this) && !Permissions.hasAllAccess(this)) {
+        if (!settings.getBoolean(PERMISSION_NEVER_ASK, false) && settings.getLong(PERMISSION_NEXT_ASK, 0L) < System.currentTimeMillis() && Permissions.canReadStorage(this) && !Permissions.hasAllAccess(this)) {
             UiTools.snackerMessageInfinite(this, getString(R.string.partial_content))?.setAction(R.string.more) {
                 AllAccessPermissionDialog.newInstance().show(supportFragmentManager, AllAccessPermissionDialog::class.simpleName)
             }?.show()
+            settings.putSingle(PERMISSION_NEXT_ASK, System.currentTimeMillis() + TimeUnit.DAYS.toMillis(2))
         }
         configurationChanged(getScreenWidth())
     }



More information about the Android mailing list