- if ((profile != null) && profile.isPostingPermitted() && !drawer.isOpen())
- fab.show();
- else
- fabHide();
- }
- public void fabHide() {
- fab.hide();
- }
- public void onAccountSummaryRowViewClicked(View view) {
- ViewGroup row;
- switch (view.getId()) {
- case R.id.account_expander:
- row = (ViewGroup) view.getParent()
- .getParent()
- .getParent();
- break;
- case R.id.account_expander_container:
- case R.id.account_row_acc_name:
- row = (ViewGroup) view.getParent()
- .getParent();
- break;
- default:
- row = (ViewGroup) view.getParent();
- break;
- }
-
- LedgerAccount acc = (LedgerAccount) row.getTag();
- switch (view.getId()) {
- case R.id.account_row_acc_name:
- case R.id.account_expander:
- case R.id.account_expander_container:
- debug("accounts", "Account expander clicked");
- if (!acc.hasSubAccounts())
- return;
-
- boolean wasExpanded = acc.isExpanded();
-
- 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;
- }