mirror of
https://github.com/android-password-store/Android-Password-Store
synced 2025-08-31 06:15:48 +00:00
User can now delete passwords
This commit is contained in:
@@ -1,13 +1,19 @@
|
|||||||
package com.zeapo.pwdstore;
|
package com.zeapo.pwdstore;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.app.Fragment;
|
import android.app.Fragment;
|
||||||
import android.support.v7.app.ActionBarActivity;
|
import android.support.v7.app.ActionBarActivity;
|
||||||
|
import android.support.v7.internal.widget.AdapterViewCompat;
|
||||||
import android.support.v7.widget.LinearLayoutManager;
|
import android.support.v7.widget.LinearLayoutManager;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.view.ContextMenu;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.MenuInflater;
|
||||||
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
@@ -70,6 +76,8 @@ public class PasswordFragment extends Fragment{
|
|||||||
//
|
//
|
||||||
// // Set the adapter
|
// // Set the adapter
|
||||||
recyclerView.setAdapter(recyclerAdapter);
|
recyclerView.setAdapter(recyclerAdapter);
|
||||||
|
|
||||||
|
registerForContextMenu(recyclerView);
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -7,7 +7,6 @@ import android.app.FragmentTransaction;
|
|||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.net.Uri;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.support.v7.app.ActionBarActivity;
|
import android.support.v7.app.ActionBarActivity;
|
||||||
@@ -18,6 +17,7 @@ import android.view.View;
|
|||||||
|
|
||||||
import com.zeapo.pwdstore.crypto.PgpHandler;
|
import com.zeapo.pwdstore.crypto.PgpHandler;
|
||||||
import com.zeapo.pwdstore.utils.PasswordItem;
|
import com.zeapo.pwdstore.utils.PasswordItem;
|
||||||
|
import com.zeapo.pwdstore.utils.PasswordRecyclerAdapter;
|
||||||
import com.zeapo.pwdstore.utils.PasswordRepository;
|
import com.zeapo.pwdstore.utils.PasswordRepository;
|
||||||
|
|
||||||
import org.apache.commons.io.FileUtils;
|
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).
|
new AlertDialog.Builder(this).
|
||||||
setMessage("Are you sure you want to delete the password \"" +
|
setMessage("Are you sure you want to delete the password \"" +
|
||||||
item + "\"")
|
item + "\"")
|
||||||
@@ -346,6 +347,7 @@ public class PasswordStore extends ActionBarActivity {
|
|||||||
public void onClick(DialogInterface dialogInterface, int i) {
|
public void onClick(DialogInterface dialogInterface, int i) {
|
||||||
String path = item.getFile().getAbsolutePath();
|
String path = item.getFile().getAbsolutePath();
|
||||||
item.getFile().delete();
|
item.getFile().delete();
|
||||||
|
adapter.remove(position);
|
||||||
|
|
||||||
setResult(RESULT_CANCELED);
|
setResult(RESULT_CANCELED);
|
||||||
Git git = new Git(PasswordRepository.getRepository(new File("")));
|
Git git = new Git(PasswordRepository.getRepository(new File("")));
|
||||||
|
@@ -42,7 +42,7 @@ public class UserPreference extends ActionBarActivity implements Preference.OnPr
|
|||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
if (getIntent() != null) {
|
if (getIntent() != null) {
|
||||||
if (getIntent().getStringExtra("operation").equals("get_ssh_key")) {
|
if ((getIntent().getStringExtra("operation") != null) && (getIntent().getStringExtra("operation").equals("get_ssh_key"))) {
|
||||||
getSshKey();
|
getSshKey();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,8 +1,11 @@
|
|||||||
package com.zeapo.pwdstore.utils;
|
package com.zeapo.pwdstore.utils;
|
||||||
|
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
|
import android.support.v7.widget.PopupMenu;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.TextView;
|
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)
|
// Replace the contents of a view (invoked by the layout manager)
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(ViewHolder holder, int position) {
|
public void onBindViewHolder(final ViewHolder holder, int position) {
|
||||||
final PasswordItem pass = values.get(position);
|
final PasswordItem pass = values.get(position);
|
||||||
holder.name.setText(pass.toString());
|
holder.name.setText(pass.toString());
|
||||||
int sdk = android.os.Build.VERSION.SDK_INT;
|
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) {
|
public void add(PasswordItem item) {
|
||||||
this.values.add(item);
|
this.values.add(item);
|
||||||
this.notifyDataSetChanged();
|
this.notifyItemInserted(values.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void remove(int position) {
|
||||||
|
this.values.remove(position);
|
||||||
|
this.notifyItemRemoved(position);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
11
app/src/main/res/menu/context_pass.xml
Normal file
11
app/src/main/res/menu/context_pass.xml
Normal file
@@ -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>
|
||||||
|
|
Reference in New Issue
Block a user