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();
}
}
Aggregations