X-Git-Url: https://git.ktnx.net/?p=mobile-ledger.git;a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fui%2Ftransaction_list%2FTransactionListAdapter.java;h=d251cc8dc79962110cf42b9f72f62c481c9a6e85;hp=45d63af47c3760e1f1226ab00061fd46fd9dd49a;hb=0a73337c99e2074aa7e7228204289896342ec636;hpb=45078f948766e426d5b1ab851a14a523a86f5fa4 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 45d63af4..d251cc8d 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 @@ -1,5 +1,5 @@ /* - * Copyright © 2019 Damyan Ivanov. + * Copyright © 2020 Damyan Ivanov. * This file is part of MoLe. * MoLe is free software: you can distribute it and/or modify it * under the term of the GNU General Public License as published by @@ -17,6 +17,7 @@ package net.ktnx.mobileledger.ui.transaction_list; +import android.app.Activity; import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.graphics.Typeface; @@ -24,34 +25,79 @@ import android.os.AsyncTask; import android.text.Spannable; import android.text.SpannableString; import android.text.style.StyleSpan; -import android.view.Gravity; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.LinearLayout; import android.widget.TextView; +import androidx.annotation.ColorInt; +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.AsyncListDiffer; +import androidx.recyclerview.widget.DiffUtil; +import androidx.recyclerview.widget.RecyclerView; + +import net.ktnx.mobileledger.App; 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.MobileLedgerProfile; import net.ktnx.mobileledger.model.TransactionListItem; import net.ktnx.mobileledger.utils.Colors; import net.ktnx.mobileledger.utils.Globals; -import net.ktnx.mobileledger.utils.MLDB; +import net.ktnx.mobileledger.utils.Misc; +import net.ktnx.mobileledger.utils.SimpleDate; import java.text.DateFormat; -import java.util.Date; import java.util.GregorianCalendar; +import java.util.Locale; import java.util.TimeZone; -import androidx.annotation.NonNull; -import androidx.appcompat.widget.AppCompatTextView; -import androidx.recyclerview.widget.RecyclerView; - -import static net.ktnx.mobileledger.utils.DimensionUtils.dp2px; - public class TransactionListAdapter extends RecyclerView.Adapter { - private String boldAccountName; + private MobileLedgerProfile profile; + private AsyncListDiffer listDiffer; + public TransactionListAdapter() { + super(); + listDiffer = new AsyncListDiffer<>(this, new DiffUtil.ItemCallback() { + @Override + public boolean areItemsTheSame(@NonNull TransactionListItem oldItem, + @NonNull TransactionListItem newItem) { + if (oldItem.getType() != newItem.getType()) + return false; + switch (oldItem.getType()) { + case DELIMITER: + return (oldItem.getDate() + .equals(newItem.getDate())); + case TRANSACTION: + return oldItem.getTransaction() + .getId() == newItem.getTransaction() + .getId(); + default: + throw new IllegalStateException( + String.format(Locale.US, "Unexpected transaction item type %s", + oldItem.getType())); + } + } + @Override + public boolean areContentsTheSame(@NonNull TransactionListItem oldItem, + @NonNull TransactionListItem newItem) { + switch (oldItem.getType()) { + case DELIMITER: + // Delimiters items are "same" for same dates and the contents are the date + return true; + case TRANSACTION: + return oldItem.getTransaction() + .equals(newItem.getTransaction()); + default: + throw new IllegalStateException( + String.format(Locale.US, "Unexpected transaction item type %s", + oldItem.getType())); + + } + } + }); + } public void onBindViewHolder(@NonNull TransactionRowHolder holder, int position) { TransactionListItem item = TransactionListViewModel.getTransactionListItem(position); @@ -59,58 +105,55 @@ public class TransactionListAdapter extends RecyclerView.Adapter