]> git.ktnx.net Git - mobile-ledger.git/commitdiff
handle menu items click hooks by code in new transaction activity
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Sun, 7 Mar 2021 09:16:34 +0000 (11:16 +0200)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Sun, 7 Mar 2021 09:16:34 +0000 (11:16 +0200)
app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionActivity.java
app/src/main/res/menu/new_transaction.xml

index 5bba06e1ddcf121d1d66c66f68d117f6a49d54b0..ce97d985d9dc8eb5593b29a5eaa46993e4bd6ed5 100644 (file)
@@ -155,9 +155,10 @@ public class NewTransactionActivity extends ProfileThemedActivity
             navController.navigate(R.id.newTransactionFragment, b);
         }
     }
-    public void simulateCrash(MenuItem item) {
+    public boolean onSimulateCrashMenuItemClicked(MenuItem item) {
         debug("crash", "Will crash intentionally");
         new AsyncCrasher().execute();
+        return true;
     }
     public boolean onCreateOptionsMenu(Menu menu) {
         super.onCreateOptionsMenu(menu);
@@ -170,6 +171,11 @@ public class NewTransactionActivity extends ProfileThemedActivity
 
         MenuCompat.setGroupDividerEnabled(menu, true);
 
+        menu.findItem(R.id.action_simulate_save)
+            .setOnMenuItemClickListener(this::onToggleSimulateSaveMenuItemClicked);
+        menu.findItem(R.id.action_simulate_crash)
+            .setOnMenuItemClickListener(this::onSimulateCrashMenuItemClicked);
+
         model.getSimulateSave()
              .observe(this, state -> {
                  menu.findItem(R.id.action_simulate_save)
@@ -195,8 +201,9 @@ public class NewTransactionActivity extends ProfileThemedActivity
         else
             navController.navigate(R.id.action_newTransactionSavingFragment_Success, b);
     }
-    public void toggleSimulateSave(MenuItem item) {
+    public boolean onToggleSimulateSaveMenuItemClicked(MenuItem item) {
         model.toggleSimulateSave();
+        return true;
     }
 
     @Override
index 15fe57b0528d39ce2ba190892be3530204791619..f4862d8c2e7a2f3a125af1eeb21bc37458cb4b64 100644 (file)
@@ -21,7 +21,6 @@
     <group android:id="@+id/new_transaction_debug_menu_items">
         <item
             android:id="@+id/action_simulate_crash"
-            android:onClick="simulateCrash"
             android:title="@string/crash_app_label"
             android:titleCondensed="@string/crash_app_condensed_label"
             app:showAsAction="never"
@@ -30,7 +29,6 @@
             android:id="@+id/action_simulate_save"
             android:checkable="true"
             android:checked="false"
-            android:onClick="toggleSimulateSave"
             android:title="@string/simulate_save_label"
             android:titleCondensed="@string/simulate_save_condensed_label"
             app:showAsAction="never"