[Android] Type alias for permissions results

Geoffrey Métais git at videolan.org
Fri Jan 25 18:15:31 CET 2019


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Fri Jan 25 17:15:18 2019 +0100| [3b5d01e8ddc90ab7ab1817ceb23bb9f5cd84e5ab] | committer: Geoffrey Métais

Type alias for permissions results

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

 .../src/org/videolan/vlc/gui/helpers/hf/BaseHeadlessFragment.kt     | 4 +++-
 .../org/videolan/vlc/gui/helpers/hf/StoragePermissionsDelegate.kt   | 6 +++---
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/helpers/hf/BaseHeadlessFragment.kt b/vlc-android/src/org/videolan/vlc/gui/helpers/hf/BaseHeadlessFragment.kt
index 59b08667f..3943e7303 100644
--- a/vlc-android/src/org/videolan/vlc/gui/helpers/hf/BaseHeadlessFragment.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/helpers/hf/BaseHeadlessFragment.kt
@@ -28,6 +28,8 @@ import android.os.Bundle
 import androidx.fragment.app.Fragment
 import kotlinx.coroutines.CompletableDeferred
 
+internal typealias PermissionResults = IntArray
+
 open class BaseHeadlessFragment : Fragment() {
     protected val deferredGrant = CompletableDeferred<Boolean>()
 
@@ -48,5 +50,5 @@ open class BaseHeadlessFragment : Fragment() {
 
     suspend fun awaitGrant() = deferredGrant.await()
 
-    protected fun IntArray.isGranted() = isNotEmpty() && get(0) == PackageManager.PERMISSION_GRANTED
+    protected fun PermissionResults.granted() = isNotEmpty() && get(0) == PackageManager.PERMISSION_GRANTED
 }
\ No newline at end of file
diff --git a/vlc-android/src/org/videolan/vlc/gui/helpers/hf/StoragePermissionsDelegate.kt b/vlc-android/src/org/videolan/vlc/gui/helpers/hf/StoragePermissionsDelegate.kt
index a1fe03593..bbcdc0e6f 100644
--- a/vlc-android/src/org/videolan/vlc/gui/helpers/hf/StoragePermissionsDelegate.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/helpers/hf/StoragePermissionsDelegate.kt
@@ -77,12 +77,12 @@ class StoragePermissionsDelegate : BaseHeadlessFragment() {
         requestPermissions(arrayOf(code), tag)
     }
 
-    override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<String>, grantResults: IntArray) {
+    override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<String>, grantResults: PermissionResults) {
         when (requestCode) {
             Permissions.PERMISSION_STORAGE_TAG -> {
                 // If request is cancelled, the result arrays are empty.
                 val ctx = activity ?: return
-                if (grantResults.isGranted()) {
+                if (grantResults.granted()) {
                     storageAccessGranted.value = true
                     deferredGrant.complete(true)
                     exit()
@@ -98,7 +98,7 @@ class StoragePermissionsDelegate : BaseHeadlessFragment() {
                 exit()
             }
             Permissions.PERMISSION_WRITE_STORAGE_TAG -> {
-                deferredGrant.complete(grantResults.isGranted())
+                deferredGrant.complete(grantResults.granted())
                 exit()
             }
         }



More information about the Android mailing list