package com.sheep.gamegroup.view.activity;

import android.app.Activity;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.sheep.gamegroup.absBase.BaseActivity;
import com.sheep.gamegroup.model.entity.GridViewEntity;
import com.sheep.gamegroup.util.CommonUtil;
import com.sheep.gamegroup.util.Jump2View;
import com.sheep.gamegroup.util.MyGridview;
import com.sheep.gamegroup.util.ViewUtil;
import com.sheep.gamegroup.view.adapter.TitleFragmentListAdapter;
import com.sheep.gamegroup.view.customview.SheepmSwipeRefreshLayout;
import com.sheep.gamegroup.view.fragment.FgtGameAgencyRecharge;
import com.sheep.jiuyan.samllsheep.R;
import com.sheep.jiuyan.samllsheep.utils.TitleBarUtils;

import java.util.ArrayList;

import butterknife.BindView;

import static com.sheep.gamegroup.util.UMConfigUtils.Event.GAME_INSTEAD_OF_RECHARGE_HELP;

/**
 * 游戏代充
 * Created by ljy on 2018/7/9.
 */

public class ActGameAgencyRecharge extends BaseActivity {
    @BindView(R.id.gridview_game)
    MyGridview gridviewGame;
    @BindView(R.id.recyclerview)
    RecyclerView recyclerview;
    @BindView(R.id.refresh)
    SheepmSwipeRefreshLayout refresh;
    @BindView(R.id.empty_view)
    View empty_view;
    @BindView(R.id.indicator)
    TabLayout indicator;
    @BindView(R.id.pager)
    ViewPager pager;
    private TitleFragmentListAdapter mAdapter;

    private Activity activity;
    private ArrayList<Object> gridviewList = new ArrayList<>();


    @Override
    protected int getLayoutId() {
        return R.layout.act_game_agency_recharge_layout;
    }

    @Override
    public void initView() {
        activity = this;
        TitleBarUtils.getInstance()
                .setTitleFinish(activity)
                .setTitle(activity, "游戏充值")
                .setShowOrHide(this, true)
                .setRightSecondBtn(activity, R.mipmap.search_black_img, new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        Jump2View.getInstance().goGameSearch(activity, null);
                    }
                })
                .setRightImgBotton(activity, R.mipmap.question_black_img, new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        GAME_INSTEAD_OF_RECHARGE_HELP.onEvent();
                        ViewUtil.showMsgDialog(activity, "充值请填写正确的游戏充值账号，角色信息，其他充值问题请联系客服。","充值帮助");
                    }
                });
        setValue();//gridview data
        gridviewV();
    }

    @Override
    protected void onResume() {
        super.onResume();
        initData();
    }

    @Override
    public void initListener() {

    }

    @Override
    public void initData() {}

    /**
     *
     */
    private void gridviewV(){

        mAdapter = new TitleFragmentListAdapter(getSupportFragmentManager());
        for(int i=0;i<gridviewList.size();i++){
            mAdapter.add(FgtGameAgencyRecharge.newInstance(((GridViewEntity)gridviewList.get(i)).getTask_type()), ((GridViewEntity)gridviewList.get(i)).getName());
        }
        pager.setAdapter(mAdapter);
        indicator.setupWithViewPager(pager);
        pager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int i, float v, int i1) {

            }

            @Override
            public void onPageSelected(int i) {
                position = i;
//                FIND_TAG.onEvent("find_tag_name", ListUtil.hasIndex(list, i - 1) ? list.get(i - 1).getName() : "全部");
            }

            @Override
            public void onPageScrollStateChanged(int i) {

            }
        });
        pager.setCurrentItem(position);
        CommonUtil.getInstance()
            .reflex(indicator, activity);
    }
    private int position = 0;//默认选中第一个

    /**
     * gridview 赋值
     */
    private void setValue(){
        gridviewList.clear();
        gridviewList.add(new GridViewEntity(true, "全 部", "1002"+",1003"+",1004"));
        gridviewList.add(new GridViewEntity(false, "平台游戏", 1002+""));
        gridviewList.add(new GridViewEntity(false, "小米游戏", 1004+""));
        gridviewList.add(new GridViewEntity(false, "腾讯游戏", 1003+""));


    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }
}
