Search in sources :

Example 1 with SearchFragment

use of net.iGap.fragments.SearchFragment 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();
    }
}
Also used : BottomNavigationFragment(net.iGap.fragments.BottomNavigationFragment) SearchFragment(net.iGap.fragments.SearchFragment) FragmentChat(net.iGap.fragments.FragmentChat) PaymentFragment(net.iGap.fragments.PaymentFragment) Fragment(androidx.fragment.app.Fragment) HelperFragment(net.iGap.helper.HelperFragment) OpenFragment(net.iGap.observers.interfaces.OpenFragment) TabletEmptyChatFragment(net.iGap.fragments.TabletEmptyChatFragment) BaseFragment(net.iGap.fragments.BaseFragment) CameraStoryFragment(net.iGap.story.CameraStoryFragment) CallSelectFragment(net.iGap.fragments.CallSelectFragment) SearchFragment(net.iGap.fragments.SearchFragment) DiscoveryFragment(net.iGap.fragments.discovery.DiscoveryFragment) BottomNavigationFragment(net.iGap.fragments.BottomNavigationFragment) RemoteException(android.os.RemoteException) IOException(java.io.IOException) ActivityNotFoundException(android.content.ActivityNotFoundException)

Aggregations

ActivityNotFoundException (android.content.ActivityNotFoundException)1 RemoteException (android.os.RemoteException)1 Fragment (androidx.fragment.app.Fragment)1 IOException (java.io.IOException)1 BaseFragment (net.iGap.fragments.BaseFragment)1 BottomNavigationFragment (net.iGap.fragments.BottomNavigationFragment)1 CallSelectFragment (net.iGap.fragments.CallSelectFragment)1 FragmentChat (net.iGap.fragments.FragmentChat)1 PaymentFragment (net.iGap.fragments.PaymentFragment)1 SearchFragment (net.iGap.fragments.SearchFragment)1 TabletEmptyChatFragment (net.iGap.fragments.TabletEmptyChatFragment)1 DiscoveryFragment (net.iGap.fragments.discovery.DiscoveryFragment)1 HelperFragment (net.iGap.helper.HelperFragment)1 OpenFragment (net.iGap.observers.interfaces.OpenFragment)1 CameraStoryFragment (net.iGap.story.CameraStoryFragment)1