- 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);
-
- 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 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 = profile.lockAccountsForWriting()) {
+ LedgerAccount realAccount = profile.locateAccount(mAccount.getName());
+ if (realAccount == null)
+ return;
+
+ mAccount = realAccount;
+ mAccount.toggleExpanded();
+ }
+ expanderContainer.animate()
+ .rotation(mAccount.isExpanded() ? 0 : 180);
+ profile.updateDisplayedAccounts();
+
+ DbOpQueue.add("update accounts set expanded=? where name=? and profile=?",
+ new Object[]{mAccount.isExpanded(), mAccount.getName(), profile.getUuid()
+ });
+
+ }
+ private void toggleAmountsExpanded() {
+ if (mAccount.getAmountCount() <= AMOUNT_LIMIT)
+ return;
+
+ mAccount.toggleAmountsExpanded();
+ if (mAccount.amountsExpanded()) {
+ tvAccountAmounts.setText(mAccount.getAmountsString());
+ accountExpanderContainer.setVisibility(View.GONE);
+ }
+ else {
+ tvAccountAmounts.setText(mAccount.getAmountsString(AMOUNT_LIMIT));
+ accountExpanderContainer.setVisibility(View.VISIBLE);
+ }
+
+ MobileLedgerProfile profile = mAccount.getProfile();
+ if (profile == null)
+ return;
+
+ DbOpQueue.add("update accounts set amounts_expanded=? where name=? and profile=?",
+ new Object[]{mAccount.amountsExpanded(), mAccount.getName(), profile.getUuid()