From: Damyan Ivanov Date: Sun, 7 Mar 2021 10:00:45 +0000 (+0200) Subject: replace TextUtils.equals() usage with Misc.equalStrings() X-Git-Tag: v0.17.0~11 X-Git-Url: https://git.ktnx.net/?a=commitdiff_plain;h=94dd025cb41a089504314a48ba2f99d4c5d911c5;p=mobile-ledger.git replace TextUtils.equals() usage with Misc.equalStrings() equalStrings() considers null to be equal to the empty string --- diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/account_summary/AccountSummaryAdapter.java b/app/src/main/java/net/ktnx/mobileledger/ui/account_summary/AccountSummaryAdapter.java index 6faa82a7..b8e4c303 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/account_summary/AccountSummaryAdapter.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/account_summary/AccountSummaryAdapter.java @@ -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, diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionItemHolder.java b/app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionItemHolder.java index 6df1b540..5757c72a 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionItemHolder.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionItemHolder.java @@ -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, diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionModel.java b/app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionModel.java index ba2903c1..23a4ef73 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionModel.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionModel.java @@ -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(),