package com.gh.gamecenter.qa.myqa;

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

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

import com.gh.gamecenter.R;
import com.gh.gamecenter.common.base.fragment.BaseFragment_TabLayout;
import com.gh.gamecenter.common.constant.EntranceConsts;
import com.gh.gamecenter.core.utils.MtaHelper;
import com.gh.gamecenter.login.user.UserManager;
import com.gh.gamecenter.qa.article.MyArticleFragment;
import com.gh.gamecenter.qa.draft.CommunityDraftWrapperActivity;

import java.util.List;

/**
 * Created by khy on 20/12/17.
 */

public class MyAskWrapperFragment extends BaseFragment_TabLayout {

    @Override
    protected void initFragmentList(List<Fragment> fragments) {
        String entrance = null;
        if (getArguments() != null) entrance = getArguments().getString(EntranceConsts.KEY_ENTRANCE);

        fragments.add(MyAnswerFragment.getInstance(entrance));
        fragments.add(MyArticleFragment.getInstance(entrance, UserManager.getInstance().getUserId()));
    }

    @Override
    protected void initTabTitleList(List<String> tabTitleList) {
        tabTitleList.add("我的回答");
        tabTitleList.add("我的帖子");
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        setNavigationTitle(R.string.my_forum);
        initMenu(R.menu.menu_my_ask_wrapper);
        if (mDividerLineView != null) {
            mDividerLineView.setVisibility(View.VISIBLE);
        }
    }

    @Override
    public void onPageSelected(int position) {
        super.onPageSelected(position);
        MtaHelper.onEvent("我的光环_新", "我的问答", mTabTitleList.get(position) + "Tab");
    }

    @Override
    public void onMenuItemClick(MenuItem menuItem) {
        super.onMenuItemClick(menuItem);
        if (menuItem.getItemId() == R.id.menu_draft) {
            MtaHelper.onEvent("我的光环_新", "我的问答", "草稿");
            startActivity(CommunityDraftWrapperActivity.getIntent(requireContext()));
        }
    }
}
