/*
- * Copyright © 2021 Damyan Ivanov.
+ * Copyright © 2024 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
package net.ktnx.mobileledger.ui.account_summary;
+import static net.ktnx.mobileledger.utils.Logger.debug;
+
import android.content.res.Resources;
-import android.os.AsyncTask;
-import android.os.Handler;
-import android.os.Looper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.recyclerview.widget.RecyclerView;
import net.ktnx.mobileledger.R;
+import net.ktnx.mobileledger.dao.BaseDAO;
import net.ktnx.mobileledger.databinding.AccountListRowBinding;
import net.ktnx.mobileledger.databinding.AccountListSummaryRowBinding;
import net.ktnx.mobileledger.db.Account;
import java.util.List;
import java.util.Locale;
-import static net.ktnx.mobileledger.utils.Logger.debug;
-
public class AccountSummaryAdapter extends RecyclerView.Adapter<AccountSummaryAdapter.RowHolder> {
public static final int AMOUNT_LIMIT = 3;
private static final int ITEM_TYPE_HEADER = 1;
@NonNull AccountListItem newItem) {
Change changes = new Change();
- final LedgerAccount oldAcc = oldItem.getAccount();
- final LedgerAccount newAcc = newItem.getAccount();
+ final LedgerAccount oldAcc = oldItem.toAccount()
+ .getAccount();
+ final LedgerAccount newAcc = newItem.toAccount()
+ .getAccount();
if (!Misc.equalStrings(oldAcc.getName(), newAcc.getName()))
changes.add(Change.NAME);
if (oldType == AccountListItem.Type.HEADER)
return true;
- return oldItem.getAccount()
- .getId() == newItem.getAccount()
+ return oldItem.toAccount()
+ .getAccount()
+ .getId() == newItem.toAccount()
+ .getAccount()
.getId();
}
@Override
return 0;
return listDiffer.getCurrentList()
.get(position)
+ .toAccount()
.getAccount()
.getId();
}
throw new IllegalStateException("Unexpected value: " + viewType);
}
- Logger.debug("acc-ui", "Creating " + result);
+// Logger.debug("acc-ui", "Creating " + result);
return result;
}
@Override
return (position == 0) ? ITEM_TYPE_HEADER : ITEM_TYPE_ACCOUNT;
}
public void setAccounts(List<AccountListItem> newList) {
- new Handler(Looper.getMainLooper()).post(() -> listDiffer.submitList(newList));
+ Misc.onMainThread(() -> listDiffer.submitList(newList));
}
static class Change {
static final int NAME = 1;
@Override
public void bind(AccountListItem item, @Nullable List<Object> payloads) {
Resources r = itemView.getResources();
- Logger.debug("acc", itemView.getContext()
- .toString());
+// Logger.debug("acc", itemView.getContext()
+// .toString());
((AccountListItem.Header) item).getText()
.observe((LifecycleOwner) itemView.getContext(),
b.lastUpdateText::setText);
return;
debug("accounts", "Account expander clicked");
- AsyncTask.execute(() -> {
+ BaseDAO.runAsync(() -> {
Account dbo = account.toDBO();
dbo.setExpanded(!dbo.isExpanded());
Logger.debug("accounts",
@NotNull
private LedgerAccount getAccount() {
return listDiffer.getCurrentList()
- .get(getAdapterPosition())
+ .get(getBindingAdapterPosition())
+ .toAccount()
.getAccount();
}
private void toggleAmountsExpanded() {
b.accountRowAmountsExpanderContainer.setVisibility(View.VISIBLE);
}
- AsyncTask.execute(() -> {
+ BaseDAO.runAsync(() -> {
Account dbo = account.toDBO();
DB.get()
.getAccountDAO()
}
@Override
public void bind(AccountListItem item, @Nullable List<Object> payloads) {
- LedgerAccount acc = item.getAccount();
+ LedgerAccount acc = item.toAccount()
+ .getAccount();
Change changes = new Change();
if (payloads != null) {
changes.add((Change) p);
}
}
- debug("accounts",
- String.format(Locale.US, "Binding to '%s' to %s", acc.getName(), this));
+// debug("accounts",
+// String.format(Locale.US, "Binding '%s' to %s", acc.getName(), this));
Resources rm = b.getRoot()
.getContext()
if (changes.has(Change.LEVEL)) {
ConstraintLayout.LayoutParams lp =
- (ConstraintLayout.LayoutParams) b.accountNameLayout.getLayoutParams();
+ (ConstraintLayout.LayoutParams) b.flowWrapper.getLayoutParams();
lp.setMarginStart(
acc.getLevel() * rm.getDimensionPixelSize(R.dimen.thumb_row_height) / 3);
}
if (changes.has(Change.EXPANDED)) {
int wantedRotation = acc.isExpanded() ? 0 : 180;
if (b.accountExpanderContainer.getRotation() != wantedRotation) {
- Logger.debug("acc-ui",
- String.format(Locale.ROOT, "Rotating %s to %d", acc.getName(),
- wantedRotation));
+// Logger.debug("acc-ui",
+// String.format(Locale.ROOT, "Rotating %s to %d", acc.getName(),
+// wantedRotation));
b.accountExpanderContainer.animate()
.rotation(wantedRotation);
}