* The purpose of this method is set The current display ui
*
* @param id the ui that has to be displayed
*/
public void setDisplay(int id) {
if (mDrawerLayout.isDrawerOpen(GravityCompat.START)) {
mDrawerLayout.closeDrawer(GravityCompat.START);
}
HideKeyboard.hideKeyboard(HomepageActivity.this);
Intent intent;
switch (id) {
//Open up home fragment
case AppConstants.DISPLAY_HOME:
if (!(mFragmentManager.findFragmentById(R.id.fragment_container) instanceof FragmentHome)) {
mFragment = new FragmentHome();
replaceFragment(mFragment, AppConstants.HOME_FRAGMENT);
}
break;
//opens up the setting section
case AppConstants.DISPLAY_SETTING:
if (!(mFragmentManager.findFragmentById(R.id.fragment_container) instanceof FragmentSetting)) {
mFragment = new FragmentSetting();
replaceFragment(mFragment, AppConstants.SETTING_FRAGMENT);
}
break;
//display the logout dialog
case AppConstants.DISPLAY_LOGOUT:
DialogManager.getInstance().showLogOutLogOut(this);
break;
//display the notification section
case AppConstants.DISPLAY_NOTIFICATION:
if (!(mFragmentManager.findFragmentById(R.id.fragment_container) instanceof FragmentNotification)) {
mFragment = new FragmentNotification();
replaceFragment(mFragment, AppConstants.NOTIFICATION_FRAGMENT);
}
break;
default:
//Setup Home Fragment as default fragment
if (!(mFragmentManager.findFragmentById(R.id.fragment_container) instanceof FragmentHome)) {
mFragment = new FragmentHome();
replaceFragment(mFragment, AppConstants.HOME_FRAGMENT);
}
break;
}
}
/*
* Insert the mFragment by replacing any existing mFragment
*
* @param fragment the fragment that has to be replaced
* @param name the tag of the fragment
*/
public void replaceFragment(final Fragment fragment, final String name) {
if(mFragmentManager.findFragmentById(R.id.fragment_container)instanceof FragmentHome) {
mFragmentManager.beginTransaction()
.replace(R.id.fragment_container, fragment, name)
.addToBackStack(name)
.commit();
} else {
mFragmentManager.beginTransaction()
.replace(R.id.fragment_container, fragment).
commit();
}
}
/**
* The purpose of this method is to remove the fragment from the stack
*/
public void removeFragmentFromStack() {
if (mFragmentManager.findFragmentById(R.id.fragment_container) instanceof FragmentHome) {
exitFromApp();
} else {
mFragmentManager.popBackStackImmediate();
}
}