]> git.ktnx.net Git - mobile-ledger.git/commitdiff
replace local utility functions with ones from TextUtils
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Thu, 17 Sep 2020 07:13:37 +0000 (07:13 +0000)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Thu, 17 Sep 2020 13:24:46 +0000 (13:24 +0000)
app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionItemHolder.java
app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionItemsAdapter.java
app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfileDetailModel.java
app/src/main/java/net/ktnx/mobileledger/utils/Misc.java

index 21c0ce28b881f84f52243452356890d8ee31a126..62f0de49677df85c70b58890907bb084994713b7 100644 (file)
@@ -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;
@@ -270,9 +271,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 -> {
@@ -389,8 +390,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 +445,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);
             }
         }
index 55e0238171d31e055419efdc3cbf5392ac834468..0da28e8e07bd69823dae2824a9de298d51ee4885 100644 (file)
@@ -20,6 +20,7 @@ package net.ktnx.mobileledger.ui.activity;
 import android.annotation.SuppressLint;
 import android.app.Activity;
 import android.database.Cursor;
+import android.text.TextUtils;
 import android.view.LayoutInflater;
 import android.view.ViewGroup;
 import android.widget.LinearLayout;
@@ -195,7 +196,7 @@ class NewTransactionItemsAdapter extends RecyclerView.Adapter<NewTransactionItem
         ArrayList<String> params = new ArrayList<>();
         StringBuilder sb = new StringBuilder("select t.profile, t.id from transactions t");
 
-        if (!Misc.isEmptyOrNull(accFilter)) {
+        if (!TextUtils.isEmpty(accFilter)) {
             sb.append(" JOIN transaction_accounts ta")
               .append(" ON ta.profile = t.profile")
               .append(" AND ta.transaction_id = t.id");
@@ -204,7 +205,7 @@ class NewTransactionItemsAdapter extends RecyclerView.Adapter<NewTransactionItem
         sb.append(" WHERE t.description=?");
         params.add(description);
 
-        if (!Misc.isEmptyOrNull(accFilter)) {
+        if (!TextUtils.isEmpty(accFilter)) {
             sb.append(" AND ta.account_name LIKE '%'||?||'%'");
             params.add(accFilter);
         }
@@ -235,7 +236,7 @@ class NewTransactionItemsAdapter extends RecyclerView.Adapter<NewTransactionItem
             }
             @Override
             public void onNoRows() {
-                if (Misc.isEmptyOrNull(accFilter))
+                if (TextUtils.isEmpty(accFilter))
                     return;
 
                 debug("description", "Trying transaction search without preferred account filter");
index 57c992180d265bbda33e61655429d8a9140e7e45..915ab032b58fc4a26e9e8be7b2f58899781685b5 100644 (file)
@@ -17,6 +17,8 @@
 
 package net.ktnx.mobileledger.ui.profiles;
 
+import android.text.TextUtils;
+
 import androidx.lifecycle.LifecycleOwner;
 import androidx.lifecycle.MutableLiveData;
 import androidx.lifecycle.Observer;
@@ -203,7 +205,7 @@ public class ProfileDetailModel extends ViewModel {
             showCommodityByDefault.setValue(mProfile.getShowCommodityByDefault());
             {
                 String comm = mProfile.getDefaultCommodity();
-                if (Misc.isEmptyOrNull(comm))
+                if (TextUtils.isEmpty(comm))
                     setDefaultCommodity(null);
                 else
                     setDefaultCommodity(new Currency(-1, comm));
index b912541fcd351f20d92b948c846ab481cb289d14..a79bcf93abee7c4845ea2c288a43d3e983ca9b19 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2019 Damyan Ivanov.
+ * Copyright © 2020 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
@@ -63,21 +63,12 @@ public class Misc {
     public static String nullIsEmpty(String str) {
         return (str == null) ? "" : str;
     }
-    public static boolean isEmptyOrNull (String str) {
-        if (str == null) return true;
-        return str.isEmpty();
-    }
     public static boolean equalStrings(String u, CharSequence text) {
         return nullIsEmpty(u).equals(text.toString());
     }
     public static boolean equalStrings(String a, String b) {
         return nullIsEmpty(a).equals(nullIsEmpty(b));
     }
-    public static boolean isEmptyOrNull(CharSequence text) {
-        if (text == null)
-            return true;
-        return text.length() == 0;
-    }
     public static String trim(@Nullable String string) {
         if (string == null)
             return null;