@Override
public void onSwiped(final RecyclerView.ViewHolder viewHolder, int direction, int position) {
Log.d(TAG, "onSwiped() position=" + position + " direction=" + direction);
// get item details
final String itemIndex = cartList.get(viewHolder.getAdapterPosition()).getIndex();
String itemSubjekt = cartList.get(viewHolder.getAdapterPosition()).getSubjekt();
String itemPrio = cartList.get(viewHolder.getAdapterPosition()).getPrio();
// from right to left = delete line
if ((viewHolder instanceof CartListAdapter.MyViewHolder) && (direction == 4)){
Log.d(TAG, "onSwiped() delete");
Context context = viewHolder.itemView.getContext();
AlertDialog adDelete = new AlertDialog.Builder(context).create();
adDelete.setTitle(context.getResources().getString(R.string.dialog_delete_nadpis));
adDelete.setMessage(context.getResources().getString(R.string.dialog_delete_really));
adDelete.setButton(DialogInterface.BUTTON_POSITIVE, "ANO", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Log.d(TAG, "Dialog delete - vybrano ANO");
final Item deletedItem = cartList.get(viewHolder.getAdapterPosition());
// final int deletedIndex = viewHolder.getAdapterPosition();
// code here to delete item in db
}
});
adDelete.setButton(DialogInterface.BUTTON_NEGATIVE, "NE", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Log.d(TAG, "Dialog delete - vybrano NE");
mAdapter.notifyItemChanged(viewHolder.getAdapterPosition());
}
});
adDelete.show();
}
// from left to right = Edit line
if ((viewHolder instanceof CartListAdapter.MyViewHolder) && (direction == 8)){
Log.d(TAG, "onSwiped() edit");
}
}