1
0
mirror of https://github.com/TeamNewPipe/NewPipe.git synced 2024-11-22 02:53:09 +01:00

Merge pull request #5878 from SpinHit/spinhit/addingDeleteConfirmation

Add a confirmation button when deleting all files in downloader
This commit is contained in:
litetex 2022-03-15 21:49:46 +01:00 committed by GitHub
commit f47f2d13fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 8 deletions

View File

@ -192,14 +192,7 @@ public class MissionsFragment extends Fragment {
updateList();
return true;
case R.id.clear_list:
AlertDialog.Builder prompt = new AlertDialog.Builder(mContext);
prompt.setTitle(R.string.clear_download_history);
prompt.setMessage(R.string.confirm_prompt);
// Intentionally misusing button's purpose in order to achieve good order
prompt.setNegativeButton(R.string.clear_download_history, (dialog, which) -> mAdapter.clearFinishedDownloads(false));
prompt.setPositiveButton(R.string.delete_downloaded_files, (dialog, which) -> mAdapter.clearFinishedDownloads(true));
prompt.setNeutralButton(R.string.cancel, null);
prompt.create().show();
showClearDownloadHistoryPrompt();
return true;
case R.id.start_downloads:
mBinder.getDownloadManager().startAllMissions();
@ -212,6 +205,32 @@ public class MissionsFragment extends Fragment {
}
}
public void showClearDownloadHistoryPrompt() {
// ask the user whether he wants to just clear history or instead delete files on disk
new AlertDialog.Builder(mContext)
.setTitle(R.string.clear_download_history)
.setMessage(R.string.confirm_prompt)
// Intentionally misusing buttons' purpose in order to achieve good order
.setNegativeButton(R.string.clear_download_history,
(dialog, which) -> mAdapter.clearFinishedDownloads(false))
.setNeutralButton(R.string.cancel, null)
.setPositiveButton(R.string.delete_downloaded_files,
(dialog, which) -> showDeleteDownloadedFilesConfirmationPrompt())
.create()
.show();
}
public void showDeleteDownloadedFilesConfirmationPrompt() {
// make sure the user confirms once more before deleting files on disk
new AlertDialog.Builder(mContext)
.setTitle(R.string.delete_downloaded_files_confirm)
.setNegativeButton(R.string.cancel, null)
.setPositiveButton(R.string.ok,
(dialog, which) -> mAdapter.clearFinishedDownloads(true))
.create()
.show();
}
private void updateList() {
if (mLinear) {
mList.setLayoutManager(mLinearManager);

View File

@ -579,6 +579,7 @@
<string name="clear_download_history">Clear download history</string>
<string name="confirm_prompt">Do you want to clear your download history or delete all downloaded files?</string>
<string name="delete_downloaded_files">Delete downloaded files</string>
<string name="delete_downloaded_files_confirm">Erase all downloaded files from disk?</string>
<plurals name="deleted_downloads_toast">
<item quantity="one">Deleted %1$s download</item>
<item quantity="other">Deleted %1$s downloads</item>