package com.gh.gamecenter.info;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;

import com.gh.gamecenter.common.base.fragment.BaseFragment_TabLayout;
import com.gh.gamecenter.core.utils.MtaHelper;
import com.gh.gamecenter.R;
import com.gh.gamecenter.eventbus.EBUISwitch;

import org.greenrobot.eventbus.EventBus;

import java.util.List;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

/**
 * @author CsHeng
 * @Date 17/06/2017
 * @Time 10:30 AM
 * <p>
 * 包裹着各种资讯的pager fragment
 */
public class InfoWrapperFragment extends BaseFragment_TabLayout {

    public static final int INDEX_INFO = 0;
    public static final int INDEX_STRATEGY = 1;
    public static final int INDEX_ORIGINAL = 2;

    public final static String EB_NEWSFRAGMENT_TAG = "InfoWrapperFragment";

    @Override
    protected void initFragmentList(List<Fragment> fragments) {
        fragments.add(new InfoFragment());
        fragments.add(new StrategyFragment());
        fragments.add(new OriginalFragment());
    }


    @Override
    protected void initTabTitleList(List<String> tabTitleList) {
        tabTitleList.add(getString(R.string.news_zixun));
        tabTitleList.add(getString(R.string.news_gonglve));
        tabTitleList.add(getString(R.string.article_gonglve_hint));
    }

    @Override
    protected View provideTabView(int position, String tabTitle) {
        if (position == INDEX_STRATEGY) {
            return LayoutInflater.from(getContext()).inflate(R.layout.tab_item_info_strategy, null);
        }
        return super.provideTabView(position, tabTitle);
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        setNavigationTitle(getString(R.string.info_center_title));
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        if (mDividerLineView != null) {
            mDividerLineView.setVisibility(View.VISIBLE);
        }
    }

    @Override
    public void onPageSelected(int position) {
        MtaHelper.onEvent("我的光环_新", "资讯中心", mTabTitleList.get(position) + "Tab");
        EventBus.getDefault().post(new EBUISwitch(EB_NEWSFRAGMENT_TAG, position));
    }
}
