From: Damyan Ivanov Date: Fri, 23 Apr 2021 19:14:52 +0000 (+0300) Subject: asking UpdateTransactionsTask to load a null profile is fine X-Git-Tag: v0.18.0~39 X-Git-Url: https://git.ktnx.net/?a=commitdiff_plain;h=63d4636c19652b688fb0a1e4f3081843c740bf78;p=mobile-ledger.git asking UpdateTransactionsTask to load a null profile is fine it would load an empty transaction list --- diff --git a/app/src/main/java/net/ktnx/mobileledger/async/UpdateTransactionsTask.java b/app/src/main/java/net/ktnx/mobileledger/async/UpdateTransactionsTask.java index 11de6a91..38db6b17 100644 --- a/app/src/main/java/net/ktnx/mobileledger/async/UpdateTransactionsTask.java +++ b/app/src/main/java/net/ktnx/mobileledger/async/UpdateTransactionsTask.java @@ -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 { 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 { .getValue(); final List 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);