+
+ currencyGapObserver =
+ hasGap -> updateCurrencyPositionAndPadding(Data.currencySymbolPosition.getValue(),
+ hasGap);
+
+ currencyPositionObserver =
+ position -> updateCurrencyPositionAndPadding(position, Data.currencyGap.getValue());
+
+ showCurrencyObserver = showCurrency -> {
+ if (showCurrency) {
+ b.currency.setVisibility(View.VISIBLE);
+ b.currencyButton.setVisibility(View.VISIBLE);
+ String defaultCommodity = mProfile.getDefaultCommodity();
+ item.setCurrency(
+ (defaultCommodity == null) ? null : Currency.loadByName(defaultCommodity));
+ }
+ else {
+ b.currency.setVisibility(View.GONE);
+ b.currencyButton.setVisibility(View.GONE);
+ item.setCurrency(null);
+ }
+ };
+
+ commentObserver = comment -> {
+ final View focusedView = b.comment.findFocus();
+ b.comment.setTypeface(null,
+ (focusedView == b.comment) ? Typeface.NORMAL : Typeface.ITALIC);
+ b.comment.setVisibility(
+ ((focusedView != b.comment) && TextUtils.isEmpty(comment)) ? View.INVISIBLE
+ : View.VISIBLE);
+ };
+
+ showCommentsObserver = show -> {
+ ConstraintLayout.LayoutParams amountLayoutParams =
+ (ConstraintLayout.LayoutParams) b.amountLayout.getLayoutParams();
+ ConstraintLayout.LayoutParams accountParams =
+ (ConstraintLayout.LayoutParams) b.accountRowAccName.getLayoutParams();
+ if (show) {
+ accountParams.endToStart = ConstraintLayout.LayoutParams.UNSET;
+ accountParams.endToEnd = ConstraintLayout.LayoutParams.PARENT_ID;
+
+ amountLayoutParams.topToTop = ConstraintLayout.LayoutParams.UNSET;
+ amountLayoutParams.topToBottom = b.accountRowAccName.getId();
+
+ b.commentLayout.setVisibility(View.VISIBLE);
+ }
+ else {
+ accountParams.endToStart = b.amountLayout.getId();
+ accountParams.endToEnd = ConstraintLayout.LayoutParams.UNSET;
+
+ amountLayoutParams.topToBottom = ConstraintLayout.LayoutParams.UNSET;
+ amountLayoutParams.topToTop = ConstraintLayout.LayoutParams.PARENT_ID;
+
+ b.commentLayout.setVisibility(View.GONE);
+ }
+
+ b.accountRowAccName.setLayoutParams(accountParams);
+ b.amountLayout.setLayoutParams(amountLayoutParams);
+
+ b.transactionCommentLayout.setVisibility(show ? View.VISIBLE : View.GONE);
+ };
+
+ amountValidityObserver = valid -> {
+ b.accountRowAccAmounts.setCompoundDrawablesRelativeWithIntrinsicBounds(
+ valid ? 0 : R.drawable.ic_error_outline_black_24dp, 0, 0, 0);
+ b.accountRowAccAmounts.setMinEms(valid ? 4 : 5);
+ };
+ }
+ private void commentFocusChanged(TextView textView, boolean hasFocus) {
+ @ColorInt int textColor;
+ textColor = b.dummyText.getTextColors()
+ .getDefaultColor();
+ if (hasFocus) {
+ textView.setTypeface(null, Typeface.NORMAL);
+ textView.setHint(R.string.transaction_account_comment_hint);
+ }
+ else {
+ int alpha = (textColor >> 24 & 0xff);
+ alpha = 3 * alpha / 4;
+ textColor = (alpha << 24) | (0x00ffffff & textColor);
+ textView.setTypeface(null, Typeface.ITALIC);
+ textView.setHint("");
+ if (TextUtils.isEmpty(textView.getText())) {
+ textView.setVisibility(View.INVISIBLE);
+ }
+ }
+ textView.setTextColor(textColor);
+
+ }
+ private void updateCurrencyPositionAndPadding(Currency.Position position, boolean hasGap) {
+ ConstraintLayout.LayoutParams amountLP =
+ (ConstraintLayout.LayoutParams) b.accountRowAccAmounts.getLayoutParams();
+ ConstraintLayout.LayoutParams currencyLP =
+ (ConstraintLayout.LayoutParams) b.currency.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 = b.currency.getId();
+
+ b.currency.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 = b.currency.getId();
+
+ b.currency.setGravity(Gravity.START);
+ }
+
+ amountLP.resolveLayoutDirection(b.accountRowAccAmounts.getLayoutDirection());
+ currencyLP.resolveLayoutDirection(b.currency.getLayoutDirection());
+
+ b.accountRowAccAmounts.setLayoutParams(amountLP);
+ b.currency.setLayoutParams(currencyLP);
+
+ // distance between the amount and the currency symbol
+ int gapSize = DimensionUtils.sp2px(b.currency.getContext(), 5);
+
+ if (position == Currency.Position.before) {
+ b.currency.setPaddingRelative(0, 0, hasGap ? gapSize : 0, 0);
+ }
+ else {
+ b.currency.setPaddingRelative(hasGap ? gapSize : 0, 0, 0, 0);
+ }
+ }
+ private void setCurrencyString(String currency) {
+ @ColorInt int textColor = b.dummyText.getTextColors()
+ .getDefaultColor();
+ if ((currency == null) || currency.isEmpty()) {
+ b.currency.setText(R.string.currency_symbol);
+ int alpha = (textColor >> 24) & 0xff;
+ alpha = alpha * 3 / 4;
+ b.currency.setTextColor((alpha << 24) | (0x00ffffff & textColor));
+ }
+ else {
+ b.currency.setText(currency);
+ b.currency.setTextColor(textColor);
+ }
+ }
+ private void setCurrency(Currency currency) {
+ setCurrencyString((currency == null) ? null : currency.getName());