]> git.ktnx.net Git - mobile-ledger.git/commitdiff
new transaction: hide currency/commodity selector by default; add menu item for showing
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Sat, 7 Mar 2020 14:44:50 +0000 (16:44 +0200)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Sat, 7 Mar 2020 14:48:04 +0000 (16:48 +0200)
app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionFragment.java
app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionItemHolder.java
app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionModel.java
app/src/main/res/layout/new_transaction_row.xml
app/src/main/res/menu/new_transaction_fragment.xml
app/src/main/res/values-bg/strings.xml
app/src/main/res/values/strings.xml

index f212bc0902eda6c7efb3cabadf8486f95d722419..55b0e6106c91ac3d0b22337df5def7f8072522d3 100644 (file)
@@ -23,6 +23,7 @@ import android.renderscript.RSInvalidStateException;
 import android.view.LayoutInflater;
 import android.view.Menu;
 import android.view.MenuInflater;
+import android.view.MenuItem;
 import android.view.View;
 import android.view.ViewGroup;
 
@@ -78,6 +79,14 @@ public class NewTransactionFragment extends Fragment {
                 listAdapter.reset();
                 return true;
             });
+        final MenuItem toggleCurrencyItem = menu.findItem(R.id.toggle_currency);
+        toggleCurrencyItem.setOnMenuItemClickListener(item -> {
+            viewModel.toggleCurrencyVisible();
+            return true;
+        });
+        final FragmentActivity activity = getActivity();
+        if (activity != null)
+            viewModel.showCurrency.observe(activity, toggleCurrencyItem::setChecked);
     }
     @Override
     public View onCreateView(LayoutInflater inflater, ViewGroup container,
index 91d45031bd373e0f788be3813606cd7df47457c3..d7017e21a6816056c18a7fc104eff8639b2ac97a 100644 (file)
@@ -91,6 +91,7 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder
     private Observer<Boolean> currencyGapObserver;
     private Observer<Locale> localeObserver;
     private Observer<Currency> currencyObserver;
+    private Observer<Boolean> showCurrencyObserver;
     private boolean inUpdate = false;
     private boolean syncingData = false;
     private View commentButton;
@@ -353,6 +354,16 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder
         };
 
         currencyObserver = this::setCurrency;
+
+        showCurrencyObserver = showCurrency -> {
+              if (showCurrency) {
+                  tvCurrency.setVisibility(View.VISIBLE);
+              }
+            else {
+                tvCurrency.setVisibility(View.GONE);
+                setCurrencyString(null);
+              }
+        };
     }
     private void updateCurrencyPositionAndPadding(Currency.Position position, boolean hasGap) {
         ConstraintLayout.LayoutParams amountLP =
@@ -552,6 +563,7 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder
                 Data.currencyGap.removeObserver(currencyGapObserver);
                 Data.locale.removeObserver(localeObserver);
                 this.item.stopObservingCurrency(currencyObserver);
+                this.item.getModel().showCurrency.removeObserver(showCurrencyObserver);
 
                 this.item = null;
             }
@@ -609,6 +621,7 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder
                 Data.currencyGap.observe(activity, currencyGapObserver);
                 Data.locale.observe(activity, localeObserver);
                 item.observeCurrency(activity, currencyObserver);
+                item.getModel().showCurrency.observe(activity, showCurrencyObserver);
             }
         }
         finally {
index 62f85ba9bed06220d66cde8722f5750e05593a4e..cad07c0def34ee0ea3acb810775aa98a81c4f270 100644 (file)
@@ -56,6 +56,7 @@ public class NewTransactionModel extends ViewModel {
     private final MutableLiveData<Integer> focusedItem = new MutableLiveData<>(0);
     private final MutableLiveData<Integer> accountCount = new MutableLiveData<>(0);
     private final MutableLiveData<Boolean> simulateSave = new MutableLiveData<>(false);
+    final MutableLiveData<Boolean> showCurrency = new MutableLiveData<>(false);
     public boolean getSimulateSave() {
         return simulateSave.getValue();
     }
@@ -318,6 +319,9 @@ public class NewTransactionModel extends ViewModel {
             items.add(itemCount - 1, acc);
         }
     }
+    public void toggleCurrencyVisible() {
+        showCurrency.setValue(!showCurrency.getValue());
+    }
     enum ItemType {generalData, transactionRow, bottomFiller}
 
     //==========================================================================================
index 11951e58dd60752fedd04a09ff96082e63b6c339..65814a79a3779d0008c7ed72a9fee04a041c23b7 100644 (file)
                 android:text="@string/currency_symbol"
                 style="@style/TextAppearance.AppCompat.Widget.Button"
                 android:textAllCaps="false"
-                android:visibility="visible"
+                android:visibility="gone"
                 android:minWidth="24dp"
                 android:gravity="center_horizontal"/>
         </androidx.constraintlayout.widget.ConstraintLayout>
index dc9b08dc992266d1e0928dfc43eab17d1abed3b0..a48b4ad687e4cd23a50ef44b0270def3ada1770d 100644 (file)
 
 <menu xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:app="http://schemas.android.com/apk/res-auto">
+    <item
+        android:id="@+id/toggle_currency"
+        android:title="@string/show_currency_input"
+        android:checkable="true"
+        android:checked="false"
+        app:showAsAction="never" />
     <item
         android:id="@+id/action_reset_new_transaction_activity"
         android:icon="@drawable/ic_refresh_white_24dp"
index 27f802a6943b7987f0250a9a883839715c04387f..d76b7d09c4a92eae493149d2105dc7c6031f0807 100644 (file)
     <string name="currency_position_left">Вляво</string>
     <string name="currency_position_right">Вдясно</string>
     <string name="new_currency_name_hint">валута/ценност</string>
+    <string name="show_currency_input">Валута</string>
 
 </resources>
index cd3753587fdb038a132656ee3e081fdde8f30c41..b8ca9493ec57186e280bc30644fe7bfc85b99ca7 100644 (file)
     <string name="currency_position_left">Left</string>
     <string name="currency_position_right">Right</string>
     <string name="currency_has_gap">Offset from the value</string>
+    <string name="show_currency_input">Currency</string>
 </resources>