2 * Copyright © 2020 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;
40 import androidx.annotation.NonNull;
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;
53 import com.google.android.material.snackbar.Snackbar;
55 import net.ktnx.mobileledger.R;
56 import net.ktnx.mobileledger.async.DbOpQueue;
57 import net.ktnx.mobileledger.async.RefreshDescriptionsTask;
58 import net.ktnx.mobileledger.async.RetrieveTransactionsTask;
59 import net.ktnx.mobileledger.model.Data;
60 import net.ktnx.mobileledger.model.LedgerAccount;
61 import net.ktnx.mobileledger.model.MobileLedgerProfile;
62 import net.ktnx.mobileledger.ui.account_summary.AccountSummaryAdapter;
63 import net.ktnx.mobileledger.ui.account_summary.AccountSummaryFragment;
64 import net.ktnx.mobileledger.ui.account_summary.AccountSummaryViewModel;
65 import net.ktnx.mobileledger.ui.profiles.ProfileDetailFragment;
66 import net.ktnx.mobileledger.ui.profiles.ProfilesRecyclerViewAdapter;
67 import net.ktnx.mobileledger.ui.transaction_list.TransactionListFragment;
68 import net.ktnx.mobileledger.ui.transaction_list.TransactionListViewModel;
69 import net.ktnx.mobileledger.utils.Colors;
70 import net.ktnx.mobileledger.utils.GetOptCallback;
71 import net.ktnx.mobileledger.utils.LockHolder;
72 import net.ktnx.mobileledger.utils.Logger;
73 import net.ktnx.mobileledger.utils.MLDB;
75 import org.jetbrains.annotations.NotNull;
77 import java.text.DateFormat;
78 import java.util.ArrayList;
79 import java.util.Date;
80 import java.util.List;
81 import java.util.Locale;
83 import static net.ktnx.mobileledger.utils.Logger.debug;
89 public class MainActivity extends ProfileThemedActivity {
90 public static final String STATE_CURRENT_PAGE = "current_page";
91 public static final String BUNDLE_SAVED_STATE = "bundle_savedState";
92 public static final String STATE_ACC_FILTER = "account_filter";
93 private static final String PREF_THEME_ID = "themeId";
95 private View profileListHeadMore, profileListHeadCancel, profileListHeadAddProfile;
96 private View bTransactionListCancelDownload;
97 private SectionsPagerAdapter mSectionsPagerAdapter;
98 private ViewPager mViewPager;
99 private FloatingActionButton fab;
100 private ProfilesRecyclerViewAdapter mProfileListAdapter;
101 private int mCurrentPage;
102 private boolean mBackMeansToAccountList = false;
103 private Toolbar mToolbar;
104 private DrawerLayout.SimpleDrawerListener drawerListener;
105 private ActionBarDrawerToggle barDrawerToggle;
106 private ViewPager.SimpleOnPageChangeListener pageChangeListener;
107 private MobileLedgerProfile profile;
109 protected void onStart() {
112 Logger.debug("MainActivity", "onStart()");
114 mViewPager.setCurrentItem(mCurrentPage, false);
117 protected void onSaveInstanceState(@NotNull Bundle outState) {
118 super.onSaveInstanceState(outState);
119 outState.putInt(STATE_CURRENT_PAGE, mViewPager.getCurrentItem());
120 if (Data.accountFilter.getValue() != null)
121 outState.putString(STATE_ACC_FILTER, Data.accountFilter.getValue());
124 protected void onDestroy() {
125 mSectionsPagerAdapter = null;
126 RecyclerView root = findViewById(R.id.nav_profile_list);
128 root.setAdapter(null);
130 drawer.removeDrawerListener(drawerListener);
131 drawerListener = null;
133 drawer.removeDrawerListener(barDrawerToggle);
134 barDrawerToggle = null;
135 if (mViewPager != null)
136 mViewPager.removeOnPageChangeListener(pageChangeListener);
137 pageChangeListener = null;
141 protected void setupProfileColors() {
142 SharedPreferences prefs = getPreferences(MODE_PRIVATE);
143 int profileColor = prefs.getInt(PREF_THEME_ID, -2);
144 if (profileColor == -2)
145 profileColor = Data.retrieveCurrentThemeIdFromDb();
146 Colors.setupTheme(this, profileColor);
147 Colors.profileThemeId = profileColor;
148 storeThemeIdInPrefs(profileColor);
151 protected void onResume() {
156 protected void onCreate(Bundle savedInstanceState) {
157 debug("MainActivity", "onCreate()/entry");
158 super.onCreate(savedInstanceState);
159 debug("MainActivity", "onCreate()/after super");
160 setContentView(R.layout.activity_main);
162 fab = findViewById(R.id.btn_add_transaction);
163 profileListHeadMore = findViewById(R.id.nav_profiles_start_edit);
164 profileListHeadCancel = findViewById(R.id.nav_profiles_cancel_edit);
165 LinearLayout profileListHeadMoreAndCancel =
166 findViewById(R.id.nav_profile_list_head_buttons);
167 profileListHeadAddProfile = findViewById(R.id.nav_new_profile_button);
168 drawer = findViewById(R.id.drawer_layout);
169 bTransactionListCancelDownload = findViewById(R.id.transaction_list_cancel_download);
170 mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
171 mViewPager = findViewById(R.id.root_frame);
173 Bundle extra = getIntent().getBundleExtra(BUNDLE_SAVED_STATE);
174 if (extra != null && savedInstanceState == null)
175 savedInstanceState = extra;
178 mToolbar = findViewById(R.id.toolbar);
179 setSupportActionBar(mToolbar);
181 Data.profile.observe(this, this::onProfileChanged);
183 Data.profiles.observe(this, this::onProfileListChanged);
185 if (barDrawerToggle == null) {
186 barDrawerToggle = new ActionBarDrawerToggle(this, drawer, mToolbar,
187 R.string.navigation_drawer_open, R.string.navigation_drawer_close);
188 drawer.addDrawerListener(barDrawerToggle);
190 barDrawerToggle.syncState();
193 PackageInfo pi = getApplicationContext().getPackageManager()
194 .getPackageInfo(getPackageName(), 0);
195 ((TextView) findViewById(R.id.nav_upper).findViewById(
196 R.id.drawer_version_text)).setText(pi.versionName);
197 ((TextView) findViewById(R.id.no_profiles_layout).findViewById(
198 R.id.drawer_version_text)).setText(pi.versionName);
200 catch (Exception e) {
204 markDrawerItemCurrent(R.id.nav_account_summary);
206 mViewPager.setAdapter(mSectionsPagerAdapter);
208 if (pageChangeListener == null) {
209 pageChangeListener = new ViewPager.SimpleOnPageChangeListener() {
211 public void onPageSelected(int position) {
212 mCurrentPage = position;
215 markDrawerItemCurrent(R.id.nav_account_summary);
218 markDrawerItemCurrent(R.id.nav_latest_transactions);
221 Log.e("MainActivity",
222 String.format("Unexpected page index %d", position));
225 super.onPageSelected(position);
228 mViewPager.addOnPageChangeListener(pageChangeListener);
232 if (savedInstanceState != null) {
233 int currentPage = savedInstanceState.getInt(STATE_CURRENT_PAGE, -1);
234 if (currentPage != -1) {
235 mCurrentPage = currentPage;
237 Data.accountFilter.setValue(savedInstanceState.getString(STATE_ACC_FILTER, null));
240 Data.lastUpdateDate.observe(this, this::updateLastUpdateDisplay);
242 findViewById(R.id.btn_no_profiles_add).setOnClickListener(
243 v -> startEditProfileActivity(null));
245 findViewById(R.id.btn_add_transaction).setOnClickListener(this::fabNewTransactionClicked);
247 findViewById(R.id.nav_new_profile_button).setOnClickListener(
248 v -> startEditProfileActivity(null));
250 RecyclerView root = findViewById(R.id.nav_profile_list);
252 throw new RuntimeException("Can't get hold on the transaction value view");
254 if (mProfileListAdapter == null)
255 mProfileListAdapter = new ProfilesRecyclerViewAdapter();
256 root.setAdapter(mProfileListAdapter);
258 mProfileListAdapter.editingProfiles.observe(this, newValue -> {
260 profileListHeadMore.setVisibility(View.GONE);
261 profileListHeadCancel.setVisibility(View.VISIBLE);
262 profileListHeadAddProfile.setVisibility(View.VISIBLE);
263 if (drawer.isDrawerOpen(GravityCompat.START)) {
264 profileListHeadMore.startAnimation(
265 AnimationUtils.loadAnimation(MainActivity.this, R.anim.fade_out));
266 profileListHeadCancel.startAnimation(
267 AnimationUtils.loadAnimation(MainActivity.this, R.anim.fade_in));
268 profileListHeadAddProfile.startAnimation(
269 AnimationUtils.loadAnimation(MainActivity.this, R.anim.fade_in));
273 profileListHeadCancel.setVisibility(View.GONE);
274 profileListHeadMore.setVisibility(View.VISIBLE);
275 profileListHeadAddProfile.setVisibility(View.GONE);
276 if (drawer.isDrawerOpen(GravityCompat.START)) {
277 profileListHeadCancel.startAnimation(
278 AnimationUtils.loadAnimation(MainActivity.this, R.anim.fade_out));
279 profileListHeadMore.startAnimation(
280 AnimationUtils.loadAnimation(MainActivity.this, R.anim.fade_in));
281 profileListHeadAddProfile.startAnimation(
282 AnimationUtils.loadAnimation(MainActivity.this, R.anim.fade_out));
286 mProfileListAdapter.notifyDataSetChanged();
289 LinearLayoutManager llm = new LinearLayoutManager(this);
291 llm.setOrientation(RecyclerView.VERTICAL);
292 root.setLayoutManager(llm);
294 profileListHeadMore.setOnClickListener((v) -> mProfileListAdapter.flipEditingProfiles());
295 profileListHeadCancel.setOnClickListener((v) -> mProfileListAdapter.flipEditingProfiles());
296 profileListHeadMoreAndCancel.setOnClickListener(
297 (v) -> mProfileListAdapter.flipEditingProfiles());
298 if (drawerListener == null) {
299 drawerListener = new DrawerLayout.SimpleDrawerListener() {
301 public void onDrawerSlide(@NonNull View drawerView, float slideOffset) {
302 if (slideOffset > 0.2)
306 public void onDrawerClosed(View drawerView) {
307 super.onDrawerClosed(drawerView);
308 mProfileListAdapter.setAnimationsEnabled(false);
309 mProfileListAdapter.editingProfiles.setValue(false);
310 Data.drawerOpen.setValue(false);
314 public void onDrawerOpened(View drawerView) {
315 super.onDrawerOpened(drawerView);
316 mProfileListAdapter.setAnimationsEnabled(true);
317 Data.drawerOpen.setValue(true);
321 drawer.addDrawerListener(drawerListener);
324 Data.drawerOpen.observe(this, open -> {
331 private void scheduleDataRetrievalIfStale(Date lastUpdate) {
332 long now = new Date().getTime();
333 if ((lastUpdate == null) || (now > (lastUpdate.getTime() + (24 * 3600 * 1000)))) {
334 if (lastUpdate == null)
335 debug("db::", "WEB data never fetched. scheduling a fetch");
337 debug("db", String.format(Locale.ENGLISH,
338 "WEB data last fetched at %1.3f and now is %1.3f. re-fetching",
339 lastUpdate.getTime() / 1000f, now / 1000f));
341 Data.scheduleTransactionListRetrieval(this);
344 private void createShortcuts(List<MobileLedgerProfile> list) {
345 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N_MR1)
348 ShortcutManager sm = getSystemService(ShortcutManager.class);
349 List<ShortcutInfo> shortcuts = new ArrayList<>();
351 for (MobileLedgerProfile p : list) {
352 if (shortcuts.size() >= sm.getMaxShortcutCountPerActivity())
355 if (!p.isPostingPermitted())
358 final ShortcutInfo.Builder builder =
359 new ShortcutInfo.Builder(this, "new_transaction_" + p.getUuid());
360 ShortcutInfo si = builder.setShortLabel(p.getName())
361 .setIcon(Icon.createWithResource(this,
362 R.drawable.thick_plus_icon))
363 .setIntent(new Intent(Intent.ACTION_VIEW, null, this,
364 NewTransactionActivity.class).putExtra("profile_uuid",
371 sm.setDynamicShortcuts(shortcuts);
373 private void onProfileListChanged(List<MobileLedgerProfile> newList) {
374 if ((newList == null) || newList.isEmpty()) {
375 findViewById(R.id.no_profiles_layout).setVisibility(View.VISIBLE);
376 findViewById(R.id.main_app_layout).setVisibility(View.GONE);
380 findViewById(R.id.main_app_layout).setVisibility(View.VISIBLE);
381 findViewById(R.id.no_profiles_layout).setVisibility(View.GONE);
383 findViewById(R.id.nav_profile_list).setMinimumHeight(
384 (int) (getResources().getDimension(R.dimen.thumb_row_height) * newList.size()));
386 debug("profiles", "profile list changed");
387 mProfileListAdapter.notifyDataSetChanged();
389 createShortcuts(newList);
392 * called when the current profile has changed
394 private void onProfileChanged(MobileLedgerProfile profile) {
395 boolean haveProfile = profile != null;
398 setTitle(profile.getName());
400 setTitle(R.string.app_name);
402 this.profile = profile;
404 int newProfileTheme = haveProfile ? profile.getThemeHue() : -1;
405 if (newProfileTheme != Colors.profileThemeId) {
407 String.format(Locale.ENGLISH, "profile theme %d → %d", Colors.profileThemeId,
409 Colors.profileThemeId = newProfileTheme;
410 profileThemeChanged();
411 // profileThemeChanged would restart the activity, so no need to reload the
416 findViewById(R.id.no_profiles_layout).setVisibility(haveProfile ? View.GONE : View.VISIBLE);
417 findViewById(R.id.pager_layout).setVisibility(haveProfile ? View.VISIBLE : View.VISIBLE);
419 mProfileListAdapter.notifyDataSetChanged();
421 Data.transactions.clear();
422 debug("transactions", "requesting list reload");
423 TransactionListViewModel.scheduleTransactionListReload();
425 Data.accounts.clear();
426 AccountSummaryViewModel.scheduleAccountListReload();
429 if (profile.isPostingPermitted()) {
430 mToolbar.setSubtitle(null);
434 mToolbar.setSubtitle(R.string.profile_subtitle_read_only);
439 mToolbar.setSubtitle(null);
443 updateLastUpdateTextFromDB();
445 private void updateLastUpdateDisplay(Date newValue) {
446 LinearLayout l = findViewById(R.id.transactions_last_update_layout);
447 TextView v = findViewById(R.id.transactions_last_update);
448 if (newValue == null) {
449 l.setVisibility(View.INVISIBLE);
450 debug("main", "no last update date :(");
453 final String text = DateFormat.getDateTimeInstance()
456 l.setVisibility(View.VISIBLE);
457 debug("main", String.format("Date formatted: %s", text));
460 scheduleDataRetrievalIfStale(newValue);
462 private void profileThemeChanged() {
463 storeThemeIdInPrefs(profile.getThemeHue());
465 // un-hook all observed LiveData
466 Data.profile.removeObservers(this);
467 Data.profiles.removeObservers(this);
468 Data.lastUpdateDate.removeObservers(this);
472 private void storeThemeIdInPrefs(int themeId) {
473 // store the new theme id in the preferences
474 SharedPreferences prefs = getPreferences(MODE_PRIVATE);
475 SharedPreferences.Editor e = prefs.edit();
476 e.putInt(PREF_THEME_ID, themeId);
479 public void startEditProfileActivity(MobileLedgerProfile profile) {
480 Intent intent = new Intent(this, ProfileDetailActivity.class);
481 Bundle args = new Bundle();
482 if (profile != null) {
483 int index = Data.getProfileIndex(profile);
485 intent.putExtra(ProfileDetailFragment.ARG_ITEM_ID, index);
487 intent.putExtras(args);
488 startActivity(intent, args);
490 private void setupProfile() {
491 MLDB.getOption(MLDB.OPT_PROFILE_UUID, null, new GetOptCallback() {
493 protected void onResult(String profileUUID) {
494 MobileLedgerProfile startupProfile;
496 startupProfile = Data.getProfile(profileUUID);
497 Data.setCurrentProfile(startupProfile);
501 public void fabNewTransactionClicked(View view) {
502 Intent intent = new Intent(this, NewTransactionActivity.class);
503 startActivity(intent);
504 overridePendingTransition(R.anim.slide_in_up, R.anim.dummy);
506 public void markDrawerItemCurrent(int id) {
507 TextView item = drawer.findViewById(id);
508 item.setBackgroundColor(Colors.tableRowDarkBG);
510 LinearLayout actions = drawer.findViewById(R.id.nav_actions);
511 for (int i = 0; i < actions.getChildCount(); i++) {
512 View view = actions.getChildAt(i);
513 if (view.getId() != id) {
514 view.setBackgroundColor(Color.TRANSPARENT);
518 public void onAccountSummaryClicked(View view) {
519 drawer.closeDrawers();
521 showAccountSummaryFragment();
523 private void showAccountSummaryFragment() {
524 mViewPager.setCurrentItem(0, true);
525 Data.accountFilter.setValue(null);
527 public void onLatestTransactionsClicked(View view) {
528 drawer.closeDrawers();
530 showTransactionsFragment((String) null);
532 private void showTransactionsFragment(String accName) {
533 Data.accountFilter.setValue(accName);
534 mViewPager.setCurrentItem(1, true);
536 private void showTransactionsFragment(LedgerAccount account) {
537 showTransactionsFragment((account == null) ? null : account.getName());
539 public void showAccountTransactions(LedgerAccount account) {
540 mBackMeansToAccountList = true;
541 showTransactionsFragment(account);
544 public void onBackPressed() {
545 DrawerLayout drawer = findViewById(R.id.drawer_layout);
546 if (drawer.isDrawerOpen(GravityCompat.START)) {
547 drawer.closeDrawer(GravityCompat.START);
550 if (mBackMeansToAccountList && (mViewPager.getCurrentItem() == 1)) {
551 Data.accountFilter.setValue(null);
552 showAccountSummaryFragment();
553 mBackMeansToAccountList = false;
556 debug("fragments", String.format(Locale.ENGLISH, "manager stack: %d",
557 getSupportFragmentManager().getBackStackEntryCount()));
559 super.onBackPressed();
563 public void updateLastUpdateTextFromDB() {
567 long last_update = profile.getLongOption(MLDB.OPT_LAST_SCRAPE, 0L);
569 debug("transactions", String.format(Locale.ENGLISH, "Last update = %d", last_update));
570 if (last_update == 0) {
571 Data.lastUpdateDate.postValue(null);
574 Data.lastUpdateDate.postValue(new Date(last_update));
577 public void onStopTransactionRefreshClick(View view) {
578 debug("interactive", "Cancelling transactions refresh");
579 Data.stopTransactionsRetrieval();
580 bTransactionListCancelDownload.setEnabled(false);
582 public void onRetrieveDone(String error) {
583 Data.transactionRetrievalDone();
584 findViewById(R.id.transaction_progress_layout).setVisibility(View.GONE);
587 updateLastUpdateTextFromDB();
589 new RefreshDescriptionsTask().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
590 TransactionListViewModel.scheduleTransactionListReload();
593 Snackbar.make(mViewPager, error, Snackbar.LENGTH_LONG)
596 public void onRetrieveStart() {
597 ProgressBar progressBar = findViewById(R.id.transaction_list_progress_bar);
598 bTransactionListCancelDownload.setEnabled(true);
599 ColorStateList csl = Colors.getColorStateList();
600 progressBar.setIndeterminateTintList(csl);
601 progressBar.setProgressTintList(csl);
602 progressBar.setIndeterminate(true);
603 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
604 progressBar.setProgress(0, false);
606 progressBar.setProgress(0);
607 findViewById(R.id.transaction_progress_layout).setVisibility(View.VISIBLE);
609 public void onRetrieveProgress(RetrieveTransactionsTask.Progress progress) {
610 ProgressBar progressBar = findViewById(R.id.transaction_list_progress_bar);
611 if ((progress.getTotal() == RetrieveTransactionsTask.Progress.INDETERMINATE) ||
612 (progress.getTotal() == 0))
614 progressBar.setIndeterminate(true);
617 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
618 progressBar.setMin(0);
620 progressBar.setMax(progress.getTotal());
621 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
622 progressBar.setProgress(progress.getProgress(), true);
625 progressBar.setProgress(progress.getProgress());
626 progressBar.setIndeterminate(false);
629 public void fabShouldShow() {
630 if ((profile != null) && profile.isPostingPermitted() && !drawer.isOpen())
635 public void fabHide() {
638 public void onAccountSummaryRowViewClicked(View view) {
640 switch (view.getId()) {
641 case R.id.account_expander:
642 row = (ViewGroup) view.getParent()
646 case R.id.account_expander_container:
647 case R.id.account_row_acc_name:
648 row = (ViewGroup) view.getParent()
652 row = (ViewGroup) view.getParent();
656 LedgerAccount acc = (LedgerAccount) row.getTag();
657 switch (view.getId()) {
658 case R.id.account_row_acc_name:
659 case R.id.account_expander:
660 case R.id.account_expander_container:
661 debug("accounts", "Account expander clicked");
662 if (!acc.hasSubAccounts())
665 boolean wasExpanded = acc.isExpanded();
667 View arrow = row.findViewById(R.id.account_expander_container);
669 arrow.clearAnimation();
670 ViewPropertyAnimator animator = arrow.animate();
672 acc.toggleExpanded();
673 DbOpQueue.add("update accounts set expanded=? where name=? and profile=?",
674 new Object[]{acc.isExpanded(), acc.getName(), profile.getUuid()
678 debug("accounts", String.format("Collapsing account '%s'", acc.getName()));
679 arrow.setRotation(0);
680 animator.rotationBy(180);
682 // removing all child accounts from the view
683 int start = -1, count = 0;
684 try (LockHolder ignored = Data.accounts.lockForWriting()) {
685 for (int i = 0; i < Data.accounts.size(); i++) {
686 if (acc.isParentOf(Data.accounts.get(i))) {
687 // debug("accounts", String.format("Found a child '%s' at position
689 // Data.accounts.get(i).getName(), i));
698 // String.format("Found a non-child '%s' at position %d",
699 // Data.accounts.get(i).getName(), i));
706 for (int j = 0; j < count; j++) {
707 // debug("accounts", String.format("Removing item %d: %s", start + j,
708 // Data.accounts.get(start).getName()));
709 Data.accounts.removeQuietly(start);
712 mAccountSummaryFragment.modelAdapter.notifyItemRangeRemoved(start,
718 debug("accounts", String.format("Expanding account '%s'", acc.getName()));
719 arrow.setRotation(180);
720 animator.rotationBy(-180);
721 List<LedgerAccount> children = profile.loadVisibleChildAccountsOf(acc);
722 try (LockHolder ignored = Data.accounts.lockForWriting()) {
723 int parentPos = Data.accounts.indexOf(acc);
724 if (parentPos != -1) {
725 // may have disappeared in a concurrent refresh operation
726 Data.accounts.addAllQuietly(parentPos + 1, children);
727 mAccountSummaryFragment.modelAdapter.notifyItemRangeInserted(
728 parentPos + 1, children.size());
733 case R.id.account_row_acc_amounts:
734 if (acc.getAmountCount() > AccountSummaryAdapter.AMOUNT_LIMIT) {
735 acc.toggleAmountsExpanded();
737 "update accounts set amounts_expanded=? where name=? and profile=?",
738 new Object[]{acc.amountsExpanded(), acc.getName(), profile.getUuid()
740 Data.accounts.triggerItemChangedNotification(acc);
746 public class SectionsPagerAdapter extends FragmentPagerAdapter {
748 SectionsPagerAdapter(FragmentManager fm) {
749 super(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
754 public Fragment getItem(int position) {
755 debug("main", String.format(Locale.ENGLISH, "Switching to fragment %d", position));
758 // debug("flow", "Creating account summary fragment");
759 return new AccountSummaryFragment();
761 return new TransactionListFragment();
763 throw new IllegalStateException(
764 String.format("Unexpected fragment index: " + "%d", position));
769 public int getCount() {