Alex Monk has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/169547

Change subject: Allow the user to delete individual history entries
......................................................................

Allow the user to delete individual history entries

Borrows a lot of code from saved pages

Change-Id: I238fb388203d61edf0cd6904c401b687a062e0f5
---
A wikipedia/res/menu/menu_history_context.xml
M wikipedia/res/values-qq/strings.xml
M wikipedia/res/values/strings.xml
M 
wikipedia/src/main/java/org/wikipedia/history/HistoryEntryPersistanceHelper.java
M wikipedia/src/main/java/org/wikipedia/history/HistoryFragment.java
5 files changed, 78 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/apps/android/wikipedia 
refs/changes/47/169547/1

diff --git a/wikipedia/res/menu/menu_history_context.xml 
b/wikipedia/res/menu/menu_history_context.xml
new file mode 100644
index 0000000..60c5ac9
--- /dev/null
+++ b/wikipedia/res/menu/menu_history_context.xml
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<menu xmlns:android="http://schemas.android.com/apk/res/android";
+    xmlns:app="http://schemas.android.com/apk/res-auto";
+    >
+    <item android:id="@+id/menu_delete_selected_history"
+        android:icon="@drawable/ic_delete"
+        android:title="@string/delete_selected_history"
+        app:showAsAction="always" />
+</menu>
\ No newline at end of file
diff --git a/wikipedia/res/values-qq/strings.xml 
b/wikipedia/res/values-qq/strings.xml
index 23a5e31..a9c8c71 100644
--- a/wikipedia/res/values-qq/strings.xml
+++ b/wikipedia/res/values-qq/strings.xml
@@ -152,6 +152,8 @@
   <string name="saved_pages_empty_message">Brief explanation of what saved 
pages are, and their benefits.</string>
   <string name="history_empty_title">Used in \"Browsing history\" page if 
there is nothing to show.</string>
   <string name="history_empty_message">Brief explanation that there are 
currently no History entries to look at. Just to fill an empty screen. This 
usually happens when a user just deleted history entries.</string>
+  <string name="delete_selected_history">Menu item text for deleting the 
currently selected history entries
+{{Identical|Delete}}</string>
   <string name="wp_stylized">A stylized string saying \"Wikipedia\". Used 
before wp_tag_line if no image representation exists. Usually the first and 
last characters are within big tags, if this fits the Wikipedia logo in your 
language.</string>
   <string name="wp_tag_line">The Wikipedia slogan. The second line of 
https://commons.wikimedia.org/wiki/Wikimedia#mediaviewer/File:Wikipedia-logo-en.png.
 You may be able to find one under 
https://commons.wikimedia.org/wiki/Wikipedia/2.0.</string>
   <string name="skip">A button or text link to trigger skipping something, 
like closing the current screen without doing anything.
diff --git a/wikipedia/res/values/strings.xml b/wikipedia/res/values/strings.xml
index 9f5d8be..e2b2dd8 100644
--- a/wikipedia/res/values/strings.xml
+++ b/wikipedia/res/values/strings.xml
@@ -113,6 +113,7 @@
     <string name="saved_pages_empty_message">Saved pages are pretty awesome. 
Think of them as bookmarks that you can read even when you are offline.</string>
     <string name="history_empty_title">No recent pages here!</string>
     <string name="history_empty_message">You probably deleted all of them. 
Next time you go to a page you can get back to it from here.</string>
+    <string name="delete_selected_history">Delete</string>
     <string 
name="wp_stylized"><![CDATA[<big>W</big>IKIPEDI<big>A</big>]]></string>
     <string name="wp_tag_line">The Free Encyclopedia</string>
     <string name="skip">Skip</string>
diff --git 
a/wikipedia/src/main/java/org/wikipedia/history/HistoryEntryPersistanceHelper.java
 
b/wikipedia/src/main/java/org/wikipedia/history/HistoryEntryPersistanceHelper.java
index 4cd0fc4..b07c55c 100644
--- 
a/wikipedia/src/main/java/org/wikipedia/history/HistoryEntryPersistanceHelper.java
+++ 
b/wikipedia/src/main/java/org/wikipedia/history/HistoryEntryPersistanceHelper.java
@@ -59,11 +59,15 @@
 
     @Override
     protected String getPrimaryKeySelection() {
-        throw new UnsupportedOperationException("No Primary Keys make sense 
for History");
+        return "site = ? AND title = ? AND timestamp = ?";
     }
 
     @Override
     protected String[] getPrimaryKeySelectionArgs(HistoryEntry obj) {
-        throw new UnsupportedOperationException("No Primary Keys make sense 
for History");
+        return new String[] {
+            obj.getTitle().getSite().getDomain(),
+            obj.getTitle().getPrefixedText(),
+            Long.toString(obj.getTimestamp().getTime())
+        };
     }
 }
diff --git a/wikipedia/src/main/java/org/wikipedia/history/HistoryFragment.java 
b/wikipedia/src/main/java/org/wikipedia/history/HistoryFragment.java
index 152b116..a065c53 100644
--- a/wikipedia/src/main/java/org/wikipedia/history/HistoryFragment.java
+++ b/wikipedia/src/main/java/org/wikipedia/history/HistoryFragment.java
@@ -11,14 +11,19 @@
 import android.support.v4.content.CursorLoader;
 import android.support.v4.content.Loader;
 import android.support.v4.widget.CursorAdapter;
+import android.support.v7.app.ActionBarActivity;
+import android.support.v7.view.ActionMode;
 import android.text.Editable;
 import android.text.TextWatcher;
+import android.util.SparseBooleanArray;
 import android.view.*;
+import android.widget.AbsListView;
 import android.widget.AdapterView;
 import android.widget.EditText;
 import android.widget.ImageView;
 import android.widget.ListView;
 import android.widget.TextView;
+
 import com.squareup.picasso.Picasso;
 import org.wikipedia.R;
 import org.wikipedia.WikipediaApp;
@@ -40,6 +45,8 @@
     private EditText entryFilter;
 
     private WikipediaApp app;
+
+    private ActionMode actionMode;
 
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
@@ -102,6 +109,58 @@
             }
         });
 
+        historyEntryList.setOnItemLongClickListener(new 
AdapterView.OnItemLongClickListener() {
+            @Override
+            public boolean onItemLongClick(AdapterView<?> parent, View view, 
int position, long id) {
+                if (actionMode != null) {
+                    return false;
+                }
+                
historyEntryList.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE);
+                actionMode = 
((ActionBarActivity)getActivity()).startSupportActionMode(new 
ActionMode.Callback() {
+                    @Override
+                    public boolean onCreateActionMode(ActionMode mode, Menu 
menu) {
+                        
mode.getMenuInflater().inflate(R.menu.menu_history_context, menu);
+                        return true;
+                    }
+
+                    @Override
+                    public boolean onPrepareActionMode(ActionMode mode, Menu 
menu) {
+                        return false;
+                    }
+
+                    @Override
+                    public boolean onActionItemClicked(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.getPersister(HistoryEntry.class).delete(
+                                        
HistoryEntry.PERSISTANCE_HELPER.fromCursor((Cursor) 
adapter.getItem(checkedItems.keyAt(i)))
+                                    );
+                                }
+                            }
+                            actionMode.finish();
+                            return true;
+                        } else {
+                            // This can't happen
+                            throw new RuntimeException("Unknown context menu 
item clicked");
+                        }
+                    }
+
+                    @Override
+                    public void onDestroyActionMode(ActionMode mode) {
+                        
historyEntryList.setChoiceMode(AbsListView.CHOICE_MODE_SINGLE);
+                        actionMode = null;
+                        // Clear all selections
+                        historyEntryList.clearChoices();
+                        historyEntryList.requestLayout(); // Required to 
immediately redraw unchecked states
+                    }
+                });
+                historyEntryList.setItemChecked(position, true);
+                return true;
+            }
+        });
+
         getActivity().getSupportLoaderManager().initLoader(LOADER_ID, null, 
this);
         getActivity().getSupportLoaderManager().restartLoader(LOADER_ID, null, 
this);
     }

-- 
To view, visit https://gerrit.wikimedia.org/r/169547
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I238fb388203d61edf0cd6904c401b687a062e0f5
Gerrit-PatchSet: 1
Gerrit-Project: apps/android/wikipedia
Gerrit-Branch: master
Gerrit-Owner: Alex Monk <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to