From: Damyan Ivanov Date: Fri, 29 Mar 2019 17:32:32 +0000 (+0200) Subject: Data.transactions -> observable list X-Git-Tag: v0.9~32 X-Git-Url: https://git.ktnx.net/?a=commitdiff_plain;h=73adeb59bc035a88a2c18d8cd79467e2f15825db;p=mobile-ledger.git Data.transactions -> observable list --- diff --git a/app/src/main/java/net/ktnx/mobileledger/async/UpdateTransactionsTask.java b/app/src/main/java/net/ktnx/mobileledger/async/UpdateTransactionsTask.java index fb1bd72f..f60ba7e3 100644 --- a/app/src/main/java/net/ktnx/mobileledger/async/UpdateTransactionsTask.java +++ b/app/src/main/java/net/ktnx/mobileledger/async/UpdateTransactionsTask.java @@ -87,7 +87,7 @@ public class UpdateTransactionsTask extends AsyncTask { lastDateString = dateString; odd = !odd; } - Data.transactions.set(newList); + Data.transactions.setList(newList); Log.d("UTT", "transaction list value updated"); } diff --git a/app/src/main/java/net/ktnx/mobileledger/model/Data.java b/app/src/main/java/net/ktnx/mobileledger/model/Data.java index d92ddef1..1fc4aa06 100644 --- a/app/src/main/java/net/ktnx/mobileledger/model/Data.java +++ b/app/src/main/java/net/ktnx/mobileledger/model/Data.java @@ -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 transactions = new ObservableList<>(new ArrayList<>()); public static ObservableList accounts = new ObservableList<>(new ArrayList<>()); public static ObservableAtomicInteger backgroundTaskCount = new ObservableAtomicInteger(0); diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/transaction_list/TransactionListAdapter.java b/app/src/main/java/net/ktnx/mobileledger/ui/transaction_list/TransactionListAdapter.java index 1e9d2d43..bad849e9 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/transaction_list/TransactionListAdapter.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/transaction_list/TransactionListAdapter.java @@ -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 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 transactions = Data.transactions.get();