2 * Copyright © 2021 Damyan Ivanov.
3 * This file is part of MoLe.
4 * MoLe is free software: you can distribute it and/or modify it
5 * under the term of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your opinion), any later version.
9 * MoLe is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License terms for details.
14 * You should have received a copy of the GNU General Public License
15 * along with MoLe. If not, see <https://www.gnu.org/licenses/>.
18 package net.ktnx.mobileledger.async;
20 import android.os.AsyncTask;
22 import net.ktnx.mobileledger.db.DB;
23 import net.ktnx.mobileledger.db.Profile;
24 import net.ktnx.mobileledger.db.TransactionWithAccounts;
25 import net.ktnx.mobileledger.model.Data;
26 import net.ktnx.mobileledger.model.LedgerTransaction;
27 import net.ktnx.mobileledger.ui.MainModel;
28 import net.ktnx.mobileledger.utils.Logger;
30 import java.util.List;
32 import static net.ktnx.mobileledger.utils.Logger.debug;
34 public class UpdateTransactionsTask extends AsyncTask<MainModel, Void, String> {
35 protected String doInBackground(MainModel[] parentModel) {
36 final Profile profile = Data.getProfile();
38 long profile_id = profile.getId();
39 Data.backgroundTaskStarted();
41 Logger.debug("UTT", "Starting DB transaction list retrieval");
43 final MainModel model = parentModel[0];
44 final String accFilter = model.getAccountFilter()
46 final List<TransactionWithAccounts> transactions;
48 if (accFilter == null) {
49 transactions = DB.get()
51 .getAllWithAccountsSync(profile_id);
54 transactions = DB.get()
56 .getAllWithAccountsFilteredSync(profile_id, accFilter);
59 TransactionAccumulator accumulator = new TransactionAccumulator(model);
61 for (TransactionWithAccounts tr : transactions) {
65 accumulator.put(new LedgerTransaction(tr));
69 debug("UTT", "transaction list value updated");
74 Data.backgroundTaskFinished();