[Android] Refactor the storage fine permission request code

Nicolas Pomepuy git at videolan.org
Mon Nov 25 11:07:02 UTC 2024


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Tue Oct 15 08:59:46 2024 +0200| [dbab387fcf9a491daa605e3166a41e6c042ca16d] | committer: Duncan McNamara

Refactor the storage fine permission request code

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

 application/vlc-android/src/org/videolan/vlc/gui/MainActivity.kt     | 2 +-
 .../src/org/videolan/vlc/gui/onboarding/OnboardingActivity.kt        | 4 ++--
 .../src/org/videolan/vlc/gui/view/EmptyLoadingStateView.kt           | 5 +++--
 application/vlc-android/src/org/videolan/vlc/util/Permissions.kt     | 2 ++
 4 files changed, 8 insertions(+), 5 deletions(-)

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 cd460e484f..afbf2da58e 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/MainActivity.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/MainActivity.kt
@@ -169,7 +169,7 @@ class MainActivity : ContentActivity(),
         grantResults: IntArray
     ) {
         super.onRequestPermissionsResult(requestCode, permissions, grantResults)
-        if (requestCode == 1000) {
+        if (requestCode == Permissions.FINE_STORAGE_PERMISSION_REQUEST_CODE) {
             if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                 forceRefresh()
             }
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/onboarding/OnboardingActivity.kt b/application/vlc-android/src/org/videolan/vlc/gui/onboarding/OnboardingActivity.kt
index 2a6f05e673..155e22eecc 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/onboarding/OnboardingActivity.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/onboarding/OnboardingActivity.kt
@@ -104,7 +104,7 @@ class OnboardingActivity : AppCompatActivity(), OnboardingFragmentListener {
         grantResults: IntArray
     ) {
         super.onRequestPermissionsResult(requestCode, permissions, grantResults)
-        if (requestCode == 1000) {
+        if (requestCode == Permissions.FINE_STORAGE_PERMISSION_REQUEST_CODE) {
             if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                 viewModel.permissionAlreadyAsked = true
                 onNext()
@@ -124,7 +124,7 @@ class OnboardingActivity : AppCompatActivity(), OnboardingFragmentListener {
                         Manifest.permission.READ_MEDIA_AUDIO,
                         Manifest.permission.READ_MEDIA_IMAGES,
                         Manifest.permission.READ_MEDIA_VIDEO
-                    ), 1000
+                    ), Permissions.FINE_STORAGE_PERMISSION_REQUEST_CODE
                 )
                 return at launch
             } else getStoragePermission(withDialog = false, onlyMedia = false)
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/view/EmptyLoadingStateView.kt b/application/vlc-android/src/org/videolan/vlc/gui/view/EmptyLoadingStateView.kt
index 213e61e6cc..2b05faa138 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/view/EmptyLoadingStateView.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/view/EmptyLoadingStateView.kt
@@ -51,6 +51,7 @@ import org.videolan.vlc.gui.SecondaryActivity
 import org.videolan.vlc.gui.helpers.getBitmapFromDrawable
 import org.videolan.vlc.gui.helpers.hf.StoragePermissionsDelegate.Companion.askStoragePermission
 import org.videolan.vlc.gui.helpers.hf.StoragePermissionsDelegate.Companion.getStoragePermission
+import org.videolan.vlc.util.Permissions
 
 class EmptyLoadingStateView : FrameLayout {
 
@@ -158,14 +159,14 @@ class EmptyLoadingStateView : FrameLayout {
                 EmptyLoadingState.MISSING_AUDIO_PERMISSION -> ActivityCompat.requestPermissions(
                     context as Activity, arrayOf(
                         Manifest.permission.READ_MEDIA_AUDIO
-                    ), 1000
+                    ), Permissions.FINE_STORAGE_PERMISSION_REQUEST_CODE
                 )
 
                 EmptyLoadingState.MISSING_VIDEO_PERMISSION -> ActivityCompat.requestPermissions(
                     context as Activity, arrayOf(
                         Manifest.permission.READ_MEDIA_VIDEO,
                         Manifest.permission.READ_MEDIA_IMAGES
-                    ), 1000
+                    ), Permissions.FINE_STORAGE_PERMISSION_REQUEST_CODE
                 )
 
                 else -> (context as? FragmentActivity)?.askStoragePermission(false, null)
diff --git a/application/vlc-android/src/org/videolan/vlc/util/Permissions.kt b/application/vlc-android/src/org/videolan/vlc/util/Permissions.kt
index 4f271fc9d7..20f43c3343 100644
--- a/application/vlc-android/src/org/videolan/vlc/util/Permissions.kt
+++ b/application/vlc-android/src/org/videolan/vlc/util/Permissions.kt
@@ -64,6 +64,8 @@ object Permissions {
     const val PERMISSION_WRITE_STORAGE_TAG = 253
     const val MANAGE_EXTERNAL_STORAGE = 256
 
+    const val FINE_STORAGE_PERMISSION_REQUEST_CODE = 100001
+
 
     const val PERMISSION_SYSTEM_RINGTONE = 42
     private const val PERMISSION_SYSTEM_BRIGHTNESS = 43



More information about the Android mailing list