X-Git-Url: https://git.ktnx.net/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fui%2Faccount_summary%2FAccountSummaryAdapter.java;h=d50601efed707a4a21f76ae64be3459604a5a919;hb=5bba2c06a81c87327fdcf3f2a85c3206d932c2f9;hp=fbbc47d7ff5080647b7a7f4e6994dcc48283fa56;hpb=0a73337c99e2074aa7e7228204289896342ec636;p=mobile-ledger-staging.git diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/account_summary/AccountSummaryAdapter.java b/app/src/main/java/net/ktnx/mobileledger/ui/account_summary/AccountSummaryAdapter.java index fbbc47d7..d50601ef 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/account_summary/AccountSummaryAdapter.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/account_summary/AccountSummaryAdapter.java @@ -37,21 +37,26 @@ import net.ktnx.mobileledger.R; 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 { public static final int AMOUNT_LIMIT = 3; - private MobileLedgerProfile profile; private AsyncListDiffer listDiffer; - AccountSummaryAdapter() { + private MainModel model; + AccountSummaryAdapter(MainModel model) { + this.model = model; + listDiffer = new AsyncListDiffer<>(this, new DiffUtil.ItemCallback() { @Override public boolean areItemsTheSame(@NotNull LedgerAccount oldItem, @@ -84,11 +89,10 @@ public class AccountSummaryAdapter return listDiffer.getCurrentList() .size(); } - public void setAccounts(MobileLedgerProfile profile, List newList) { - this.profile = profile; + public void setAccounts(List newList) { listDiffer.submitList(newList); } - static class LedgerRowHolder extends RecyclerView.ViewHolder { + class LedgerRowHolder extends RecyclerView.ViewHolder { TextView tvAccountName, tvAccountAmounts; ConstraintLayout row; View expanderContainer; @@ -128,8 +132,8 @@ public class AccountSummaryAdapter 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; @@ -138,7 +142,7 @@ public class AccountSummaryAdapter } 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() @@ -189,6 +193,7 @@ public class AccountSummaryAdapter 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;