From 6d8645bc5ffd9ad56124ddc21b2477c687c15ff7 Mon Sep 17 00:00:00 2001 From: Damyan Ivanov Date: Sat, 7 Mar 2020 16:44:50 +0200 Subject: [PATCH] new transaction: hide currency/commodity selector by default; add menu item for showing --- .../ui/activity/NewTransactionFragment.java | 9 +++++++++ .../ui/activity/NewTransactionItemHolder.java | 13 +++++++++++++ .../ui/activity/NewTransactionModel.java | 4 ++++ app/src/main/res/layout/new_transaction_row.xml | 2 +- app/src/main/res/menu/new_transaction_fragment.xml | 6 ++++++ app/src/main/res/values-bg/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + 7 files changed, 35 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionFragment.java b/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionFragment.java index f212bc09..55b0e610 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionFragment.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionFragment.java @@ -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, diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionItemHolder.java b/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionItemHolder.java index 91d45031..d7017e21 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionItemHolder.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionItemHolder.java @@ -91,6 +91,7 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder private Observer currencyGapObserver; private Observer localeObserver; private Observer currencyObserver; + private Observer 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 { diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionModel.java b/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionModel.java index 62f85ba9..cad07c0d 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionModel.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionModel.java @@ -56,6 +56,7 @@ public class NewTransactionModel extends ViewModel { private final MutableLiveData focusedItem = new MutableLiveData<>(0); private final MutableLiveData accountCount = new MutableLiveData<>(0); private final MutableLiveData simulateSave = new MutableLiveData<>(false); + final MutableLiveData 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} //========================================================================================== diff --git a/app/src/main/res/layout/new_transaction_row.xml b/app/src/main/res/layout/new_transaction_row.xml index 11951e58..65814a79 100644 --- a/app/src/main/res/layout/new_transaction_row.xml +++ b/app/src/main/res/layout/new_transaction_row.xml @@ -155,7 +155,7 @@ 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"/> diff --git a/app/src/main/res/menu/new_transaction_fragment.xml b/app/src/main/res/menu/new_transaction_fragment.xml index dc9b08dc..a48b4ad6 100644 --- a/app/src/main/res/menu/new_transaction_fragment.xml +++ b/app/src/main/res/menu/new_transaction_fragment.xml @@ -18,6 +18,12 @@ + Вляво Вдясно валута/ценност + Валута diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index cd375358..b8ca9493 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -154,4 +154,5 @@ Left Right Offset from the value + Currency -- 2.39.5