mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2024-11-16 06:44:55 +00:00
bugs fixes
* fix storage warning dialogs created on invalid contexts * implement mkdirs in StoredDirectoryHelper
This commit is contained in:
parent
cdc8fe86ce
commit
ac5e2e0532
@ -217,6 +217,32 @@ public class DownloadDialog extends DialogFragment implements RadioGroup.OnCheck
|
|||||||
okButton.setEnabled(true);
|
okButton.setEnabled(true);
|
||||||
|
|
||||||
context.unbindService(this);
|
context.unbindService(this);
|
||||||
|
|
||||||
|
// check of download paths are defined
|
||||||
|
if (!askForSavePath) {
|
||||||
|
String msg = "";
|
||||||
|
if (mainStorageVideo == null) msg += getString(R.string.download_path_title);
|
||||||
|
if (mainStorageAudio == null)
|
||||||
|
msg += getString(R.string.download_path_audio_title);
|
||||||
|
|
||||||
|
if (!msg.isEmpty()) {
|
||||||
|
String title;
|
||||||
|
if (mainStorageVideo == null && mainStorageAudio == null) {
|
||||||
|
title = getString(R.string.general_error);
|
||||||
|
msg = getString(R.string.no_available_dir) + ":\n" + msg;
|
||||||
|
} else {
|
||||||
|
title = msg;
|
||||||
|
msg = getString(R.string.no_available_dir);
|
||||||
|
}
|
||||||
|
|
||||||
|
new AlertDialog.Builder(context)
|
||||||
|
.setPositiveButton(android.R.string.ok, null)
|
||||||
|
.setTitle(title)
|
||||||
|
.setMessage(msg)
|
||||||
|
.create()
|
||||||
|
.show();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -520,6 +546,7 @@ public class DownloadDialog extends DialogFragment implements RadioGroup.OnCheck
|
|||||||
|
|
||||||
private void showFailedDialog(@StringRes int msg) {
|
private void showFailedDialog(@StringRes int msg) {
|
||||||
new AlertDialog.Builder(context)
|
new AlertDialog.Builder(context)
|
||||||
|
.setTitle(R.string.general_error)
|
||||||
.setMessage(msg)
|
.setMessage(msg)
|
||||||
.setNegativeButton(android.R.string.ok, null)
|
.setNegativeButton(android.R.string.ok, null)
|
||||||
.create()
|
.create()
|
||||||
@ -631,6 +658,12 @@ public class DownloadDialog extends DialogFragment implements RadioGroup.OnCheck
|
|||||||
// This part is called if:
|
// This part is called if:
|
||||||
// * the filename is not used in a pending/finished download
|
// * the filename is not used in a pending/finished download
|
||||||
// * the file does not exists, create
|
// * the file does not exists, create
|
||||||
|
|
||||||
|
if (!mainStorage.mkdirs()) {
|
||||||
|
showFailedDialog(R.string.error_path_creation);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
storage = mainStorage.createFile(filename, mime);
|
storage = mainStorage.createFile(filename, mime);
|
||||||
if (storage == null || !storage.canWrite()) {
|
if (storage == null || !storage.canWrite()) {
|
||||||
showFailedDialog(R.string.error_file_creation);
|
showFailedDialog(R.string.error_file_creation);
|
||||||
|
@ -1195,7 +1195,7 @@ public class VideoDetailFragment
|
|||||||
downloadDialog.setSelectedVideoStream(selectedVideoStreamIndex);
|
downloadDialog.setSelectedVideoStream(selectedVideoStreamIndex);
|
||||||
downloadDialog.setSubtitleStreams(currentInfo.getSubtitles());
|
downloadDialog.setSubtitleStreams(currentInfo.getSubtitles());
|
||||||
|
|
||||||
downloadDialog.show(activity.getSupportFragmentManager(), "downloadDialog");
|
downloadDialog.show(getActivity().getSupportFragmentManager(), "downloadDialog");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
ErrorActivity.ErrorInfo info = ErrorActivity.ErrorInfo.make(UserAction.UI_ERROR,
|
ErrorActivity.ErrorInfo info = ErrorActivity.ErrorInfo.make(UserAction.UI_ERROR,
|
||||||
ServiceList.all()
|
ServiceList.all()
|
||||||
|
@ -144,6 +144,52 @@ public class StoredDirectoryHelper {
|
|||||||
return docTree == null ? ioTree.exists() : docTree.exists();
|
return docTree == null ? ioTree.exists() : docTree.exists();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates whatever if is possible access using the {@code java.io} API
|
||||||
|
*
|
||||||
|
* @return {@code true} for Java I/O API, otherwise, {@code false} for Storage Access Framework
|
||||||
|
*/
|
||||||
|
public boolean isDirect() {
|
||||||
|
return docTree == null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Only using Java I/O. Creates the directory named by this abstract pathname, including any
|
||||||
|
* necessary but nonexistent parent directories. Note that if this
|
||||||
|
* operation fails it may have succeeded in creating some of the necessary
|
||||||
|
* parent directories.
|
||||||
|
*
|
||||||
|
* @return <code>true</code> if and only if the directory was created,
|
||||||
|
* along with all necessary parent directories or already exists; <code>false</code>
|
||||||
|
* otherwise
|
||||||
|
*/
|
||||||
|
public boolean mkdirs() {
|
||||||
|
if (docTree == null) {
|
||||||
|
return ioTree.exists() || ioTree.mkdirs();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (docTree.exists()) return true;
|
||||||
|
|
||||||
|
try {
|
||||||
|
DocumentFile parent;
|
||||||
|
String child = docTree.getName();
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
parent = docTree.getParentFile();
|
||||||
|
if (parent == null || child == null) break;
|
||||||
|
if (parent.exists()) return true;
|
||||||
|
|
||||||
|
parent.createDirectory(child);
|
||||||
|
|
||||||
|
child = parent.getName();// for the next iteration
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
// no more parent directories or unsupported by the storage provider
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public String getTag() {
|
public String getTag() {
|
||||||
return tag;
|
return tag;
|
||||||
}
|
}
|
||||||
|
@ -270,33 +270,6 @@ public class DownloadManagerService extends Service {
|
|||||||
Toast.makeText(this, "Permission denied (write)", Toast.LENGTH_SHORT).show();
|
Toast.makeText(this, "Permission denied (write)", Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check download save paths
|
|
||||||
|
|
||||||
String msg = "";
|
|
||||||
if (mManager.mMainStorageVideo == null)
|
|
||||||
msg += getString(R.string.download_path_title);
|
|
||||||
else if (mManager.mMainStorageAudio == null)
|
|
||||||
msg += getString(R.string.download_path_audio_title);
|
|
||||||
|
|
||||||
if (!msg.isEmpty()) {
|
|
||||||
String title;
|
|
||||||
if (mManager.mMainStorageVideo == null && mManager.mMainStorageAudio == null) {
|
|
||||||
title = getString(R.string.general_error);
|
|
||||||
msg = getString(R.string.no_available_dir) + ":\n" + msg;
|
|
||||||
} else {
|
|
||||||
title = msg;
|
|
||||||
msg = getString(R.string.no_available_dir);
|
|
||||||
}
|
|
||||||
|
|
||||||
new AlertDialog.Builder(this)
|
|
||||||
.setPositiveButton(android.R.string.ok, null)
|
|
||||||
.setTitle(title)
|
|
||||||
.setMessage(msg)
|
|
||||||
.create()
|
|
||||||
.show();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return mBinder;
|
return mBinder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user