From 54e5fba7c07d819f1499a6fcf29b9696fbcde9cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Sch=C3=A4ttgen?= Date: Tue, 1 Nov 2016 22:57:21 +0100 Subject: [PATCH] Added AlertDialog to delete process --- .../main/java/me/impy/aegis/MainActivity.java | 33 +++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/me/impy/aegis/MainActivity.java b/app/src/main/java/me/impy/aegis/MainActivity.java index 2d8f74ce..a0669678 100644 --- a/app/src/main/java/me/impy/aegis/MainActivity.java +++ b/app/src/main/java/me/impy/aegis/MainActivity.java @@ -4,11 +4,13 @@ import android.app.FragmentManager; import android.content.ClipData; import android.content.ClipboardManager; import android.content.Context; +import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; import android.preference.PreferenceManager; import android.support.design.widget.BottomSheetDialog; import android.support.design.widget.FloatingActionButton; +import android.support.v7.app.AlertDialog; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.support.v7.widget.LinearLayoutManager; @@ -209,9 +211,36 @@ public class MainActivity extends AppCompatActivity { Toast.makeText(this.getApplicationContext(), "Code successfully copied to the clipboard", Toast.LENGTH_SHORT).show(); }); - - return bottomDialog; + deleteLayout.setOnClickListener(view -> { + bottomDialog.dismiss(); + + KeyProfile keyProfile = mKeyProfiles.get(clickedItemPosition); + deleteProfile(keyProfile); + }); + + editLayout.setOnClickListener(view -> { + bottomDialog.dismiss(); + Toast.makeText(this.getApplicationContext(), "Coming soon", Toast.LENGTH_SHORT).show(); + }); + + return bottomDialog; + } + + 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) -> { + database.removeKey(profile); + mKeyProfiles.remove(clickedItemPosition); + mKeyProfileAdapter.notifyItemRemoved(clickedItemPosition); + }) + .setNegativeButton(android.R.string.no, (dialog, which) -> { + + }) + .show(); } @Override