]> git.ktnx.net Git - mobile-ledger.git/commitdiff
Data.transactions -> observable list
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Fri, 29 Mar 2019 17:32:32 +0000 (19:32 +0200)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Fri, 29 Mar 2019 17:32:32 +0000 (19:32 +0200)
app/src/main/java/net/ktnx/mobileledger/async/UpdateTransactionsTask.java
app/src/main/java/net/ktnx/mobileledger/model/Data.java
app/src/main/java/net/ktnx/mobileledger/ui/transaction_list/TransactionListAdapter.java
app/src/main/java/net/ktnx/mobileledger/ui/transaction_list/TransactionListViewModel.java

index fb1bd72fd2a359c790e6611a83fe15ad827847a1..f60ba7e3c109e16c59b8eefd61771707c692be3d 100644 (file)
@@ -87,7 +87,7 @@ public class UpdateTransactionsTask extends AsyncTask<String, Void, String> {
                     lastDateString = dateString;
                     odd = !odd;
                 }
-                Data.transactions.set(newList);
+                Data.transactions.setList(newList);
                 Log.d("UTT", "transaction list value updated");
             }
 
index d92ddef1c8c8ebba2bb3ba9588afab50309b5096..1fc4aa06a8962e1c07bf225e3024ee48a8a83518 100644 (file)
@@ -28,7 +28,7 @@ import java.util.Date;
 import java.util.List;
 
 public final class Data {
-    public static TransactionList transactions = new TransactionList();
+    public static ObservableList<TransactionListItem> transactions = new ObservableList<>(new ArrayList<>());
     public static ObservableList<LedgerAccount> accounts =
             new ObservableList<>(new ArrayList<>());
     public static ObservableAtomicInteger backgroundTaskCount = new ObservableAtomicInteger(0);
index 1e9d2d43fd046178180a0f3534353a0b0bbbbf76..bad849e95bf95477c207ff8213dc51f0be4c2351 100644 (file)
@@ -32,6 +32,7 @@ import android.widget.LinearLayout;
 import android.widget.TextView;
 
 import net.ktnx.mobileledger.R;
+import net.ktnx.mobileledger.model.Data;
 import net.ktnx.mobileledger.model.LedgerTransaction;
 import net.ktnx.mobileledger.model.LedgerTransactionAccount;
 import net.ktnx.mobileledger.model.TransactionListItem;
@@ -126,7 +127,7 @@ public class TransactionListAdapter extends RecyclerView.Adapter<TransactionRowH
 
     @Override
     public int getItemCount() {
-        return TransactionListViewModel.getTransactionCount() + 1;
+        return Data.transactions.size() + 1;
     }
     public void setBoldAccountName(String boldAccountName) {
         this.boldAccountName = boldAccountName;
index 513bf9f48f0aeef72e8649955a19ac48d574de15..7e0214c1f909795ff23627a2e9a04c0a06917ffb 100644 (file)
@@ -40,11 +40,12 @@ public class TransactionListViewModel extends ViewModel {
         task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, 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);
+        try(LockHolder lh = Data.transactions.lockForReading()) {
+            if (Data.transactions == null) return null;
+            if (position >= Data.transactions.size() + 1) return null;
+            if (position == Data.transactions.size()) return new TransactionListItem();
+            return Data.transactions.get(position);
+        }
     }
     public static int getTransactionCount() {
         List<TransactionListItem> transactions = Data.transactions.get();