Restyle password cards

This commit is contained in:
DSIW 2016-06-10 03:13:09 +02:00
parent f6f0576caf
commit b36d082b9f
3 changed files with 57 additions and 48 deletions

View file

@ -71,19 +71,18 @@ public class PasswordRecyclerAdapter extends RecyclerView.Adapter<PasswordRecycl
holder.name.setText(pass.toString()); holder.name.setText(pass.toString());
int sdk = android.os.Build.VERSION.SDK_INT; int sdk = android.os.Build.VERSION.SDK_INT;
holder.type.setText(pass.getFullPathName());
if (pass.getType() == PasswordItem.TYPE_CATEGORY) { if (pass.getType() == PasswordItem.TYPE_CATEGORY) {
holder.type.setText(pass.getFullPathName()); holder.card.setCardBackgroundColor(activity.getResources().getColor(R.color.blue_grey_200));
holder.card.setCardBackgroundColor(activity.getResources().getColor(R.color.deep_orange_400));
} else { } else {
holder.type.setText(pass.getFullPathName()); holder.card.setCardBackgroundColor(activity.getResources().getColor(R.color.blue_grey_50));
holder.card.setCardBackgroundColor(activity.getResources().getColor(R.color.blue_grey_400));
} }
holder.view.setOnClickListener(new View.OnClickListener() { holder.view.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
if (mActionMode != null) { if (mActionMode != null) {
toggleSelection(holder.getAdapterPosition(), holder.card, pass.getType()); toggleSelection(holder, holder.getAdapterPosition(), holder.card, pass.getType());
if (selectedItems.isEmpty()) { if (selectedItems.isEmpty()) {
mActionMode.finish(); mActionMode.finish();
} else if (selectedItems.size() == 1 && !canEdit) { } else if (selectedItems.size() == 1 && !canEdit) {
@ -107,7 +106,7 @@ public class PasswordRecyclerAdapter extends RecyclerView.Adapter<PasswordRecycl
if (mActionMode != null) { if (mActionMode != null) {
return false; return false;
} }
toggleSelection(holder.getAdapterPosition(), holder.card, pass.getType()); toggleSelection(holder, holder.getAdapterPosition(), holder.card, pass.getType());
canEdit = pass.getType() == PasswordItem.TYPE_PASSWORD; canEdit = pass.getType() == PasswordItem.TYPE_PASSWORD;
// Start the CAB using the ActionMode.Callback // Start the CAB using the ActionMode.Callback
mActionMode = activity.startSupportActionMode(mActionModeCallback); mActionMode = activity.startSupportActionMode(mActionModeCallback);
@ -205,21 +204,19 @@ public class PasswordRecyclerAdapter extends RecyclerView.Adapter<PasswordRecycl
updateSelectedItems(position, selectedItems); updateSelectedItems(position, selectedItems);
} }
public void toggleSelection(int position, CardView card, char type) { public void toggleSelection(ViewHolder holder, int position, CardView card, char type) {
if (!selectedItems.remove(position)) { if (!selectedItems.remove(position)) {
selectedItems.add(position); selectedItems.add(position);
if (type == PasswordItem.TYPE_CATEGORY) { if (type == PasswordItem.TYPE_CATEGORY) {
card.setCardBackgroundColor(activity.getResources().getColor(R.color.deep_orange_200)); card.setCardBackgroundColor(activity.getResources().getColor(R.color.blue_grey_100));
} } else {
else { card.setCardBackgroundColor(activity.getResources().getColor(R.color.blue_grey_100));
card.setCardBackgroundColor(activity.getResources().getColor(R.color.blue_grey_200));
} }
} else { } else {
if (type == PasswordItem.TYPE_CATEGORY) { if (type == PasswordItem.TYPE_CATEGORY) {
card.setCardBackgroundColor(activity.getResources().getColor(R.color.deep_orange_400)); card.setCardBackgroundColor(activity.getResources().getColor(R.color.blue_grey_200));
} } else {
else { card.setCardBackgroundColor(activity.getResources().getColor(R.color.blue_grey_50));
card.setCardBackgroundColor(activity.getResources().getColor(R.color.blue_grey_400));
} }
} }
} }

View file

@ -11,11 +11,7 @@
android:id="@+id/pass_recycler" android:id="@+id/pass_recycler"
android:scrollbars="vertical" android:scrollbars="vertical"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"/>
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"/>
<android.support.design.widget.FloatingActionButton <android.support.design.widget.FloatingActionButton
android:id="@+id/fab" android:id="@+id/fab"

View file

@ -1,40 +1,56 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto" xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="4dp" android:layout_marginBottom="0dp"
android:layout_marginBottom="4dp"> android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="0dp">
<android.support.v7.widget.CardView <android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/password_card" android:id="@+id/password_card"
android:layout_gravity="center" style="@style/CardView.Light"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="60dp" android:layout_height="wrap_content"
card_view:contentPaddingTop="4dp" android:layout_gravity="center"
card_view:contentPaddingLeft="4dp"
card_view:cardCornerRadius="4dp" card_view:cardCornerRadius="4dp"
card_view:cardElevation="3dp" card_view:cardElevation="4dp"
card_view:cardBackgroundColor="@color/light_blue_50"> card_view:cardUseCompatPadding="true"
card_view:contentPaddingLeft="4dp"
card_view:contentPaddingTop="4dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="8dp"
android:gravity="left">
<TextView <TextView
android:id="@+id/type" android:id="@+id/type"
android:text="TYPE" android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:textColor="@android:color/white" android:alpha="0.5"
android:textStyle="italic" android:maxLines="1"
android:maxLines="1" /> android:ellipsize="start"
android:text="TYPE"
android:textSize="14dp"
android:textColor="@android:color/black"
android:layout_alignParentTop="true"
android:layout_alignLeft="@+id/label"
android:layout_alignStart="@+id/label" />
<TextView <TextView
android:id="@+id/label" android:id="@+id/label"
android:text="FILE_NAME" android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical"
android:padding="8dp" android:text="FILE_NAME"
android:textColor="@android:color/white" android:textColor="@android:color/black"
android:textStyle="bold" /> android:textSize="18dp"
android:layout_below="@+id/type"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
</android.support.v7.widget.CardView> </android.support.v7.widget.CardView>
</LinearLayout> </LinearLayout>