package com.genlot.ninglottery.game.playtype;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.genlot.ninglottery.R;
import com.genlot.ninglottery.base.BaseDialogActivity;
import com.genlot.ninglottery.event.NewPlayType;
import com.genlot.ninglottery.game.GameManager;
import com.genlot.ninglottery.toolkit.LogTool;
import com.genlot.ninglottery.widget.decoration.GridItemDecoration;

import org.greenrobot.eventbus.EventBus;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import butterknife.BindView;

/**
 * @author ZhuYongKang
 * @description 更多玩法游戏界面
 * @date 2019/10/12
 */
public class MorePlayTypeActivity extends BaseDialogActivity {

    private List<String> mList;
    private PlayTypeAdapter mAdapter;
    String[] names = {"包号", "旋转组合", "包胆", "3D通选", "猜大小", "猜奇偶", "1D", "猜1D", "2D", "猜2D",
            "包选", "包选三", "包选六", "和数", "猜三同", "拖拉机", "直选复式", "组三复式", "组六复式",
            "单选胆拖", "组选胆拖", "组选三胆拖", "组选六胆拖", "跨度单选", "跨度组三", "跨度组六",
            "单选组三复式", "单选组六复式", "单选全组三", "包串"};
    @Override
    public int getLayoutID() {
        return R.layout.activity_play_type;
    }

    @Override
    public void initViews(Bundle savedInstanceState) {
        initData();
        mRecyclerView.setLayoutManager(new GridLayoutManager(this, 5));
        mRecyclerView.addItemDecoration(new GridItemDecoration(20, 20));
        mAdapter = new PlayTypeAdapter(R.layout.item_play_type, mList);
        mRecyclerView.setAdapter(mAdapter);
        mRecyclerView.addOnItemTouchListener(new OnItemClickListener() {
            @Override
            public void onSimpleItemClick(BaseQuickAdapter adapter, View view, int position) {
                String name = mList.get(position);
                int ID = GameManager.getPlayTypeID(name);
                LogTool.logD("select name:" + name + " " + ID);
                EventBus.getDefault().post(new NewPlayType(ID));
                finish();
            }
        });
    }

    private void initData() {
        mList = new ArrayList<>();
        mList.addAll(Arrays.asList(names));
    }

    @BindView(R.id.rv_playType)
    RecyclerView mRecyclerView;

    class PlayTypeAdapter extends BaseQuickAdapter<String, BaseViewHolder>{

        public PlayTypeAdapter(int layoutResId, @Nullable List<String> data) {
            super(layoutResId, data);
        }

        @Override
        protected void convert(@NonNull BaseViewHolder helper, String item) {
            helper.setText(R.id.tv_play_name, item);
        }
    }
}
