From 4bdc78a229343b7b8d47f4114a576e9611a00494 Mon Sep 17 00:00:00 2001 From: Page Asgardius Date: Wed, 7 Sep 2022 10:44:34 -0700 Subject: [PATCH] delete confirmation --- .../page/s3manager/MainActivity.java | 43 ++++++++++++++----- app/src/main/res/values/strings.xml | 2 + 2 files changed, 34 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/asgardius/page/s3manager/MainActivity.java b/app/src/main/java/asgardius/page/s3manager/MainActivity.java index a299997..f5349e6 100644 --- a/app/src/main/java/asgardius/page/s3manager/MainActivity.java +++ b/app/src/main/java/asgardius/page/s3manager/MainActivity.java @@ -1,5 +1,6 @@ package asgardius.page.s3manager; +import android.content.DialogInterface; import android.content.Intent; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; @@ -10,6 +11,7 @@ import android.widget.Button; import android.widget.PopupMenu; import android.widget.Toast; +import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AppCompatActivity; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; @@ -49,7 +51,7 @@ public class MainActivity extends AppCompatActivity { Img.add(R.drawable.account); } } else { - System.out.println("Database Missing"); + Toast.makeText(getApplicationContext(),getResources().getString(R.string.broken_database), Toast.LENGTH_SHORT).show(); } Thread listaccount = new Thread(new Runnable() { @@ -79,7 +81,7 @@ public class MainActivity extends AppCompatActivity { @Override public void run() { - Toast.makeText(getApplicationContext(),getResources().getString(R.string.media_list_fail), Toast.LENGTH_SHORT).show(); + Toast.makeText(getApplicationContext(),getResources().getString(R.string.broken_database), Toast.LENGTH_SHORT).show(); } }); //Toast.makeText(getApplicationContext(),getResources().getString(R.string.media_list_fail), Toast.LENGTH_SHORT).show(); @@ -145,16 +147,35 @@ public class MainActivity extends AppCompatActivity { } } else if (menuItem.getTitle() == getResources().getString(R.string.accountdel_button)) { - if (db != null) { - // Database Queries - try { - db.execSQL("DELETE FROM account where id=\""+ Name.get(position).toString()+ "\""); - Toast.makeText(getApplicationContext(),getResources().getString(R.string.accountdel_success), Toast.LENGTH_SHORT).show(); - mainmenu(); - } catch (Exception e) { - Toast.makeText(getApplicationContext(),getResources().getString(R.string.accountadd_fail), Toast.LENGTH_SHORT).show(); + AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); + builder.setCancelable(true); + builder.setTitle(getResources().getString(R.string.accountdel_button)); + builder.setMessage(getResources().getString(R.string.accountdel_confirm)); + builder.setPositiveButton(android.R.string.ok, + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + if (db != null) { + // Database Queries + try { + db.execSQL("DELETE FROM account where id=\""+ Name.get(position).toString()+ "\""); + Toast.makeText(getApplicationContext(),getResources().getString(R.string.accountdel_success), Toast.LENGTH_SHORT).show(); + mainmenu(); + } catch (Exception e) { + Toast.makeText(getApplicationContext(),getResources().getString(R.string.broken_database), Toast.LENGTH_SHORT).show(); + } + } + } + }); + builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { } - } + }); + + AlertDialog dialog = builder.create(); + dialog.show(); + /**/ //Toast.makeText(MainActivity.this, "Delete Account", Toast.LENGTH_SHORT).show(); } return true; diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a557386..ec513ce 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,6 +1,7 @@ Asgardius S3 Manager VideoPlayer + Local database is corrupted. Please reinstall this app Please choose an account Add Account Test credentials @@ -14,6 +15,7 @@ All fields are required Remove Account Account removed successfully + Do you want to remove this accunt? Edit Account Save Changes Account edited successfully