aboutsummaryrefslogtreecommitdiff
path: root/app/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main')
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/PasswordFragment.java8
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/PasswordStore.java6
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/UserPreference.java2
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/utils/PasswordRecyclerAdapter.java32
-rw-r--r--app/src/main/res/menu/context_pass.xml11
5 files changed, 54 insertions, 5 deletions
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<PasswordRecycl
// Replace the contents of a view (invoked by the layout manager)
@Override
- public void onBindViewHolder(ViewHolder holder, int position) {
+ public void onBindViewHolder(final ViewHolder holder, int position) {
final PasswordItem pass = values.get(position);
holder.name.setText(pass.toString());
int sdk = android.os.Build.VERSION.SDK_INT;
@@ -90,6 +93,26 @@ public class PasswordRecyclerAdapter extends RecyclerView.Adapter<PasswordRecycl
}
});
+ holder.view.setOnLongClickListener(new View.OnLongClickListener() {
+ @Override
+ public boolean onLongClick(View v) {
+ PopupMenu p = new PopupMenu(activity, v);
+ p.getMenuInflater().inflate(
+ R.menu.context_pass, p.getMenu());
+ p.show();
+ p.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
+ @Override
+ public boolean onMenuItemClick(MenuItem menuItem) {
+ if (menuItem.getItemId() == R.id.menu_delete_password) {
+ activity.deletePassword(PasswordRecyclerAdapter.this, holder.position);
+ }
+ return false;
+ }
+ });
+ return false;
+ }
+ });
+
}
@@ -115,7 +138,12 @@ public class PasswordRecyclerAdapter extends RecyclerView.Adapter<PasswordRecycl
public void add(PasswordItem item) {
this.values.add(item);
- this.notifyDataSetChanged();
+ this.notifyItemInserted(values.size());
+ }
+
+ public void remove(int position) {
+ this.values.remove(position);
+ this.notifyItemRemoved(position);
}
} \ No newline at end of file
diff --git a/app/src/main/res/menu/context_pass.xml b/app/src/main/res/menu/context_pass.xml
new file mode 100644
index 00000000..fce0d5fe
--- /dev/null
+++ b/app/src/main/res/menu/context_pass.xml
@@ -0,0 +1,11 @@
+<menu xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:tools="http://schemas.android.com/tools"
+ xmlns:app="http://schemas.android.com/apk/res-auto"
+ tools:context=".pwdstore">
+
+ <item android:id="@+id/menu_delete_password"
+ android:icon="@drawable/ico_del"
+ app:showAsAction="always"
+ android:title="Delete"/>
+</menu>
+