]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionItemsAdapter.java
new transaction model: add setDate method
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / ui / activity / NewTransactionItemsAdapter.java
index 4b3fa8e67a94675e5c0c51205ec34da245d3cb47..0dc51aaa3b5d6bd312c47132156a0db73ec38e6a 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,9 +20,9 @@ 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;
 
 import androidx.annotation.NonNull;
 import androidx.annotation.Nullable;
@@ -34,6 +34,7 @@ import com.google.android.material.snackbar.Snackbar;
 import net.ktnx.mobileledger.BuildConfig;
 import net.ktnx.mobileledger.R;
 import net.ktnx.mobileledger.async.DescriptionSelectedCallback;
+import net.ktnx.mobileledger.databinding.NewTransactionRowBinding;
 import net.ktnx.mobileledger.model.Currency;
 import net.ktnx.mobileledger.model.Data;
 import net.ktnx.mobileledger.model.LedgerTransaction;
@@ -53,9 +54,9 @@ import static net.ktnx.mobileledger.utils.Logger.debug;
 
 class NewTransactionItemsAdapter extends RecyclerView.Adapter<NewTransactionItemHolder>
         implements DescriptionSelectedCallback {
-    private NewTransactionModel model;
+    private final NewTransactionModel model;
+    private final ItemTouchHelper touchHelper;
     private MobileLedgerProfile mProfile;
-    private ItemTouchHelper touchHelper;
     private RecyclerView recyclerView;
     private int checkHoldCounter = 0;
     NewTransactionItemsAdapter(NewTransactionModel viewModel, MobileLedgerProfile profile) {
@@ -142,11 +143,11 @@ class NewTransactionItemsAdapter extends RecyclerView.Adapter<NewTransactionItem
     @NonNull
     @Override
     public NewTransactionItemHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
-        LinearLayout row = (LinearLayout) LayoutInflater.from(parent.getContext())
-                                                        .inflate(R.layout.new_transaction_row,
-                                                                parent, false);
+        NewTransactionRowBinding b =
+                NewTransactionRowBinding.inflate(LayoutInflater.from(parent.getContext()), parent,
+                        false);
 
-        return new NewTransactionItemHolder(row, this);
+        return new NewTransactionItemHolder(b, this);
     }
     @Override
     public void onBindViewHolder(@NonNull NewTransactionItemHolder holder, int position) {
@@ -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");
@@ -283,7 +284,7 @@ class NewTransactionItemsAdapter extends RecyclerView.Adapter<NewTransactionItem
                     profileUUID, transactionId));
 
         tr = profile.loadTransaction(transactionId);
-        ArrayList<LedgerTransactionAccount> accounts = tr.getAccounts();
+        List<LedgerTransactionAccount> accounts = tr.getAccounts();
         NewTransactionModel.Item firstNegative = null;
         NewTransactionModel.Item firstPositive = null;
         int singleNegativeIndex = -1;
@@ -651,7 +652,7 @@ class NewTransactionItemsAdapter extends RecyclerView.Adapter<NewTransactionItem
     }
 
     private static class BalanceForCurrency {
-        private HashMap<String, Float> hashMap = new HashMap<>();
+        private final HashMap<String, Float> hashMap = new HashMap<>();
         float get(String currencyName) {
             Float f = hashMap.get(currencyName);
             if (f == null) {
@@ -672,7 +673,7 @@ class NewTransactionItemsAdapter extends RecyclerView.Adapter<NewTransactionItem
     }
 
     private static class ItemsForCurrency {
-        private HashMap<String, List<NewTransactionModel.Item>> hashMap = new HashMap<>();
+        private final HashMap<String, List<NewTransactionModel.Item>> hashMap = new HashMap<>();
         @NonNull
         List<NewTransactionModel.Item> getList(@Nullable String currencyName) {
             List<NewTransactionModel.Item> list = hashMap.get(currencyName);