/*
- * 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();
}
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;
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) {
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);
}