+
+ currencyGapObserver =
+ hasGap -> updateCurrencyPositionAndPadding(Data.currencySymbolPosition.getValue(),
+ hasGap);
+
+ currencyPositionObserver =
+ position -> updateCurrencyPositionAndPadding(position, Data.currencyGap.getValue());
+
+ showCurrencyObserver = showCurrency -> {
+ if (showCurrency) {
+ tvCurrency.setVisibility(View.VISIBLE);
+ }
+ else {
+ tvCurrency.setVisibility(View.GONE);
+ item.setCurrency(null);
+ }
+ };
+
+ commentObserver = comment -> {
+ final View focusedView = tvComment.findFocus();
+ tvComment.setTypeface(null,
+ (focusedView == tvComment) ? Typeface.NORMAL : Typeface.ITALIC);
+ tvComment.setVisibility(
+ ((focusedView != tvComment) && Misc.isEmptyOrNull(comment)) ? View.INVISIBLE
+ : View.VISIBLE);
+ };
+
+ busyFlagObserver = isBusy -> {p.setVisibility(isBusy ? View.VISIBLE : View.INVISIBLE);};
+ }
+ private void updateCurrencyPositionAndPadding(Currency.Position position, boolean hasGap) {
+ ConstraintLayout.LayoutParams amountLP =
+ (ConstraintLayout.LayoutParams) tvAmount.getLayoutParams();
+ ConstraintLayout.LayoutParams currencyLP =
+ (ConstraintLayout.LayoutParams) tvCurrency.getLayoutParams();
+
+ if (position == Currency.Position.before) {
+ currencyLP.startToStart = ConstraintLayout.LayoutParams.PARENT_ID;
+ currencyLP.endToEnd = ConstraintLayout.LayoutParams.UNSET;
+
+ amountLP.endToEnd = ConstraintLayout.LayoutParams.PARENT_ID;
+ amountLP.endToStart = ConstraintLayout.LayoutParams.UNSET;
+ amountLP.startToStart = ConstraintLayout.LayoutParams.UNSET;
+ amountLP.startToEnd = tvCurrency.getId();
+
+ tvCurrency.setGravity(Gravity.END);
+ }
+ else {
+ currencyLP.startToStart = ConstraintLayout.LayoutParams.UNSET;
+ currencyLP.endToEnd = ConstraintLayout.LayoutParams.PARENT_ID;
+
+ amountLP.startToStart = ConstraintLayout.LayoutParams.PARENT_ID;
+ amountLP.startToEnd = ConstraintLayout.LayoutParams.UNSET;
+ amountLP.endToEnd = ConstraintLayout.LayoutParams.UNSET;
+ amountLP.endToStart = tvCurrency.getId();
+
+ tvCurrency.setGravity(Gravity.START);
+ }
+
+ amountLP.resolveLayoutDirection(tvAmount.getLayoutDirection());
+ currencyLP.resolveLayoutDirection(tvCurrency.getLayoutDirection());
+
+ tvAmount.setLayoutParams(amountLP);
+ tvCurrency.setLayoutParams(currencyLP);
+
+ // distance between the amount and the currency symbol
+ int gapSize = DimensionUtils.sp2px(tvCurrency.getContext(), 5);
+
+ if (position == Currency.Position.before) {
+ tvCurrency.setPaddingRelative(0, 0, hasGap ? gapSize : 0, 0);
+ }
+ else {
+ tvCurrency.setPaddingRelative(hasGap ? gapSize : 0, 0, 0, 0);
+ }
+ }
+ private void setCurrencyString(String currency) {
+ if ((currency == null) || currency.isEmpty()) {
+ tvCurrency.setText(R.string.currency_symbol);
+ tvCurrency.setTextColor(0x7f000000 + (0x00ffffff & Colors.defaultTextColor));
+ }
+ else {
+ tvCurrency.setText(currency);
+ tvCurrency.setTextColor(Colors.defaultTextColor);
+ }
+ }
+ private void setCurrency(Currency currency) {
+ setCurrencyString((currency == null) ? null : currency.getName());
+ }
+ private void setEditable(Boolean editable) {
+ tvDate.setEnabled(editable);
+ tvDescription.setEnabled(editable);
+ tvAccount.setEnabled(editable);
+ tvAmount.setEnabled(editable);
+ }
+ private void setCommentVisible(@NotNull Boolean visible) {
+ if (visible) {
+ // showing; show the comment view and align the comment button to it
+ tvComment.setVisibility(View.VISIBLE);
+ tvComment.requestFocus();
+ ConstraintLayout.LayoutParams lp =
+ (ConstraintLayout.LayoutParams) commentButton.getLayoutParams();
+ lp.bottomToBottom = R.id.comment;
+
+ commentButton.setLayoutParams(lp);
+ }
+ else {
+ // hiding; hide the comment view and align the comment bottom to the amount
+ tvComment.setVisibility(View.GONE);
+ ConstraintLayout.LayoutParams lp =
+ (ConstraintLayout.LayoutParams) commentButton.getLayoutParams();
+ lp.bottomToBottom = R.id.amount_layout; // R.id.parent doesn't work here
+
+ commentButton.setLayoutParams(lp);
+ }