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;
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.MLDB;
74 import org.jetbrains.annotations.NotNull;
76 import java.text.DateFormat;
77 import java.util.ArrayList;
78 import java.util.Date;
79 import java.util.List;
80 import java.util.Locale;
82 import static net.ktnx.mobileledger.utils.Logger.debug;
88 public class MainActivity extends ProfileThemedActivity {
89 public static final String STATE_CURRENT_PAGE = "current_page";
90 public static final String BUNDLE_SAVED_STATE = "bundle_savedState";
91 public static final String STATE_ACC_FILTER = "account_filter";
92 private static final String PREF_THEME_ID = "themeId";
93 public AccountSummaryFragment mAccountSummaryFragment;
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 mViewPager.setCurrentItem(mCurrentPage, false);
115 protected void onSaveInstanceState(@NotNull Bundle outState) {
116 super.onSaveInstanceState(outState);
117 outState.putInt(STATE_CURRENT_PAGE, mViewPager.getCurrentItem());
118 if (Data.accountFilter.getValue() != null)
119 outState.putString(STATE_ACC_FILTER, Data.accountFilter.getValue());
122 protected void onDestroy() {
123 mSectionsPagerAdapter = null;
124 RecyclerView root = findViewById(R.id.nav_profile_list);
126 root.setAdapter(null);
128 drawer.removeDrawerListener(drawerListener);
129 drawerListener = null;
131 drawer.removeDrawerListener(barDrawerToggle);
132 barDrawerToggle = null;
133 if (mViewPager != null)
134 mViewPager.removeOnPageChangeListener(pageChangeListener);
135 pageChangeListener = null;
139 protected void setupProfileColors() {
140 SharedPreferences prefs = getPreferences(MODE_PRIVATE);
141 int profileColor = prefs.getInt(PREF_THEME_ID, -2);
142 if (profileColor == -2)
143 profileColor = Data.retrieveCurrentThemeIdFromDb();
144 Colors.setupTheme(this, profileColor);
145 Colors.profileThemeId = profileColor;
146 storeThemeIdInPrefs(profileColor);
149 protected void onResume() {
154 protected void onCreate(Bundle savedInstanceState) {
155 super.onCreate(savedInstanceState);
156 debug("flow", "MainActivity.onCreate()");
157 setContentView(R.layout.activity_main);
159 fab = findViewById(R.id.btn_add_transaction);
160 profileListHeadMore = findViewById(R.id.nav_profiles_start_edit);
161 profileListHeadCancel = findViewById(R.id.nav_profiles_cancel_edit);
162 LinearLayout profileListHeadMoreAndCancel =
163 findViewById(R.id.nav_profile_list_head_buttons);
164 profileListHeadAddProfile = findViewById(R.id.nav_new_profile_button);
165 drawer = findViewById(R.id.drawer_layout);
166 bTransactionListCancelDownload = findViewById(R.id.transaction_list_cancel_download);
167 mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
168 mViewPager = findViewById(R.id.root_frame);
170 Bundle extra = getIntent().getBundleExtra(BUNDLE_SAVED_STATE);
171 if (extra != null && savedInstanceState == null)
172 savedInstanceState = extra;
175 mToolbar = findViewById(R.id.toolbar);
176 setSupportActionBar(mToolbar);
178 Data.profile.observe(this, this::onProfileChanged);
180 Data.profiles.observe(this, this::onProfileListChanged);
182 if (barDrawerToggle == null) {
183 barDrawerToggle = new ActionBarDrawerToggle(this, drawer, mToolbar,
184 R.string.navigation_drawer_open, R.string.navigation_drawer_close);
185 drawer.addDrawerListener(barDrawerToggle);
187 barDrawerToggle.syncState();
188 drawer.addDrawerListener(new DrawerLayout.DrawerListener() {
190 public void onDrawerSlide(@NonNull View drawerView, float slideOffset) {
191 if (slideOffset > 0.2)
195 public void onDrawerOpened(@NonNull View drawerView) {
199 public void onDrawerClosed(@NonNull View drawerView) {
203 public void onDrawerStateChanged(int newState) {}
208 PackageInfo pi = getApplicationContext().getPackageManager()
209 .getPackageInfo(getPackageName(), 0);
210 ((TextView) findViewById(R.id.nav_upper).findViewById(
211 R.id.drawer_version_text)).setText(pi.versionName);
212 ((TextView) findViewById(R.id.no_profiles_layout).findViewById(
213 R.id.drawer_version_text)).setText(pi.versionName);
215 catch (Exception e) {
219 markDrawerItemCurrent(R.id.nav_account_summary);
221 mViewPager.setAdapter(mSectionsPagerAdapter);
223 if (pageChangeListener == null) {
224 pageChangeListener = new ViewPager.SimpleOnPageChangeListener() {
226 public void onPageSelected(int position) {
227 mCurrentPage = position;
230 markDrawerItemCurrent(R.id.nav_account_summary);
233 markDrawerItemCurrent(R.id.nav_latest_transactions);
236 Log.e("MainActivity",
237 String.format("Unexpected page index %d", position));
240 super.onPageSelected(position);
243 mViewPager.addOnPageChangeListener(pageChangeListener);
247 if (savedInstanceState != null) {
248 int currentPage = savedInstanceState.getInt(STATE_CURRENT_PAGE, -1);
249 if (currentPage != -1) {
250 mCurrentPage = currentPage;
252 Data.accountFilter.setValue(savedInstanceState.getString(STATE_ACC_FILTER, null));
255 Data.lastUpdateDate.observe(this, this::updateLastUpdateDisplay);
257 findViewById(R.id.btn_no_profiles_add).setOnClickListener(
258 v -> startEditProfileActivity(null));
260 findViewById(R.id.btn_add_transaction).setOnClickListener(this::fabNewTransactionClicked);
262 findViewById(R.id.nav_new_profile_button).setOnClickListener(
263 v -> startEditProfileActivity(null));
265 RecyclerView root = findViewById(R.id.nav_profile_list);
267 throw new RuntimeException("Can't get hold on the transaction value view");
269 if (mProfileListAdapter == null)
270 mProfileListAdapter = new ProfilesRecyclerViewAdapter();
271 root.setAdapter(mProfileListAdapter);
273 mProfileListAdapter.editingProfiles.observe(this, newValue -> {
275 profileListHeadMore.setVisibility(View.GONE);
276 profileListHeadCancel.setVisibility(View.VISIBLE);
277 profileListHeadAddProfile.setVisibility(View.VISIBLE);
278 if (drawer.isDrawerOpen(GravityCompat.START)) {
279 profileListHeadMore.startAnimation(
280 AnimationUtils.loadAnimation(MainActivity.this, R.anim.fade_out));
281 profileListHeadCancel.startAnimation(
282 AnimationUtils.loadAnimation(MainActivity.this, R.anim.fade_in));
283 profileListHeadAddProfile.startAnimation(
284 AnimationUtils.loadAnimation(MainActivity.this, R.anim.fade_in));
288 profileListHeadCancel.setVisibility(View.GONE);
289 profileListHeadMore.setVisibility(View.VISIBLE);
290 profileListHeadAddProfile.setVisibility(View.GONE);
291 if (drawer.isDrawerOpen(GravityCompat.START)) {
292 profileListHeadCancel.startAnimation(
293 AnimationUtils.loadAnimation(MainActivity.this, R.anim.fade_out));
294 profileListHeadMore.startAnimation(
295 AnimationUtils.loadAnimation(MainActivity.this, R.anim.fade_in));
296 profileListHeadAddProfile.startAnimation(
297 AnimationUtils.loadAnimation(MainActivity.this, R.anim.fade_out));
301 mProfileListAdapter.notifyDataSetChanged();
304 LinearLayoutManager llm = new LinearLayoutManager(this);
306 llm.setOrientation(RecyclerView.VERTICAL);
307 root.setLayoutManager(llm);
309 profileListHeadMore.setOnClickListener((v) -> mProfileListAdapter.flipEditingProfiles());
310 profileListHeadCancel.setOnClickListener((v) -> mProfileListAdapter.flipEditingProfiles());
311 profileListHeadMoreAndCancel.setOnClickListener(
312 (v) -> mProfileListAdapter.flipEditingProfiles());
313 if (drawerListener == null) {
314 drawerListener = new DrawerLayout.SimpleDrawerListener() {
316 public void onDrawerClosed(View drawerView) {
317 super.onDrawerClosed(drawerView);
318 mProfileListAdapter.setAnimationsEnabled(false);
319 mProfileListAdapter.editingProfiles.setValue(false);
322 public void onDrawerOpened(View drawerView) {
323 super.onDrawerOpened(drawerView);
324 mProfileListAdapter.setAnimationsEnabled(true);
327 drawer.addDrawerListener(drawerListener);
330 private void scheduleDataRetrievalIfStale(Date lastUpdate) {
331 long now = new Date().getTime();
332 if ((lastUpdate == null) || (now > (lastUpdate.getTime() + (24 * 3600 * 1000)))) {
333 if (lastUpdate == null)
334 debug("db::", "WEB data never fetched. scheduling a fetch");
336 debug("db", String.format(Locale.ENGLISH,
337 "WEB data last fetched at %1.3f and now is %1.3f. re-fetching",
338 lastUpdate.getTime() / 1000f, now / 1000f));
340 Data.scheduleTransactionListRetrieval(this);
343 private void createShortcuts(List<MobileLedgerProfile> list) {
344 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N_MR1)
347 ShortcutManager sm = getSystemService(ShortcutManager.class);
348 List<ShortcutInfo> shortcuts = new ArrayList<>();
350 for (MobileLedgerProfile p : list) {
351 if (shortcuts.size() >= sm.getMaxShortcutCountPerActivity())
354 if (!p.isPostingPermitted())
358 new ShortcutInfo.Builder(this, "new_transaction_" + p.getUuid()).setShortLabel(
361 Icon.createWithResource(
363 R.drawable.svg_thick_plus_white))
369 NewTransactionActivity.class).putExtra(
377 sm.setDynamicShortcuts(shortcuts);
379 private void onProfileListChanged(List<MobileLedgerProfile> newList) {
380 if (newList == null) {
381 // profiles not yet loaded from DB
382 findViewById(R.id.loading_layout).setVisibility(View.VISIBLE);
383 findViewById(R.id.no_profiles_layout).setVisibility(View.GONE);
384 findViewById(R.id.main_app_layout).setVisibility(View.GONE);
388 if (newList.isEmpty()) {
389 findViewById(R.id.no_profiles_layout).setVisibility(View.VISIBLE);
390 findViewById(R.id.main_app_layout).setVisibility(View.GONE);
391 findViewById(R.id.loading_layout).setVisibility(View.GONE);
395 findViewById(R.id.main_app_layout).setVisibility(View.VISIBLE);
396 findViewById(R.id.no_profiles_layout).setVisibility(View.GONE);
397 findViewById(R.id.loading_layout).setVisibility(View.GONE);
399 findViewById(R.id.nav_profile_list).setMinimumHeight(
400 (int) (getResources().getDimension(R.dimen.thumb_row_height) * newList.size()));
402 debug("profiles", "profile list changed");
403 mProfileListAdapter.notifyDataSetChanged();
405 createShortcuts(newList);
408 * called when the current profile has changed
410 private void onProfileChanged(MobileLedgerProfile profile) {
411 boolean haveProfile = profile != null;
414 setTitle(profile.getName());
416 setTitle(R.string.app_name);
418 this.profile = profile;
420 int newProfileTheme = haveProfile ? profile.getThemeHue() : -1;
421 if (newProfileTheme != Colors.profileThemeId) {
423 String.format(Locale.ENGLISH, "profile theme %d → %d", Colors.profileThemeId,
425 Colors.profileThemeId = newProfileTheme;
426 profileThemeChanged();
427 // profileThemeChanged would restart the activity, so no need to reload the
432 findViewById(R.id.no_profiles_layout).setVisibility(haveProfile ? View.GONE : View.VISIBLE);
433 findViewById(R.id.pager_layout).setVisibility(haveProfile ? View.VISIBLE : View.VISIBLE);
435 mProfileListAdapter.notifyDataSetChanged();
437 drawer.closeDrawers();
439 Data.transactions.clear();
440 debug("transactions", "requesting list reload");
441 TransactionListViewModel.scheduleTransactionListReload();
443 Data.accounts.clear();
444 AccountSummaryViewModel.scheduleAccountListReload();
447 if (profile.isPostingPermitted()) {
448 mToolbar.setSubtitle(null);
452 mToolbar.setSubtitle(R.string.profile_subtitle_read_only);
457 mToolbar.setSubtitle(null);
461 updateLastUpdateTextFromDB();
463 private void updateLastUpdateDisplay(Date newValue) {
464 LinearLayout l = findViewById(R.id.transactions_last_update_layout);
465 TextView v = findViewById(R.id.transactions_last_update);
466 if (newValue == null) {
467 l.setVisibility(View.INVISIBLE);
468 debug("main", "no last update date :(");
471 final String text = DateFormat.getDateTimeInstance()
474 l.setVisibility(View.VISIBLE);
475 debug("main", String.format("Date formatted: %s", text));
478 scheduleDataRetrievalIfStale(newValue);
480 private void profileThemeChanged() {
481 storeThemeIdInPrefs(profile.getThemeHue());
483 // un-hook all observed LiveData
484 Data.profile.removeObservers(this);
485 Data.profiles.removeObservers(this);
486 Data.lastUpdateDate.removeObservers(this);
490 private void storeThemeIdInPrefs(int themeId) {
491 // store the new theme id in the preferences
492 SharedPreferences prefs = getPreferences(MODE_PRIVATE);
493 SharedPreferences.Editor e = prefs.edit();
494 e.putInt(PREF_THEME_ID, themeId);
497 public void startEditProfileActivity(MobileLedgerProfile profile) {
498 Intent intent = new Intent(this, ProfileDetailActivity.class);
499 Bundle args = new Bundle();
500 if (profile != null) {
501 int index = Data.getProfileIndex(profile);
503 intent.putExtra(ProfileDetailFragment.ARG_ITEM_ID, index);
505 intent.putExtras(args);
506 startActivity(intent, args);
508 private void setupProfile() {
509 MLDB.getOption(MLDB.OPT_PROFILE_UUID, null, new GetOptCallback() {
511 protected void onResult(String profileUUID) {
512 MobileLedgerProfile startupProfile;
514 startupProfile = Data.getProfile(profileUUID);
515 Data.setCurrentProfile(startupProfile);
519 public void fabNewTransactionClicked(View view) {
520 Intent intent = new Intent(this, NewTransactionActivity.class);
521 startActivity(intent);
522 overridePendingTransition(R.anim.slide_in_up, R.anim.dummy);
524 public void markDrawerItemCurrent(int id) {
525 TextView item = drawer.findViewById(id);
526 item.setBackgroundColor(Colors.tableRowDarkBG);
528 LinearLayout actions = drawer.findViewById(R.id.nav_actions);
529 for (int i = 0; i < actions.getChildCount(); i++) {
530 View view = actions.getChildAt(i);
531 if (view.getId() != id) {
532 view.setBackgroundColor(Color.TRANSPARENT);
536 public void onAccountSummaryClicked(View view) {
537 drawer.closeDrawers();
539 showAccountSummaryFragment();
541 private void showAccountSummaryFragment() {
542 mViewPager.setCurrentItem(0, true);
543 Data.accountFilter.setValue(null);
545 public void onLatestTransactionsClicked(View view) {
546 drawer.closeDrawers();
548 showTransactionsFragment((String) null);
550 private void showTransactionsFragment(String accName) {
551 Data.accountFilter.setValue(accName);
552 mViewPager.setCurrentItem(1, true);
554 private void showTransactionsFragment(LedgerAccount account) {
555 showTransactionsFragment((account == null) ? null : account.getName());
557 public void showAccountTransactions(LedgerAccount account) {
558 mBackMeansToAccountList = true;
559 showTransactionsFragment(account);
562 public void onBackPressed() {
563 DrawerLayout drawer = findViewById(R.id.drawer_layout);
564 if (drawer.isDrawerOpen(GravityCompat.START)) {
565 drawer.closeDrawer(GravityCompat.START);
568 if (mBackMeansToAccountList && (mViewPager.getCurrentItem() == 1)) {
569 Data.accountFilter.setValue(null);
570 showAccountSummaryFragment();
571 mBackMeansToAccountList = false;
574 debug("fragments", String.format(Locale.ENGLISH, "manager stack: %d",
575 getSupportFragmentManager().getBackStackEntryCount()));
577 super.onBackPressed();
581 public void updateLastUpdateTextFromDB() {
585 long last_update = profile.getLongOption(MLDB.OPT_LAST_SCRAPE, 0L);
587 debug("transactions", String.format(Locale.ENGLISH, "Last update = %d", last_update));
588 if (last_update == 0) {
589 Data.lastUpdateDate.postValue(null);
592 Data.lastUpdateDate.postValue(new Date(last_update));
595 public void onStopTransactionRefreshClick(View view) {
596 debug("interactive", "Cancelling transactions refresh");
597 Data.stopTransactionsRetrieval();
598 bTransactionListCancelDownload.setEnabled(false);
600 public void onRetrieveDone(String error) {
601 Data.transactionRetrievalDone();
602 findViewById(R.id.transaction_progress_layout).setVisibility(View.GONE);
605 updateLastUpdateTextFromDB();
607 new RefreshDescriptionsTask().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
608 TransactionListViewModel.scheduleTransactionListReload();
611 Snackbar.make(mViewPager, error, Snackbar.LENGTH_LONG)
614 public void onRetrieveStart() {
615 ProgressBar progressBar = findViewById(R.id.transaction_list_progress_bar);
616 bTransactionListCancelDownload.setEnabled(true);
617 ColorStateList csl = Colors.getColorStateList();
618 progressBar.setIndeterminateTintList(csl);
619 progressBar.setProgressTintList(csl);
620 progressBar.setIndeterminate(true);
621 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
622 progressBar.setProgress(0, false);
624 progressBar.setProgress(0);
625 findViewById(R.id.transaction_progress_layout).setVisibility(View.VISIBLE);
627 public void onRetrieveProgress(RetrieveTransactionsTask.Progress progress) {
628 ProgressBar progressBar = findViewById(R.id.transaction_list_progress_bar);
629 if ((progress.getTotal() == RetrieveTransactionsTask.Progress.INDETERMINATE) ||
630 (progress.getTotal() == 0))
632 progressBar.setIndeterminate(true);
635 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
636 progressBar.setMin(0);
638 progressBar.setMax(progress.getTotal());
639 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
640 progressBar.setProgress(progress.getProgress(), true);
643 progressBar.setProgress(progress.getProgress());
644 progressBar.setIndeterminate(false);
647 public void fabShouldShow() {
648 if ((profile != null) && profile.isPostingPermitted() && !drawer.isOpen())
653 public void fabHide() {
656 public void onAccountSummaryRowViewClicked(View view) {
658 if (view.getId() == R.id.account_expander)
659 row = (ViewGroup) view.getParent()
662 row = (ViewGroup) view.getParent();
664 LedgerAccount acc = (LedgerAccount) row.getTag();
665 switch (view.getId()) {
666 case R.id.account_row_acc_name:
667 case R.id.account_expander:
668 case R.id.account_expander_container:
669 debug("accounts", "Account expander clicked");
670 if (!acc.hasSubAccounts())
673 boolean wasExpanded = acc.isExpanded();
675 View arrow = row.findViewById(R.id.account_expander_container);
677 arrow.clearAnimation();
678 ViewPropertyAnimator animator = arrow.animate();
680 acc.toggleExpanded();
681 DbOpQueue.add("update accounts set expanded=? where name=? and profile=?",
682 new Object[]{acc.isExpanded(), acc.getName(), profile.getUuid()
686 debug("accounts", String.format("Collapsing account '%s'", acc.getName()));
687 arrow.setRotation(0);
688 animator.rotationBy(180);
690 // removing all child accounts from the view
691 int start = -1, count = 0;
692 try (LockHolder ignored = Data.accounts.lockForWriting()) {
693 for (int i = 0; i < Data.accounts.size(); i++) {
694 if (acc.isParentOf(Data.accounts.get(i))) {
695 // debug("accounts", String.format("Found a child '%s' at position
697 // Data.accounts.get(i).getName(), i));
706 // String.format("Found a non-child '%s' at position %d",
707 // Data.accounts.get(i).getName(), i));
714 for (int j = 0; j < count; j++) {
715 // debug("accounts", String.format("Removing item %d: %s", start + j,
716 // Data.accounts.get(start).getName()));
717 Data.accounts.removeQuietly(start);
720 mAccountSummaryFragment.modelAdapter.notifyItemRangeRemoved(start,
726 debug("accounts", String.format("Expanding account '%s'", acc.getName()));
727 arrow.setRotation(180);
728 animator.rotationBy(-180);
729 List<LedgerAccount> children = profile.loadVisibleChildAccountsOf(acc);
730 try (LockHolder ignored = Data.accounts.lockForWriting()) {
731 int parentPos = Data.accounts.indexOf(acc);
732 if (parentPos != -1) {
733 // may have disappeared in a concurrent refresh operation
734 Data.accounts.addAllQuietly(parentPos + 1, children);
735 mAccountSummaryFragment.modelAdapter.notifyItemRangeInserted(
736 parentPos + 1, children.size());
741 case R.id.account_row_acc_amounts:
742 if (acc.getAmountCount() > AccountSummaryAdapter.AMOUNT_LIMIT) {
743 acc.toggleAmountsExpanded();
745 "update accounts set amounts_expanded=? where name=? and profile=?",
746 new Object[]{acc.amountsExpanded(), acc.getName(), profile.getUuid()
748 Data.accounts.triggerItemChangedNotification(acc);
754 public class SectionsPagerAdapter extends FragmentPagerAdapter {
756 SectionsPagerAdapter(FragmentManager fm) {
757 super(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
762 public Fragment getItem(int position) {
763 debug("main", String.format(Locale.ENGLISH, "Switching to fragment %d", position));
766 // debug("flow", "Creating account summary fragment");
767 return mAccountSummaryFragment = new AccountSummaryFragment();
769 return new TransactionListFragment();
771 throw new IllegalStateException(
772 String.format("Unexpected fragment index: " + "%d", position));
777 public int getCount() {