Confirm before removing an account

This commit is contained in:
Jakob Nixdorf 2017-07-03 08:18:05 +02:00
parent 5440cb96c7
commit 20b81bf41c
No known key found for this signature in database
GPG key ID: BE99BF86574A7DBC
3 changed files with 31 additions and 8 deletions

View file

@ -22,6 +22,9 @@
package org.shadowice.flocke.andotp;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
@ -38,10 +41,12 @@ import java.util.Collections;
public class EntriesCardAdapter extends RecyclerView.Adapter<EntriesCardAdapter.EntryViewHolder>
implements ItemTouchHelperAdapter {
private Context context;
private ArrayList<Entry> entries;
public ViewHolderEventCallback viewHolderEventCallback;
public EntriesCardAdapter(ArrayList<Entry> entries) {
public EntriesCardAdapter(Context context, ArrayList<Entry> entries) {
this.context = context;
this.entries = entries;
}
@ -75,9 +80,27 @@ public class EntriesCardAdapter extends RecyclerView.Adapter<EntriesCardAdapter.
}
@Override
public void onItemDismiss(int position) {
entries.remove(position);
notifyItemRemoved(position);
public void onItemDismiss(final int position) {
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(context.getString(R.string.alert_remove))
.setMessage(context.getString(R.string.msg_confirm_delete))
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
entries.remove(position);
notifyItemRemoved(position);
SettingsHelper.store(context, entries);
}
})
.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
notifyItemChanged(position);
}
})
.show();
}
@Override
@ -93,6 +116,8 @@ public class EntriesCardAdapter extends RecyclerView.Adapter<EntriesCardAdapter.
}
notifyItemMoved(fromPosition, toPosition);
SettingsHelper.store(context, entries);
return true;
}

View file

@ -271,7 +271,7 @@ public class MainActivity extends AppCompatActivity {
entries = SettingsHelper.load(this);
adapter = new EntriesCardAdapter(entries);
adapter = new EntriesCardAdapter(this, entries);
recList.setAdapter(adapter);
ItemTouchHelper.Callback callback = new SimpleItemTouchHelperCallback(adapter);
@ -287,8 +287,6 @@ public class MainActivity extends AppCompatActivity {
@Override
public void onMoveEventStop() {
startUpdater();
SettingsHelper.store(getBaseContext(), entries);
}
@Override

View file

@ -14,7 +14,7 @@
<string name="msg_account_removed">Account removed</string>
<string name="button_add">Add</string>
<string name="alert_rename">Rename</string>
<string name="alert_remove">"Remove "</string>
<string name="alert_remove">Remove</string>
<string name="msg_camera_permission">Camera permission not granted</string>
<string name="msg_storage_permissions">Storage permissions not granted</string>
<string name="msg_security_warning">Security warning</string>