import android.widget.TextView;
import net.ktnx.mobileledger.async.RetrieveTransactionsTask;
-import net.ktnx.mobileledger.model.LedgerTransaction;
import net.ktnx.mobileledger.ui.transaction_list.TransactionListViewModel;
import net.ktnx.mobileledger.utils.MLDB;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Date;
-import java.util.List;
public class TransactionListActivity extends AppCompatActivity {
public TransactionListViewModel model;
tvLastUpdate = findViewById(R.id.transactions_last_update);
updateLastUpdateText();
model = ViewModelProviders.of(this).get(TransactionListViewModel.class);
- List<LedgerTransaction> transactions = model.getTransactions(this);
- modelAdapter = new TransactionListAdapter(transactions);
+ modelAdapter = new TransactionListAdapter(model);
RecyclerView root = findViewById(R.id.transaction_root);
root.setAdapter(modelAdapter);
swiper.setColorSchemeResources(R.color.colorPrimary, R.color.colorAccent);
-// update_transactions();
+ updateLastUpdateText();
+ long last_update = MLDB.get_option_value(this, MLDB.OPT_TRANSACTION_LIST_STAMP, 0L);
+ Log.d("transactions", String.format("Last update = %d", last_update));
+ if (last_update == 0) {
+ update_transactions();
+ }
}
private void setupActionBar() {
ActionBar actionBar = getSupportActionBar();
swiper.setRefreshing(false);
updateLastUpdateText();
if (success) {
+ Log.d("transactions", "calling notifyDataSetChanged()");
modelAdapter.notifyDataSetChanged();
}
}
{
long last_update = MLDB.get_option_value(this, MLDB.OPT_TRANSACTION_LIST_STAMP, 0L);
Log.d("transactions", String.format("Last update = %d", last_update));
- if (last_update == 0) tvLastUpdate.setText(getString(R.string.transaction_last_update_never));
+ if (last_update == 0) {
+ tvLastUpdate.setText(getString(R.string.transaction_last_update_never));
+ }
else {
Date date = new Date(last_update);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
import net.ktnx.mobileledger.model.LedgerTransaction;
import net.ktnx.mobileledger.model.LedgerTransactionAccount;
+import net.ktnx.mobileledger.ui.transaction_list.TransactionListViewModel;
import net.ktnx.mobileledger.utils.Globals;
import net.ktnx.mobileledger.utils.MLDB;
-import java.util.List;
-
import static net.ktnx.mobileledger.utils.DimensionUtils.dp2px;
class TransactionListAdapter
extends RecyclerView.Adapter<TransactionListAdapter.TransactionRowHolder> {
- private List<LedgerTransaction> transactions;
-
- TransactionListAdapter(List<LedgerTransaction> transactions) {
- this.transactions = transactions;
+ TransactionListViewModel model;
+ public TransactionListAdapter(TransactionListViewModel model) {
+ this.model = model;
}
-
public void onBindViewHolder(@NonNull TransactionRowHolder holder, int position) {
+ LedgerTransaction tr = model.getTransaction(position);
// in a race when transaction list is reduced, but the model hasn't been notified yet
// the view will disappear when the notifications reaches the model, so by simply omitting
// the out-of-range get() call nothing bad happens - just a to-be-deleted view remains
// a bit longer
- if (position >= transactions.size()) return;
+ if (tr == null) return;
- LedgerTransaction tr = transactions.get(position);
Context ctx = holder.row.getContext();
try (SQLiteDatabase db = MLDB.getReadableDatabase(ctx)) {
else {
holder.row.setBackgroundColor(Globals.table_row_odd_bg);
}
+
+ Log.d("transactions", String.format("Filled position %d", position));
}
}
}
@Override
- public int getItemCount() {
- return transactions.size();
+ public int getItemCount()
+ {
+ return model.getTransactionCount();
}
class TransactionRowHolder extends RecyclerView.ViewHolder {
TextView tvDescription, tvDate;