package com.sheep.gamegroup.view.activity;

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

import com.sheep.gamegroup.absBase.BaseActivity;
import com.sheep.gamegroup.event.BigEvent;
import com.sheep.gamegroup.model.entity.DialogConfig;
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.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;

/**
 * 试着赚钱页面
 * Created by ljy on 2018/3/10.
 */

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

    private AdpTryMakemoney mAdapter;

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

    private String title;

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

    @Override
    public void initView() {
        activity = this;
        EventBus.getDefault().register(activity);
        is_succession = getIntent()
                .getIntExtra(
                        "is_succession", 0);
        if (is_succession == 1) {
            title = "连续奖励";
        } else {
            title = "试玩赚钱";
        }
        TitleBarUtils
                .getInstance()
                .setTitle(activity, title).setTitleFinish(activity)
                .setShowOrHide(this, true)
                .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(TryMakeMoneyact.this, ActDownloadMgr.class));
                        UMConfigUtils.onEvent(UMConfigUtils.Event.GAME_DOWNLOAD_MANAGER);
                    }
                });

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

        indicator.setVisibility(View.GONE);
    }

    @Override
    public void initListener() {
    }

    @Override
    public void initData() {
        //真tm神经病 需求改了无数次
    }

    /**
     * 获取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:
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        TitleBarUtils.getInstance()
                                .setRightRedPoint(activity, View.VISIBLE);
                    }
                });
                break;
        }
    }
}
