]> git.ktnx.net Git - mobile-ledger.git/commitdiff
add divider after debug items in the new transaction menu
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Sun, 7 Mar 2021 09:09:03 +0000 (11:09 +0200)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Sun, 7 Mar 2021 09:09:03 +0000 (11:09 +0200)
also, call super.onCreateOptionsMenu to let the system put any system
menu items if needed

also, don't bother with debug menu items in the release build

app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionActivity.java
app/src/main/res/menu/new_transaction.xml
app/src/main/res/menu/new_transaction_fragment.xml

index 3e1772608fd931f652258204f9ccc3bd6558d8ef..5bba06e1ddcf121d1d66c66f68d117f6a49d54b0 100644 (file)
@@ -31,6 +31,7 @@ import android.view.View;
 
 import androidx.activity.result.ActivityResultLauncher;
 import androidx.annotation.NonNull;
+import androidx.core.view.MenuCompat;
 import androidx.lifecycle.LiveData;
 import androidx.lifecycle.ViewModelProvider;
 import androidx.navigation.NavController;
@@ -159,15 +160,15 @@ public class NewTransactionActivity extends ProfileThemedActivity
         new AsyncCrasher().execute();
     }
     public boolean onCreateOptionsMenu(Menu menu) {
+        super.onCreateOptionsMenu(menu);
+
+        if (!BuildConfig.DEBUG)
+            return true;
+
         // Inflate the menu; this adds items to the action bar if it is present.
         getMenuInflater().inflate(R.menu.new_transaction, menu);
 
-        if (BuildConfig.DEBUG) {
-            menu.findItem(R.id.action_simulate_crash)
-                .setVisible(true);
-            menu.findItem(R.id.action_simulate_save)
-                .setVisible(true);
-        }
+        MenuCompat.setGroupDividerEnabled(menu, true);
 
         model.getSimulateSave()
              .observe(this, state -> {
index 060750803728d9bb0905680803133d37eb07819c..15fe57b0528d39ce2ba190892be3530204791619 100644 (file)
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?><!--
-  ~ Copyright © 2019 Damyan Ivanov.
+  ~ Copyright © 2021 Damyan Ivanov.
   ~ This file is part of MoLe.
   ~ MoLe is free software: you can distribute it and/or modify it
   ~ under the term of the GNU General Public License as published by
   -->
 
 <menu xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:app="http://schemas.android.com/apk/res-auto">
-    <item
-        android:id="@+id/action_simulate_crash"
-        android:title="@string/crash_app_label"
-        android:titleCondensed="@string/crash_app_condensed_label"
-        android:onClick="simulateCrash"
-        android:visible="false"
-        app:showAsAction="never" />
-    <item
-        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"
-        android:visible="false"
-        app:showAsAction="never" />
+    xmlns:app="http://schemas.android.com/apk/res-auto"
+    >
+    <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"
+            />
+        <item
+            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"
+            />
+    </group>
 </menu>
\ No newline at end of file
index 1fe3824330b8fc54a396d97f8c111835b01df46d..b9a34687adc330e3ddf187cddf837273a350f5ae 100644 (file)
@@ -1,5 +1,4 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
+<?xml version="1.0" encoding="utf-8"?><!--
   ~ Copyright © 2021 Damyan Ivanov.
   ~ This file is part of MoLe.
   ~ MoLe is free software: you can distribute it and/or modify it
 <menu xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:app="http://schemas.android.com/apk/res-auto"
     >
-    <item
-        android:id="@+id/scan_qr"
-        android:icon="@drawable/ic_baseline_qr_code_scanner_24"
-        android:title="@string/scan_qr"
-        app:showAsAction="ifRoom"
-        />
-    <item
-        android:id="@+id/toggle_currency"
-        android:title="@string/show_currency_input"
-        android:checkable="true"
-        android:checked="false"
-        app:actionLayout="@layout/switch_item"
-        app:showAsAction="never"
-        />
-    <item
-        android:id="@+id/toggle_comments"
-        android:checkable="true"
-        android:title="@string/show_comments_switch"
-        app:actionLayout="@layout/switch_item"
-        app:showAsAction="never" />
-    <item
-        android:id="@+id/action_reset_new_transaction_activity"
-        android:icon="@drawable/ic_refresh_white_24dp"
-        android:title="@string/action_reset_new_transaction_activity_title"
-        app:showAsAction="never" />
-
+    <group android:id="@+id/new_transaction_fragment_menu_items">
+        <item
+            android:id="@+id/scan_qr"
+            android:icon="@drawable/ic_baseline_qr_code_scanner_24"
+            android:title="@string/scan_qr"
+            app:showAsAction="ifRoom"
+            />
+        <item
+            android:id="@+id/toggle_currency"
+            android:checkable="true"
+            android:checked="false"
+            android:title="@string/show_currency_input"
+            app:actionLayout="@layout/switch_item"
+            app:showAsAction="never"
+            />
+        <item
+            android:id="@+id/toggle_comments"
+            android:checkable="true"
+            android:title="@string/show_comments_switch"
+            app:actionLayout="@layout/switch_item"
+            app:showAsAction="never"
+            />
+        <item
+            android:id="@+id/action_reset_new_transaction_activity"
+            android:icon="@drawable/ic_refresh_white_24dp"
+            android:title="@string/action_reset_new_transaction_activity_title"
+            app:showAsAction="never"
+            />
+    </group>
 </menu>
\ No newline at end of file