+ row.setOnLongClickListener(this::onItemLongClick);
+
+ tvAccountName.setOnClickListener(v -> toggleAccountExpanded());
+ expanderContainer.setOnClickListener(v -> toggleAccountExpanded());
+ expander.setOnClickListener(v -> toggleAccountExpanded());
+ tvAccountAmounts.setOnClickListener(v -> toggleAmountsExpanded());
+ }
+ private @NonNull
+ LedgerAccount getAccount() {
+ final ArrayList<LedgerAccount> accountList = profile.getAccounts()
+ .getValue();
+ if (accountList == null)
+ throw new IllegalStateException("No account list");
+
+ return accountList.get(getAdapterPosition());
+ }
+ private void toggleAccountExpanded() {
+ LedgerAccount acc = getAccount();
+ if (!acc.hasSubAccounts())
+ return;
+ debug("accounts", "Account expander clicked");
+
+ acc.toggleExpanded();
+ expanderContainer.animate()
+ .rotation(acc.isExpanded() ? 0 : 180);
+
+ MobileLedgerProfile profile = acc.getProfile();
+ if (profile == null)
+ return;
+
+ DbOpQueue.add("update accounts set expanded=? where name=? and profile=?",
+ new Object[]{acc.isExpanded(), acc.getName(), profile.getUuid()
+ }, profile::scheduleAccountListReload);
+
+ }
+ private void toggleAmountsExpanded() {
+ LedgerAccount acc = getAccount();
+ if (acc.getAmountCount() <= AMOUNT_LIMIT)
+ return;
+
+ acc.toggleAmountsExpanded();
+ if (acc.amountsExpanded()) {
+ tvAccountAmounts.setText(acc.getAmountsString());
+ accountExpanderContainer.setVisibility(View.GONE);
+ }
+ else {
+ tvAccountAmounts.setText(acc.getAmountsString(AMOUNT_LIMIT));
+ accountExpanderContainer.setVisibility(View.VISIBLE);
+ }
+
+ MobileLedgerProfile profile = acc.getProfile();
+ if (profile == null)
+ return;
+
+ DbOpQueue.add("update accounts set amounts_expanded=? where name=? and profile=?",
+ new Object[]{acc.amountsExpanded(), acc.getName(), profile.getUuid()
+ });
+