Add confirmation button before deleting all files.

Co-authored-by: TiA4f8R <74829229+TiA4f8R@users.noreply.github.com>
This commit is contained in:
Spinhit 2021-03-22 11:45:33 +01:00 committed by Stypox
parent b8e389c6e8
commit 483dc06ecb
No known key found for this signature in database
GPG Key ID: 4BDF1B40A49FDD23
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

@ -580,6 +580,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>