import net.ktnx.mobileledger.async.DbOpQueue;
import net.ktnx.mobileledger.model.LedgerAccount;
import net.ktnx.mobileledger.model.MobileLedgerProfile;
+import net.ktnx.mobileledger.ui.MainModel;
import net.ktnx.mobileledger.ui.activity.MainActivity;
import net.ktnx.mobileledger.utils.Locker;
+import net.ktnx.mobileledger.utils.Logger;
import org.jetbrains.annotations.NotNull;
import java.util.List;
+import java.util.Locale;
import static net.ktnx.mobileledger.utils.Logger.debug;
public class AccountSummaryAdapter
extends RecyclerView.Adapter<AccountSummaryAdapter.LedgerRowHolder> {
public static final int AMOUNT_LIMIT = 3;
- private MobileLedgerProfile profile;
private AsyncListDiffer<LedgerAccount> listDiffer;
- AccountSummaryAdapter() {
+ private MainModel model;
+ AccountSummaryAdapter(MainModel model) {
+ this.model = model;
+
listDiffer = new AsyncListDiffer<>(this, new DiffUtil.ItemCallback<LedgerAccount>() {
@Override
public boolean areItemsTheSame(@NotNull LedgerAccount oldItem,
return listDiffer.getCurrentList()
.size();
}
- public void setAccounts(MobileLedgerProfile profile, List<LedgerAccount> newList) {
- this.profile = profile;
+ public void setAccounts(List<LedgerAccount> newList) {
listDiffer.submitList(newList);
}
- static class LedgerRowHolder extends RecyclerView.ViewHolder {
+ class LedgerRowHolder extends RecyclerView.ViewHolder {
TextView tvAccountName, tvAccountAmounts;
ConstraintLayout row;
View expanderContainer;
if (profile == null) {
return;
}
- try (Locker ignored = profile.lockAccountsForWriting()) {
- LedgerAccount realAccount = profile.locateAccount(mAccount.getName());
+ try (Locker ignored = model.lockAccountsForWriting()) {
+ LedgerAccount realAccount = model.locateAccount(mAccount.getName());
if (realAccount == null)
return;
}
expanderContainer.animate()
.rotation(mAccount.isExpanded() ? 0 : 180);
- profile.updateDisplayedAccounts();
+ model.updateDisplayedAccounts();
DbOpQueue.add("update accounts set expanded=? where name=? and profile=?",
new Object[]{mAccount.isExpanded(), mAccount.getName(), profile.getUuid()
return true;
}
public void bindToAccount(LedgerAccount acc) {
+ Logger.debug("accounts", String.format(Locale.US, "Binding to '%s'", acc.getName()));
Context ctx = row.getContext();
Resources rm = ctx.getResources();
mAccount = acc;