+ class LedgerRowHolder extends RecyclerView.ViewHolder {
+ private final TextView tvAccountName, tvAccountAmounts;
+ private final ConstraintLayout row;
+ private final View expanderContainer;
+ private final View amountExpanderContainer;
+ private final View lLastUpdate;
+ private final TextView tvLastUpdate;
+ private final View vAccountNameLayout;
+ LedgerAccount mAccount;
+ private AccountListItem.Type lastType;
+ private Observer lastUpdateObserver;
+ public LedgerRowHolder(@NonNull View itemView) {
+ super(itemView);
+
+ row = itemView.findViewById(R.id.account_summary_row);
+ vAccountNameLayout = itemView.findViewById(R.id.account_name_layout);
+ tvAccountName = itemView.findViewById(R.id.account_row_acc_name);
+ tvAccountAmounts = itemView.findViewById(R.id.account_row_acc_amounts);
+ expanderContainer = itemView.findViewById(R.id.account_expander_container);
+ ImageView expander = itemView.findViewById(R.id.account_expander);
+ amountExpanderContainer =
+ itemView.findViewById(R.id.account_row_amounts_expander_container);
+ lLastUpdate = itemView.findViewById(R.id.last_update_container);
+ tvLastUpdate = itemView.findViewById(R.id.last_update_text);
+
+ itemView.setOnLongClickListener(this::onItemLongClick);
+ tvAccountName.setOnLongClickListener(this::onItemLongClick);
+ tvAccountAmounts.setOnLongClickListener(this::onItemLongClick);
+ expanderContainer.setOnLongClickListener(this::onItemLongClick);
+ expander.setOnLongClickListener(this::onItemLongClick);
+ row.setOnLongClickListener(this::onItemLongClick);
+
+ tvAccountName.setOnClickListener(v -> toggleAccountExpanded());
+ expanderContainer.setOnClickListener(v -> toggleAccountExpanded());
+ expander.setOnClickListener(v -> toggleAccountExpanded());
+ tvAccountAmounts.setOnClickListener(v -> toggleAmountsExpanded());
+
+ }
+ private void toggleAccountExpanded() {
+ if (!mAccount.hasSubAccounts())
+ return;
+ debug("accounts", "Account expander clicked");
+
+ // make sure we use the same object as the one in the allAccounts list
+ MobileLedgerProfile profile = mAccount.getProfile();
+ if (profile == null) {
+ return;
+ }
+ try (Locker ignored = model.lockAccountsForWriting()) {
+ LedgerAccount realAccount = model.locateAccount(mAccount.getName());
+ if (realAccount == null)
+ return;
+
+ mAccount = realAccount;
+ mAccount.toggleExpanded();