- class LedgerRowHolder extends RecyclerView.ViewHolder {
- CheckBox selectionCb;
- TextView tvAccountName, tvAccountAmounts;
- ConstraintLayout row;
- View vTrailer;
- FrameLayout expanderContainer;
- ImageView expander;
- public LedgerRowHolder(@NonNull View itemView) {
- super(itemView);
- 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);
- });
+ Change changes = new Change();
+ if (payloads != null) {
+ for (Object p : payloads) {
+ if (p instanceof Change)
+ changes.add((Change) p);
+ }
+ }
+// debug("accounts",
+// String.format(Locale.US, "Binding '%s' to %s", acc.getName(), this));
+
+ Resources rm = b.getRoot()
+ .getContext()
+ .getResources();
+
+ if (changes.has(Change.NAME))
+ b.accountRowAccName.setText(acc.getShortName());
+
+ if (changes.has(Change.LEVEL)) {
+ ConstraintLayout.LayoutParams lp =
+ (ConstraintLayout.LayoutParams) b.flowWrapper.getLayoutParams();
+ lp.setMarginStart(
+ acc.getLevel() * rm.getDimensionPixelSize(R.dimen.thumb_row_height) / 3);
+ }
+
+ if (acc.hasSubAccounts()) {
+ b.accountExpanderContainer.setVisibility(View.VISIBLE);
+
+ if (changes.has(Change.EXPANDED)) {
+ int wantedRotation = acc.isExpanded() ? 0 : 180;
+ if (b.accountExpanderContainer.getRotation() != wantedRotation) {
+// Logger.debug("acc-ui",
+// String.format(Locale.ROOT, "Rotating %s to %d", acc.getName(),
+// wantedRotation));
+ b.accountExpanderContainer.animate()
+ .rotation(wantedRotation);
+ }
+ }
+ }
+ else {
+ b.accountExpanderContainer.setVisibility(View.GONE);
+ }
+
+ if (changes.has(Change.EXPANDED_AMOUNTS)) {
+ int amounts = acc.getAmountCount();
+ if ((amounts > AMOUNT_LIMIT) && !acc.amountsExpanded()) {
+ b.accountRowAccAmounts.setText(acc.getAmountsString(AMOUNT_LIMIT));
+ b.accountRowAmountsExpanderContainer.setVisibility(View.VISIBLE);
+ }
+ else {
+ b.accountRowAccAmounts.setText(acc.getAmountsString());
+ b.accountRowAmountsExpanderContainer.setVisibility(View.GONE);
+ }
+ }