Don't close the EditProfileActivity to show a delete entry dialog

This commit is contained in:
Alexander Bakker 2018-05-10 23:11:21 +02:00
parent da529608fa
commit e45735faa1
3 changed files with 37 additions and 19 deletions

View file

@ -31,6 +31,7 @@ import me.impy.aegis.encoding.Base32;
import me.impy.aegis.helpers.EditTextHelper;
import me.impy.aegis.helpers.SpinnerHelper;
import me.impy.aegis.helpers.TextDrawableHelper;
import me.impy.aegis.ui.dialogs.Dialogs;
import me.impy.aegis.ui.views.KeyProfile;
public class EditProfileActivity extends AegisActivity {
@ -231,14 +232,20 @@ public class EditProfileActivity extends AegisActivity {
switch (item.getItemId()) {
case android.R.id.home:
onBackPressed();
return true;
break;
case R.id.action_save:
return onSave();
onSave();
break;
case R.id.action_delete:
return onDelete();
Dialogs.showDeleteEntryDialog(this, (dialog, which) -> {
finish(true);
});
break;
default:
return super.onOptionsItemSelected(item);
}
return true;
}
@Override
@ -258,11 +265,6 @@ public class EditProfileActivity extends AegisActivity {
finish();
}
private boolean onDelete() {
finish(true);
return true;
}
private boolean onSave() {
if (_textSecret.length() == 0) {
onError("Secret is a required field.");

View file

@ -27,6 +27,7 @@ import me.impy.aegis.db.DatabaseManagerException;
import me.impy.aegis.db.DatabaseEntry;
import me.impy.aegis.db.DatabaseManager;
import me.impy.aegis.helpers.PermissionHelper;
import me.impy.aegis.ui.dialogs.Dialogs;
import me.impy.aegis.ui.views.KeyProfile;
import me.impy.aegis.ui.views.KeyProfileView;
@ -378,7 +379,9 @@ public class MainActivity extends AegisActivity implements KeyProfileView.Listen
deleteLayout.setOnClickListener(view -> {
bottomDialog.dismiss();
deleteProfile(profile);
Dialogs.showDeleteEntryDialog(this, (dialog, which) -> {
deleteProfile(profile);
});
});
editLayout.setOnClickListener(view -> {
@ -390,17 +393,10 @@ public class MainActivity extends AegisActivity implements KeyProfileView.Listen
}
private void deleteProfile(KeyProfile profile) {
new AlertDialog.Builder(MainActivity.this)
.setTitle("Delete entry")
.setMessage("Are you sure you want to delete this profile?")
.setPositiveButton(android.R.string.yes, (dialog, which) -> {
_db.removeKey(profile.getEntry());
saveDatabase();
_db.removeKey(profile.getEntry());
saveDatabase();
_keyProfileView.removeKey(profile);
})
.setNegativeButton(android.R.string.no, null)
.show();
_keyProfileView.removeKey(profile);
}
@Override

View file

@ -0,0 +1,20 @@
package me.impy.aegis.ui.dialogs;
import android.content.Context;
import android.content.DialogInterface;
import android.support.v7.app.AlertDialog;
public class Dialogs {
private Dialogs() {
}
public static AlertDialog showDeleteEntryDialog(Context context, DialogInterface.OnClickListener onDelete) {
return new AlertDialog.Builder(context)
.setTitle("Delete entry")
.setMessage("Are you sure you want to delete this entry?")
.setPositiveButton(android.R.string.yes, onDelete)
.setNegativeButton(android.R.string.no, null)
.show();
}
}