summaryrefslogtreecommitdiff
path: root/app/src/main
diff options
context:
space:
mode:
authorDSIW <dsiw@dsiw-it.de>2016-06-10 04:50:24 +0200
committerDSIW <dsiw@dsiw-it.de>2016-06-10 04:50:56 +0200
commit7a25cbf1d69d74142e1f694481a8aebbb90ab466 (patch)
tree48c1b3b6425c0ed002eb37bb4b47a1a31a5bec0e /app/src/main
parent0e700ce21b042030f41d3c488807afb925461f08 (diff)
Fix multiple selection with RecyclerView
Diffstat (limited to 'app/src/main')
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/utils/PasswordRecyclerAdapter.java33
-rw-r--r--app/src/main/res/layout/password_recycler_view.xml2
-rw-r--r--app/src/main/res/layout/password_row_layout.xml2
-rw-r--r--app/src/main/res/values/colors.xml2
4 files changed, 21 insertions, 18 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 e1b33e2a..e9109bce 100644
--- a/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRecyclerAdapter.java
+++ b/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRecyclerAdapter.java
@@ -1,8 +1,8 @@
package com.zeapo.pwdstore.utils;
+import android.graphics.Color;
import android.os.Build;
import android.support.v7.view.ActionMode;
-import android.support.v7.widget.CardView;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.Menu;
@@ -91,7 +91,8 @@ public class PasswordRecyclerAdapter extends RecyclerView.Adapter<PasswordRecycl
@Override
public void onClick(View v) {
if (mActionMode != null) {
- toggleSelection(holder, holder.getAdapterPosition(), null, pass.getType());
+ toggleSelection(holder.getAdapterPosition());
+ mActionMode.setTitle("" + selectedItems.size());
if (selectedItems.isEmpty()) {
mActionMode.finish();
} else if (selectedItems.size() == 1 && !canEdit) {
@@ -106,6 +107,7 @@ public class PasswordRecyclerAdapter extends RecyclerView.Adapter<PasswordRecycl
} else {
listener.onFragmentInteraction(pass);
}
+ notifyItemChanged(holder.getAdapterPosition());
}
});
@@ -115,17 +117,27 @@ public class PasswordRecyclerAdapter extends RecyclerView.Adapter<PasswordRecycl
if (mActionMode != null) {
return false;
}
- toggleSelection(holder, holder.getAdapterPosition(), null, pass.getType());
+ toggleSelection(holder.getAdapterPosition());
canEdit = pass.getType() == PasswordItem.TYPE_PASSWORD;
// Start the CAB using the ActionMode.Callback
mActionMode = activity.startSupportActionMode(mActionModeCallback);
+ mActionMode.setTitle("" + selectedItems.size());
mActionMode.invalidate();
+ notifyItemChanged(holder.getAdapterPosition());
return true;
}
});
// after removal, everything is rebound for some reason; views are shuffled?
- holder.view.setSelected(selectedItems.contains(position));
+ boolean selected = selectedItems.contains(position);
+ holder.view.setSelected(selected);
+ if (selected) {
+ holder.itemView.setBackgroundResource(R.color.orange_200);
+ holder.type.setTextColor(Color.BLACK);
+ } else {
+ holder.itemView.setBackgroundResource(Color.alpha(1));
+ holder.type.setTextColor(activity.getColor(R.color.grey_500));
+ }
}
private ActionMode.Callback mActionModeCallback = new ActionMode.Callback() {
@@ -213,20 +225,9 @@ public class PasswordRecyclerAdapter extends RecyclerView.Adapter<PasswordRecycl
updateSelectedItems(position, selectedItems);
}
- public void toggleSelection(ViewHolder holder, int position, CardView card, char type) {
+ public void toggleSelection(int position) {
if (!selectedItems.remove(position)) {
selectedItems.add(position);
- if (type == PasswordItem.TYPE_CATEGORY) {
-// card.setCardBackgroundColor(activity.getResources().getColor(R.color.blue_grey_100));
- } else {
-// card.setCardBackgroundColor(activity.getResources().getColor(R.color.blue_grey_100));
- }
- } else {
- if (type == PasswordItem.TYPE_CATEGORY) {
-// card.setCardBackgroundColor(activity.getResources().getColor(R.color.blue_grey_200));
- } else {
-// card.setCardBackgroundColor(activity.getResources().getColor(R.color.blue_grey_50));
- }
}
}
diff --git a/app/src/main/res/layout/password_recycler_view.xml b/app/src/main/res/layout/password_recycler_view.xml
index 15a49597..14495ea9 100644
--- a/app/src/main/res/layout/password_recycler_view.xml
+++ b/app/src/main/res/layout/password_recycler_view.xml
@@ -21,7 +21,7 @@
android:layout_gravity="bottom|end"
app:elevation="6dp"
app:pressedTranslationZ="12dp"
- app:backgroundTint="@color/blue_grey_500"
+ app:backgroundTint="@color/accent"
app:rippleColor="@color/blue_grey_50"
app:borderWidth="0dp"
android:layout_margin="@dimen/fab_compat_margin"
diff --git a/app/src/main/res/layout/password_row_layout.xml b/app/src/main/res/layout/password_row_layout.xml
index ce69051c..5fd62249 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:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:layout_height="wrap_content">
+ android:background="?android:attr/activatedBackgroundIndicator">
<RelativeLayout
android:layout_width="match_parent"
diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml
index 0a789153..96ebf1bb 100644
--- a/app/src/main/res/values/colors.xml
+++ b/app/src/main/res/values/colors.xml
@@ -1,5 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
+ <color name="accent">#ff7043</color>
+
<color name="red_50">#fde0dc</color>
<color name="red_100">#f9bdbb</color>
<color name="red_200">#f69988</color>