Search in sources :

Example 1 with AccountsFragment

use of com.huetoyou.chatexchange.ui.frags.AccountsFragment in project ChatExchange by HueToYou.

the class MainActivity method addFragmentByTab.

private void addFragmentByTab(TabLayout.Tab tab) {
    if (tab != null) {
        Fragment fragment;
        if (mCurrentFragments.get(tab.getPosition()) != null) {
            fragment = mCurrentFragments.get(tab.getPosition());
        } else {
            switch(tab.getTag().toString()) {
                case "home":
                    fragment = new AccountsFragment();
                    break;
                default:
                    fragment = new ChatFragment();
                    break;
            }
            mCurrentFragments.put(tab.getPosition(), fragment);
            if (fragment instanceof ChatFragment) {
                Bundle args = new Bundle();
                if (tab.getText() != null)
                    args.putString("chatTitle", tab.getText().toString());
                if (tab.getTag() != null)
                    args.putString("chatUrl", tab.getTag().toString());
                if (tab.getContentDescription() != null)
                    args.putInt("AppBarColor", Integer.decode(tab.getContentDescription().toString()));
                fragment.setArguments(args);
                if (mSharedPrefs.getBoolean("dynamicallyColorBar", false)) {
                    hueUtils.setAddChatFabColor(this, Integer.decode(tab.getContentDescription().toString()));
                }
            }
        }
        String tag = "";
        if (tab.getTag() != null)
            tag = tab.getTag().toString();
        if (mFragmentManager.findFragmentByTag(fragment.getTag()) == null) {
            mFragmentManager.beginTransaction().add(R.id.content_main, fragment, tag).detach(fragment).commit();
        }
        if (tab.getPosition() == HOME_INDEX) {
            mFragmentManager.beginTransaction().attach(fragment).commit();
        }
        mFragmentManager.executePendingTransactions();
    }
}
Also used : ChatFragment(com.huetoyou.chatexchange.ui.frags.ChatFragment) AccountsFragment(com.huetoyou.chatexchange.ui.frags.AccountsFragment) Bundle(android.os.Bundle) Fragment(android.support.v4.app.Fragment) ChatFragment(com.huetoyou.chatexchange.ui.frags.ChatFragment) AccountsFragment(com.huetoyou.chatexchange.ui.frags.AccountsFragment)

Aggregations

Bundle (android.os.Bundle)1 Fragment (android.support.v4.app.Fragment)1 AccountsFragment (com.huetoyou.chatexchange.ui.frags.AccountsFragment)1 ChatFragment (com.huetoyou.chatexchange.ui.frags.ChatFragment)1