+ markDrawerItemCurrent(R.id.nav_account_summary);
+
+ b.mainPager.setAdapter(mSectionsPagerAdapter);
+ b.mainPager.setOffscreenPageLimit(1);
+
+ if (pageChangeCallback == null) {
+ pageChangeCallback = new ViewPager2.OnPageChangeCallback() {
+ @Override
+ public void onPageSelected(int position) {
+ mCurrentPage = position;
+ switch (position) {
+ case 0:
+ markDrawerItemCurrent(R.id.nav_account_summary);
+ break;
+ case 1:
+ markDrawerItemCurrent(R.id.nav_latest_transactions);
+ break;
+ default:
+ Log.e("MainActivity",
+ String.format("Unexpected page index %d", position));
+ }
+
+ super.onPageSelected(position);
+ }
+ };
+ b.mainPager.registerOnPageChangeCallback(pageChangeCallback);
+ }
+
+ mCurrentPage = 0;
+ if (savedInstanceState != null) {
+ int currentPage = savedInstanceState.getInt(STATE_CURRENT_PAGE, -1);
+ if (currentPage != -1) {
+ mCurrentPage = currentPage;
+ }
+ mainModel.getAccountFilter()
+ .setValue(savedInstanceState.getString(STATE_ACC_FILTER, null));
+ }
+
+ b.btnNoProfilesAdd.setOnClickListener(v -> ProfileDetailActivity.start(this, null));
+
+ b.btnAddTransaction.setOnClickListener(this::fabNewTransactionClicked);
+
+ b.navNewProfileButton.setOnClickListener(v -> ProfileDetailActivity.start(this, null));
+
+ b.transactionListCancelDownload.setOnClickListener(this::onStopTransactionRefreshClick);
+
+ if (mProfileListAdapter == null)
+ mProfileListAdapter = new ProfilesRecyclerViewAdapter();
+ b.navProfileList.setAdapter(mProfileListAdapter);
+
+ mProfileListAdapter.editingProfiles.observe(this, newValue -> {
+ if (newValue) {
+ b.navProfilesStartEdit.setVisibility(View.GONE);
+ b.navProfilesCancelEdit.setVisibility(View.VISIBLE);
+ b.navNewProfileButton.setVisibility(View.VISIBLE);
+ if (b.drawerLayout.isDrawerOpen(GravityCompat.START)) {
+ b.navProfilesStartEdit.startAnimation(
+ AnimationUtils.loadAnimation(MainActivity.this, R.anim.fade_out));
+ b.navProfilesCancelEdit.startAnimation(
+ AnimationUtils.loadAnimation(MainActivity.this, R.anim.fade_in));
+ b.navNewProfileButton.startAnimation(
+ AnimationUtils.loadAnimation(MainActivity.this, R.anim.fade_in));
+ }
+ }
+ else {
+ b.navProfilesCancelEdit.setVisibility(View.GONE);
+ b.navProfilesStartEdit.setVisibility(View.VISIBLE);
+ b.navNewProfileButton.setVisibility(View.GONE);
+ if (b.drawerLayout.isDrawerOpen(GravityCompat.START)) {
+ b.navProfilesCancelEdit.startAnimation(
+ AnimationUtils.loadAnimation(MainActivity.this, R.anim.fade_out));
+ b.navProfilesStartEdit.startAnimation(
+ AnimationUtils.loadAnimation(MainActivity.this, R.anim.fade_in));
+ b.navNewProfileButton.startAnimation(
+ AnimationUtils.loadAnimation(MainActivity.this, R.anim.fade_out));
+ }
+ }
+
+ mProfileListAdapter.notifyDataSetChanged();
+ });