From 113dadd227a4d1cb4d9d12ee8c77c475fa19b577 Mon Sep 17 00:00:00 2001 From: Matthew Wong Date: Tue, 11 Aug 2015 17:39:35 -0400 Subject: Open password deletion dialogs one-by-one instead of all at once, don't rely on the order of opening (potentially prevent #115) --- .../java/com/zeapo/pwdstore/PasswordStore.java | 16 ++++++++++-- .../pwdstore/utils/PasswordRecyclerAdapter.java | 29 ++++++++++++---------- 2 files changed, 30 insertions(+), 15 deletions(-) (limited to 'app/src/main') diff --git a/app/src/main/java/com/zeapo/pwdstore/PasswordStore.java b/app/src/main/java/com/zeapo/pwdstore/PasswordStore.java index 97ac2d02..3d17ce10 100644 --- a/app/src/main/java/com/zeapo/pwdstore/PasswordStore.java +++ b/app/src/main/java/com/zeapo/pwdstore/PasswordStore.java @@ -32,7 +32,9 @@ import org.eclipse.jgit.lib.Repository; import java.io.File; import java.util.HashSet; +import java.util.Iterator; import java.util.Set; +import java.util.TreeSet; public class PasswordStore extends AppCompatActivity { private static final String TAG = "PwdStrAct"; @@ -355,7 +357,13 @@ public class PasswordStore extends AppCompatActivity { startActivityForResult(intent, PgpHandler.REQUEST_CODE_ENCRYPT); } - public void deletePassword(final PasswordRecyclerAdapter adapter, final int position) { + // deletes passwords in order from top to bottom + public void deletePasswords(final PasswordRecyclerAdapter adapter, final Set selectedItems) { + final Iterator it = selectedItems.iterator(); + if (!it.hasNext()) { + return; + } + final int position = (int) it.next(); final PasswordItem item = adapter.getValues().get(position); new AlertDialog.Builder(this). setMessage(this.getResources().getString(R.string.delete_dialog_text) + @@ -366,6 +374,8 @@ public class PasswordStore extends AppCompatActivity { String path = item.getFile().getAbsolutePath(); item.getFile().delete(); adapter.remove(position); + it.remove(); + adapter.updateSelectedItems(position, selectedItems); setResult(RESULT_CANCELED); Repository repo = PasswordRepository.getRepository(PasswordRepository.getRepositoryDirectory(activity)); @@ -375,12 +385,14 @@ public class PasswordStore extends AppCompatActivity { git.rm().addFilepattern(path.replace(PasswordRepository.getWorkTree() + "/", "")), git.commit().setMessage("[ANDROID PwdStore] Remove " + item + " from store.") ); + deletePasswords(adapter, selectedItems); } }) .setNegativeButton(this.getResources().getString(R.string.dialog_no), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { - + it.remove(); + deletePasswords(adapter, selectedItems); } }) .show(); diff --git a/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRecyclerAdapter.java b/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRecyclerAdapter.java index b4ad1d81..4bf9cb98 100644 --- a/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRecyclerAdapter.java +++ b/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRecyclerAdapter.java @@ -140,9 +140,7 @@ public class PasswordRecyclerAdapter extends RecyclerView.Adapter(selectedItems)); mode.finish(); // Action picked, so close the CAB return true; default: @@ -193,16 +191,7 @@ public class PasswordRecyclerAdapter extends RecyclerView.Adapter temp = new TreeSet<>(); - for (int selected : selectedItems) { - if (selected > position) { - temp.add(selected - 1); - } else { - temp.add(selected); - } - } - selectedItems.clear(); - selectedItems.addAll(temp); + updateSelectedItems(position, selectedItems); } public void toggleSelection(int position, View view) { @@ -214,4 +203,18 @@ public class PasswordRecyclerAdapter extends RecyclerView.Adapter selectedItems) { + Set temp = new TreeSet<>(); + for (int selected : selectedItems) { + if (selected > position) { + temp.add(selected - 1); + } else { + temp.add(selected); + } + } + selectedItems.clear(); + selectedItems.addAll(temp); + } } \ No newline at end of file -- cgit v1.2.3