package com.sheep.gamegroup.view.fragment;

import android.app.Activity;
import android.content.Intent;
import android.provider.MediaStore;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;

import com.kfzs.duanduan.utils.NumberFormatUtils;
import com.sheep.gamegroup.model.entity.ArticleTag;
import com.sheep.gamegroup.model.entity.BaseMessage;
import com.sheep.gamegroup.model.util.SheepSubscriber;
import com.sheep.gamegroup.util.CommonUtil;
import com.sheep.gamegroup.util.DataUtil;
import com.sheep.gamegroup.util.Jump2View;
import com.sheep.gamegroup.util.ListUtil;
import com.sheep.gamegroup.util.UMConfigUtils;
import com.sheep.gamegroup.util.ViewUtil;
import com.sheep.gamegroup.view.activity.ActDownloadMgr;
import com.sheep.gamegroup.view.activity.ActMain;
import com.sheep.gamegroup.view.adapter.TitleFragmentListAdapter;
import com.sheep.jiuyan.samllsheep.R;
import com.sheep.jiuyan.samllsheep.SheepApp;
import com.sheep.jiuyan.samllsheep.base.BaseFragment;
import com.sheep.jiuyan.samllsheep.utils.G;

import org.afinal.simplecache.ApiKey;

import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import rx.functions.Action1;

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

/**
 * Created by realicing on 2018/6/27.
 * realicing@sina.com
 * 主页--发现模块
 */
public class FgtGameCenter extends BaseFragment {

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

    @Override
    public void onViewCreated() {
        initView();
    }

    @BindView(R.id.indicator)
    TabLayout indicator;
    @BindView(R.id.pager)
    ViewPager pager;
    @BindView(R.id.back_btn)
    ImageButton backBtn;
    @BindView(R.id.download_btn)
    ImageButton downloadBtn;
    @BindView(R.id.search_btn)
    ImageButton searchBtn;
    @BindView(R.id.my_walfare_btn)
    Button myWalfareBtn;

    private TitleFragmentListAdapter mAdapter;

    private void initView() {
        backBtn.setVisibility((getActivity() instanceof ActMain) ? View.GONE : View.VISIBLE);
        mAdapter = new TitleFragmentListAdapter(getChildFragmentManager());
        mAdapter.add(new FgtPlayGame(), "玩转游戏");
        mAdapter.add(new FgtWelfareCenter(), "福利中心");
        pager.setAdapter(mAdapter);
        indicator.setupWithViewPager(pager);
        pager.setOffscreenPageLimit(3);
        pager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int i, float v, int i1) {

            }

            @Override
            public void onPageSelected(int i) {
                downloadBtn.setVisibility(i == 0 ? View.VISIBLE : View.GONE);
                searchBtn.setVisibility(i == 0 ? View.VISIBLE : View.GONE);
                myWalfareBtn.setVisibility(i == 0 ? View.GONE : View.VISIBLE);
            }

            @Override
            public void onPageScrollStateChanged(int i) {

            }
        });
    }

    private void initData() {
    }

    @Override
    public void initDataOnVisibleToUser() {

    }

    @Override
    public void onResume() {
        super.onResume();
    }

    @OnClick(R.id.back_btn)
    public void doBack(View v) {
        getActivity().finish();
    }

    @OnClick(R.id.download_btn)
    public void doDownload(View v) {
        startActivity(new Intent(getContext(), ActDownloadMgr.class));
        UMConfigUtils.onEvent(UMConfigUtils.Event.GAME_DOWNLOAD_MANAGER);
    }

    @OnClick(R.id.search_btn)
    public void doSearch(View v) {
        Jump2View.getInstance().goAppSearch(getActivity(), null);
    }

    @OnClick(R.id.my_walfare_btn)
    public void doGoMyWalfare(View v) {
        Jump2View.getInstance().goMyWelfare(getActivity());
    }

}
