From 483dc06ecbdce8d7efe6c240ae040aed3376b299 Mon Sep 17 00:00:00 2001 From: Spinhit Date: Mon, 22 Mar 2021 11:45:33 +0100 Subject: [PATCH] Add confirmation button before deleting all files. Co-authored-by: TiA4f8R <74829229+TiA4f8R@users.noreply.github.com> --- .../giga/ui/fragment/MissionsFragment.java | 35 ++++++++++++++----- app/src/main/res/values/strings.xml | 1 + 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/us/shandian/giga/ui/fragment/MissionsFragment.java b/app/src/main/java/us/shandian/giga/ui/fragment/MissionsFragment.java index dda2d6dee..b5fc0297c 100644 --- a/app/src/main/java/us/shandian/giga/ui/fragment/MissionsFragment.java +++ b/app/src/main/java/us/shandian/giga/ui/fragment/MissionsFragment.java @@ -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); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 8b8945b40..f004a676a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -580,6 +580,7 @@ Clear download history Do you want to clear your download history or delete all downloaded files? Delete downloaded files + Erase all downloaded files from disk? Deleted %1$s download Deleted %1$s downloads