]> git.ktnx.net Git - mobile-ledger.git/commitdiff
replace TextUtils.equals() usage with Misc.equalStrings()
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Sun, 7 Mar 2021 10:00:45 +0000 (12:00 +0200)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Sun, 7 Mar 2021 10:00:45 +0000 (12:00 +0200)
equalStrings() considers null to be equal to the empty string

app/src/main/java/net/ktnx/mobileledger/ui/account_summary/AccountSummaryAdapter.java
app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionItemHolder.java
app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionModel.java

index 6faa82a73b8f271a198fe0eeffcc75c90bd17618..b8e4c303b588a1f9514763fde3e04f317d6133fb 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
@@ -19,7 +19,6 @@ package net.ktnx.mobileledger.ui.account_summary;
 
 import android.content.Context;
 import android.content.res.Resources;
-import android.text.TextUtils;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
@@ -42,6 +41,7 @@ import net.ktnx.mobileledger.model.MobileLedgerProfile;
 import net.ktnx.mobileledger.ui.MainModel;
 import net.ktnx.mobileledger.ui.activity.MainActivity;
 import net.ktnx.mobileledger.utils.Locker;
+import net.ktnx.mobileledger.utils.Misc;
 
 import org.jetbrains.annotations.NotNull;
 
@@ -71,9 +71,9 @@ public class AccountSummaryAdapter
                 if (oldType != newType)
                     return false;
 
-                return TextUtils.equals(oldItem.getAccount()
-                                               .getName(), newItem.getAccount()
-                                                                  .getName());
+                return Misc.equalStrings(oldItem.getAccount()
+                                                .getName(), newItem.getAccount()
+                                                                   .getName());
             }
             @Override
             public boolean areContentsTheSame(@NotNull AccountListItem oldItem,
index 6df1b5406cac95c88d9f25565f4374b4764cf2b6..5757c72a249073360e5a2a20a4c3d8eb7fb7b67a 100644 (file)
@@ -566,7 +566,7 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder
                     else
                         currValue = curr;
 
-                    if (!significantChange && !TextUtils.equals(acc.getCurrency(), currValue))
+                    if (!significantChange && !Misc.equalStrings(acc.getCurrency(), currValue))
                         significantChange = true;
                     acc.setCurrency(currValue);
                 }
@@ -630,7 +630,7 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder
 
                     final String incomingAccountName = acc.getAccountName();
                     final String presentAccountName = String.valueOf(b.accountRowAccName.getText());
-                    if (!TextUtils.equals(incomingAccountName, presentAccountName)) {
+                    if (!Misc.equalStrings(incomingAccountName, presentAccountName)) {
                         Logger.debug("bind",
                                 String.format("Setting account name from '%s' to '%s' (| @ %d)",
                                         presentAccountName, incomingAccountName,
index ba2903c1d3bf3d6ea363f64b411bd1116d89e29b..23a4ef73cafcd6eddefcfa9ff59b1e832e5187ec 100644 (file)
@@ -688,7 +688,7 @@ public class NewTransactionModel extends ViewModel {
                         if (item == receiver) {
                             final String hint = String.format("%1.2f", -currencyBalance);
                             if (!acc.isAmountHintSet() ||
-                                !TextUtils.equals(acc.getAmountHint(), hint))
+                                !Misc.equalStrings(acc.getAmountHint(), hint))
                             {
                                 Logger.debug("submittable",
                                         String.format("Setting amount hint of {%s} to %s [%s]",
@@ -1007,8 +1007,8 @@ public class NewTransactionModel extends ViewModel {
                 return false;
 
             return Objects.equals(date, other.date) &&
-                   TextUtils.equals(description, other.description) &&
-                   TextUtils.equals(comment, other.comment);
+                   Misc.equalStrings(description, other.description) &&
+                   Misc.equalStrings(comment, other.comment);
         }
     }
 
@@ -1150,16 +1150,16 @@ public class NewTransactionModel extends ViewModel {
             if (other == null)
                 return false;
 
-            boolean equal = TextUtils.equals(accountName, other.accountName);
-            equal = equal && TextUtils.equals(comment, other.comment) &&
+            boolean equal = Misc.equalStrings(accountName, other.accountName);
+            equal = equal && Misc.equalStrings(comment, other.comment) &&
                     (amountSet ? other.amountSet && amount == other.amount : !other.amountSet);
 
             // compare amount hint only if there is no amount
             if (!amountSet)
                 equal = equal && (amountHintIsSet ? other.amountHintIsSet &&
-                                                    TextUtils.equals(amountHint, other.amountHint)
+                                                    Misc.equalStrings(amountHint, other.amountHint)
                                                   : !other.amountHintIsSet);
-            equal = equal && TextUtils.equals(currency, other.currency) && isLast == other.isLast;
+            equal = equal && Misc.equalStrings(currency, other.currency) && isLast == other.isLast;
 
             Logger.debug("new-trans",
                     String.format("Comparing {%s} and {%s}: %s", this.toString(), other.toString(),