Simplify the storage APIs use

* use Java I/O (classic way) on older android versions
* use Storage Access Framework on newer android versions (Android Lollipop or later)
* both changes have the external SD Card write permission
* add option to ask the save path on each download
* warn the user if the save paths are not defined, this only happens on the first NewPipe run (Android Lollipop or later)
This commit is contained in:
kapodamy 2019-04-19 16:18:19 -03:00
parent d9fb7cb420
commit b92b434e2c
9 changed files with 119 additions and 182 deletions

View file

@ -212,6 +212,7 @@ public class DownloadDialog extends DialogFragment implements RadioGroup.OnCheck
mainStorageAudio = mgr.getMainStorageAudio();
mainStorageVideo = mgr.getMainStorageVideo();
downloadManager = mgr.getDownloadManager();
askForSavePath = mgr.askForSavePath();
okButton.setEnabled(true);
@ -509,6 +510,7 @@ public class DownloadDialog extends DialogFragment implements RadioGroup.OnCheck
DownloadManager downloadManager = null;
ActionMenuItemView okButton = null;
Context context;
boolean askForSavePath;
private String getNameEditText() {
String str = nameEditText.getText().toString().trim();
@ -567,10 +569,11 @@ public class DownloadDialog extends DialogFragment implements RadioGroup.OnCheck
throw new RuntimeException("No stream selected");
}
if (mainStorage == null) {
if (mainStorage == null || askForSavePath) {
// This part is called if with SAF preferred:
// * older android version running
// * save path not defined (via download settings)
// * the user as checked the "ask where to download" option
StoredFileHelper.requestSafWithFileCreation(this, REQUEST_DOWNLOAD_PATH_SAF, filename, mime);
return;