]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionItemHolder.java
new transaction: bigger currency button area
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / ui / activity / NewTransactionItemHolder.java
index 21c0ce28b881f84f52243452356890d8ee31a126..b2dd24dac890eef4b68bf3a0be189caf2b977c7b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2020 Damyan Ivanov.
+ * Copyright © 2021 Damyan Ivanov.
  * This file is part of MoLe.
  * MoLe is free software: you can distribute it and/or modify it
  * under the term of the GNU General Public License as published by
@@ -20,6 +20,7 @@ package net.ktnx.mobileledger.ui.activity;
 import android.annotation.SuppressLint;
 import android.graphics.Typeface;
 import android.text.Editable;
+import android.text.TextUtils;
 import android.text.TextWatcher;
 import android.view.Gravity;
 import android.view.View;
@@ -89,6 +90,7 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder
     private final Observer<Boolean> showCurrencyObserver;
     private final Observer<String> commentObserver;
     private final Observer<Boolean> amountValidityObserver;
+    private final View tvCurrencyButton;
     private String decimalSeparator;
     private NewTransactionModel.Item item;
     private Date date;
@@ -104,6 +106,7 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder
         new TextViewClearHelper().attachToTextView((EditText) tvComment);
         tvAmount = itemView.findViewById(R.id.account_row_acc_amounts);
         tvCurrency = itemView.findViewById(R.id.currency);
+        tvCurrencyButton = lAccount.findViewById(R.id.currencyButton);
         tvDate = itemView.findViewById(R.id.new_transaction_date);
         tvDescription = itemView.findViewById(R.id.new_transaction_description);
         tvDummy = itemView.findViewById(R.id.dummy_text);
@@ -236,7 +239,7 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder
         tvComment.addTextChangedListener(tw);
         tvAmount.addTextChangedListener(amountWatcher);
 
-        tvCurrency.setOnClickListener(v -> {
+        tvCurrencyButton.setOnClickListener(v -> {
             CurrencySelectorFragment cpf = new CurrencySelectorFragment();
             cpf.showPositionAndPadding();
             cpf.setOnCurrencySelectedListener(c -> item.setCurrency(c));
@@ -270,9 +273,9 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder
             final View focusedView = tvTransactionComment.findFocus();
             tvTransactionComment.setTypeface(null,
                     (focusedView == tvTransactionComment) ? Typeface.NORMAL : Typeface.ITALIC);
-            tvTransactionComment.setVisibility(((focusedView != tvTransactionComment) &&
-                                                Misc.isEmptyOrNull(transactionComment))
-                                               ? View.INVISIBLE : View.VISIBLE);
+            tvTransactionComment.setVisibility(
+                    ((focusedView != tvTransactionComment) && TextUtils.isEmpty(transactionComment))
+                    ? View.INVISIBLE : View.VISIBLE);
 
         };
         hintObserver = hint -> {
@@ -308,7 +311,7 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder
                             break;
                         case Description:
                             boolean focused = tvDescription.requestFocus();
-                            tvDescription.dismissDropDown();
+//                            tvDescription.dismissDropDown();
                             if (focused)
                                 Misc.showSoftKeyboard(
                                         (NewTransactionActivity) tvDescription.getContext());
@@ -377,9 +380,14 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder
         showCurrencyObserver = showCurrency -> {
             if (showCurrency) {
                 tvCurrency.setVisibility(View.VISIBLE);
+                tvCurrencyButton.setVisibility(View.VISIBLE);
+                String defaultCommodity = mProfile.getDefaultCommodity();
+                item.setCurrency(
+                        (defaultCommodity == null) ? null : Currency.loadByName(defaultCommodity));
             }
             else {
                 tvCurrency.setVisibility(View.GONE);
+                tvCurrencyButton.setVisibility(View.GONE);
                 item.setCurrency(null);
             }
         };
@@ -389,8 +397,8 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder
             tvComment.setTypeface(null,
                     (focusedView == tvComment) ? Typeface.NORMAL : Typeface.ITALIC);
             tvComment.setVisibility(
-                    ((focusedView != tvComment) && Misc.isEmptyOrNull(comment)) ? View.INVISIBLE
-                                                                                : View.VISIBLE);
+                    ((focusedView != tvComment) && TextUtils.isEmpty(comment)) ? View.INVISIBLE
+                                                                               : View.VISIBLE);
         };
 
         showCommentsObserver = show -> {
@@ -444,7 +452,7 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder
             textColor = (alpha << 24) | (0x00ffffff & textColor);
             textView.setTypeface(null, Typeface.ITALIC);
             textView.setHint("");
-            if (Misc.isEmptyOrNull(textView.getText())) {
+            if (TextUtils.isEmpty(textView.getText())) {
                 textView.setVisibility(View.INVISIBLE);
             }
         }