[Android] Ask for permission if needed in ML settings

Geoffrey Métais git at videolan.org
Thu Apr 19 16:10:00 CEST 2018


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Apr 19 14:37:20 2018 +0200| [47b00642c6ca31fcca4b8669de5f75d494ec4d42] | committer: Geoffrey Métais

Ask for permission if needed in ML settings

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

 .../org/videolan/vlc/gui/preferences/PreferencesFragment.java  | 10 +++++-----
 .../videolan/vlc/gui/tv/preferences/PreferencesActivity.java   |  4 ++--
 .../videolan/vlc/gui/tv/preferences/PreferencesFragment.java   |  8 +++++---
 3 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesFragment.java b/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesFragment.java
index 6f03e8b23..ddfbf371b 100644
--- a/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesFragment.java
@@ -87,13 +87,13 @@ public class PreferencesFragment extends BasePreferenceFragment implements Share
             case "directories":
                 if (VLCApplication.getMLInstance().isWorking())
                     UiTools.snacker(getView(), getString(R.string.settings_ml_block_scan));
-                else {
-                    final FragmentActivity activity = getActivity();
-                    final Intent intent = new Intent(VLCApplication.getAppContext(), SecondaryActivity.class);
+                else if (Permissions.canReadStorage(requireContext())) {
+                    final FragmentActivity activity = requireActivity();
+                    final Intent intent = new Intent(activity.getApplicationContext(), SecondaryActivity.class);
                     intent.putExtra("fragment", SecondaryActivity.STORAGE_BROWSER);
                     startActivity(intent);
-                    if (activity != null) activity.setResult(PreferencesActivity.RESULT_RESTART);
-                }
+                    activity.setResult(PreferencesActivity.RESULT_RESTART);
+                } else Permissions.showStoragePermissionDialog(requireActivity(), false);
                 return true;
             case "ui_category":
                 loadFragment(new PreferencesUi());
diff --git a/vlc-android/src/org/videolan/vlc/gui/tv/preferences/PreferencesActivity.java b/vlc-android/src/org/videolan/vlc/gui/tv/preferences/PreferencesActivity.java
index 21f69cd38..90b84f6ae 100644
--- a/vlc-android/src/org/videolan/vlc/gui/tv/preferences/PreferencesActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/tv/preferences/PreferencesActivity.java
@@ -24,12 +24,12 @@
 package org.videolan.vlc.gui.tv.preferences;
 
 import android.annotation.TargetApi;
-import android.app.Activity;
 import android.content.Intent;
 import android.content.SharedPreferences;
 import android.os.Build;
 import android.os.Bundle;
 import android.preference.PreferenceManager;
+import android.support.v4.app.FragmentActivity;
 import android.view.MenuItem;
 
 import org.videolan.vlc.PlaybackService;
@@ -37,7 +37,7 @@ import org.videolan.vlc.R;
 
 @SuppressWarnings("deprecation")
 @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
-public class PreferencesActivity extends Activity implements PlaybackService.Client.Callback {
+public class PreferencesActivity extends FragmentActivity implements PlaybackService.Client.Callback {
 
     public final static String TAG = "VLC/PreferencesActivity";
 
diff --git a/vlc-android/src/org/videolan/vlc/gui/tv/preferences/PreferencesFragment.java b/vlc-android/src/org/videolan/vlc/gui/tv/preferences/PreferencesFragment.java
index 37c3190e0..2ad87e581 100644
--- a/vlc-android/src/org/videolan/vlc/gui/tv/preferences/PreferencesFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/tv/preferences/PreferencesFragment.java
@@ -27,6 +27,7 @@ import android.annotation.TargetApi;
 import android.content.Intent;
 import android.os.Build;
 import android.os.Bundle;
+import android.support.v4.app.FragmentActivity;
 import android.support.v7.preference.Preference;
 import android.widget.Toast;
 
@@ -34,6 +35,7 @@ import org.videolan.vlc.R;
 import org.videolan.vlc.VLCApplication;
 import org.videolan.vlc.gui.SecondaryActivity;
 import org.videolan.vlc.util.AndroidDevices;
+import org.videolan.vlc.util.Permissions;
 
 import static org.videolan.vlc.gui.preferences.PreferencesActivity.KEY_VIDEO_APP_SWITCH;
 
@@ -74,12 +76,12 @@ public class PreferencesFragment extends BasePreferenceFragment {
             case "directories":
                 if (VLCApplication.getMLInstance().isWorking())
                     Toast.makeText(getContext(), getString(R.string.settings_ml_block_scan), Toast.LENGTH_SHORT).show();
-                else {
-                    final Intent intent = new Intent(VLCApplication.getAppContext(), SecondaryActivity.class);
+                else if (Permissions.canReadStorage(getContext())) {
+                    final Intent intent = new Intent(getContext().getApplicationContext(), SecondaryActivity.class);
                     intent.putExtra("fragment", SecondaryActivity.STORAGE_BROWSER);
                     startActivity(intent);
                     getActivity().setResult(PreferencesActivity.RESULT_RESTART);
-                }
+                } else Permissions.showStoragePermissionDialog((FragmentActivity) getActivity(), false);
                 return true;
             case "ui_category":
                 loadFragment(new PreferencesUi());



More information about the Android mailing list