From c2ff9d75057e338e64a3513ae3bd9cef66dca684 Mon Sep 17 00:00:00 2001 From: Page Asgardius Date: Mon, 5 Sep 2022 09:50:05 -0700 Subject: [PATCH] account delete option --- .idea/misc.xml | 1 + .../page/s3manager/MainActivity.java | 32 +++++++++++++++++++ app/src/main/res/menu/popup_menu.xml | 12 +++++++ app/src/main/res/values/strings.xml | 3 ++ 4 files changed, 48 insertions(+) create mode 100644 app/src/main/res/menu/popup_menu.xml diff --git a/.idea/misc.xml b/.idea/misc.xml index cfd40a7..22346e9 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -10,6 +10,7 @@ + diff --git a/app/src/main/java/asgardius/page/s3manager/MainActivity.java b/app/src/main/java/asgardius/page/s3manager/MainActivity.java index dac9de2..aba58dd 100644 --- a/app/src/main/java/asgardius/page/s3manager/MainActivity.java +++ b/app/src/main/java/asgardius/page/s3manager/MainActivity.java @@ -4,8 +4,10 @@ import android.content.Intent; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.os.Bundle; +import android.view.MenuItem; import android.view.View; import android.widget.Button; +import android.widget.PopupMenu; import android.widget.Toast; import androidx.appcompat.app.AppCompatActivity; @@ -115,6 +117,36 @@ public class MainActivity extends AppCompatActivity { @Override public void onLongClick(View view, int position) { System.out.println("Long click on "+Name.get(position).toString()); + // Initializing the popup menu and giving the reference as current context + PopupMenu popupMenu = new PopupMenu(MainActivity.this, recyclerView); + + // Inflating popup menu from popup_menu.xml file + popupMenu.getMenuInflater().inflate(R.menu.popup_menu, popupMenu.getMenu()); + popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { + @Override + public boolean onMenuItemClick(MenuItem menuItem) { + // Toast message on menu item clicked + //Toast.makeText(MainActivity.this, "You Clicked " + menuItem.getTitle(), Toast.LENGTH_SHORT).show(); + if (menuItem.getTitle() == getResources().getString(R.string.accountedit_button)) { + Toast.makeText(MainActivity.this, "Edit Account", Toast.LENGTH_SHORT).show(); + } + 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(); + } catch (Exception e) { + Toast.makeText(getApplicationContext(),getResources().getString(R.string.accountadd_fail), Toast.LENGTH_SHORT).show(); + } + } + //Toast.makeText(MainActivity.this, "Delete Account", Toast.LENGTH_SHORT).show(); + } + return true; + } + }); + // Showing the popup menu + popupMenu.show(); } })); diff --git a/app/src/main/res/menu/popup_menu.xml b/app/src/main/res/menu/popup_menu.xml new file mode 100644 index 0000000..8a6f6db --- /dev/null +++ b/app/src/main/res/menu/popup_menu.xml @@ -0,0 +1,12 @@ + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 8525e03..16af0a1 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -10,6 +10,9 @@ Account added successfully This alias is already in use All fields are required + Remove Account + Account removed successfully + Edit Account File Explorer Test Video Test Cannot retrieve media file