package com.sheep.gamegroup.view.fragment;

import android.app.Activity;
import android.content.Intent;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.ImageButton;

import com.sheep.gamegroup.util.Jump2View;
import com.sheep.gamegroup.util.UMConfigUtils;
import com.sheep.gamegroup.view.activity.ActDownloadMgr;
import com.sheep.gamegroup.view.activity.ActGameCenter;
import com.sheep.jiuyan.samllsheep.R;
import com.sheep.jiuyan.samllsheep.base.BaseFragment;
import com.sheep.jiuyan.samllsheep.utils.TitleBarUtils;

import butterknife.BindView;

/**
 * Created by realicing on 2018/8/29.
 * realicing@sina.com
 */
public class FgtGameCenter extends BaseFragment {
    @BindView(R.id.act_game_center_vp)
    ViewPager act_game_center_vp;
    @BindView(R.id.fgt_game_center_top)
    View fgt_game_center_top;

    @Override
    public int getLayoutId() {
        return R.layout.fgt_game_center;
    }

    @Override
    public void onViewCreated() {
        activity = getActivity();
        TitleBarUtils.getInstance().setTitleListen(activity, -2, null);
        if (activity instanceof ActGameCenter) {
            fgt_game_center_top.setVisibility(View.GONE);
        }
    }


    private Activity activity;

    @Override
    protected void initViewOnVisibleToUser() {
        final TitleBarUtils titleBarUtils = TitleBarUtils.getInstance();
        titleBarUtils.addTabs(this, act_game_center_vp, "玩转游戏", new FgtPlayGame(), "福利中心", new FgtWelfareCenter(),
                new ViewPager.OnPageChangeListener() {
                    @Override
                    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

                    }

                    @Override
                    public void onPageSelected(int position) {
                        FgtGameCenter.this.onPageSelected(titleBarUtils, position);

                    }

                    @Override
                    public void onPageScrollStateChanged(int state) {

                    }
                });
        onPageSelected(titleBarUtils, 0);

    }

    private void onPageSelected(TitleBarUtils titleBarUtils, int position) {
        switch (position) {
            case 0:
                titleBarUtils
                        .setRightSecondBtn(getView(), R.mipmap.search_black_img, new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                Jump2View.getInstance().goAppSearch(activity, null);
                            }
                        })
                        .setRightImgBotton(getView(), R.drawable.index_download, new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                TitleBarUtils.getInstance()
                                        .setRightRedPoint(activity, View.GONE);
                                startActivity(new Intent(activity, ActDownloadMgr.class));
                                UMConfigUtils.onEvent(UMConfigUtils.Event.GAME_DOWNLOAD_MANAGER);
                            }
                        });
                break;
            case 1:
                ImageButton secondImageButton = findViewById(R.id.ibtn_two_right);

                secondImageButton.setVisibility(View.GONE);
                titleBarUtils.setRightBtn(getView(), "我的福利", 0, new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        // 进入我的福利界面
                        Jump2View.getInstance().goMyWelfare(activity);
                    }
                });
                break;
        }
    }
}
