From 5943bc460339092a808a2fb22a0d57e6fdb2ac7b Mon Sep 17 00:00:00 2001 From: Jakob Nixdorf Date: Mon, 7 Aug 2017 20:50:05 +0200 Subject: [PATCH] Add getRealIndex function for the adapter --- .../flocke/andotp/EntriesCardAdapter.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/org/shadowice/flocke/andotp/EntriesCardAdapter.java b/app/src/main/java/org/shadowice/flocke/andotp/EntriesCardAdapter.java index 2f11d3da..701b07c5 100644 --- a/app/src/main/java/org/shadowice/flocke/andotp/EntriesCardAdapter.java +++ b/app/src/main/java/org/shadowice/flocke/andotp/EntriesCardAdapter.java @@ -89,6 +89,10 @@ public class EntriesCardAdapter extends RecyclerView.Adapter entriesChanged(); } + private int getRealIndex(int displayPosition) { + return entries.indexOf(displayedEntries.get(displayPosition)); + } + public void entriesChanged() { displayedEntries = sortEntries(entries); notifyDataSetChanged(); @@ -190,7 +194,7 @@ public class EntriesCardAdapter extends RecyclerView.Adapter .setPositiveButton(R.string.button_save, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { - int realIndex = entries.indexOf(displayedEntries.get(pos)); + int realIndex = getRealIndex(pos); String newLabel = input.getEditableText().toString(); displayedEntries.get(pos).setLabel(newLabel); @@ -213,7 +217,7 @@ public class EntriesCardAdapter extends RecyclerView.Adapter .show(); } - public void removeItem(final int position) { + public void removeItem(final int pos) { AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setTitle(R.string.dialog_title_remove) @@ -221,10 +225,10 @@ public class EntriesCardAdapter extends RecyclerView.Adapter .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { - int realIndex = entries.indexOf(displayedEntries.get(position)); + int realIndex = getRealIndex(pos); - displayedEntries.remove(position); - notifyItemRemoved(position); + displayedEntries.remove(pos); + notifyItemRemoved(pos); entries.remove(realIndex); DatabaseHelper.saveDatabase(context, entries); @@ -232,9 +236,7 @@ public class EntriesCardAdapter extends RecyclerView.Adapter }) .setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() { @Override - public void onClick(DialogInterface dialogInterface, int i) { - notifyItemChanged(position); - } + public void onClick(DialogInterface dialogInterface, int i) {} }) .show(); }