+ View arrow = row.findViewById(R.id.account_expander_container);
+
+ arrow.clearAnimation();
+ ViewPropertyAnimator animator = arrow.animate();
+
+ acc.toggleExpanded();
+ DbOpQueue.add("update accounts set expanded=? where name=? and profile=?",
+ new Object[]{acc.isExpanded(), acc.getName(), profile.getUuid()
+ });
+
+ if (wasExpanded) {
+ debug("accounts", String.format("Collapsing account '%s'", acc.getName()));
+ arrow.setRotation(0);
+ animator.rotationBy(180);
+
+ // removing all child accounts from the view
+ int start = -1, count = 0;
+ try (LockHolder ignored = Data.accounts.lockForWriting()) {
+ for (int i = 0; i < Data.accounts.size(); i++) {
+ if (acc.isParentOf(Data.accounts.get(i))) {
+// debug("accounts", String.format("Found a child '%s' at position
+// %d",
+// Data.accounts.get(i).getName(), i));
+ if (start == -1) {
+ start = i;
+ }
+ count++;
+ }
+ else {
+ if (start != -1) {
+// debug("accounts",
+// String.format("Found a non-child '%s' at position %d",
+// Data.accounts.get(i).getName(), i));
+ break;
+ }
+ }
+ }
+
+ if (start != -1) {
+ for (int j = 0; j < count; j++) {
+// debug("accounts", String.format("Removing item %d: %s", start + j,
+// Data.accounts.get(start).getName()));
+ Data.accounts.removeQuietly(start);
+ }
+
+ mAccountSummaryFragment.modelAdapter.notifyItemRangeRemoved(start,
+ count);
+ }
+ }
+ }
+ else {
+ debug("accounts", String.format("Expanding account '%s'", acc.getName()));
+ arrow.setRotation(180);
+ animator.rotationBy(-180);
+ List<LedgerAccount> children = profile.loadVisibleChildAccountsOf(acc);
+ try (LockHolder ignored = Data.accounts.lockForWriting()) {
+ int parentPos = Data.accounts.indexOf(acc);
+ if (parentPos != -1) {
+ // may have disappeared in a concurrent refresh operation
+ Data.accounts.addAllQuietly(parentPos + 1, children);
+ mAccountSummaryFragment.modelAdapter.notifyItemRangeInserted(
+ parentPos + 1, children.size());
+ }
+ }
+ }
+ break;
+ case R.id.account_row_acc_amounts:
+ if (acc.getAmountCount() > AccountSummaryAdapter.AMOUNT_LIMIT) {
+ acc.toggleAmountsExpanded();
+ DbOpQueue.add(
+ "update accounts set amounts_expanded=? where name=? and profile=?",
+ new Object[]{acc.amountsExpanded(), acc.getName(), profile.getUuid()
+ });
+ Data.accounts.triggerItemChangedNotification(acc);
+ }
+ break;
+ }
+ }
+
+ public class SectionsPagerAdapter extends FragmentPagerAdapter {
+
+ SectionsPagerAdapter(FragmentManager fm) {
+ super(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
+ }
+
+ @NotNull
+ @Override
+ public Fragment getItem(int position) {
+ debug("main", String.format(Locale.ENGLISH, "Switching to fragment %d", position));
+ switch (position) {
+ case 0:
+// debug("flow", "Creating account summary fragment");
+ return mAccountSummaryFragment = new AccountSummaryFragment();
+ case 1:
+ return new TransactionListFragment();
+ default:
+ throw new IllegalStateException(
+ String.format("Unexpected fragment index: " + "%d", position));
+ }
+ }
+
+ @Override
+ public int getCount() {
+ return 2;
+ }
+ }