Search in sources :

Example 1 with ChatFragment

use of com.huetoyou.chatexchange.ui.frags.ChatFragment 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)

Example 2 with ChatFragment

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

the class FragStuff method addFragment.

/**
 * Instantiate/create the appropriate chat fragment, if necessary
 *
 * @param url   URL of chat
 * @param name  Name of chat
 * @param color Accent color of chat
 * @param id    ID of chat
 * @return the created Fragment
 */
private Fragment addFragment(String url, String name, Integer color, Integer id) {
    Fragment fragment;
    if (mainActivity.mFragmentManager.findFragmentByTag(url) != null) {
        fragment = mainActivity.mFragmentManager.findFragmentByTag(url);
    } else {
        fragment = new ChatFragment();
        Bundle args = new Bundle();
        args.putString("chatTitle", name);
        args.putString("chatUrl", url);
        args.putInt("chatColor", color);
        args.putInt("chatId", id);
        fragment.setArguments(args);
    }
    return fragment;
}
Also used : ChatFragment(com.huetoyou.chatexchange.ui.frags.ChatFragment) Bundle(android.os.Bundle) Fragment(android.support.v4.app.Fragment) HomeFragment(com.huetoyou.chatexchange.ui.frags.HomeFragment) ChatFragment(com.huetoyou.chatexchange.ui.frags.ChatFragment)

Aggregations

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