]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/ui/transaction_list/TransactionListViewModel.java
transaction list: no crash of the transaction list is not loaded yet and an item...
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / ui / transaction_list / TransactionListViewModel.java
index 10aa2e9bc62630949cf9df03607463bc12d306de..02affd86735f85bf5710f59395e379043c0163fe 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2018 Damyan Ivanov.
+ * Copyright © 2019 Damyan Ivanov.
  * This file is part of Mobile-Ledger.
  * Mobile-Ledger is free software: you can distribute it and/or modify it
  * under the term of the GNU General Public License as published by
 package net.ktnx.mobileledger.ui.transaction_list;
 
 import android.arch.lifecycle.ViewModel;
+import android.os.AsyncTask;
+
+import net.ktnx.mobileledger.async.UpdateTransactionsTask;
+import net.ktnx.mobileledger.model.Data;
+import net.ktnx.mobileledger.model.TransactionListItem;
+import net.ktnx.mobileledger.utils.ObservableValue;
+
+import java.util.List;
 
 public class TransactionListViewModel extends ViewModel {
-    // TODO: Implement the ViewModel
+    public static ObservableValue<Boolean> updating = new ObservableValue<>();
+    public static ObservableValue<String> updateError = new ObservableValue<>();
+
+    public static void scheduleTransactionListReload() {
+        String filter = TransactionListFragment.accountFilter.get();
+        AsyncTask<String, Void, String> task = new UTT();
+        task.execute(filter);
+    }
+    public static TransactionListItem getTransactionListItem(int position) {
+        List<TransactionListItem> transactions = Data.transactions.get();
+        if (transactions == null) return null;
+        if (position >= transactions.size() + 1) return null;
+        if (position == transactions.size()) return new TransactionListItem();
+        return transactions.get(position);
+    }
+    public static int getTransactionCount() {
+        List<TransactionListItem> transactions = Data.transactions.get();
+        if (transactions == null) return 0;
+        return transactions.size();
+    }
+    private static class UTT extends UpdateTransactionsTask {
+        @Override
+        protected void onPostExecute(String error) {
+            super.onPostExecute(error);
+            if (error != null) updateError.set(error);
+        }
+    }
 }