diff options
author | Martin Fietz <Martin.Fietz@gmail.com> | 2016-02-02 09:39:23 +0100 |
---|---|---|
committer | Martin Fietz <Martin.Fietz@gmail.com> | 2016-02-03 19:36:01 +0100 |
commit | eba11a9fe57dea3b16c77853b923023f9bf229eb (patch) | |
tree | 9d33e3e011d0fcd86e214104643da423c4d958cb | |
parent | 9077ad6b3d5a72060895a1559f6cd98e6169577d (diff) | |
download | AntennaPod-eba11a9fe57dea3b16c77853b923023f9bf229eb.zip |
Show restricted choose data folder dialog only on Lollipop; ask for permission on Marshmallow
3 files changed, 37 insertions, 5 deletions
diff --git a/app/src/main/java/de/danoeh/antennapod/activity/StorageErrorActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/StorageErrorActivity.java index 870983b97..e980764ec 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/StorageErrorActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/StorageErrorActivity.java @@ -6,6 +6,7 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; +import android.content.pm.PackageManager; import android.os.Build; import android.os.Bundle; import android.support.v4.app.ActivityCompat; @@ -33,6 +34,11 @@ public class StorageErrorActivity extends AppCompatActivity { private static final String TAG = "StorageErrorActivity"; + private static final String[] EXTERNAL_STORAGE_PERMISSIONS = { + Manifest.permission.READ_EXTERNAL_STORAGE, + Manifest.permission.WRITE_EXTERNAL_STORAGE }; + private static final int PERMISSION_REQUEST_EXTERNAL_STORAGE = 42; + @Override protected void onCreate(Bundle savedInstanceState) { setTheme(UserPreferences.getTheme()); @@ -174,10 +180,15 @@ public class StorageErrorActivity extends AppCompatActivity { public void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == Activity.RESULT_OK && requestCode == DirectoryChooserActivity.RESULT_CODE_DIR_SELECTED) { - String dir = data.getStringExtra(DirectoryChooserActivity.RESULT_SELECTED_DIR); + String dir = data.getStringExtra(DirectoryChooserActivity.RESULT_SELECTED_DIR); - File path = new File(dir); - String message = null; + File path; + if (dir != null) { + path = new File(dir); + } else { + path = getExternalFilesDir(null); + } + String message = null; if(!path.exists()) { message = String.format(getString(R.string.folder_does_not_exist_error), dir); } else if(!path.canRead()) { diff --git a/app/src/main/java/de/danoeh/antennapod/preferences/PreferenceController.java b/app/src/main/java/de/danoeh/antennapod/preferences/PreferenceController.java index 3bf16e51c..1b8787a8d 100644 --- a/app/src/main/java/de/danoeh/antennapod/preferences/PreferenceController.java +++ b/app/src/main/java/de/danoeh/antennapod/preferences/PreferenceController.java @@ -1,11 +1,13 @@ package de.danoeh.antennapod.preferences; +import android.Manifest; import android.annotation.SuppressLint; import android.app.Activity; import android.app.TimePickerDialog; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; +import android.content.pm.PackageManager; import android.content.res.Resources; import android.net.Uri; import android.net.wifi.WifiConfiguration; @@ -85,6 +87,11 @@ public class PreferenceController implements SharedPreferences.OnSharedPreferenc private CheckBoxPreference[] selectedNetworks; + private static final String[] EXTERNAL_STORAGE_PERMISSIONS = { + Manifest.permission.READ_EXTERNAL_STORAGE, + Manifest.permission.WRITE_EXTERNAL_STORAGE }; + private static final int PERMISSION_REQUEST_EXTERNAL_STORAGE = 41; + public PreferenceController(PreferenceUI ui) { this.ui = ui; PreferenceManager.getDefaultSharedPreferences(ui.getActivity().getApplicationContext()) @@ -182,8 +189,8 @@ public class PreferenceController implements SharedPreferences.OnSharedPreferenc } return true; } - } - ); + } + ); ui.findPreference(UserPreferences.PREF_THEME) .setOnPreferenceChangeListener( (preference, newValue) -> { @@ -670,6 +677,19 @@ public class PreferenceController implements SharedPreferences.OnSharedPreferenc builder.create().show(); } + // CHOOSE DATA FOLDER + + private void requestPermission() { + ActivityCompat.requestPermissions(ui.getActivity(), EXTERNAL_STORAGE_PERMISSIONS, + PERMISSION_REQUEST_EXTERNAL_STORAGE); + } + + private void openDirectoryChooser() { + Activity activity = ui.getActivity(); + Intent intent = new Intent(activity, DirectoryChooserActivity.class); + activity.startActivityForResult(intent, DirectoryChooserActivity.RESULT_CODE_DIR_SELECTED); + } + private void showChooseDataFolderDialog() { Context context = ui.getActivity(); File dataFolder = UserPreferences.getDataFolder(null); diff --git a/core/src/main/res/values/strings.xml b/core/src/main/res/values/strings.xml index 7f2599474..912a60f55 100644 --- a/core/src/main/res/values/strings.xml +++ b/core/src/main/res/values/strings.xml @@ -485,6 +485,7 @@ <string name="create_folder_label">Create folder</string> <string name="choose_data_directory">Choose Data Folder</string> <string name="choose_data_directory_message">Please choose the base of your data folder. AntennaPod will create the appropriate sub-directories.</string> + <string name="choose_data_directory_permission_rationale">Access to external storage is required to change the data folder</string> <string name="create_folder_msg">Create new folder with name "%1$s"?</string> <string name="create_folder_success">Created new folder</string> <string name="create_folder_error_no_write_access">Cannot write to this folder</string> |