- this.row = itemView.findViewById(R.id.account_summary_row);
- this.tvAccountName = itemView.findViewById(R.id.account_row_acc_name);
- this.tvAccountAmounts = itemView.findViewById(R.id.account_row_acc_amounts);
- this.selectionCb = itemView.findViewById(R.id.account_row_check);
- this.vTrailer = itemView.findViewById(R.id.account_summary_trailer);
- this.expanderContainer = itemView.findViewById(R.id.account_expander_container);
- this.expander = itemView.findViewById(R.id.account_expander);
-
- MainActivity activity = (MainActivity) row.getContext();
-
- expanderContainer.addOnLayoutChangeListener(
- (v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> {
- int w = right - left;
- int h = bottom - top;
- if (h > w) {
- int p = (h - w) / 2;
- v.setPadding(0, p, 0, p);
- }
- else v.setPadding(0, 0, 0, 0);
- });
+ row = itemView.findViewById(R.id.account_summary_row);
+ 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);
+ expander = itemView.findViewById(R.id.account_expander);
+ accountExpanderContainer =
+ itemView.findViewById(R.id.account_row_amounts_expander_container);
+
+ 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 @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;