2 * Copyright © 2019 Damyan Ivanov.
3 * This file is part of Mobile-Ledger.
4 * Mobile-Ledger 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 * Mobile-Ledger 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 Mobile-Ledger. If not, see <https://www.gnu.org/licenses/>.
18 package net.ktnx.mobileledger.ui.transaction_list;
20 import android.arch.lifecycle.ViewModel;
21 import android.os.AsyncTask;
23 import net.ktnx.mobileledger.async.UpdateTransactionsTask;
24 import net.ktnx.mobileledger.model.Data;
25 import net.ktnx.mobileledger.model.LedgerTransaction;
26 import net.ktnx.mobileledger.utils.ObservableValue;
28 import java.util.List;
30 public class TransactionListViewModel extends ViewModel {
31 public static ObservableValue<Boolean> updating = new ObservableValue<>();
33 public static void scheduleTransactionListReload() {
34 String filter = TransactionListFragment.accountFilter.get();
35 AsyncTask<String, Void, List<LedgerTransaction>> task = new UTT();
38 public static LedgerTransaction getTransaction(int position) {
39 List<LedgerTransaction> transactions = Data.transactions.get();
40 if (position >= transactions.size()) return null;
41 return transactions.get(position);
43 public static int getTransactionCount() {
44 List<LedgerTransaction> transactions = Data.transactions.get();
45 if (transactions == null) return 0;
46 return transactions.size();
48 private static class UTT extends UpdateTransactionsTask {
50 protected void onPostExecute(List<LedgerTransaction> list) {
51 super.onPostExecute(list);
52 if (list != null) Data.transactions.set(list);