+ if (progressBar == null)
+ throw new RuntimeException("Can't get hold on the transaction value progress bar");
+ if (progressLayout == null) throw new RuntimeException(
+ "Can't get hold on the transaction value progress bar layout");
+
+ markDrawerItemCurrent(R.id.nav_account_summary);
+
+ mViewPager.setAdapter(mSectionsPagerAdapter);
+
+ if (pageChangeListener == null) {
+ pageChangeListener = new ViewPager.SimpleOnPageChangeListener() {
+ @Override
+ public void onPageSelected(int 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);
+ }
+ };
+ mViewPager.addOnPageChangeListener(pageChangeListener);
+ }
+
+ mCurrentPage = 0;
+ if (savedInstanceState != null) {
+ int currentPage = savedInstanceState.getInt(STATE_CURRENT_PAGE, -1);
+ if (currentPage != -1) {
+ mCurrentPage = currentPage;
+ }
+ mAccountFilter = savedInstanceState.getString(STATE_ACC_FILTER, null);
+ }
+ else mAccountFilter = null;
+
+ Data.lastUpdateDate.observe(this, this::updateLastUpdateDisplay);
+
+ findViewById(R.id.btn_no_profiles_add)
+ .setOnClickListener(v -> startEditProfileActivity(null));
+
+ findViewById(R.id.btn_add_transaction).setOnClickListener(this::fabNewTransactionClicked);
+
+ findViewById(R.id.nav_new_profile_button)
+ .setOnClickListener(v -> startEditProfileActivity(null));
+
+ RecyclerView root = findViewById(R.id.nav_profile_list);
+ if (root == null)
+ throw new RuntimeException("Can't get hold on the transaction value view");
+
+ if (mProfileListAdapter == null) mProfileListAdapter = new ProfilesRecyclerViewAdapter();
+ root.setAdapter(mProfileListAdapter);
+
+ if (editingProfilesObserver == null) {
+ editingProfilesObserver = (o, arg) -> {
+ if (mProfileListAdapter.isEditingProfiles()) {
+ profileListHeadArrow.clearAnimation();
+ profileListHeadArrow.setVisibility(View.GONE);
+ profileListHeadMore.setVisibility(View.GONE);
+ profileListHeadMore
+ .startAnimation(AnimationUtils.loadAnimation(this, R.anim.fade_out));
+ profileListHeadCancel.setVisibility(View.VISIBLE);
+ profileListHeadCancel
+ .startAnimation(AnimationUtils.loadAnimation(this, R.anim.fade_in));
+ }
+ else {
+ profileListHeadArrow.setRotation(180f);
+ profileListHeadArrow.setVisibility(View.VISIBLE);
+ profileListHeadCancel.setVisibility(View.GONE);
+ profileListHeadCancel
+ .startAnimation(AnimationUtils.loadAnimation(this, R.anim.fade_out));
+ profileListHeadMore.setVisibility(View.GONE);
+ if (profileListExpanded) {
+ profileListHeadMore.setVisibility(View.VISIBLE);
+ profileListHeadMore
+ .startAnimation(AnimationUtils.loadAnimation(this, R.anim.fade_in));
+ }
+ else profileListHeadMore.setVisibility(View.GONE);
+ }
+ };
+ mProfileListAdapter.addEditingProfilesObserver(editingProfilesObserver);
+ }
+
+ LinearLayoutManager llm = new LinearLayoutManager(this);
+
+ llm.setOrientation(RecyclerView.VERTICAL);
+ root.setLayoutManager(llm);
+
+ profileListHeadMore.setOnClickListener((v) -> mProfileListAdapter.flipEditingProfiles());
+ profileListHeadCancel.setOnClickListener((v) -> mProfileListAdapter.flipEditingProfiles());
+ profileListHeadMoreAndCancel
+ .setOnClickListener((v) -> mProfileListAdapter.flipEditingProfiles());
+
+ if (drawerListener == null) {
+ drawerListener = new DrawerLayout.SimpleDrawerListener() {
+ @Override
+ public void onDrawerClosed(View drawerView) {
+ super.onDrawerClosed(drawerView);
+ collapseProfileList();
+ }
+ };
+ drawer.addDrawerListener(drawerListener);
+ }
+
+ findViewById(R.id.nav_profile_list_head_layout)
+ .setOnClickListener(this::navProfilesHeadClicked);
+ findViewById(R.id.nav_profiles_label).setOnClickListener(this::navProfilesHeadClicked);
+ boolean initialStart = Data.profile.get() == null;
+ setupProfile();
+ if (!initialStart) onProfileChanged(null);
+
+ updateLastUpdateTextFromDB();