- List<LedgerAccount> accounts = Data.accounts.get();
- if (position < accounts.size()) {
- LedgerAccount acc = accounts.get(position);
- Context ctx = holder.row.getContext();
- Resources rm = ctx.getResources();
-
- holder.row.setVisibility(View.VISIBLE);
- holder.vTrailer.setVisibility(View.GONE);
- holder.tvAccountName.setText(acc.getShortName());
- holder.tvAccountName.setPadding(
- acc.getLevel() * rm.getDimensionPixelSize(R.dimen.activity_horizontal_margin) /
- 2, 0, 0, 0);
- holder.tvAccountAmounts.setText(acc.getAmountsString());
-
- if (acc.isHidden()) {
- holder.tvAccountName.setTypeface(null, Typeface.ITALIC);
- holder.tvAccountAmounts.setTypeface(null, Typeface.ITALIC);
+ try (LockHolder lh = Data.accounts.lockForReading()) {
+ if (position < Data.accounts.size()) {
+ LedgerAccount acc = Data.accounts.get(position);
+ Context ctx = holder.row.getContext();
+ Resources rm = ctx.getResources();
+
+ holder.row.setTag(acc);
+ holder.row.setVisibility(View.VISIBLE);
+ holder.vTrailer.setVisibility(View.GONE);
+ holder.tvAccountName.setText(acc.getShortName());
+ ConstraintLayout.LayoutParams lp =
+ (ConstraintLayout.LayoutParams) holder.tvAccountName.getLayoutParams();
+ lp.setMarginStart(
+ acc.getLevel() * rm.getDimensionPixelSize(R.dimen.thumb_row_height) / 3);
+ holder.expanderContainer.setVisibility(
+ acc.hasSubAccounts() ? View.VISIBLE : View.GONE);
+ holder.expanderContainer.setRotation(acc.isExpanded() ? 0 : 180);
+ int amounts = acc.getAmountCount();
+ if ((amounts > AMOUNT_LIMIT) && !acc.amountsExpanded()) {
+ holder.tvAccountAmounts.setText(acc.getAmountsString(AMOUNT_LIMIT));
+ holder.accountExpanderContainer.setVisibility(View.VISIBLE);
+ }
+ else {
+ holder.tvAccountAmounts.setText(acc.getAmountsString());
+ holder.accountExpanderContainer.setVisibility(View.GONE);
+ }
+
+ if (acc.isHiddenByStar()) {
+ holder.tvAccountName.setTypeface(null, Typeface.ITALIC);
+ holder.tvAccountAmounts.setTypeface(null, Typeface.ITALIC);
+ }
+ else {
+ holder.tvAccountName.setTypeface(null, Typeface.NORMAL);
+ holder.tvAccountAmounts.setTypeface(null, Typeface.NORMAL);
+ }
+
+ holder.row.setTag(R.id.POS, position);