]> git.ktnx.net Git - mobile-ledger.git/commitdiff
asking UpdateTransactionsTask to load a null profile is fine
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Fri, 23 Apr 2021 19:14:52 +0000 (22:14 +0300)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Sun, 25 Apr 2021 17:07:58 +0000 (17:07 +0000)
it would load an empty transaction list

app/src/main/java/net/ktnx/mobileledger/async/UpdateTransactionsTask.java

index 11de6a915e7de6c25392109f93fe270734674c78..38db6b17f8c7b30648a92d980f23626f4fbe222e 100644 (file)
@@ -27,15 +27,17 @@ import net.ktnx.mobileledger.model.LedgerTransaction;
 import net.ktnx.mobileledger.ui.MainModel;
 import net.ktnx.mobileledger.utils.Logger;
 
+import java.util.ArrayList;
 import java.util.List;
 
+import static net.ktnx.mobileledger.db.Profile.NO_PROFILE_ID;
 import static net.ktnx.mobileledger.utils.Logger.debug;
 
 public class UpdateTransactionsTask extends AsyncTask<MainModel, Void, String> {
     protected String doInBackground(MainModel[] parentModel) {
         final Profile profile = Data.getProfile();
 
-        long profile_id = profile.getId();
+        long profileId = (profile == null) ? NO_PROFILE_ID : profile.getId();
         Data.backgroundTaskStarted();
         try {
             Logger.debug("UTT", "Starting DB transaction list retrieval");
@@ -45,15 +47,17 @@ public class UpdateTransactionsTask extends AsyncTask<MainModel, Void, String> {
                                           .getValue();
             final List<TransactionWithAccounts> transactions;
 
-            if (accFilter == null) {
+            if (profileId == NO_PROFILE_ID)
+                transactions = new ArrayList<>();
+            else if (accFilter == null) {
                 transactions = DB.get()
                                  .getTransactionDAO()
-                                 .getAllWithAccountsSync(profile_id);
+                                 .getAllWithAccountsSync(profileId);
             }
             else {
                 transactions = DB.get()
                                  .getTransactionDAO()
-                                 .getAllWithAccountsFilteredSync(profile_id, accFilter);
+                                 .getAllWithAccountsFilteredSync(profileId, accFilter);
             }
 
             TransactionAccumulator accumulator = new TransactionAccumulator(model);