2 * Copyright © 2019 Damyan Ivanov.
3 * This file is part of MoLe.
4 * MoLe is free software: you can distribute it and/or modify it
5 * under the term of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your opinion), any later version.
9 * MoLe is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License terms for details.
14 * You should have received a copy of the GNU General Public License
15 * along with MoLe. If not, see <https://www.gnu.org/licenses/>.
18 package net.ktnx.mobileledger.ui.activity;
20 import android.content.Intent;
21 import android.content.SharedPreferences;
22 import android.content.pm.PackageInfo;
23 import android.content.pm.ShortcutInfo;
24 import android.content.pm.ShortcutManager;
25 import android.content.res.ColorStateList;
26 import android.graphics.Color;
27 import android.graphics.drawable.Icon;
28 import android.os.AsyncTask;
29 import android.os.Build;
30 import android.os.Bundle;
31 import android.util.Log;
32 import android.view.View;
33 import android.view.ViewGroup;
34 import android.view.ViewPropertyAnimator;
35 import android.view.animation.AnimationUtils;
36 import android.widget.LinearLayout;
37 import android.widget.ProgressBar;
38 import android.widget.TextView;
39 import android.widget.Toast;
41 import androidx.appcompat.app.ActionBarDrawerToggle;
42 import androidx.appcompat.widget.Toolbar;
43 import androidx.core.view.GravityCompat;
44 import androidx.drawerlayout.widget.DrawerLayout;
45 import androidx.fragment.app.Fragment;
46 import androidx.fragment.app.FragmentManager;
47 import androidx.fragment.app.FragmentPagerAdapter;
48 import androidx.recyclerview.widget.LinearLayoutManager;
49 import androidx.recyclerview.widget.RecyclerView;
50 import androidx.viewpager.widget.ViewPager;
52 import com.google.android.material.floatingactionbutton.FloatingActionButton;
54 import net.ktnx.mobileledger.R;
55 import net.ktnx.mobileledger.async.DbOpQueue;
56 import net.ktnx.mobileledger.async.RefreshDescriptionsTask;
57 import net.ktnx.mobileledger.async.RetrieveTransactionsTask;
58 import net.ktnx.mobileledger.model.Data;
59 import net.ktnx.mobileledger.model.LedgerAccount;
60 import net.ktnx.mobileledger.model.MobileLedgerProfile;
61 import net.ktnx.mobileledger.ui.account_summary.AccountSummaryAdapter;
62 import net.ktnx.mobileledger.ui.account_summary.AccountSummaryFragment;
63 import net.ktnx.mobileledger.ui.account_summary.AccountSummaryViewModel;
64 import net.ktnx.mobileledger.ui.profiles.ProfileDetailFragment;
65 import net.ktnx.mobileledger.ui.profiles.ProfilesRecyclerViewAdapter;
66 import net.ktnx.mobileledger.ui.transaction_list.TransactionListFragment;
67 import net.ktnx.mobileledger.ui.transaction_list.TransactionListViewModel;
68 import net.ktnx.mobileledger.utils.Colors;
69 import net.ktnx.mobileledger.utils.GetOptCallback;
70 import net.ktnx.mobileledger.utils.LockHolder;
71 import net.ktnx.mobileledger.utils.MLDB;
73 import org.jetbrains.annotations.NotNull;
75 import java.text.DateFormat;
76 import java.util.ArrayList;
77 import java.util.Date;
78 import java.util.List;
79 import java.util.Locale;
81 import static net.ktnx.mobileledger.utils.Logger.debug;
87 public class MainActivity extends ProfileThemedActivity {
88 public static final String STATE_CURRENT_PAGE = "current_page";
89 public static final String BUNDLE_SAVED_STATE = "bundle_savedState";
90 public static final String STATE_ACC_FILTER = "account_filter";
91 private static final String PREF_THEME_ID = "themeId";
92 public AccountSummaryFragment mAccountSummaryFragment;
94 private View profileListHeadMore, profileListHeadCancel, profileListHeadAddProfile;
95 private View bTransactionListCancelDownload;
96 private SectionsPagerAdapter mSectionsPagerAdapter;
97 private ViewPager mViewPager;
98 private FloatingActionButton fab;
99 private ProfilesRecyclerViewAdapter mProfileListAdapter;
100 private int mCurrentPage;
101 private boolean mBackMeansToAccountList = false;
102 private Toolbar mToolbar;
103 private DrawerLayout.SimpleDrawerListener drawerListener;
104 private ActionBarDrawerToggle barDrawerToggle;
105 private ViewPager.SimpleOnPageChangeListener pageChangeListener;
106 private MobileLedgerProfile profile;
108 protected void onStart() {
111 mViewPager.setCurrentItem(mCurrentPage, false);
114 protected void onSaveInstanceState(@NotNull Bundle outState) {
115 super.onSaveInstanceState(outState);
116 outState.putInt(STATE_CURRENT_PAGE, mViewPager.getCurrentItem());
117 if (Data.accountFilter.getValue() != null)
118 outState.putString(STATE_ACC_FILTER, Data.accountFilter.getValue());
121 protected void onDestroy() {
122 mSectionsPagerAdapter = null;
123 RecyclerView root = findViewById(R.id.nav_profile_list);
125 root.setAdapter(null);
127 drawer.removeDrawerListener(drawerListener);
128 drawerListener = null;
130 drawer.removeDrawerListener(barDrawerToggle);
131 barDrawerToggle = null;
132 if (mViewPager != null)
133 mViewPager.removeOnPageChangeListener(pageChangeListener);
134 pageChangeListener = null;
138 protected void setupProfileColors() {
139 SharedPreferences prefs = getPreferences(MODE_PRIVATE);
140 int profileColor = prefs.getInt(PREF_THEME_ID, -2);
141 if (profileColor == -2)
142 profileColor = Data.retrieveCurrentThemeIdFromDb();
143 Colors.setupTheme(this, profileColor);
144 Colors.profileThemeId = profileColor;
145 storeThemeIdInPrefs(profileColor);
148 protected void onResume() {
153 protected void onCreate(Bundle savedInstanceState) {
154 super.onCreate(savedInstanceState);
155 debug("flow", "MainActivity.onCreate()");
156 setContentView(R.layout.activity_main);
158 fab = findViewById(R.id.btn_add_transaction);
159 profileListHeadMore = findViewById(R.id.nav_profiles_start_edit);
160 profileListHeadCancel = findViewById(R.id.nav_profiles_cancel_edit);
161 LinearLayout profileListHeadMoreAndCancel =
162 findViewById(R.id.nav_profile_list_head_buttons);
163 profileListHeadAddProfile = findViewById(R.id.nav_new_profile_button);
164 drawer = findViewById(R.id.drawer_layout);
165 bTransactionListCancelDownload = findViewById(R.id.transaction_list_cancel_download);
166 mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
167 mViewPager = findViewById(R.id.root_frame);
169 Bundle extra = getIntent().getBundleExtra(BUNDLE_SAVED_STATE);
170 if (extra != null && savedInstanceState == null)
171 savedInstanceState = extra;
174 mToolbar = findViewById(R.id.toolbar);
175 setSupportActionBar(mToolbar);
177 Data.profile.observe(this, this::onProfileChanged);
179 Data.profiles.observe(this, this::onProfileListChanged);
181 if (barDrawerToggle == null) {
182 barDrawerToggle = new ActionBarDrawerToggle(this, drawer, mToolbar,
183 R.string.navigation_drawer_open, R.string.navigation_drawer_close);
184 drawer.addDrawerListener(barDrawerToggle);
186 barDrawerToggle.syncState();
188 TextView ver = drawer.findViewById(R.id.drawer_version_text);
191 PackageInfo pi = getApplicationContext().getPackageManager()
192 .getPackageInfo(getPackageName(), 0);
193 ver.setText(pi.versionName);
195 catch (Exception e) {
199 markDrawerItemCurrent(R.id.nav_account_summary);
201 mViewPager.setAdapter(mSectionsPagerAdapter);
203 if (pageChangeListener == null) {
204 pageChangeListener = new ViewPager.SimpleOnPageChangeListener() {
206 public void onPageSelected(int position) {
207 mCurrentPage = position;
210 markDrawerItemCurrent(R.id.nav_account_summary);
213 markDrawerItemCurrent(R.id.nav_latest_transactions);
216 Log.e("MainActivity",
217 String.format("Unexpected page index %d", position));
220 super.onPageSelected(position);
223 mViewPager.addOnPageChangeListener(pageChangeListener);
227 if (savedInstanceState != null) {
228 int currentPage = savedInstanceState.getInt(STATE_CURRENT_PAGE, -1);
229 if (currentPage != -1) {
230 mCurrentPage = currentPage;
232 Data.accountFilter.setValue(savedInstanceState.getString(STATE_ACC_FILTER, null));
235 Data.lastUpdateDate.observe(this, this::updateLastUpdateDisplay);
237 findViewById(R.id.btn_no_profiles_add).setOnClickListener(
238 v -> startEditProfileActivity(null));
240 findViewById(R.id.btn_add_transaction).setOnClickListener(this::fabNewTransactionClicked);
242 findViewById(R.id.nav_new_profile_button).setOnClickListener(
243 v -> startEditProfileActivity(null));
245 RecyclerView root = findViewById(R.id.nav_profile_list);
247 throw new RuntimeException("Can't get hold on the transaction value view");
249 if (mProfileListAdapter == null)
250 mProfileListAdapter = new ProfilesRecyclerViewAdapter();
251 root.setAdapter(mProfileListAdapter);
253 mProfileListAdapter.editingProfiles.observe(this, newValue -> {
255 profileListHeadMore.setVisibility(View.GONE);
256 profileListHeadCancel.setVisibility(View.VISIBLE);
257 profileListHeadAddProfile.setVisibility(View.VISIBLE);
258 if (drawer.isDrawerOpen(GravityCompat.START)) {
259 profileListHeadMore.startAnimation(
260 AnimationUtils.loadAnimation(MainActivity.this, R.anim.fade_out));
261 profileListHeadCancel.startAnimation(
262 AnimationUtils.loadAnimation(MainActivity.this, R.anim.fade_in));
263 profileListHeadAddProfile.startAnimation(
264 AnimationUtils.loadAnimation(MainActivity.this, R.anim.fade_in));
268 profileListHeadCancel.setVisibility(View.GONE);
269 profileListHeadMore.setVisibility(View.VISIBLE);
270 profileListHeadAddProfile.setVisibility(View.GONE);
271 if (drawer.isDrawerOpen(GravityCompat.START)) {
272 profileListHeadCancel.startAnimation(
273 AnimationUtils.loadAnimation(MainActivity.this, R.anim.fade_out));
274 profileListHeadMore.startAnimation(
275 AnimationUtils.loadAnimation(MainActivity.this, R.anim.fade_in));
276 profileListHeadAddProfile.startAnimation(
277 AnimationUtils.loadAnimation(MainActivity.this, R.anim.fade_out));
281 mProfileListAdapter.notifyDataSetChanged();
284 LinearLayoutManager llm = new LinearLayoutManager(this);
286 llm.setOrientation(RecyclerView.VERTICAL);
287 root.setLayoutManager(llm);
289 profileListHeadMore.setOnClickListener((v) -> mProfileListAdapter.flipEditingProfiles());
290 profileListHeadCancel.setOnClickListener((v) -> mProfileListAdapter.flipEditingProfiles());
291 profileListHeadMoreAndCancel.setOnClickListener(
292 (v) -> mProfileListAdapter.flipEditingProfiles());
293 if (drawerListener == null) {
294 drawerListener = new DrawerLayout.SimpleDrawerListener() {
296 public void onDrawerClosed(View drawerView) {
297 super.onDrawerClosed(drawerView);
298 mProfileListAdapter.setAnimationsEnabled(false);
299 mProfileListAdapter.editingProfiles.setValue(false);
302 public void onDrawerOpened(View drawerView) {
303 super.onDrawerOpened(drawerView);
304 mProfileListAdapter.setAnimationsEnabled(true);
307 drawer.addDrawerListener(drawerListener);
311 private void scheduleDataRetrievalIfStale(Date lastUpdate) {
312 long now = new Date().getTime();
313 if ((lastUpdate == null) || (now > (lastUpdate.getTime() + (24 * 3600 * 1000)))) {
314 if (lastUpdate == null)
315 debug("db::", "WEB data never fetched. scheduling a fetch");
317 debug("db", String.format(Locale.ENGLISH,
318 "WEB data last fetched at %1.3f and now is %1.3f. re-fetching",
319 lastUpdate.getTime() / 1000f, now / 1000f));
321 Data.scheduleTransactionListRetrieval(this);
324 private void createShortcuts(List<MobileLedgerProfile> list) {
325 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N_MR1)
328 List<ShortcutInfo> shortcuts = new ArrayList<>();
330 for (MobileLedgerProfile p : list) {
331 if (!p.isPostingPermitted())
335 new ShortcutInfo.Builder(this, "new_transaction_" + p.getUuid()).setShortLabel(
338 Icon.createWithResource(
340 R.drawable.svg_thick_plus_white))
346 NewTransactionActivity.class).putExtra(
354 ShortcutManager sm = getSystemService(ShortcutManager.class);
355 sm.setDynamicShortcuts(shortcuts);
357 private void onProfileListChanged(List<MobileLedgerProfile> newList) {
358 if (newList == null) {
359 // profiles not yet loaded from DB
360 findViewById(R.id.loading_layout).setVisibility(View.VISIBLE);
361 findViewById(R.id.no_profiles_layout).setVisibility(View.GONE);
362 findViewById(R.id.pager_layout).setVisibility(View.GONE);
366 if (newList.isEmpty()) {
367 findViewById(R.id.no_profiles_layout).setVisibility(View.VISIBLE);
368 findViewById(R.id.pager_layout).setVisibility(View.GONE);
369 findViewById(R.id.loading_layout).setVisibility(View.GONE);
373 findViewById(R.id.pager_layout).setVisibility(View.VISIBLE);
374 findViewById(R.id.no_profiles_layout).setVisibility(View.GONE);
375 findViewById(R.id.loading_layout).setVisibility(View.GONE);
377 findViewById(R.id.nav_profile_list).setMinimumHeight(
378 (int) (getResources().getDimension(R.dimen.thumb_row_height) * newList.size()));
380 debug("profiles", "profile list changed");
381 mProfileListAdapter.notifyDataSetChanged();
383 createShortcuts(newList);
386 * called when the current profile has changed
388 private void onProfileChanged(MobileLedgerProfile profile) {
389 boolean haveProfile = profile != null;
390 findViewById(R.id.no_profiles_layout).setVisibility(haveProfile ? View.GONE : View.VISIBLE);
391 findViewById(R.id.pager_layout).setVisibility(haveProfile ? View.VISIBLE : View.VISIBLE);
394 setTitle(profile.getName());
396 setTitle(R.string.app_name);
398 this.profile = profile;
400 mProfileListAdapter.notifyDataSetChanged();
402 int newProfileTheme = haveProfile ? profile.getThemeId() : -1;
403 if (newProfileTheme != Colors.profileThemeId) {
405 String.format(Locale.ENGLISH, "profile theme %d → %d", Colors.profileThemeId,
407 MainActivity.this.profileThemeChanged();
408 Colors.profileThemeId = newProfileTheme;
409 // profileThemeChanged would restart the activity, so no need to reload the
414 drawer.closeDrawers();
416 Data.transactions.clear();
417 debug("transactions", "requesting list reload");
418 TransactionListViewModel.scheduleTransactionListReload();
420 Data.accounts.clear();
421 AccountSummaryViewModel.scheduleAccountListReload();
424 if (profile.isPostingPermitted()) {
425 mToolbar.setSubtitle(null);
429 mToolbar.setSubtitle(R.string.profile_subitlte_read_only);
434 mToolbar.setSubtitle(null);
438 updateLastUpdateTextFromDB();
440 private void updateLastUpdateDisplay(Date newValue) {
441 LinearLayout l = findViewById(R.id.transactions_last_update_layout);
442 TextView v = findViewById(R.id.transactions_last_update);
443 if (newValue == null) {
444 l.setVisibility(View.INVISIBLE);
445 debug("main", "no last update date :(");
448 final String text = DateFormat.getDateTimeInstance()
451 l.setVisibility(View.VISIBLE);
452 debug("main", String.format("Date formatted: %s", text));
455 scheduleDataRetrievalIfStale(newValue);
457 private void profileThemeChanged() {
458 Bundle bundle = new Bundle();
459 onSaveInstanceState(bundle);
461 storeThemeIdInPrefs(profile.getThemeId());
463 // restart activity to reflect theme change
466 // un-hook all observed LiveData
467 Data.profile.removeObservers(this);
468 Data.profiles.removeObservers(this);
469 Data.lastUpdateDate.removeObservers(this);
470 Intent intent = new Intent(this, this.getClass());
471 intent.putExtra(BUNDLE_SAVED_STATE, bundle);
472 startActivity(intent);
474 private void storeThemeIdInPrefs(int themeId) {
475 // store the new theme id in the preferences
476 SharedPreferences prefs = getPreferences(MODE_PRIVATE);
477 SharedPreferences.Editor e = prefs.edit();
478 e.putInt(PREF_THEME_ID, themeId);
481 public void startEditProfileActivity(MobileLedgerProfile profile) {
482 Intent intent = new Intent(this, ProfileDetailActivity.class);
483 Bundle args = new Bundle();
484 if (profile != null) {
485 int index = Data.getProfileIndex(profile);
487 intent.putExtra(ProfileDetailFragment.ARG_ITEM_ID, index);
489 intent.putExtras(args);
490 startActivity(intent, args);
492 private void setupProfile() {
493 MLDB.getOption(MLDB.OPT_PROFILE_UUID, null, new GetOptCallback() {
495 protected void onResult(String profileUUID) {
496 MobileLedgerProfile startupProfile;
498 startupProfile = Data.getProfile(profileUUID);
499 Data.setCurrentProfile(startupProfile);
503 public void fabNewTransactionClicked(View view) {
504 Intent intent = new Intent(this, NewTransactionActivity.class);
505 startActivity(intent);
506 overridePendingTransition(R.anim.slide_in_up, R.anim.dummy);
508 public void markDrawerItemCurrent(int id) {
509 TextView item = drawer.findViewById(id);
510 item.setBackgroundColor(Colors.tableRowDarkBG);
512 LinearLayout actions = drawer.findViewById(R.id.nav_actions);
513 for (int i = 0; i < actions.getChildCount(); i++) {
514 View view = actions.getChildAt(i);
515 if (view.getId() != id) {
516 view.setBackgroundColor(Color.TRANSPARENT);
520 public void onAccountSummaryClicked(View view) {
521 drawer.closeDrawers();
523 showAccountSummaryFragment();
525 private void showAccountSummaryFragment() {
526 mViewPager.setCurrentItem(0, true);
527 Data.accountFilter.setValue(null);
529 public void onLatestTransactionsClicked(View view) {
530 drawer.closeDrawers();
532 showTransactionsFragment((String) null);
534 private void showTransactionsFragment(String accName) {
535 Data.accountFilter.setValue(accName);
536 mViewPager.setCurrentItem(1, true);
538 private void showTransactionsFragment(LedgerAccount account) {
539 showTransactionsFragment((account == null) ? null : account.getName());
541 public void showAccountTransactions(LedgerAccount account) {
542 mBackMeansToAccountList = true;
543 showTransactionsFragment(account);
546 public void onBackPressed() {
547 DrawerLayout drawer = findViewById(R.id.drawer_layout);
548 if (drawer.isDrawerOpen(GravityCompat.START)) {
549 drawer.closeDrawer(GravityCompat.START);
552 if (mBackMeansToAccountList && (mViewPager.getCurrentItem() == 1)) {
553 Data.accountFilter.setValue(null);
554 showAccountSummaryFragment();
555 mBackMeansToAccountList = false;
558 debug("fragments", String.format(Locale.ENGLISH, "manager stack: %d",
559 getSupportFragmentManager().getBackStackEntryCount()));
561 super.onBackPressed();
565 public void updateLastUpdateTextFromDB() {
569 long last_update = profile.getLongOption(MLDB.OPT_LAST_SCRAPE, 0L);
571 debug("transactions", String.format(Locale.ENGLISH, "Last update = %d", last_update));
572 if (last_update == 0) {
573 Data.lastUpdateDate.postValue(null);
576 Data.lastUpdateDate.postValue(new Date(last_update));
579 public void onStopTransactionRefreshClick(View view) {
580 debug("interactive", "Cancelling transactions refresh");
581 Data.stopTransactionsRetrieval();
582 bTransactionListCancelDownload.setEnabled(false);
584 public void onRetrieveDone(String error) {
585 Data.transactionRetrievalDone();
586 findViewById(R.id.transaction_progress_layout).setVisibility(View.GONE);
589 updateLastUpdateTextFromDB();
591 new RefreshDescriptionsTask().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
592 TransactionListViewModel.scheduleTransactionListReload();
595 Toast.makeText(this, error, Toast.LENGTH_LONG)
598 public void onRetrieveStart() {
599 ProgressBar progressBar = findViewById(R.id.transaction_list_progress_bar);
600 bTransactionListCancelDownload.setEnabled(true);
601 ColorStateList csl = Colors.getColorStateList();
602 progressBar.setIndeterminateTintList(csl);
603 progressBar.setProgressTintList(csl);
604 progressBar.setIndeterminate(true);
605 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
606 progressBar.setProgress(0, false);
608 progressBar.setProgress(0);
609 findViewById(R.id.transaction_progress_layout).setVisibility(View.VISIBLE);
611 public void onRetrieveProgress(RetrieveTransactionsTask.Progress progress) {
612 ProgressBar progressBar = findViewById(R.id.transaction_list_progress_bar);
613 if ((progress.getTotal() == RetrieveTransactionsTask.Progress.INDETERMINATE) ||
614 (progress.getTotal() == 0))
616 progressBar.setIndeterminate(true);
619 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
620 progressBar.setMin(0);
622 progressBar.setMax(progress.getTotal());
623 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
624 progressBar.setProgress(progress.getProgress(), true);
627 progressBar.setProgress(progress.getProgress());
628 progressBar.setIndeterminate(false);
631 public void fabShouldShow() {
632 if ((profile != null) && profile.isPostingPermitted())
635 public void fabHide() {
638 public void onAccountSummaryRowViewClicked(View view) {
640 if (view.getId() == R.id.account_expander)
641 row = (ViewGroup) view.getParent()
644 row = (ViewGroup) view.getParent();
646 LedgerAccount acc = (LedgerAccount) row.getTag();
647 switch (view.getId()) {
648 case R.id.account_row_acc_name:
649 case R.id.account_expander:
650 case R.id.account_expander_container:
651 debug("accounts", "Account expander clicked");
652 if (!acc.hasSubAccounts())
655 boolean wasExpanded = acc.isExpanded();
657 View arrow = row.findViewById(R.id.account_expander_container);
659 arrow.clearAnimation();
660 ViewPropertyAnimator animator = arrow.animate();
662 acc.toggleExpanded();
663 DbOpQueue.add("update accounts set expanded=? where name=? and profile=?",
664 new Object[]{acc.isExpanded(), acc.getName(), profile.getUuid()
668 debug("accounts", String.format("Collapsing account '%s'", acc.getName()));
669 arrow.setRotation(0);
670 animator.rotationBy(180);
672 // removing all child accounts from the view
673 int start = -1, count = 0;
674 try (LockHolder ignored = Data.accounts.lockForWriting()) {
675 for (int i = 0; i < Data.accounts.size(); i++) {
676 if (acc.isParentOf(Data.accounts.get(i))) {
677 // debug("accounts", String.format("Found a child '%s' at position
679 // Data.accounts.get(i).getName(), i));
688 // String.format("Found a non-child '%s' at position %d",
689 // Data.accounts.get(i).getName(), i));
696 for (int j = 0; j < count; j++) {
697 // debug("accounts", String.format("Removing item %d: %s", start + j,
698 // Data.accounts.get(start).getName()));
699 Data.accounts.removeQuietly(start);
702 mAccountSummaryFragment.modelAdapter.notifyItemRangeRemoved(start,
708 debug("accounts", String.format("Expanding account '%s'", acc.getName()));
709 arrow.setRotation(180);
710 animator.rotationBy(-180);
711 List<LedgerAccount> children = profile.loadVisibleChildAccountsOf(acc);
712 try (LockHolder ignored = Data.accounts.lockForWriting()) {
713 int parentPos = Data.accounts.indexOf(acc);
714 if (parentPos != -1) {
715 // may have disappeared in a concurrent refresh operation
716 Data.accounts.addAllQuietly(parentPos + 1, children);
717 mAccountSummaryFragment.modelAdapter.notifyItemRangeInserted(
718 parentPos + 1, children.size());
723 case R.id.account_row_acc_amounts:
724 if (acc.getAmountCount() > AccountSummaryAdapter.AMOUNT_LIMIT) {
725 acc.toggleAmountsExpanded();
727 "update accounts set amounts_expanded=? where name=? and profile=?",
728 new Object[]{acc.amountsExpanded(), acc.getName(), profile.getUuid()
730 Data.accounts.triggerItemChangedNotification(acc);
736 public class SectionsPagerAdapter extends FragmentPagerAdapter {
738 SectionsPagerAdapter(FragmentManager fm) {
739 super(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
744 public Fragment getItem(int position) {
745 debug("main", String.format(Locale.ENGLISH, "Switching to fragment %d", position));
748 // debug("flow", "Creating account summary fragment");
749 return mAccountSummaryFragment = new AccountSummaryFragment();
751 return new TransactionListFragment();
753 throw new IllegalStateException(
754 String.format("Unexpected fragment index: " + "%d", position));
759 public int getCount() {