[Android] Improve permission grant management

Geoffrey Métais git at videolan.org
Thu Feb 21 16:50:01 CET 2019


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Feb 21 16:09:03 2019 +0100| [c18b03176dc26560e2c57b94c8a7996bf35d8cf2] | committer: Geoffrey Métais

Improve permission grant management

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

 .../vlc/gui/onboarding/OnboardingActivity.kt       | 28 ++++++++++------------
 1 file changed, 13 insertions(+), 15 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/onboarding/OnboardingActivity.kt b/vlc-android/src/org/videolan/vlc/gui/onboarding/OnboardingActivity.kt
index 500d6f74f..e63c30ca7 100644
--- a/vlc-android/src/org/videolan/vlc/gui/onboarding/OnboardingActivity.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/onboarding/OnboardingActivity.kt
@@ -88,12 +88,19 @@ class OnboardingActivity : AppCompatActivity(), ViewPager.OnPageChangeListener,
         }
 
         nextButton.setOnClickListener {
-            if (viewPager.currentItem == 0 && !viewModel.permissionGranted) {
-                checkPermissions()
-                return at setOnClickListener
-            }
-            if (viewPager.currentItem < viewPager.adapter!!.count) {
-                viewPager.currentItem = viewPager.currentItem + 1
+            launch {
+                if (viewPager.currentItem == 0 && !viewModel.permissionGranted) {
+                    viewModel.permissionGranted = Permissions.canReadStorage(applicationContext)
+                            || StoragePermissionsDelegate.getStoragePermission(this at OnboardingActivity, false)
+                    if (!viewModel.permissionGranted) {
+                        return at launch
+                    } else {
+                        viewPager.scrollEnabled = true
+                    }
+                }
+                if (viewPager.currentItem < viewPager.adapter!!.count) {
+                    viewPager.currentItem = viewPager.currentItem + 1
+                }
             }
         }
 
@@ -169,15 +176,6 @@ class OnboardingActivity : AppCompatActivity(), ViewPager.OnPageChangeListener,
         }
     }
 
-    fun checkPermissions() = launch {
-        if (StoragePermissionsDelegate.getStoragePermission(this at OnboardingActivity, false)) {
-            viewPager.currentItem = 1
-
-            viewPager.scrollEnabled = true
-            viewModel.permissionGranted = true
-        }
-    }
-
     override fun onPageScrollStateChanged(state: Int) { }
 
     override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {}



More information about the Android mailing list