From 6fdb62c5385048a80aa877386f15eef02796e728 Mon Sep 17 00:00:00 2001 From: MrLetsplay Date: Tue, 20 Jun 2023 21:57:08 +0200 Subject: [PATCH] Delete action --- .../cringe_authenticator/MainActivity.java | 4 +-- .../fragment/MenuFragment.java | 14 +++++++- app/src/main/res/layout/authenticate_totp.xml | 36 +++++++++++-------- app/src/main/res/layout/menu_item.xml | 2 +- 4 files changed, 38 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/com/cringe_studios/cringe_authenticator/MainActivity.java b/app/src/main/java/com/cringe_studios/cringe_authenticator/MainActivity.java index 5521506..36e5bf6 100644 --- a/app/src/main/java/com/cringe_studios/cringe_authenticator/MainActivity.java +++ b/app/src/main/java/com/cringe_studios/cringe_authenticator/MainActivity.java @@ -73,11 +73,11 @@ public class MainActivity extends AppCompatActivity { public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. - if(NavigationUtil.getCurrentFragment(this) instanceof DynamicFragment) { + /*if(NavigationUtil.getCurrentFragment(this) instanceof DynamicFragment) { TODO: vs. fabs? //getMenuInflater().inflate(R.menu.menu_dynamic, menu); getMenuInflater().inflate(R.menu.menu_dynamic, menu); return true; - } + }*/ getMenuInflater().inflate(R.menu.menu_main, menu); return true; diff --git a/app/src/main/java/com/cringe_studios/cringe_authenticator/fragment/MenuFragment.java b/app/src/main/java/com/cringe_studios/cringe_authenticator/fragment/MenuFragment.java index 44a680a..023b4e5 100644 --- a/app/src/main/java/com/cringe_studios/cringe_authenticator/fragment/MenuFragment.java +++ b/app/src/main/java/com/cringe_studios/cringe_authenticator/fragment/MenuFragment.java @@ -11,6 +11,7 @@ import android.widget.Button; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.appcompat.app.AlertDialog; import androidx.fragment.app.Fragment; import com.cringe_studios.cringe_authenticator.R; @@ -40,7 +41,18 @@ public class MenuFragment extends Fragment { bundle.putString("tab", item); NavigationUtil.navigate(this, DynamicFragment.class, bundle); }); - binding.menuItems.addView(itemBinding.getRoot(), 0); + itemBinding.button.setOnLongClickListener(view -> { + new AlertDialog.Builder(getContext()) + .setTitle("Delete?") + .setMessage("Delete this?") + .setPositiveButton("Yes", (dialog, which) -> itemBinding.button.setVisibility(View.GONE)) + .setNegativeButton("No", (dialog, which) -> {}) + .show(); + // TODO: better method? + // TODO: actually delete + return true; + }); + binding.menuItems.addView(itemBinding.getRoot()); } binding.editSwitch.setOnCheckedChangeListener((view, checked) -> { diff --git a/app/src/main/res/layout/authenticate_totp.xml b/app/src/main/res/layout/authenticate_totp.xml index 61bb572..ea28f90 100644 --- a/app/src/main/res/layout/authenticate_totp.xml +++ b/app/src/main/res/layout/authenticate_totp.xml @@ -1,21 +1,29 @@ - - + android:layout_height="match_parent" + android:background="@drawable/rectangle" + android:layout_margin="5dp" + android:padding="5dp" + android:orientation="vertical"> + - + + \ No newline at end of file diff --git a/app/src/main/res/layout/menu_item.xml b/app/src/main/res/layout/menu_item.xml index 12db4d8..5702cb1 100644 --- a/app/src/main/res/layout/menu_item.xml +++ b/app/src/main/res/layout/menu_item.xml @@ -8,5 +8,5 @@ android:id="@+id/button" android:layout_width="match_parent" android:layout_height="wrap_content" - android:text="Button" /> + android:text="Button"/> \ No newline at end of file