Probz360 has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/331957 )
Change subject: Prompt user before selected viewed items are deleted from history ...................................................................... Prompt user before selected viewed items are deleted from history When full history is deleted the user is prompted to confirm deletion, applied same functionality to when a single (or several) item(s) are selected for deletion to remain consistent. May be preferable to delete via async task, a little beyond my abilities, but happy to refactor on a larger effort if preferred. T103685 Change-Id: Ia0a7b24e02bbebe9ef95629218ad28a195fa1fbe --- M app/src/main/java/org/wikipedia/history/HistoryFragment.java M app/src/main/java/org/wikipedia/main/MainFragment.java M app/src/main/res/values/strings.xml 3 files changed, 41 insertions(+), 10 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/apps/android/wikipedia refs/changes/57/331957/1 diff --git a/app/src/main/java/org/wikipedia/history/HistoryFragment.java b/app/src/main/java/org/wikipedia/history/HistoryFragment.java index 3993d25..d5f4f42 100644 --- a/app/src/main/java/org/wikipedia/history/HistoryFragment.java +++ b/app/src/main/java/org/wikipedia/history/HistoryFragment.java @@ -50,6 +50,7 @@ public interface Callback { void onLoadPage(PageTitle title, HistoryEntry entry); void onClearHistory(); + void onSelectHistoryDelete(ActionMode mode); } private ListView historyEntryList; @@ -62,6 +63,7 @@ private String currentSearchQuery; private LoaderCallback loaderCallback; + private SparseBooleanArray checkedItems; private ActionMode actionMode; private SearchActionModeCallback searchActionModeCallback = new HistorySearchCallback(); @@ -275,18 +277,30 @@ } @Override - public boolean onActionItemClicked(ActionMode mode, MenuItem item) { + public boolean onActionItemClicked(final ActionMode mode, MenuItem item) { if (item.getItemId() == R.id.menu_delete_selected_history) { - SparseBooleanArray checkedItems = historyEntryList.getCheckedItemPositions(); - for (int i = 0; i < checkedItems.size(); i++) { - if (checkedItems.valueAt(i)) { - app.getDatabaseClient(HistoryEntry.class).delete( - HistoryEntry.DATABASE_TABLE.fromCursor((Cursor) adapter.getItem(checkedItems.keyAt(i))), - PageHistoryContract.PageWithImage.SELECTION); - } - } - mode.finish(); + checkedItems = historyEntryList.getCheckedItemPositions(); + new AlertDialog.Builder(getContext()) + .setTitle(R.string.dialog_title_delete_selected_history) + .setMessage(R.string.dialog_message_delete_selected_history) + .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + // Clear selected history + for (int i = 0; i < checkedItems.size(); i++) { + if (checkedItems.valueAt(i)) { + app.getDatabaseClient(HistoryEntry.class).delete( + HistoryEntry.DATABASE_TABLE.fromCursor((Cursor) adapter.getItem(checkedItems.keyAt(i))), + PageHistoryContract.PageWithImage.SELECTION); + } + } + + onSelectHistoryDelete(mode); + } + }) + .setNegativeButton(R.string.no, null).create().show(); return true; + } else { throw new RuntimeException("Unknown context menu item clicked"); } @@ -358,6 +372,14 @@ } } + private void onSelectHistoryDelete(ActionMode mode) { + Callback callback = callback(); + if (callback != null) { + callback.onSelectHistoryDelete(mode); + } + mode.finish(); + } + private void restartLoader() { getActivity().getSupportLoaderManager().restartLoader(HISTORY_FRAGMENT_LOADER_ID, null, loaderCallback); } @@ -398,4 +420,5 @@ @Nullable private Callback callback() { return FragmentUtil.getCallback(this, Callback.class); } + } diff --git a/app/src/main/java/org/wikipedia/main/MainFragment.java b/app/src/main/java/org/wikipedia/main/MainFragment.java index b77aac2..f967e71 100644 --- a/app/src/main/java/org/wikipedia/main/MainFragment.java +++ b/app/src/main/java/org/wikipedia/main/MainFragment.java @@ -19,6 +19,7 @@ import android.support.design.widget.TabLayout; import android.support.v4.app.Fragment; import android.support.v4.view.ViewPager; +import android.support.v7.view.ActionMode; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -305,6 +306,11 @@ } @Override + public void onSelectHistoryDelete(ActionMode mode) { + // todo: [overhaul] clear history. + } + + @Override public void onSearchResultCopyLink(@NonNull PageTitle title) { copyLink(title.getCanonicalUri()); } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 246e75d..41af593 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -23,6 +23,8 @@ <string name="nav_item_saved_pages">Saved pages</string> <string name="share_via">Share via</string> <string name="search_redirect_from">Redirected from %s</string> + <string name="dialog_title_delete_selected_history">Clear selected browsing history</string> + <string name="dialog_message_delete_selected_history">This will delete your selected browsing history. Are you sure?</string> <!-- Page toolbar menu --> <string name="menu_page_show_tabs">Show tabs</string> -- To view, visit https://gerrit.wikimedia.org/r/331957 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ia0a7b24e02bbebe9ef95629218ad28a195fa1fbe Gerrit-PatchSet: 1 Gerrit-Project: apps/android/wikipedia Gerrit-Branch: master Gerrit-Owner: Probz360 <probz...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits