X-Git-Url: https://git.ktnx.net/?p=mobile-ledger.git;a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fui%2Factivity%2FMainActivity.java;h=cfceb7ca7f1786d9a9470dd6c0934dbaf5e9b8c6;hp=877740731df959a7c7a5114c8740bda69e41d888;hb=b1b663239741e95fc1087de186a10e5e762135db;hpb=c6fe580ac5a93cff593d95a0fe34bd6c2c7bddfc diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java b/app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java index 87774073..cfceb7ca 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java @@ -38,6 +38,7 @@ import android.widget.Toast; import com.google.android.material.floatingactionbutton.FloatingActionButton; import net.ktnx.mobileledger.R; +import net.ktnx.mobileledger.async.DbOpQueue; import net.ktnx.mobileledger.async.RefreshDescriptionsTask; import net.ktnx.mobileledger.async.RetrieveTransactionsTask; import net.ktnx.mobileledger.model.Data; @@ -166,6 +167,12 @@ public class MainActivity extends ProfileThemedActivity { } }); }); + Data.profiles.addObserver((o, arg) -> { + findViewById(R.id.nav_profile_list).setMinimumHeight( + (int) (getResources().getDimension(R.dimen.thumb_row_height) * + Data.profiles.size())); + mProfileListAdapter.notifyDataSetChanged(); + }); ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, @@ -556,64 +563,75 @@ public class MainActivity extends ProfileThemedActivity { } public void onAccountSummaryRowViewClicked(View view) { ViewGroup row = (ViewGroup) view.getParent(); - if (view.getId() == R.id.account_expander_container) { - Log.d("accounts", "Account expander clicked"); - LedgerAccount acc = (LedgerAccount) row.getTag(); - if (!acc.hasSubAccounts()) return; - - boolean wasExpanded = acc.isExpanded(); - - view.clearAnimation(); - ViewPropertyAnimator animator = view.animate(); - - acc.toggleExpanded(); - Data.profile.get().storeAccount(MLDB.getWritableDatabase(), acc); - - if (wasExpanded) { - Log.d("accounts", String.format("Collapsing account '%s'", acc.getName())); - animator.rotationBy(180); - - // removing all child accounts from the view - int start = -1, count = 0; - int i = 0; - final ArrayList accountList = Data.accounts.get(); - for (LedgerAccount a : accountList) { - if (acc.isParentOf(a)) { - if (start == -1) { - start = i; + LedgerAccount acc = (LedgerAccount) row.getTag(); + switch (view.getId()) { + case R.id.account_row_acc_name: + case R.id.account_expander_container: + Log.d("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(); + Data.profile.get().storeAccount(MLDB.getDatabase(), acc); + + if (wasExpanded) { + Log.d("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; + int i = 0; + final ArrayList accountList = Data.accounts.get(); + for (LedgerAccount a : accountList) { + if (acc.isParentOf(a)) { + if (start == -1) { + start = i; + } + count++; } - count++; - } - else { - if (start != -1) { - break; + else { + if (start != -1) { + break; + } } + i++; } - i++; - } - if (start != -1) { - for (int j = 0; j < count; j++) { - Log.d("accounts", String.format("Removing item %d: %s", start + j, - accountList.get(start).getName())); - accountList.remove(start); - } + if (start != -1) { + for (int j = 0; j < count; j++) { + Log.d("accounts", String.format("Removing item %d: %s", start + j, + accountList.get(start).getName())); + accountList.remove(start); + } - mAccountSummaryFragment.modelAdapter.notifyItemRangeRemoved(start, count); + mAccountSummaryFragment.modelAdapter.notifyItemRangeRemoved(start, count); + } } - } - else { - Log.d("accounts", String.format("Expanding account '%s'", acc.getName())); - animator.rotationBy(-180); - ArrayList accounts = Data.accounts.get(); - List children = Data.profile.get().loadVisibleChildAccountsOf(acc); - int parentPos = accounts.indexOf(acc); - if (parentPos == -1) throw new RuntimeException( - "Can't find index of clicked account " + acc.getName()); - accounts.addAll(parentPos + 1, children); - mAccountSummaryFragment.modelAdapter - .notifyItemRangeInserted(parentPos + 1, children.size()); - } + else { + Log.d("accounts", String.format("Expanding account '%s'", acc.getName())); + arrow.setRotation(180); + animator.rotationBy(-180); + ArrayList accounts = Data.accounts.get(); + List children = + Data.profile.get().loadVisibleChildAccountsOf(acc); + int parentPos = accounts.indexOf(acc); + if (parentPos == -1) throw new RuntimeException( + "Can't find index of clicked account " + acc.getName()); + accounts.addAll(parentPos + 1, children); + mAccountSummaryFragment.modelAdapter + .notifyItemRangeInserted(parentPos + 1, children.size()); + } + break; + case R.id.account_row_acc_amounts: + showAccountTransactions(acc); + break; } }