import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
+import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
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,
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;
};
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 =
Data.currencyGap.removeObserver(currencyGapObserver);
Data.locale.removeObserver(localeObserver);
this.item.stopObservingCurrency(currencyObserver);
+ this.item.getModel().showCurrency.removeObserver(showCurrencyObserver);
this.item = null;
}
Data.currencyGap.observe(activity, currencyGapObserver);
Data.locale.observe(activity, localeObserver);
item.observeCurrency(activity, currencyObserver);
+ item.getModel().showCurrency.observe(activity, showCurrencyObserver);
}
}
finally {
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();
}
items.add(itemCount - 1, acc);
}
}
+ public void toggleCurrencyVisible() {
+ showCurrency.setValue(!showCurrency.getValue());
+ }
enum ItemType {generalData, transactionRow, bottomFiller}
//==========================================================================================
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>
<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"
<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>
<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>