]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionItemHolder.java
convert switch on resource IDs with a series of if/else
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / ui / activity / NewTransactionItemHolder.java
index 5596d5746c072201361fbb5762a354a34c5ac7e1..f8d6002be3635d4fef7ca6b0acfdb0736886a496 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
@@ -90,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;
@@ -105,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);
@@ -142,22 +144,20 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder
                 try {
                     final int pos = getAdapterPosition();
                     adapter.updateFocusedItem(pos);
-                    switch (id) {
-                        case R.id.account_row_acc_name:
-                            adapter.noteFocusIsOnAccount(pos);
-                            break;
-                        case R.id.account_row_acc_amounts:
-                            adapter.noteFocusIsOnAmount(pos);
-                            break;
-                        case R.id.comment:
-                            adapter.noteFocusIsOnComment(pos);
-                            break;
-                        case R.id.transaction_comment:
-                            adapter.noteFocusIsOnTransactionComment(pos);
-                            break;
-                        case R.id.new_transaction_description:
-                            adapter.noteFocusIsOnDescription(pos);
-                            break;
+                    if (id == R.id.account_row_acc_name) {
+                        adapter.noteFocusIsOnAccount(pos);
+                    }
+                    else if (id == R.id.account_row_acc_amounts) {
+                        adapter.noteFocusIsOnAmount(pos);
+                    }
+                    else if (id == R.id.comment) {
+                        adapter.noteFocusIsOnComment(pos);
+                    }
+                    else if (id == R.id.transaction_comment) {
+                        adapter.noteFocusIsOnTransactionComment(pos);
+                    }
+                    else if (id == R.id.new_transaction_description) {
+                        adapter.noteFocusIsOnDescription(pos);
                     }
                 }
                 finally {
@@ -237,7 +237,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));
@@ -309,7 +309,7 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder
                             break;
                         case Description:
                             boolean focused = tvDescription.requestFocus();
-                            tvDescription.dismissDropDown();
+//                            tvDescription.dismissDropDown();
                             if (focused)
                                 Misc.showSoftKeyboard(
                                         (NewTransactionActivity) tvDescription.getContext());
@@ -378,12 +378,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);
             }
         };