Remove CardView and use divider for separation
This commit is contained in:
parent
b36d082b9f
commit
09f12c81c1
5 changed files with 97 additions and 51 deletions
|
@ -0,0 +1,51 @@
|
||||||
|
package com.zeapo.pwdstore;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.res.TypedArray;
|
||||||
|
import android.graphics.Canvas;
|
||||||
|
import android.graphics.drawable.Drawable;
|
||||||
|
import android.support.v4.content.ContextCompat;
|
||||||
|
import android.support.v7.widget.RecyclerView;
|
||||||
|
import android.view.View;
|
||||||
|
|
||||||
|
public class DividerItemDecoration extends RecyclerView.ItemDecoration {
|
||||||
|
|
||||||
|
private static final int[] ATTRS = new int[]{android.R.attr.listDivider};
|
||||||
|
|
||||||
|
private Drawable mDivider;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default divider will be used
|
||||||
|
*/
|
||||||
|
public DividerItemDecoration(Context context) {
|
||||||
|
final TypedArray styledAttributes = context.obtainStyledAttributes(ATTRS);
|
||||||
|
mDivider = styledAttributes.getDrawable(0);
|
||||||
|
styledAttributes.recycle();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Custom divider will be used
|
||||||
|
*/
|
||||||
|
public DividerItemDecoration(Context context, int resId) {
|
||||||
|
mDivider = ContextCompat.getDrawable(context, resId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
|
||||||
|
int left = parent.getPaddingLeft();
|
||||||
|
int right = parent.getWidth() - parent.getPaddingRight();
|
||||||
|
|
||||||
|
int childCount = parent.getChildCount();
|
||||||
|
for (int i = 0; i < childCount; i++) {
|
||||||
|
View child = parent.getChildAt(i);
|
||||||
|
|
||||||
|
RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
|
||||||
|
|
||||||
|
int top = child.getBottom() + params.bottomMargin;
|
||||||
|
int bottom = top + mDivider.getIntrinsicHeight();
|
||||||
|
|
||||||
|
mDivider.setBounds(left, top, right, bottom);
|
||||||
|
mDivider.draw(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -74,8 +74,11 @@ public class PasswordFragment extends Fragment{
|
||||||
|
|
||||||
recyclerView = (RecyclerView) view.findViewById(R.id.pass_recycler);
|
recyclerView = (RecyclerView) view.findViewById(R.id.pass_recycler);
|
||||||
recyclerView.setLayoutManager(mLayoutManager);
|
recyclerView.setLayoutManager(mLayoutManager);
|
||||||
//
|
|
||||||
// // Set the adapter
|
// use divider
|
||||||
|
recyclerView.addItemDecoration(new DividerItemDecoration(getActivity(), R.drawable.divider));
|
||||||
|
|
||||||
|
// Set the adapter
|
||||||
recyclerView.setAdapter(recyclerAdapter);
|
recyclerView.setAdapter(recyclerAdapter);
|
||||||
|
|
||||||
final FloatingActionButton fab = (FloatingActionButton) view.findViewById(R.id.fab);
|
final FloatingActionButton fab = (FloatingActionButton) view.findViewById(R.id.fab);
|
||||||
|
|
|
@ -33,14 +33,12 @@ public class PasswordRecyclerAdapter extends RecyclerView.Adapter<PasswordRecycl
|
||||||
public static class ViewHolder extends RecyclerView.ViewHolder {
|
public static class ViewHolder extends RecyclerView.ViewHolder {
|
||||||
// each data item is just a string in this case
|
// each data item is just a string in this case
|
||||||
public View view;
|
public View view;
|
||||||
public CardView card;
|
|
||||||
public TextView name;
|
public TextView name;
|
||||||
public TextView type;
|
public TextView type;
|
||||||
|
|
||||||
public ViewHolder(View v) {
|
public ViewHolder(View v) {
|
||||||
super(v);
|
super(v);
|
||||||
view = v;
|
view = v;
|
||||||
card = (CardView) view.findViewById(R.id.password_card);
|
|
||||||
name = (TextView) view.findViewById(R.id.label);
|
name = (TextView) view.findViewById(R.id.label);
|
||||||
type = (TextView) view.findViewById(R.id.type);
|
type = (TextView) view.findViewById(R.id.type);
|
||||||
}
|
}
|
||||||
|
@ -73,16 +71,16 @@ public class PasswordRecyclerAdapter extends RecyclerView.Adapter<PasswordRecycl
|
||||||
|
|
||||||
holder.type.setText(pass.getFullPathName());
|
holder.type.setText(pass.getFullPathName());
|
||||||
if (pass.getType() == PasswordItem.TYPE_CATEGORY) {
|
if (pass.getType() == PasswordItem.TYPE_CATEGORY) {
|
||||||
holder.card.setCardBackgroundColor(activity.getResources().getColor(R.color.blue_grey_200));
|
// holder.card.setCardBackgroundColor(activity.getResources().getColor(R.color.blue_grey_200));
|
||||||
} else {
|
} else {
|
||||||
holder.card.setCardBackgroundColor(activity.getResources().getColor(R.color.blue_grey_50));
|
// holder.card.setCardBackgroundColor(activity.getResources().getColor(R.color.blue_grey_50));
|
||||||
}
|
}
|
||||||
|
|
||||||
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, holder.getAdapterPosition(), holder.card, pass.getType());
|
toggleSelection(holder, holder.getAdapterPosition(), null, pass.getType());
|
||||||
if (selectedItems.isEmpty()) {
|
if (selectedItems.isEmpty()) {
|
||||||
mActionMode.finish();
|
mActionMode.finish();
|
||||||
} else if (selectedItems.size() == 1 && !canEdit) {
|
} else if (selectedItems.size() == 1 && !canEdit) {
|
||||||
|
@ -106,7 +104,7 @@ public class PasswordRecyclerAdapter extends RecyclerView.Adapter<PasswordRecycl
|
||||||
if (mActionMode != null) {
|
if (mActionMode != null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
toggleSelection(holder, holder.getAdapterPosition(), holder.card, pass.getType());
|
toggleSelection(holder, holder.getAdapterPosition(), null, 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);
|
||||||
|
@ -208,15 +206,15 @@ public class PasswordRecyclerAdapter extends RecyclerView.Adapter<PasswordRecycl
|
||||||
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.blue_grey_100));
|
// 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_100));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (type == PasswordItem.TYPE_CATEGORY) {
|
if (type == PasswordItem.TYPE_CATEGORY) {
|
||||||
card.setCardBackgroundColor(activity.getResources().getColor(R.color.blue_grey_200));
|
// 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_50));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
6
app/src/main/res/drawable/divider.xml
Normal file
6
app/src/main/res/drawable/divider.xml
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:shape="rectangle">
|
||||||
|
<size android:height="1dp" />
|
||||||
|
<solid android:color="@color/grey_300" />
|
||||||
|
</shape>
|
|
@ -8,49 +8,37 @@
|
||||||
android:layout_marginRight="8dp"
|
android:layout_marginRight="8dp"
|
||||||
android:layout_marginTop="0dp">
|
android:layout_marginTop="0dp">
|
||||||
|
|
||||||
<android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
|
<RelativeLayout
|
||||||
android:id="@+id/password_card"
|
|
||||||
style="@style/CardView.Light"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="center"
|
android:padding="8dp"
|
||||||
card_view:cardCornerRadius="4dp"
|
android:gravity="left">
|
||||||
card_view:cardElevation="4dp"
|
|
||||||
card_view:cardUseCompatPadding="true"
|
|
||||||
card_view:contentPaddingLeft="4dp"
|
|
||||||
card_view:contentPaddingTop="4dp">
|
|
||||||
|
|
||||||
<RelativeLayout
|
<TextView
|
||||||
android:layout_width="match_parent"
|
android:id="@+id/type"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:padding="8dp"
|
android:alpha="0.5"
|
||||||
android:gravity="left">
|
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/type"
|
android:id="@+id/label"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:alpha="0.5"
|
android:layout_gravity="center_vertical"
|
||||||
android:maxLines="1"
|
android:text="FILE_NAME"
|
||||||
android:ellipsize="start"
|
android:textColor="@android:color/black"
|
||||||
android:text="TYPE"
|
android:textSize="18dp"
|
||||||
android:textSize="14dp"
|
android:layout_below="@+id/type"
|
||||||
android:textColor="@android:color/black"
|
android:layout_alignParentLeft="true"
|
||||||
android:layout_alignParentTop="true"
|
android:layout_alignParentStart="true" />
|
||||||
android:layout_alignLeft="@+id/label"
|
</RelativeLayout>
|
||||||
android:layout_alignStart="@+id/label" />
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/label"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_gravity="center_vertical"
|
|
||||||
android:text="FILE_NAME"
|
|
||||||
android:textColor="@android:color/black"
|
|
||||||
android:textSize="18dp"
|
|
||||||
android:layout_below="@+id/type"
|
|
||||||
android:layout_alignParentLeft="true"
|
|
||||||
android:layout_alignParentStart="true" />
|
|
||||||
</RelativeLayout>
|
|
||||||
</android.support.v7.widget.CardView>
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
Loading…
Add table
Add a link
Reference in a new issue