Instantly share code, notes, and snippets.
Last active
January 24, 2018 20:44
-
Star
0
(0)
You must be signed in to star a gist -
Fork
0
(0)
You must be signed in to fork a gist
-
Save gvr23/f2ae76ee29458888395644ddb81c0473 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ANDROID | |
=================================================================================================================================== | |
In the Manifest | |
================================================================================================================================= | |
compile 'com.tubb.smrv:swipemenu-recyclerview:3.0.4' | |
================================================================================================================================= | |
In the Activity | |
=================================================================================================================================== | |
private void preLoad() { | |
clientAdapter = new ClientAdapter(new ArrayList<ClienteBean>()); | |
clientAdapter.setListener(this); | |
smrvClient.setLayoutManager(new LinearLayoutManager(getContext())); | |
DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(smrvClient.getContext(), | |
LinearLayoutManager.VERTICAL); | |
smrvClient.addItemDecoration(dividerItemDecoration); | |
smrvClient.setCloseInterpolator(new BounceInterpolator()); | |
smrvClient.setOpenInterpolator(new BounceInterpolator()); | |
smrvClient.setAdapter(clientAdapter); | |
} | |
==================================================================================================================================== | |
ADAPTER | |
================================================================================================================================= | |
private List<ClienteBean> clienteList; | |
private OnClienteAdapter mListener; | |
public interface OnClienteAdapter{ | |
void onEditClient(ClienteBean item); | |
void onDeleteClient(ClienteBean clientToDelete, int position); | |
} | |
public void removeClient(int position){ | |
clienteList.remove(position); | |
notifyDataSetChanged(); | |
} | |
@Override | |
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { | |
View newClient = LayoutInflater.from(parent.getContext()).inflate(R.layout.row_liquidation_client_swipe, parent, false); | |
return new ClientAdapter.ViewHolder(newClient); | |
} | |
@Override | |
public void onBindViewHolder(ViewHolder holder, int position) { | |
final ClienteBean client = clienteList.get(position); | |
final int adapterPosition = holder.getAdapterPosition(); | |
holder.tvClientCode.setText(client.getCodigo()); | |
holder.tvClientName.setText(client.getNombre()); | |
holder.ivClientZoom.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
mListener.onEditClient(client); | |
} | |
}); | |
holder.flEdit.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
mListener.onEditClient(client); | |
} | |
}); | |
holder.flDelete.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
mListener.onDeleteClient(client, adapterPosition); | |
} | |
}); | |
} | |
class ViewHolder extends RecyclerView.ViewHolder{ | |
private TextView tvClientCode; | |
private TextView tvClientName; | |
private ImageView ivClientZoom; | |
private FrameLayout flEdit; | |
private FrameLayout flDelete; | |
public ViewHolder(View rootView) { | |
super(rootView); | |
tvClientCode = rootView.findViewById(R.id.tvClientCode); | |
tvClientName = rootView.findViewById(R.id.tvClientName); | |
ivClientZoom = rootView.findViewById(R.id.ivClientZoom); | |
flEdit = rootView.findViewById(R.id.flEdit); | |
flDelete = rootView.findViewById(R.id.flDelete); | |
} | |
} | |
================================================================================================================================ | |
LAYOUTS | |
================================================================================================================================ | |
<?xml version="1.0" encoding="utf-8"?> | |
<com.tubb.smrv.SwipeMenuLayout | |
xmlns:android="http://schemas.android.com/apk/res/android" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content"> | |
<include | |
android:id="@+id/smContentView" | |
layout="@layout/client_row"/> | |
<include | |
android:id="@+id/smMenuView" | |
layout="@layout/row_menu_liquidation_client"/> | |
</com.tubb.smrv.SwipeMenuLayout> | |
================================================================================================================================= | |
<?xml version="1.0" encoding="utf-8"?> | |
<LinearLayout | |
xmlns:android="http://schemas.android.com/apk/res/android" | |
android:orientation="horizontal" | |
android:layout_width="match_parent" | |
android:layout_height="70dp" | |
android:layout_margin="@dimen/margin_normal"> | |
<ImageView | |
android:id="@+id/ivClientZoom" | |
android:layout_width="0dp" | |
android:layout_height="match_parent" | |
android:layout_weight="0.8" | |
android:layout_gravity="center" | |
android:src="@drawable/customer"/> | |
<TextView | |
android:id="@+id/tvClientCode" | |
android:layout_width="0dp" | |
android:layout_height="match_parent" | |
android:layout_weight="0.52" | |
android:gravity="center" /> | |
<TextView | |
android:layout_width="0dp" | |
android:layout_height="match_parent" | |
android:layout_weight="0.1" | |
android:gravity="center" | |
android:text="-"/> | |
<TextView | |
android:id="@+id/tvClientName" | |
android:layout_width="0dp" | |
android:layout_height="match_parent" | |
android:layout_weight="1.5" | |
android:gravity="center_vertical" | |
android:paddingStart="@dimen/padding_small" | |
android:paddingEnd="0dp"/> | |
</LinearLayout> | |
================================================================================================================================ | |
<?xml version="1.0" encoding="utf-8"?> | |
<LinearLayout | |
xmlns:android="http://schemas.android.com/apk/res/android" | |
android:layout_width="wrap_content" | |
android:layout_height="match_parent" | |
android:orientation="horizontal"> | |
<FrameLayout | |
android:id="@+id/flEdit" | |
android:layout_width="64dp" | |
android:layout_height="match_parent" | |
android:background="@color/color_claim"> | |
<ImageView | |
android:layout_width="40dp" | |
android:layout_height="40dp" | |
android:layout_gravity="center" | |
android:layout_marginBottom="@dimen/margin_small" | |
android:src="@drawable/ic_action_edit" /> | |
<TextView | |
style="@style/SubTitleStyleWhite" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_gravity="bottom|center_horizontal" | |
android:layout_marginBottom="@dimen/margin_small" | |
android:text="Editar" /> | |
</FrameLayout> | |
<FrameLayout | |
android:id="@+id/flDelete" | |
android:layout_width="64dp" | |
android:layout_height="match_parent" | |
android:background="@color/color_red_login"> | |
<ImageView | |
android:layout_width="24dp" | |
android:layout_height="24dp" | |
android:layout_gravity="center" | |
android:layout_marginBottom="@dimen/margin_small" | |
android:src="@drawable/delete" /> | |
<TextView | |
style="@style/SubTitleStyleWhite" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_gravity="bottom|center_horizontal" | |
android:layout_marginBottom="@dimen/margin_small" | |
android:text="Eliminar" /> | |
</FrameLayout> | |
</LinearLayout> | |
================================================================================================================================ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment