]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/ui/MainModel.java
debug refinements
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / ui / MainModel.java
index c860e41b4f4e691e7011d3ad60bf22ae8c7ff9d9..2355d2a833c2f5192d64887fac87162f39bc9bf2 100644 (file)
@@ -18,7 +18,6 @@
 package net.ktnx.mobileledger.ui;
 
 import android.os.AsyncTask;
-import android.text.TextUtils;
 
 import androidx.lifecycle.LiveData;
 import androidx.lifecycle.MutableLiveData;
@@ -42,7 +41,7 @@ import java.util.Locale;
 public class MainModel extends ViewModel {
     public final MutableLiveData<Integer> foundTransactionItemIndex = new MutableLiveData<>(null);
     private final MutableLiveData<Boolean> updatingFlag = new MutableLiveData<>(false);
-    private final MutableLiveData<String> accountFilter = new MutableLiveData<>();
+    private final MutableLiveData<String> accountFilter = new MutableLiveData<>(null);
     private final MutableLiveData<List<TransactionListItem>> displayedTransactions =
             new MutableLiveData<>(new ArrayList<>());
     private final MutableLiveData<String> updateError = new MutableLiveData<>();
@@ -83,21 +82,6 @@ public class MainModel extends ViewModel {
     public void setLastTransactionDate(SimpleDate latestDate) {
         this.lastTransactionDate = latestDate;
     }
-    private void applyTransactionFilter(List<LedgerTransaction> list) {
-        final String accFilter = accountFilter.getValue();
-        ArrayList<TransactionListItem> newList = new ArrayList<>();
-
-        TransactionAccumulator accumulator = new TransactionAccumulator(this);
-        if (TextUtils.isEmpty(accFilter))
-            for (LedgerTransaction tr : list)
-                newList.add(new TransactionListItem(tr));
-        else
-            for (LedgerTransaction tr : list)
-                if (tr.hasAccountNamedLike(accFilter))
-                    newList.add(new TransactionListItem(tr));
-
-        displayedTransactions.postValue(newList);
-    }
     public synchronized void scheduleTransactionListRetrieval() {
         if (retrieveTransactionsTask != null) {
             Logger.debug("db", "Ignoring request for transaction retrieval - already active");
@@ -113,6 +97,8 @@ public class MainModel extends ViewModel {
     public synchronized void stopTransactionsRetrieval() {
         if (retrieveTransactionsTask != null)
             retrieveTransactionsTask.cancel(true);
+        else
+            Data.backgroundTaskProgress.setValue(null);
     }
     public void transactionRetrievalDone() {
         retrieveTransactionsTask = null;
@@ -141,13 +127,12 @@ public class MainModel extends ViewModel {
         @Override
         public void run() {
             List<LedgerAccount> newDisplayed = new ArrayList<>();
-            Logger.debug("dFilter", "waiting for synchronized block");
             Logger.debug("dFilter", String.format(Locale.US,
                     "entered synchronized block (about to examine %d transactions)", list.size()));
             String accNameFilter = model.getAccountFilter()
                                         .getValue();
 
-            TransactionAccumulator acc = new TransactionAccumulator(model);
+            TransactionAccumulator acc = new TransactionAccumulator(accNameFilter);
             for (LedgerTransaction tr : list) {
                 if (isInterrupted()) {
                     return;
@@ -157,10 +142,12 @@ public class MainModel extends ViewModel {
                     acc.put(tr, tr.getDate());
                 }
             }
-            if (!isInterrupted()) {
-                acc.done();
-            }
-            Logger.debug("dFilter", "left synchronized block");
+
+            if (isInterrupted())
+                return;
+
+            acc.publishResults(model);
+            Logger.debug("dFilter", "transaction list updated");
         }
     }
 }