2 * Copyright © 2018 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.app.Activity;
21 import android.arch.lifecycle.ViewModel;
22 import android.os.AsyncTask;
23 import android.view.View;
24 import android.widget.AutoCompleteTextView;
26 import net.ktnx.mobileledger.R;
27 import net.ktnx.mobileledger.async.UpdateTransactionsTask;
28 import net.ktnx.mobileledger.model.Data;
29 import net.ktnx.mobileledger.model.LedgerTransaction;
30 import net.ktnx.mobileledger.model.ObservableValue;
32 import java.util.List;
34 public class TransactionListViewModel extends ViewModel {
35 public static ObservableValue<Boolean> updating = new ObservableValue<>();
37 public static void scheduleTransactionListReload(Activity act) {
39 act.findViewById(R.id.transaction_list_account_name_filter).getVisibility() ==
41 String accFilter = hasFilter ? String.valueOf(
42 ((AutoCompleteTextView) act.findViewById(R.id.transaction_filter_account_name))
44 AsyncTask<String, Void, List<LedgerTransaction>> task = new UTT();
45 task.execute(accFilter);
47 public static LedgerTransaction getTransaction(int position) {
48 List<LedgerTransaction> transactions = Data.transactions.get();
49 if (position >= transactions.size()) return null;
50 return transactions.get(position);
52 public static int getTransactionCount() {
53 List<LedgerTransaction> transactions = Data.transactions.get();
54 if (transactions == null) return 0;
55 return transactions.size();
57 private static class UTT extends UpdateTransactionsTask {
59 protected void onPostExecute(List<LedgerTransaction> list) {
60 super.onPostExecute(list);
61 if (list != null) Data.transactions.set(list);