package com.sheep.gamegroup.view.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.LinearLayout;

import com.sheep.gamegroup.event.BigEvent;
import com.sheep.gamegroup.absBase.BaseActivity;
import com.sheep.gamegroup.model.entity.DialogConfig;
import com.sheep.gamegroup.util.CommonUtil;
import com.sheep.gamegroup.util.UMConfigUtils;
import com.sheep.gamegroup.util.ViewUtil;
import com.sheep.gamegroup.view.adapter.AdpTryMakemoney;
import com.sheep.gamegroup.view.fragment.FgtMyGame;
import com.sheep.gamegroup.view.fragment.FgtTryMakeMoney;
import com.sheep.jiuyan.samllsheep.R;
import com.sheep.jiuyan.samllsheep.utils.TitleBarUtils;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 游戏任务
 * Created by ljy on 2018/6/12.
 */

public class GamemakeMoneyAct extends BaseActivity {
    @BindView(R.id.indicator)
    TabLayout indicator;
    @BindView(R.id.pager)
    ViewPager pager;
    @BindView(R.id.show_flow_layout)
    LinearLayout show_flow_layout;
    private Activity activity;

    private AdpTryMakemoney mAdapter;
    private String[] titles = new String[]{"推荐任务", "我的游戏"};

    private boolean clickFlag = false;

    private int is_succession;//0:一般任务 1:连续任务

    private String title = "游戏任务";

    private int currentItem;

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

    @Override
    public void initView() {
        activity = this;
        EventBus.getDefault().register(activity);
        is_succession = getIntent()
                .getIntExtra(
                        "is_succession", 0);
        currentItem = getIntent()
                .getIntExtra("current_item", 0);
        TitleBarUtils
                .getInstance()
                .setShowOrHide(this, true)
                .setTitle(activity, title)
                .setTitleFinish(activity)
                .setRightSecondBtn(activity, R.mipmap.question_black_img, new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        ViewUtil.showMsgDialog(activity, new DialogConfig().setTitle("温馨提示").setBtnLeftText("我知道了")
                                .setMsg("该栏目为日常福利，不可提现，不参与好友提成。"));
                    }
                })
                .setRightImgBotton(activity, 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);
                    }
                });

        mAdapter = new AdpTryMakemoney(getSupportFragmentManager(), this);
        mAdapter.add(FgtTryMakeMoney.newInstance(0), titles[0]);
        mAdapter.add(FgtMyGame.newInstance(2), titles[1]);
        pager.setAdapter(mAdapter);
        indicator.setupWithViewPager(pager);

        pager.setCurrentItem(currentItem);
        CommonUtil.getInstance().reflex(indicator, activity);
    }

    @Override
    public void initListener() {
    }

    @Override
    public void initData() {
        show_flow_layout.setVisibility(View.VISIBLE);

    }

    /**
     * 获取is_succession，是否是连续任务
     */
    public int getIsSuccession(){
        return is_succession;
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }

    /**
     * 主要的事件广播接收更新处理
     *
     * @param event
     */
    @Subscribe
    public void onEventMainThread(BigEvent event) {
        switch (event.getEventTypes()) {
            case TIPS_DOWN_ICON:
                TitleBarUtils.getInstance()
                        .setRightRedPoint(activity, View.VISIBLE);
                break;
        }
    }
}
