package com.sheep.gamegroup.view.activity;

import android.app.Activity;
import android.graphics.drawable.Drawable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.content.ContextCompat;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.kfzs.duanduan.fragment.FgtSignRankings;
import com.sheep.gamegroup.absBase.BaseActivity;
import com.sheep.gamegroup.util.UMConfigUtils;
import com.sheep.jiuyan.samllsheep.R;
import com.sheep.jiuyan.samllsheep.utils.TitleBarUtils;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 本月排行榜
 */

public class SignRankingsAct extends BaseActivity {

    Activity activity;


    @BindView(R.id.sign_ViewPager)
    ViewPager signViewPager;
    @BindView(R.id.sign_tv_ljdl)
    TextView signTvLjdl;
    @BindView(R.id.sign_rl_ljdl)
    RelativeLayout signRlLjdl;
    @BindView(R.id.sign_tv_lxdl)
    TextView signTvLxdl;
    @BindView(R.id.sign_rl_lxdl)
    RelativeLayout signRlLxdl;

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

    @Override
    public void initView() {
        activity = this;
        TitleBarUtils
                .getInstance()
                .setTitle(activity, "本月排行榜")
                .setTitleFinish(activity);


        signViewPager.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {
            @Override
            public Fragment getItem(int position) {
                FgtSignRankings fragment = FgtSignRankings.getInstance(position);
                return fragment;
            }

            @Override
            public int getCount() {
                return 2;
            }
        });
        signViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int i, float v, int i1) {

            }

            @Override
            public void onPageSelected(int i) {
                switch (i){
                    case 0:
                        selectLeft();
                        break;
                    case 1:
                        selectRight();
                        break;
                }
            }

            @Override
            public void onPageScrollStateChanged(int i) {

            }
        });
    }


    @Override
    public void initListener() {}

    @Override
    public void initData() {}


    @OnClick({R.id.sign_rl_ljdl, R.id.sign_rl_lxdl})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.sign_rl_ljdl:
                signViewPager.setCurrentItem(0);
                selectLeft();

                break;
            case R.id.sign_rl_lxdl:
                signViewPager.setCurrentItem(1);
                selectRight();
                break;
        }
    }

    private void selectLeft() {
        signRlLjdl.setBackgroundResource(R.drawable.shape_sign_rankings_left_hold);
        signTvLjdl.setTextColor(ContextCompat.getColor(activity,R.color.white));
        signRlLxdl.setBackgroundResource(R.drawable.shape_sign_rankings_right_normal);
        signTvLxdl.setTextColor(ContextCompat.getColor(activity,R.color.black));


        Drawable drawable= getResources().getDrawable(R.drawable.sign_lxdk_bg);
        drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
        signTvLxdl.setCompoundDrawables(drawable,null,null,null);


        Drawable drawable1= getResources().getDrawable(R.drawable.sign_ljdk_w_bg);
        drawable1.setBounds(0, 0, drawable1.getMinimumWidth(), drawable1.getMinimumHeight());
        signTvLjdl.setCompoundDrawables(drawable1,null,null,null);

        UMConfigUtils.Event.PUNCH_ACCUMULATIVE_LIST.onEvent();
    }
    private void selectRight() {
        signRlLjdl.setBackgroundResource(R.drawable.shape_sign_rankings_left_normal);
        signTvLjdl.setTextColor(ContextCompat.getColor(activity,R.color.black));
        signRlLxdl.setBackgroundResource(R.drawable.shape_sign_rankings_right_hold);
        signTvLxdl.setTextColor(ContextCompat.getColor(activity,R.color.white));

        Drawable drawable2= getResources().getDrawable(R.drawable.sign_lxdk_w_bg);
        drawable2.setBounds(0, 0, drawable2.getMinimumWidth(), drawable2.getMinimumHeight());
        signTvLxdl.setCompoundDrawables(drawable2,null,null,null);


        Drawable drawable3= getResources().getDrawable(R.drawable.sign_ljdk_bg);
        drawable3.setBounds(0, 0, drawable3.getMinimumWidth(), drawable3.getMinimumHeight());
        signTvLjdl.setCompoundDrawables(drawable3,null,null,null);

        UMConfigUtils.Event.PUNCH_CONTINUATION.onEvent();
    }

}
