@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); LocaleUtil.initLocale(this); boolean shouldRefresh = getIntent().getBooleanExtra(EXTRA_SHOULD_REFRESH, false); binding = DataBindingUtil.setContentView(this, R.layout.activity_main); DataBindingUtil.bind(binding.navView.getHeaderView(0)); MainApplication.getComponent(this).inject(this); subscription.add( brokerProvider .get() .observe() .subscribe( page -> { toggleToolbarElevation(page.shouldToggleToolbar()); changePage(page.getTitleResId(), page.createFragment()); binding.navView.setCheckedItem(page.getMenuId()); })); initView(); AppUtil.setTaskDescription( this, getString(R.string.all_sessions), AppUtil.getThemeColorPrimary(this)); if (savedInstanceState == null) { replaceFragment(SessionsFragment.newInstance(shouldRefresh)); } else { binding.toolbar.setTitle(savedInstanceState.getString(EXTRA_TITLE)); } getSupportFragmentManager().addOnBackStackChangedListener(this); }
private void changePage(@StringRes int titleRes, @NonNull Fragment fragment) { new Handler() .postDelayed( () -> { binding.toolbar.setTitle(titleRes); AppUtil.setTaskDescription( this, getString(titleRes), AppUtil.getThemeColorPrimary(this)); replaceFragment(fragment); }, 300); }