use of net.iGap.fragments.BaseFragment in project iGap-Android by KianIranian-STDG.
the class ActivityMain method onBackPressed.
@Override
public void onBackPressed() {
Log.wtf(this.getClass().getName(), "onBackPressed");
if (G.ISRealmOK) {
if (G.onBackPressedWebView != null) {
Log.wtf(this.getClass().getName(), "onBackPressedWebView");
if (G.onBackPressedWebView.onBack()) {
return;
}
}
if (G.onBackPressedChat != null) {
Log.wtf(this.getClass().getName(), "onBackPressedChat");
if (G.onBackPressedChat.onBack()) {
return;
}
}
if (onBackPressedListener != null) {
Log.wtf(this.getClass().getName(), "onBackPressedChat");
onBackPressedListener.doBack();
}
if (G.twoPaneMode) {
Log.wtf(this.getClass().getName(), "twoPaneMode");
if (findViewById(R.id.fullScreenFrame).getVisibility() == View.VISIBLE) {
// handle back in fragment show like dialog
Log.wtf(this.getClass().getName(), "fullScreenFrame VISIBLE");
Fragment frag = getSupportFragmentManager().findFragmentById(R.id.fullScreenFrame);
if (frag == null) {
Log.wtf(this.getClass().getName(), "pop from: detailFrame");
Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.detailFrame);
if (fragment != null) {
getSupportFragmentManager().popBackStackImmediate();
}
Fragment fragmentShowed = getSupportFragmentManager().findFragmentById(R.id.detailFrame);
if (fragmentShowed == null) {
findViewById(R.id.fullScreenFrame).setVisibility(View.GONE);
}
} else {
Log.wtf(this.getClass().getName(), "pop from: fullScreenFrame");
getSupportFragmentManager().popBackStackImmediate();
findViewById(R.id.fullScreenFrame).setVisibility(View.GONE);
}
} else {
Log.wtf(this.getClass().getName(), "fullScreenFrame not VISIBLE");
if (getSupportFragmentManager().getBackStackEntryCount() > 2) {
Log.wtf(this.getClass().getName(), "pop from: backStack");
if (getSupportFragmentManager().getBackStackEntryAt(2).getName().equals(FragmentChat.class.getName())) {
if (G.isLandscape) {
Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.roomListFrame);
if (fragment instanceof BottomNavigationFragment) {
if (((BottomNavigationFragment) fragment).isAllowToBackPressed()) {
getSupportFragmentManager().popBackStackImmediate();
}
} else {
getSupportFragmentManager().popBackStackImmediate();
}
} else {
getSupportFragmentManager().popBackStackImmediate();
findViewById(R.id.mainFrame).setVisibility(View.GONE);
findViewById(R.id.roomListFrame).setVisibility(View.VISIBLE);
}
} else {
getSupportFragmentManager().popBackStackImmediate();
}
} else {
Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.roomListFrame);
if (fragment instanceof BottomNavigationFragment) {
if (((BottomNavigationFragment) fragment).isAllowToBackPressed()) {
if (((BottomNavigationFragment) fragment).isFirstTabItem()) {
Log.wtf(this.getClass().getName(), "pop from: finish");
finish();
}
}
}
}
}
} else {
if (getSupportFragmentManager().getBackStackEntryCount() > 1) {
// List fragmentList = getSupportFragmentManager().getFragments();
boolean handled = false;
try {
// because some of our fragments are NOT extended from BaseFragment
if (getSupportFragmentManager().findFragmentById(R.id.chatContainer) instanceof SearchFragment) {
SearchFragment searchFragment = (SearchFragment) getSupportFragmentManager().findFragmentById(R.id.chatContainer);
if (searchFragment != null && searchFragment.isVisible()) {
searchFragment.onSearchCollapsed();
}
}
Fragment frag = getSupportFragmentManager().findFragmentByTag(getSupportFragmentManager().getBackStackEntryAt(getSupportFragmentManager().getBackStackEntryCount() - 1).getName());
handled = ((BaseFragment) frag).onBackPressed();
} catch (Exception e) {
e.printStackTrace();
}
if (!handled) {
super.onBackPressed();
}
} else {
Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.mainFrame);
if (fragment instanceof BottomNavigationFragment) {
if (((BottomNavigationFragment) fragment).isAllowToBackPressed()) {
if (((BottomNavigationFragment) fragment).isFirstTabItem()) {
finish();
}
}
}
}
}
} else {
super.onBackPressed();
}
}
Aggregations