From 84b5da3ada3b3859153c8a8e709f5c7adc8a7bd0 Mon Sep 17 00:00:00 2001 From: Matthew Wong Date: Wed, 1 Jul 2015 01:49:02 -0400 Subject: Implement multi-select with actionbar --- .../pwdstore/utils/PasswordRecyclerAdapter.java | 88 ++++++++++++++++++---- 1 file changed, 73 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRecyclerAdapter.java b/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRecyclerAdapter.java index 2bcfd7ef..e72b9e07 100644 --- a/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRecyclerAdapter.java +++ b/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRecyclerAdapter.java @@ -1,10 +1,14 @@ package com.zeapo.pwdstore.utils; import android.graphics.Color; +import android.support.v7.app.AppCompatActivity; +import android.support.v7.view.ActionMode; import android.support.v7.widget.PopupMenu; import android.support.v7.widget.RecyclerView; import android.util.Log; +import android.util.SparseBooleanArray; import android.view.LayoutInflater; +import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; @@ -20,6 +24,8 @@ public class PasswordRecyclerAdapter extends RecyclerView.Adapter values; private final PasswordFragment.OnFragmentInteractionListener listener; + private final SparseBooleanArray selectedItems; + private ActionMode mActionMode; // Provide a reference to the views for each data item // Complex data items may need more than one view per item, and @@ -44,6 +50,7 @@ public class PasswordRecyclerAdapter extends RecyclerView.Adapter Date: Wed, 1 Jul 2015 01:50:12 -0400 Subject: Selected rows color --- .../main/res/drawable/password_row_background.xml | 5 +++++ app/src/main/res/drawable/selected_rectangle.xml | 21 +++++++++++++++++++++ app/src/main/res/layout/password_row_layout.xml | 2 +- 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 app/src/main/res/drawable/password_row_background.xml create mode 100644 app/src/main/res/drawable/selected_rectangle.xml diff --git a/app/src/main/res/drawable/password_row_background.xml b/app/src/main/res/drawable/password_row_background.xml new file mode 100644 index 00000000..8f39b056 --- /dev/null +++ b/app/src/main/res/drawable/password_row_background.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/selected_rectangle.xml b/app/src/main/res/drawable/selected_rectangle.xml new file mode 100644 index 00000000..bd3c40ae --- /dev/null +++ b/app/src/main/res/drawable/selected_rectangle.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/password_row_layout.xml b/app/src/main/res/layout/password_row_layout.xml index ab6f31af..99ee58eb 100644 --- a/app/src/main/res/layout/password_row_layout.xml +++ b/app/src/main/res/layout/password_row_layout.xml @@ -3,7 +3,7 @@ xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" - android:background="@drawable/rectangle" + android:background="@drawable/password_row_background" android:layout_marginTop="4dp" android:layout_marginBottom="4dp" android:layout_gravity="start|center_vertical"> -- cgit v1.2.3 From 6d0abdcad2288ff751c6b5ad195a314c812491c0 Mon Sep 17 00:00:00 2001 From: Matthew Wong Date: Wed, 1 Jul 2015 02:33:23 -0400 Subject: Finish action bar mode when all items are deselected --- .../main/java/com/zeapo/pwdstore/utils/PasswordRecyclerAdapter.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRecyclerAdapter.java b/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRecyclerAdapter.java index e72b9e07..5ad1b890 100644 --- a/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRecyclerAdapter.java +++ b/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRecyclerAdapter.java @@ -98,6 +98,9 @@ public class PasswordRecyclerAdapter extends RecyclerView.Adapter Date: Wed, 1 Jul 2015 19:31:11 -0400 Subject: Make selectedItems Set instead of SparseBooleanArray --- .../pwdstore/utils/PasswordRecyclerAdapter.java | 32 +++++++++------------- app/src/main/res/drawable/selected_rectangle.xml | 2 +- 2 files changed, 14 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRecyclerAdapter.java b/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRecyclerAdapter.java index 5ad1b890..857c8276 100644 --- a/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRecyclerAdapter.java +++ b/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRecyclerAdapter.java @@ -1,12 +1,9 @@ package com.zeapo.pwdstore.utils; import android.graphics.Color; -import android.support.v7.app.AppCompatActivity; import android.support.v7.view.ActionMode; -import android.support.v7.widget.PopupMenu; import android.support.v7.widget.RecyclerView; import android.util.Log; -import android.util.SparseBooleanArray; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuItem; @@ -19,12 +16,14 @@ import com.zeapo.pwdstore.PasswordStore; import com.zeapo.pwdstore.R; import java.util.ArrayList; +import java.util.Set; +import java.util.TreeSet; public class PasswordRecyclerAdapter extends RecyclerView.Adapter { private final PasswordStore activity; private final ArrayList values; private final PasswordFragment.OnFragmentInteractionListener listener; - private final SparseBooleanArray selectedItems; + private final Set selectedItems; private ActionMode mActionMode; // Provide a reference to the views for each data item @@ -50,7 +49,7 @@ public class PasswordRecyclerAdapter extends RecyclerView.Adapter(); } // Create new views (invoked by the layout manager) @@ -98,7 +97,7 @@ public class PasswordRecyclerAdapter extends RecyclerView.Adapter - + -- cgit v1.2.3