]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionItemsAdapter.java
major rework of parsed transaction/descriptions/accounts storage
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / ui / activity / NewTransactionItemsAdapter.java
index dcb1ffdd7832a893395ddf44823c53a261f08383..5118d2c64db6e8fc35de4c471eb2cd47f5ef8b94 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
@@ -29,6 +29,8 @@ import androidx.annotation.Nullable;
 import androidx.recyclerview.widget.ItemTouchHelper;
 import androidx.recyclerview.widget.RecyclerView;
 
+import com.google.android.material.snackbar.Snackbar;
+
 import net.ktnx.mobileledger.BuildConfig;
 import net.ktnx.mobileledger.R;
 import net.ktnx.mobileledger.async.DescriptionSelectedCallback;
@@ -184,7 +186,7 @@ class NewTransactionItemsAdapter extends RecyclerView.Adapter<NewTransactionItem
         this.recyclerView = null;
     }
     public void descriptionSelected(String description) {
-        debug("descr selected", description);
+        debug("description selected", description);
         if (!accountListIsEmpty())
             return;
 
@@ -207,11 +209,11 @@ class NewTransactionItemsAdapter extends RecyclerView.Adapter<NewTransactionItem
             params.add(accFilter);
         }
 
-        sb.append(" ORDER BY t.date DESC LIMIT 1");
+        sb.append(" ORDER BY t.year desc, t.month desc, t.day desc LIMIT 1");
 
         final String sql = sb.toString();
-        debug("descr", sql);
-        debug("descr", params.toString());
+        debug("description", sql);
+        debug("description", params.toString());
 
         Activity activity = (Activity) recyclerView.getContext();
         // FIXME: handle exceptions?
@@ -236,14 +238,19 @@ class NewTransactionItemsAdapter extends RecyclerView.Adapter<NewTransactionItem
                 if (Misc.isEmptyOrNull(accFilter))
                     return;
 
-                debug("descr", "Trying transaction search without preferred account filter");
+                debug("description", "Trying transaction search without preferred account filter");
 
                 final String broaderSql =
                         "select t.profile, t.id from transactions t where t.description=?" +
-                        " ORDER BY date desc LIMIT 1";
+                        " ORDER BY year desc, month desc, day desc LIMIT 1";
                 params.remove(1);
-                debug("descr", broaderSql);
-                debug("descr", description);
+                debug("description", broaderSql);
+                debug("description", description);
+
+                activity.runOnUiThread(
+                        () -> Snackbar.make(recyclerView, R.string.ignoring_preferred_account,
+                                Snackbar.LENGTH_LONG)
+                                      .show());
 
                 MLDB.queryInBackground(broaderSql, new String[]{description},
                         new MLDB.CallbackHelper() {
@@ -276,7 +283,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;
@@ -363,6 +370,12 @@ class NewTransactionItemsAdapter extends RecyclerView.Adapter<NewTransactionItem
     void noteFocusIsOnComment(int position) {
         model.noteFocusChanged(position, NewTransactionModel.FocusedElement.Comment);
     }
+    void noteFocusIsOnTransactionComment(int position) {
+        model.noteFocusChanged(position, NewTransactionModel.FocusedElement.TransactionComment);
+    }
+    public void noteFocusIsOnDescription(int pos) {
+        model.noteFocusChanged(pos, NewTransactionModel.FocusedElement.Description);
+    }
     private void holdSubmittableChecks() {
         checkHoldCounter++;
     }
@@ -459,7 +472,12 @@ class NewTransactionItemsAdapter extends RecyclerView.Adapter<NewTransactionItem
                     itemsWithAccountForCurrency.add(currName, item);
                 }
 
-                if (acc.isAmountSet()) {
+                if (!acc.isAmountValid()) {
+                    Logger.debug("submittable",
+                            String.format("Not submittable: row %d has an invalid amount", i + 1));
+                    submittable = false;
+                }
+                else if (acc.isAmountSet()) {
                     itemsWithAmountForCurrency.add(currName, item);
                     balance.add(currName, acc.getAmount());
                 }