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;
83 public class MainActivity extends ProfileThemedActivity {
84 public static final String STATE_CURRENT_PAGE = "current_page";
85 public static final String BUNDLE_SAVED_STATE = "bundle_savedState";
86 public static final String STATE_ACC_FILTER = "account_filter";
87 private static final String PREF_THEME_ID = "themeId";
88 public AccountSummaryFragment mAccountSummaryFragment;
90 private View profileListHeadMore, profileListHeadCancel, profileListHeadAddProfile;
91 private View bTransactionListCancelDownload;
92 private SectionsPagerAdapter mSectionsPagerAdapter;
93 private ViewPager mViewPager;
94 private FloatingActionButton fab;
95 private ProfilesRecyclerViewAdapter mProfileListAdapter;
96 private int mCurrentPage;
97 private boolean mBackMeansToAccountList = false;
98 private Toolbar mToolbar;
99 private DrawerLayout.SimpleDrawerListener drawerListener;
100 private ActionBarDrawerToggle barDrawerToggle;
101 private ViewPager.SimpleOnPageChangeListener pageChangeListener;
102 private MobileLedgerProfile profile;
104 protected void onStart() {
107 mViewPager.setCurrentItem(mCurrentPage, false);
110 protected void onSaveInstanceState(@NotNull Bundle outState) {
111 super.onSaveInstanceState(outState);
112 outState.putInt(STATE_CURRENT_PAGE, mViewPager.getCurrentItem());
113 if (Data.accountFilter.getValue() != null)
114 outState.putString(STATE_ACC_FILTER, Data.accountFilter.getValue());
117 protected void onDestroy() {
118 mSectionsPagerAdapter = null;
119 RecyclerView root = findViewById(R.id.nav_profile_list);
120 if (root != null) root.setAdapter(null);
121 if (drawer != null) drawer.removeDrawerListener(drawerListener);
122 drawerListener = null;
123 if (drawer != null) drawer.removeDrawerListener(barDrawerToggle);
124 barDrawerToggle = null;
125 if (mViewPager != null) mViewPager.removeOnPageChangeListener(pageChangeListener);
126 pageChangeListener = null;
130 protected void setupProfileColors() {
131 SharedPreferences prefs = getPreferences(MODE_PRIVATE);
132 int profileColor = prefs.getInt(PREF_THEME_ID, -2);
133 if (profileColor == -2) profileColor = Data.retrieveCurrentThemeIdFromDb();
134 Colors.setupTheme(this, profileColor);
135 Colors.profileThemeId = profileColor;
136 storeThemeIdInPrefs(profileColor);
139 protected void onResume() {
144 protected void onCreate(Bundle savedInstanceState) {
145 super.onCreate(savedInstanceState);
146 debug("flow", "MainActivity.onCreate()");
147 setContentView(R.layout.activity_main);
149 fab = findViewById(R.id.btn_add_transaction);
150 profileListHeadMore = findViewById(R.id.nav_profiles_start_edit);
151 profileListHeadCancel = findViewById(R.id.nav_profiles_cancel_edit);
152 LinearLayout profileListHeadMoreAndCancel =
153 findViewById(R.id.nav_profile_list_head_buttons);
154 profileListHeadAddProfile = findViewById(R.id.nav_new_profile_button);
155 drawer = findViewById(R.id.drawer_layout);
156 bTransactionListCancelDownload = findViewById(R.id.transaction_list_cancel_download);
157 mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
158 mViewPager = findViewById(R.id.root_frame);
160 Bundle extra = getIntent().getBundleExtra(BUNDLE_SAVED_STATE);
161 if (extra != null && savedInstanceState == null) savedInstanceState = extra;
164 mToolbar = findViewById(R.id.toolbar);
165 setSupportActionBar(mToolbar);
167 Data.profile.observe(this, this::onProfileChanged);
169 Data.profiles.observe(this, this::onProfileListChanged);
171 if (barDrawerToggle == null) {
172 barDrawerToggle = new ActionBarDrawerToggle(this, drawer, mToolbar,
173 R.string.navigation_drawer_open, R.string.navigation_drawer_close);
174 drawer.addDrawerListener(barDrawerToggle);
176 barDrawerToggle.syncState();
178 TextView ver = drawer.findViewById(R.id.drawer_version_text);
182 getApplicationContext().getPackageManager().getPackageInfo(getPackageName(), 0);
183 ver.setText(pi.versionName);
185 catch (Exception e) {
189 markDrawerItemCurrent(R.id.nav_account_summary);
191 mViewPager.setAdapter(mSectionsPagerAdapter);
193 if (pageChangeListener == null) {
194 pageChangeListener = new ViewPager.SimpleOnPageChangeListener() {
196 public void onPageSelected(int position) {
197 mCurrentPage = position;
200 markDrawerItemCurrent(R.id.nav_account_summary);
203 markDrawerItemCurrent(R.id.nav_latest_transactions);
206 Log.e("MainActivity",
207 String.format("Unexpected page index %d", position));
210 super.onPageSelected(position);
213 mViewPager.addOnPageChangeListener(pageChangeListener);
217 if (savedInstanceState != null) {
218 int currentPage = savedInstanceState.getInt(STATE_CURRENT_PAGE, -1);
219 if (currentPage != -1) {
220 mCurrentPage = currentPage;
222 Data.accountFilter.setValue(savedInstanceState.getString(STATE_ACC_FILTER, null));
225 Data.lastUpdateDate.observe(this, this::updateLastUpdateDisplay);
227 findViewById(R.id.btn_no_profiles_add)
228 .setOnClickListener(v -> startEditProfileActivity(null));
230 findViewById(R.id.btn_add_transaction).setOnClickListener(this::fabNewTransactionClicked);
232 findViewById(R.id.nav_new_profile_button)
233 .setOnClickListener(v -> startEditProfileActivity(null));
235 RecyclerView root = findViewById(R.id.nav_profile_list);
237 throw new RuntimeException("Can't get hold on the transaction value view");
239 if (mProfileListAdapter == null) mProfileListAdapter = new ProfilesRecyclerViewAdapter();
240 root.setAdapter(mProfileListAdapter);
242 mProfileListAdapter.editingProfiles.observe(this, newValue -> {
244 profileListHeadMore.setVisibility(View.GONE);
245 profileListHeadCancel.setVisibility(View.VISIBLE);
246 profileListHeadAddProfile.setVisibility(View.VISIBLE);
247 if (drawer.isDrawerOpen(GravityCompat.START)) {
248 profileListHeadMore.startAnimation(
249 AnimationUtils.loadAnimation(MainActivity.this, R.anim.fade_out));
250 profileListHeadCancel.startAnimation(
251 AnimationUtils.loadAnimation(MainActivity.this, R.anim.fade_in));
252 profileListHeadAddProfile.startAnimation(
253 AnimationUtils.loadAnimation(MainActivity.this, R.anim.fade_in));
257 profileListHeadCancel.setVisibility(View.GONE);
258 profileListHeadMore.setVisibility(View.VISIBLE);
259 profileListHeadAddProfile.setVisibility(View.GONE);
260 if (drawer.isDrawerOpen(GravityCompat.START)) {
261 profileListHeadCancel.startAnimation(
262 AnimationUtils.loadAnimation(MainActivity.this, R.anim.fade_out));
263 profileListHeadMore.startAnimation(
264 AnimationUtils.loadAnimation(MainActivity.this, R.anim.fade_in));
265 profileListHeadAddProfile.startAnimation(
266 AnimationUtils.loadAnimation(MainActivity.this, R.anim.fade_out));
270 mProfileListAdapter.notifyDataSetChanged();
273 LinearLayoutManager llm = new LinearLayoutManager(this);
275 llm.setOrientation(RecyclerView.VERTICAL);
276 root.setLayoutManager(llm);
278 profileListHeadMore.setOnClickListener((v) -> mProfileListAdapter.flipEditingProfiles());
279 profileListHeadCancel.setOnClickListener((v) -> mProfileListAdapter.flipEditingProfiles());
280 profileListHeadMoreAndCancel
281 .setOnClickListener((v) -> mProfileListAdapter.flipEditingProfiles());
282 if (drawerListener == null) {
283 drawerListener = new DrawerLayout.SimpleDrawerListener() {
285 public void onDrawerClosed(View drawerView) {
286 super.onDrawerClosed(drawerView);
287 mProfileListAdapter.setAnimationsEnabled(false);
288 mProfileListAdapter.editingProfiles.setValue(false);
291 public void onDrawerOpened(View drawerView) {
292 super.onDrawerOpened(drawerView);
293 mProfileListAdapter.setAnimationsEnabled(true);
296 drawer.addDrawerListener(drawerListener);
300 private void scheduleDataRetrievalIfStale(Date lastUpdate) {
301 long now = new Date().getTime();
302 if ((lastUpdate == null) || (now > (lastUpdate.getTime() + (24 * 3600 * 1000)))) {
303 if (lastUpdate == null) debug("db::", "WEB data never fetched. scheduling a fetch");
304 else debug("db", String.format(Locale.ENGLISH,
305 "WEB data last fetched at %1.3f and now is %1.3f. re-fetching",
306 lastUpdate.getTime() / 1000f, now / 1000f));
308 Data.scheduleTransactionListRetrieval(this);
311 private void createShortcuts(List<MobileLedgerProfile> list) {
312 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N_MR1) return;
314 List<ShortcutInfo> shortcuts = new ArrayList<>();
316 for (MobileLedgerProfile p : list) {
317 if (!p.isPostingPermitted()) continue;
319 ShortcutInfo si = new ShortcutInfo.Builder(this, "new_transaction_" + p.getUuid())
320 .setShortLabel(p.getName())
321 .setIcon(Icon.createWithResource(this, R.drawable.svg_thick_plus_white))
323 new Intent(Intent.ACTION_VIEW, null, this, NewTransactionActivity.class)
324 .putExtra("profile_uuid", p.getUuid())).setRank(i).build();
328 ShortcutManager sm = getSystemService(ShortcutManager.class);
329 sm.setDynamicShortcuts(shortcuts);
331 private void onProfileListChanged(List<MobileLedgerProfile> newList) {
332 if (newList == null) {
333 // profiles not yet loaded from DB
334 findViewById(R.id.loading_layout).setVisibility(View.VISIBLE);
335 findViewById(R.id.no_profiles_layout).setVisibility(View.GONE);
336 findViewById(R.id.pager_layout).setVisibility(View.GONE);
340 if (newList.isEmpty()) {
341 findViewById(R.id.no_profiles_layout).setVisibility(View.VISIBLE);
342 findViewById(R.id.pager_layout).setVisibility(View.GONE);
343 findViewById(R.id.loading_layout).setVisibility(View.GONE);
347 findViewById(R.id.pager_layout).setVisibility(View.VISIBLE);
348 findViewById(R.id.no_profiles_layout).setVisibility(View.GONE);
349 findViewById(R.id.loading_layout).setVisibility(View.GONE);
351 findViewById(R.id.nav_profile_list).setMinimumHeight(
352 (int) (getResources().getDimension(R.dimen.thumb_row_height) * newList.size()));
354 debug("profiles", "profile list changed");
355 mProfileListAdapter.notifyDataSetChanged();
357 createShortcuts(newList);
360 * called when the current profile has changed
362 private void onProfileChanged(MobileLedgerProfile profile) {
363 boolean haveProfile = profile != null;
364 findViewById(R.id.no_profiles_layout).setVisibility(haveProfile ? View.GONE : View.VISIBLE);
365 findViewById(R.id.pager_layout).setVisibility(haveProfile ? View.VISIBLE : View.VISIBLE);
367 if (haveProfile) setTitle(profile.getName());
368 else setTitle(R.string.app_name);
370 this.profile = profile;
372 mProfileListAdapter.notifyDataSetChanged();
374 int newProfileTheme = haveProfile ? profile.getThemeId() : -1;
375 if (newProfileTheme != Colors.profileThemeId) {
377 String.format(Locale.ENGLISH, "profile theme %d → %d", Colors.profileThemeId,
379 MainActivity.this.profileThemeChanged();
380 Colors.profileThemeId = newProfileTheme;
381 // profileThemeChanged would restart the activity, so no need to reload the
386 drawer.closeDrawers();
388 Data.transactions.clear();
389 debug("transactions", "requesting list reload");
390 TransactionListViewModel.scheduleTransactionListReload();
392 Data.accounts.clear();
393 AccountSummaryViewModel.scheduleAccountListReload();
396 if (profile.isPostingPermitted()) {
397 mToolbar.setSubtitle(null);
401 mToolbar.setSubtitle(R.string.profile_subitlte_read_only);
406 mToolbar.setSubtitle(null);
410 updateLastUpdateTextFromDB();
412 private void updateLastUpdateDisplay(Date newValue) {
413 LinearLayout l = findViewById(R.id.transactions_last_update_layout);
414 TextView v = findViewById(R.id.transactions_last_update);
415 if (newValue == null) {
416 l.setVisibility(View.INVISIBLE);
417 debug("main", "no last update date :(");
420 final String text = DateFormat.getDateTimeInstance().format(newValue);
422 l.setVisibility(View.VISIBLE);
423 debug("main", String.format("Date formatted: %s", text));
426 scheduleDataRetrievalIfStale(newValue);
428 private void profileThemeChanged() {
429 Bundle bundle = new Bundle();
430 onSaveInstanceState(bundle);
432 storeThemeIdInPrefs(profile.getThemeId());
434 // restart activity to reflect theme change
437 // un-hook all observed LiveData
438 Data.profile.removeObservers(this);
439 Data.profiles.removeObservers(this);
440 Data.lastUpdateDate.removeObservers(this);
441 Intent intent = new Intent(this, this.getClass());
442 intent.putExtra(BUNDLE_SAVED_STATE, bundle);
443 startActivity(intent);
445 private void storeThemeIdInPrefs(int themeId) {
446 // store the new theme id in the preferences
447 SharedPreferences prefs = getPreferences(MODE_PRIVATE);
448 SharedPreferences.Editor e = prefs.edit();
449 e.putInt(PREF_THEME_ID, themeId);
452 public void startEditProfileActivity(MobileLedgerProfile profile) {
453 Intent intent = new Intent(this, ProfileDetailActivity.class);
454 Bundle args = new Bundle();
455 if (profile != null) {
456 int index = Data.getProfileIndex(profile);
457 if (index != -1) intent.putExtra(ProfileDetailFragment.ARG_ITEM_ID, index);
459 intent.putExtras(args);
460 startActivity(intent, args);
462 private void setupProfile() {
463 MLDB.getOption(MLDB.OPT_PROFILE_UUID, null, new GetOptCallback() {
465 protected void onResult(String profileUUID) {
466 MobileLedgerProfile startupProfile;
468 startupProfile = Data.getProfile(profileUUID);
469 Data.setCurrentProfile(startupProfile);
473 public void fabNewTransactionClicked(View view) {
474 Intent intent = new Intent(this, NewTransactionActivity.class);
475 startActivity(intent);
476 overridePendingTransition(R.anim.slide_in_right, R.anim.dummy);
478 public void navSettingsClicked(View view) {
479 Intent intent = new Intent(this, SettingsActivity.class);
480 startActivity(intent);
481 drawer.closeDrawers();
483 public void markDrawerItemCurrent(int id) {
484 TextView item = drawer.findViewById(id);
485 item.setBackgroundColor(Colors.tableRowDarkBG);
487 LinearLayout actions = drawer.findViewById(R.id.nav_actions);
488 for (int i = 0; i < actions.getChildCount(); i++) {
489 View view = actions.getChildAt(i);
490 if (view.getId() != id) {
491 view.setBackgroundColor(Color.TRANSPARENT);
495 public void onAccountSummaryClicked(View view) {
496 drawer.closeDrawers();
498 showAccountSummaryFragment();
500 private void showAccountSummaryFragment() {
501 mViewPager.setCurrentItem(0, true);
502 Data.accountFilter.setValue(null);
504 public void onLatestTransactionsClicked(View view) {
505 drawer.closeDrawers();
507 showTransactionsFragment((String) null);
509 private void showTransactionsFragment(String accName) {
510 Data.accountFilter.setValue(accName);
511 mViewPager.setCurrentItem(1, true);
513 private void showTransactionsFragment(LedgerAccount account) {
514 showTransactionsFragment((account == null) ? null : account.getName());
516 public void showAccountTransactions(LedgerAccount account) {
517 mBackMeansToAccountList = true;
518 showTransactionsFragment(account);
521 public void onBackPressed() {
522 DrawerLayout drawer = findViewById(R.id.drawer_layout);
523 if (drawer.isDrawerOpen(GravityCompat.START)) {
524 drawer.closeDrawer(GravityCompat.START);
527 if (mBackMeansToAccountList && (mViewPager.getCurrentItem() == 1)) {
528 Data.accountFilter.setValue(null);
529 showAccountSummaryFragment();
530 mBackMeansToAccountList = false;
533 debug("fragments", String.format(Locale.ENGLISH, "manager stack: %d",
534 getSupportFragmentManager().getBackStackEntryCount()));
536 super.onBackPressed();
540 public void updateLastUpdateTextFromDB() {
541 if (profile == null) return;
543 long last_update = profile.getLongOption(MLDB.OPT_LAST_SCRAPE, 0L);
545 debug("transactions", String.format(Locale.ENGLISH, "Last update = %d", last_update));
546 if (last_update == 0) {
547 Data.lastUpdateDate.postValue(null);
550 Data.lastUpdateDate.postValue(new Date(last_update));
553 public void onStopTransactionRefreshClick(View view) {
554 debug("interactive", "Cancelling transactions refresh");
555 Data.stopTransactionsRetrieval();
556 bTransactionListCancelDownload.setEnabled(false);
558 public void onRetrieveDone(String error) {
559 Data.transactionRetrievalDone();
560 findViewById(R.id.transaction_progress_layout).setVisibility(View.GONE);
563 updateLastUpdateTextFromDB();
565 new RefreshDescriptionsTask().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
566 TransactionListViewModel.scheduleTransactionListReload();
568 else Toast.makeText(this, error, Toast.LENGTH_LONG).show();
570 public void onRetrieveStart() {
571 ProgressBar progressBar = findViewById(R.id.transaction_list_progress_bar);
572 bTransactionListCancelDownload.setEnabled(true);
573 ColorStateList csl = Colors.getColorStateList();
574 progressBar.setIndeterminateTintList(csl);
575 progressBar.setProgressTintList(csl);
576 progressBar.setIndeterminate(true);
577 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) progressBar.setProgress(0, false);
578 else progressBar.setProgress(0);
579 findViewById(R.id.transaction_progress_layout).setVisibility(View.VISIBLE);
581 public void onRetrieveProgress(RetrieveTransactionsTask.Progress progress) {
582 ProgressBar progressBar = findViewById(R.id.transaction_list_progress_bar);
583 if ((progress.getTotal() == RetrieveTransactionsTask.Progress.INDETERMINATE) ||
584 (progress.getTotal() == 0))
586 progressBar.setIndeterminate(true);
589 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
590 progressBar.setMin(0);
592 progressBar.setMax(progress.getTotal());
593 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
594 progressBar.setProgress(progress.getProgress(), true);
596 else progressBar.setProgress(progress.getProgress());
597 progressBar.setIndeterminate(false);
600 public void fabShouldShow() {
601 if ((profile != null) && profile.isPostingPermitted()) fab.show();
603 public void fabHide() {
606 public void onAccountSummaryRowViewClicked(View view) {
608 if (view.getId() == R.id.account_expander) row = (ViewGroup) view.getParent().getParent();
609 else row = (ViewGroup) view.getParent();
611 LedgerAccount acc = (LedgerAccount) row.getTag();
612 switch (view.getId()) {
613 case R.id.account_row_acc_name:
614 case R.id.account_expander:
615 case R.id.account_expander_container:
616 debug("accounts", "Account expander clicked");
617 if (!acc.hasSubAccounts()) return;
619 boolean wasExpanded = acc.isExpanded();
621 View arrow = row.findViewById(R.id.account_expander_container);
623 arrow.clearAnimation();
624 ViewPropertyAnimator animator = arrow.animate();
626 acc.toggleExpanded();
627 DbOpQueue.add("update accounts set expanded=? where name=? and profile=?",
628 new Object[]{acc.isExpanded(), acc.getName(), profile.getUuid()
632 debug("accounts", String.format("Collapsing account '%s'", acc.getName()));
633 arrow.setRotation(0);
634 animator.rotationBy(180);
636 // removing all child accounts from the view
637 int start = -1, count = 0;
638 try (LockHolder ignored = Data.accounts.lockForWriting()) {
639 for (int i = 0; i < Data.accounts.size(); i++) {
640 if (acc.isParentOf(Data.accounts.get(i))) {
641 // debug("accounts", String.format("Found a child '%s' at position %d",
642 // Data.accounts.get(i).getName(), i));
651 // String.format("Found a non-child '%s' at position %d",
652 // Data.accounts.get(i).getName(), i));
659 for (int j = 0; j < count; j++) {
660 // debug("accounts", String.format("Removing item %d: %s", start + j,
661 // Data.accounts.get(start).getName()));
662 Data.accounts.removeQuietly(start);
665 mAccountSummaryFragment.modelAdapter
666 .notifyItemRangeRemoved(start, count);
671 debug("accounts", String.format("Expanding account '%s'", acc.getName()));
672 arrow.setRotation(180);
673 animator.rotationBy(-180);
674 List<LedgerAccount> children = profile.loadVisibleChildAccountsOf(acc);
675 try (LockHolder ignored = Data.accounts.lockForWriting()) {
676 int parentPos = Data.accounts.indexOf(acc);
677 if (parentPos != -1) {
678 // may have disappeared in a concurrent refresh operation
679 Data.accounts.addAllQuietly(parentPos + 1, children);
680 mAccountSummaryFragment.modelAdapter
681 .notifyItemRangeInserted(parentPos + 1, children.size());
686 case R.id.account_row_acc_amounts:
687 if (acc.getAmountCount() > AccountSummaryAdapter.AMOUNT_LIMIT) {
688 acc.toggleAmountsExpanded();
690 .add("update accounts set amounts_expanded=? where name=? and profile=?",
691 new Object[]{acc.amountsExpanded(), acc.getName(),
694 Data.accounts.triggerItemChangedNotification(acc);
700 public class SectionsPagerAdapter extends FragmentPagerAdapter {
702 SectionsPagerAdapter(FragmentManager fm) {
708 public Fragment getItem(int position) {
709 debug("main", String.format(Locale.ENGLISH, "Switching to fragment %d", position));
712 // debug("flow", "Creating account summary fragment");
713 return mAccountSummaryFragment = new AccountSummaryFragment();
715 return new TransactionListFragment();
717 throw new IllegalStateException(
718 String.format("Unexpected fragment index: " + "%d", position));
723 public int getCount() {