From 0c5c6947055e149c10cc190a5ef8f3ac07ba1a0a Mon Sep 17 00:00:00 2001 From: zeapo Date: Mon, 20 Oct 2014 00:02:07 +0200 Subject: User can now delete passwords --- .../java/com/zeapo/pwdstore/PasswordFragment.java | 8 ++++++ .../java/com/zeapo/pwdstore/PasswordStore.java | 6 ++-- .../java/com/zeapo/pwdstore/UserPreference.java | 2 +- .../pwdstore/utils/PasswordRecyclerAdapter.java | 32 ++++++++++++++++++++-- app/src/main/res/menu/context_pass.xml | 11 ++++++++ 5 files changed, 54 insertions(+), 5 deletions(-) create mode 100644 app/src/main/res/menu/context_pass.xml diff --git a/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.java b/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.java index 2c898cb4..3d93fe6c 100644 --- a/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.java +++ b/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.java @@ -1,13 +1,19 @@ package com.zeapo.pwdstore; import android.app.Activity; +import android.content.Intent; +import android.net.Uri; import android.os.Bundle; import android.app.Fragment; import android.support.v7.app.ActionBarActivity; +import android.support.v7.internal.widget.AdapterViewCompat; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.util.Log; +import android.view.ContextMenu; import android.view.LayoutInflater; +import android.view.MenuInflater; +import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; @@ -70,6 +76,8 @@ public class PasswordFragment extends Fragment{ // // // Set the adapter recyclerView.setAdapter(recyclerAdapter); + + registerForContextMenu(recyclerView); return view; } diff --git a/app/src/main/java/com/zeapo/pwdstore/PasswordStore.java b/app/src/main/java/com/zeapo/pwdstore/PasswordStore.java index 25200c92..83681a06 100644 --- a/app/src/main/java/com/zeapo/pwdstore/PasswordStore.java +++ b/app/src/main/java/com/zeapo/pwdstore/PasswordStore.java @@ -7,7 +7,6 @@ import android.app.FragmentTransaction; import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; -import android.net.Uri; import android.os.Bundle; import android.preference.PreferenceManager; import android.support.v7.app.ActionBarActivity; @@ -18,6 +17,7 @@ import android.view.View; import com.zeapo.pwdstore.crypto.PgpHandler; import com.zeapo.pwdstore.utils.PasswordItem; +import com.zeapo.pwdstore.utils.PasswordRecyclerAdapter; import com.zeapo.pwdstore.utils.PasswordRepository; import org.apache.commons.io.FileUtils; @@ -337,7 +337,8 @@ public class PasswordStore extends ActionBarActivity { } } - public void deletePassword(final PasswordItem item) { + public void deletePassword(final PasswordRecyclerAdapter adapter, final int position) { + final PasswordItem item = adapter.getValues().get(position); new AlertDialog.Builder(this). setMessage("Are you sure you want to delete the password \"" + item + "\"") @@ -346,6 +347,7 @@ public class PasswordStore extends ActionBarActivity { public void onClick(DialogInterface dialogInterface, int i) { String path = item.getFile().getAbsolutePath(); item.getFile().delete(); + adapter.remove(position); setResult(RESULT_CANCELED); Git git = new Git(PasswordRepository.getRepository(new File(""))); diff --git a/app/src/main/java/com/zeapo/pwdstore/UserPreference.java b/app/src/main/java/com/zeapo/pwdstore/UserPreference.java index f811efea..f49d463b 100644 --- a/app/src/main/java/com/zeapo/pwdstore/UserPreference.java +++ b/app/src/main/java/com/zeapo/pwdstore/UserPreference.java @@ -42,7 +42,7 @@ public class UserPreference extends ActionBarActivity implements Preference.OnPr public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (getIntent() != null) { - if (getIntent().getStringExtra("operation").equals("get_ssh_key")) { + if ((getIntent().getStringExtra("operation") != null) && (getIntent().getStringExtra("operation").equals("get_ssh_key"))) { getSshKey(); } } 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 7a6d1320..2bcfd7ef 100644 --- a/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRecyclerAdapter.java +++ b/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRecyclerAdapter.java @@ -1,8 +1,11 @@ package com.zeapo.pwdstore.utils; import android.graphics.Color; +import android.support.v7.widget.PopupMenu; import android.support.v7.widget.RecyclerView; +import android.util.Log; import android.view.LayoutInflater; +import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; @@ -56,7 +59,7 @@ public class PasswordRecyclerAdapter extends RecyclerView.Adapter + + + + -- cgit v1.2.3