package com.genlot.ninglottery.game.d3;

import android.content.Intent;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.InputFilter;
import android.text.TextUtils;
import android.view.View;
import android.widget.CompoundButton;
import android.widget.RadioButton;

import com.blankj.utilcode.util.ScreenUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.genlot.ninglottery.R;
import com.genlot.ninglottery.event.NewPlayType;
import com.genlot.ninglottery.game.GameManager;
import com.genlot.ninglottery.game.bet.IBetBean;
import com.genlot.ninglottery.game.bet.BetManager;
import com.genlot.ninglottery.game.bet.BetNumber;
import com.genlot.ninglottery.game.common.CommonFragment;
import com.genlot.ninglottery.game.common.NumberAdapter;
import com.genlot.ninglottery.game.common.SingleView;
import com.genlot.ninglottery.game.d3.bean.BaseBox3;
import com.genlot.ninglottery.game.d3.bean.BaseBox6;
import com.genlot.ninglottery.game.d3.bean.BaseD3;
import com.genlot.ninglottery.game.d3.bean.BetD3;
import com.genlot.ninglottery.game.d3.bean.BitMulti;
import com.genlot.ninglottery.game.d3.bean.BoxSum;
import com.genlot.ninglottery.game.d3.bean.Box3Sum;
import com.genlot.ninglottery.game.d3.bean.Box6Sum;
import com.genlot.ninglottery.game.d3.bean.DifferenceBox3;
import com.genlot.ninglottery.game.d3.bean.DifferenceBox6;
import com.genlot.ninglottery.game.d3.bean.Guess1D;
import com.genlot.ninglottery.game.d3.bean.Guess2D;
import com.genlot.ninglottery.game.d3.bean.Guess3Same;
import com.genlot.ninglottery.game.d3.bean.GuessBG;
import com.genlot.ninglottery.game.d3.bean.GuessOE;
import com.genlot.ninglottery.game.d3.bean.MultiBox3;
import com.genlot.ninglottery.game.d3.bean.MultiBox6;
import com.genlot.ninglottery.game.d3.bean.MultiD3;
import com.genlot.ninglottery.game.d3.bean.OneD;
import com.genlot.ninglottery.game.d3.bean.SingleD3;
import com.genlot.ninglottery.game.d3.bean.StraightBase;
import com.genlot.ninglottery.game.d3.bean.StraightString;
import com.genlot.ninglottery.game.d3.bean.TwoD;
import com.genlot.ninglottery.game.d3.bean.ZuXuan;
import com.genlot.ninglottery.game.d3.bean.ZuXuan3;
import com.genlot.ninglottery.game.d3.bean.ZuXuan6;
import com.genlot.ninglottery.game.d3.betview.BaseD3View;
import com.genlot.ninglottery.game.d3.betview.MultiBoxView;
import com.genlot.ninglottery.game.d3.betview.MultiD3View;
import com.genlot.ninglottery.game.d3.betview.OneRowView;
import com.genlot.ninglottery.game.d3.betview.SingleD3View;
import com.genlot.ninglottery.game.playtype.MorePlayTypeActivity;
import com.genlot.ninglottery.model.PlayTypeID;
import com.genlot.ninglottery.toolkit.GameUtil;
import com.genlot.ninglottery.toolkit.LogTool;
import com.genlot.ninglottery.toolkit.StringTool;
import com.genlot.ninglottery.widget.Diaolog.CommonDialog;
import com.genlot.ninglottery.widget.Diaolog.ViewConvertListener;
import com.genlot.ninglottery.widget.KeyboardEditText;
import com.genlot.ninglottery.widget.decoration.GridItemDecoration;

import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

import butterknife.BindView;
import butterknife.OnCheckedChanged;
import butterknife.OnClick;

/**
 * @author ZhuYongKang
 * @description 3D游戏界面
 * @date 2019/8/22
 */
public class D3Fragment extends CommonFragment {
    private List<BetNumber> mList1, mList2, mList3;
    private NumberAdapter mAdapter1, mAdapter2, mAdapter3;
    private int mDanNum, mTuoNum;

    @OnClick(R.id.radio8)
    public void goAllPlayType() {
        Intent intent = new Intent(activity, MorePlayTypeActivity.class);
        activity.startActivity(intent);
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onNewPlayType(NewPlayType event) {
        int playID = event.getID();
        changePlayType(playID);
    }

    @OnCheckedChanged({R.id.radio1, R.id.radio2, R.id.radio3, R.id.radio4, R.id.radio5,
            R.id.radio6, R.id.radio7, R.id.radio9})
    public void playTypeChanged(CompoundButton buttonView, boolean isChecked) {
        if (isChecked) {
            String playName = buttonView.getText().toString().trim();
            changePlayType(GameManager.getPlayTypeID(playName));
        }
    }

    @Override
    public void changePlayType(int playTypeId) {
        if (mPlayType == playTypeId) {
            return;
        }
        LogTool.logD("changePlayType: " + playTypeId);
        mPlayType = playTypeId;
        BetManager.getInstance().setPlayType(mPlayType);
        frameBet.removeAllViews();
        switch (playTypeId) {
            case PlayTypeID.D3_ZHIXUAN_SINGLE:
                radio1.setChecked(true);
                radio9.setVisibility(View.GONE);
                showCommonNumber();
                changeRandomVisible(true, true);
                mBetView = new SingleD3View(activity, SingleD3.class);
                break;
            case PlayTypeID.D3_ZUXUAN:
                radio2.setChecked(true);
                radio9.setVisibility(View.GONE);
                showCommonNumber();
                changeRandomVisible(true, true);
                mBetView = new SingleD3View(activity, ZuXuan.class);
                break;
            case PlayTypeID.D3_ZUSAN:
                radio6.setChecked(true);
                radio9.setVisibility(View.GONE);
                showCommonNumber();
                changeRandomVisible(true, true);
                mBetView = new SingleD3View(activity, ZuXuan3.class);
                break;
            case PlayTypeID.D3_ZULIU:
                radio7.setChecked(true);
                radio9.setVisibility(View.GONE);
                showCommonNumber();
                changeRandomVisible(true, true);
                mBetView = new SingleD3View(activity, ZuXuan6.class);
                break;
            case PlayTypeID.D3_BOX_SUM:
                radio3.setChecked(true);
                radio9.setVisibility(View.GONE);
                showBoxSumNumber();
                changeRandomVisible(true, false);
                mBetView = new OneRowView(activity, BoxSum.class);
                break;
            case PlayTypeID.D3_BOX3_SUM:
                radio4.setChecked(true);
                radio9.setVisibility(View.GONE);
                showBox3SumNumber();
                changeRandomVisible(true, false);
                mBetView = new OneRowView(activity, Box3Sum.class);
                break;
            case PlayTypeID.D3_BOX6_SUM:
                radio5.setChecked(true);
                radio9.setVisibility(View.GONE);
                showBox6SumNumber();
                changeRandomVisible(true, false);
                mBetView = new OneRowView(activity, Box6Sum.class);
                break;
            case PlayTypeID.D3_ZHIXUAN_BIT_MULTI:
                showRadio9("包号",20);
                showBitMultiNumber();
                changeRandomVisible(true, false);
                mBetView = new OneRowView(activity, BitMulti.class);
                break;
            case PlayTypeID.D3_REVERSE_BOX:
                showRadio9("旋转组合",20);
                showCommonNumber();
                changeRandomVisible(true, false);
                mBetView = new OneRowView(activity, SingleD3.class);
                break;
            case PlayTypeID.D3_STRAIGHT_BASE:
                showRadio9("包胆",20);
                showStraightBaseNumber();
                changeRandomVisible(true, false);
                mBetView = new OneRowView(activity, StraightBase.class);
                ((OneRowView) mBetView).setRandomGone();
                break;
            case PlayTypeID.D3_STRAIGHT_ALL:
                showRadio9("3D通选",20);
                showCommonNumber();
                changeRandomVisible(true, true);
                mBetView = new SingleD3View(activity, SingleD3.class);
                break;
            case PlayTypeID.D3_GUESS_BS:
                showRadio9("猜大小",20);
                showGuessBGNumber();
                changeRandomVisible(true, true);
                mBetView = new SingleD3View(activity, GuessBG.class);
                break;
            case PlayTypeID.D3_GUESS_OE:
                showRadio9("猜奇偶",20);
                showGuessOENumber();
                changeRandomVisible(true, true);
                mBetView = new SingleD3View(activity, GuessOE.class);
                break;
            case PlayTypeID.D3_1D:
                showRadio9("1D",20);
                show1DNumber();
                changeRandomVisible(true, true);
                mBetView = new SingleD3View(activity, OneD.class);
                break;
            case PlayTypeID.D3_2D:
                showRadio9("2D",20);
                show1DNumber();
                changeRandomVisible(true, true);
                mBetView = new SingleD3View(activity, TwoD.class);
                break;
            case PlayTypeID.D3_GUESS_1D:
                showRadio9("猜1D",20);
                showStraightBaseNumber();
                changeRandomVisible(true, true);
                mBetView = new SingleD3View(activity, Guess1D.class);
                break;
            case PlayTypeID.D3_GUESS_2D:
                showRadio9("猜2D",20);
                showGuess2DNumber();
                changeRandomVisible(true, true);
                mBetView = new SingleD3View(activity, Guess2D.class);
                break;
            case PlayTypeID.D3_PACK:
                showRadio9("包选",20);
                showCommonNumber();
                changeRandomVisible(true, true);
                mBetView = new SingleD3View(activity, ZuXuan.class);
                break;
            case PlayTypeID.D3_PACK3:
                showRadio9("包选三",20);
                showCommonNumber();
                changeRandomVisible(true, true);
                mBetView = new SingleD3View(activity, ZuXuan3.class);
                break;
            case PlayTypeID.D3_PACK6:
                showRadio9("包选六",20);
                showCommonNumber();
                changeRandomVisible(true, true);
                mBetView = new SingleD3View(activity, ZuXuan6.class);
                break;
            case PlayTypeID.D3_SUM:
                showRadio9("和数",20);
                showBoxSumNumber();
                changeRandomVisible(true, true);
                mBetView = new SingleD3View(activity, BoxSum.class);
                break;
            case PlayTypeID.D3_GUESS_3SAME:
                showRadio9("猜三同",20);
                showNoNumber();
                changeRandomVisible(false, false);
                mBetView = new OneRowView(activity, Guess3Same.class);
                ((OneRowView) mBetView).setRandomGone();
                ((OneRowView) mBetView).refreshRow();
                break;
            case PlayTypeID.D3_TRACTOR:
                showRadio9("拖拉机",20);
                showNoNumber();
                changeRandomVisible(false, false);
                mBetView = new OneRowView(activity, Guess3Same.class);
                ((OneRowView) mBetView).setRandomGone();
                ((OneRowView) mBetView).refreshRow();
                break;
            case PlayTypeID.D3_MULTI:
                showRadio9("直选复式",20);
                showCommonNumber();
                changeRandomVisible(false, false);
                mBetView = new MultiD3View(activity);
                break;
            case PlayTypeID.D3_MULTI_BOX3:
                showRadio9("组三复式",20);
                showStraightBaseNumber();
                changeRandomVisible(true, false);
                mBetView = new MultiBoxView(activity, MultiBox3.class);
                break;
            case PlayTypeID.D3_MULTI_STRAIGHT_BOX3:
                showRadio9("单选组三复式",16);
                showStraightBaseNumber();
                changeRandomVisible(true, false);
                mBetView = new MultiBoxView(activity, MultiBox3.class);
                break;
            case PlayTypeID.D3_MULTI_BOX6:
                showRadio9("组六复式",20);
                showStraightBaseNumber();
                changeRandomVisible(true, false);
                mBetView = new MultiBoxView(activity, MultiBox6.class);
                break;
            case PlayTypeID.D3_MULTI_STRAIGHT_BOX6:
                showRadio9("单选组六复式",16);
                showStraightBaseNumber();
                changeRandomVisible(true, false);
                mBetView = new MultiBoxView(activity, MultiBox6.class);
                break;
            case PlayTypeID.D3_STRAIGHT_ALL_BOX3:
                showRadio9("单选全组三",18);
                showNoNumber();
                changeRandomVisible(false, false);
                mBetView = new OneRowView(activity, Guess3Same.class);
                ((OneRowView) mBetView).setRandomGone();
                ((OneRowView) mBetView).refreshRow();
                break;
            case PlayTypeID.D3_BASE:
                showRadio9("单选胆拖",20);
                showStraightBaseNumber();
                changeRandomVisible(true, false);
                mBetView = new BaseD3View(activity, BaseD3.class);
                break;
            case PlayTypeID.D3_BASE_BOX:
                showRadio9("组选胆拖",20);
                showStraightBaseNumber();
                changeRandomVisible(true, false);
                mBetView = new BaseD3View(activity, BaseD3.class);
                break;
            case PlayTypeID.D3_BASE_BOX3:
                showRadio9("组选三胆拖",18);
                showStraightBaseNumber();
                changeRandomVisible(true, false);
                mBetView = new BaseD3View(activity, BaseBox3.class);
                break;
            case PlayTypeID.D3_BASE_BOX6:
                showRadio9("组选六胆拖",18);
                showStraightBaseNumber();
                changeRandomVisible(true, false);
                mBetView = new BaseD3View(activity, BaseBox6.class);
                break;
            case PlayTypeID.D3_DIFFERENCE:
                showRadio9("跨度单选",20);
                showDifference3Number();
                changeRandomVisible(true, false);
                mBetView = new OneRowView(activity, DifferenceBox3.class);
                break;
            case PlayTypeID.D3_DIFFERENCE_BOX3:
                showRadio9("跨度组三",20);
                showDifference3Number();
                changeRandomVisible(true, false);
                mBetView = new OneRowView(activity, DifferenceBox3.class);
                break;
            case PlayTypeID.D3_DIFFERENCE_BOX6:
                showRadio9("跨度组六",20);
                showDifference6Number();
                changeRandomVisible(true, false);
                mBetView = new OneRowView(activity, DifferenceBox6.class);
                break;
            case PlayTypeID.D3_STRING:
                showRadio9("包串",20);
                showStraightBaseNumber();
                changeRandomVisible(true, false);
                mBetView = new OneRowView(activity, StraightString.class);
                ((OneRowView) mBetView).setRandomGone();
                ((OneRowView) mBetView).changeBetSize(7, 7, 0);
                break;
        }
        frameBet.addView(mBetView);
        clearUI();
        if (isRandom) {
            clearRandom();
        }
    }

    private void showRadio9(String content,int size) {
        radio9.setText(content);
        radio9.setTextSize(size);
        radio9.setVisibility(View.VISIBLE);
        radio9.setChecked(true);
    }

    private void changeRandomVisible(boolean random1, boolean random5) {
        if (random1 && btRandom.getVisibility() == View.GONE) {
            btRandom.setVisibility(View.VISIBLE);
        }
        if (!random1 && btRandom.getVisibility() == View.VISIBLE) {
            btRandom.setVisibility(View.GONE);
        }
        if (random5 && btRandom5.getVisibility() == View.GONE) {
            btRandom5.setVisibility(View.VISIBLE);
        }
        if (!random5 && btRandom5.getVisibility() == View.VISIBLE) {
            btRandom5.setVisibility(View.GONE);
        }
    }

    /**
     * 猜大小玩法号码界面
     */
    private void showGuessBGNumber() {
        rvNumber2.setVisibility(View.GONE);
        rvNumber3.setVisibility(View.GONE);
        mList1.clear();
        BetNumber number1 = new BetNumber("小");
        mList1.add(number1);
        BetNumber number2 = new BetNumber("大");
        mList1.add(number2);
        mAdapter1.notifyDataSetChanged();
    }

    /**
     * 猜奇偶玩法号码界面
     */
    private void showGuessOENumber() {
        rvNumber2.setVisibility(View.GONE);
        rvNumber3.setVisibility(View.GONE);
        mList1.clear();
        BetNumber number1 = new BetNumber("偶");
        mList1.add(number1);
        BetNumber number2 = new BetNumber("奇");
        mList1.add(number2);
        mAdapter1.notifyDataSetChanged();
    }

    private void showCommonNumber() {
        rvNumber2.setVisibility(View.VISIBLE);
        rvNumber3.setVisibility(View.VISIBLE);
        mList1.clear();
        mList2.clear();
        mList3.clear();
        for (int i = 0; i <= 9; i++) {
            BetNumber number = new BetNumber(String.valueOf(i));
            mList1.add(number);
        }
        for (int i = 0; i <= 9; i++) {
            BetNumber number = new BetNumber(String.valueOf(i));
            mList2.add(number);
        }
        for (int i = 0; i <= 9; i++) {
            BetNumber number = new BetNumber(String.valueOf(i));
            mList3.add(number);
        }
        mAdapter1.notifyDataSetChanged();
        mAdapter2.notifyDataSetChanged();
        mAdapter3.notifyDataSetChanged();
    }

    /**
     * 猜三同
     */
    private void showNoNumber() {
        rvNumber2.setVisibility(View.GONE);
        rvNumber3.setVisibility(View.GONE);
        mList1.clear();
        mAdapter1.notifyDataSetChanged();
    }

    /**
     * 包胆 猜1D 玩法号码界面
     */
    private void showStraightBaseNumber() {
        rvNumber2.setVisibility(View.GONE);
        rvNumber3.setVisibility(View.GONE);
        mList1.clear();
        for (int i = 0; i <= 9; i++) {
            BetNumber number = new BetNumber(String.valueOf(i));
            mList1.add(number);
        }
        mAdapter1.notifyDataSetChanged();
    }

    /**
     * 跨度组三号码界面
     */
    private void showDifference3Number() {
        rvNumber2.setVisibility(View.GONE);
        rvNumber3.setVisibility(View.GONE);
        mList1.clear();
        for (int i = 1; i <= 9; i++) {
            BetNumber number = new BetNumber(String.valueOf(i));
            mList1.add(number);
        }
        mAdapter1.notifyDataSetChanged();
    }

    /**
     * 跨度组六号码界面
     */
    private void showDifference6Number() {
        rvNumber2.setVisibility(View.GONE);
        rvNumber3.setVisibility(View.GONE);
        mList1.clear();
        for (int i = 2; i <= 9; i++) {
            BetNumber number = new BetNumber(String.valueOf(i));
            mList1.add(number);
        }
        mAdapter1.notifyDataSetChanged();
    }

    /**
     * 猜2D 玩法号码界面
     */
    private void showGuess2DNumber() {
        rvNumber2.setVisibility(View.VISIBLE);
        rvNumber3.setVisibility(View.GONE);
        mList1.clear();
        mList2.clear();
        for (int i = 0; i <= 9; i++) {
            BetNumber number = new BetNumber(String.valueOf(i));
            mList1.add(number);
        }
        for (int i = 0; i <= 9; i++) {
            BetNumber number = new BetNumber(String.valueOf(i));
            mList2.add(number);
        }
        mAdapter1.notifyDataSetChanged();
        mAdapter2.notifyDataSetChanged();
    }

    /**
     * 包点 和数 玩法号码界面
     */
    private void showBoxSumNumber() {
        rvNumber2.setVisibility(View.GONE);
        rvNumber3.setVisibility(View.GONE);
        mList1.clear();
        for (int i = 0; i <= 27; i++) {
            BetNumber number = new BetNumber(StringTool.format2(i));
            mList1.add(number);
        }
        mAdapter1.notifyDataSetChanged();
    }

    /**
     * 组三包点玩法号码界面
     */
    private void showBox3SumNumber() {
        rvNumber2.setVisibility(View.GONE);
        rvNumber3.setVisibility(View.GONE);
        mList1.clear();
        for (int i = 1; i <= 26; i++) {
            BetNumber number = new BetNumber(StringTool.format2(i));
            mList1.add(number);
        }
        mAdapter1.notifyDataSetChanged();
    }

    /**
     * 组六包点玩法号码界面
     */
    private void showBox6SumNumber() {
        rvNumber2.setVisibility(View.GONE);
        rvNumber3.setVisibility(View.GONE);
        mList1.clear();
        for (int i = 3; i <= 24; i++) {
            BetNumber number = new BetNumber(StringTool.format2(i));
            mList1.add(number);
        }
        mAdapter1.notifyDataSetChanged();
    }

    /**
     * 包号玩法号码界面
     */
    private void showBitMultiNumber() {
        rvNumber2.setVisibility(View.VISIBLE);
        rvNumber3.setVisibility(View.VISIBLE);
        mList1.clear();
        mList2.clear();
        mList3.clear();
        for (int i = 0; i <= 9; i++) {
            BetNumber number = new BetNumber(String.valueOf(i));
            mList1.add(number);
        }
        mList1.add(new BetNumber("*"));
        for (int i = 0; i <= 9; i++) {
            BetNumber number = new BetNumber(String.valueOf(i));
            mList2.add(number);
        }
        mList2.add(new BetNumber("*"));
        for (int i = 0; i <= 9; i++) {
            BetNumber number = new BetNumber(String.valueOf(i));
            mList3.add(number);
        }
        mList3.add(new BetNumber("*"));
        mAdapter1.notifyDataSetChanged();
        mAdapter2.notifyDataSetChanged();
        mAdapter3.notifyDataSetChanged();
    }

    /**
     * 1D 2D玩法号码界面
     */
    private void show1DNumber() {
        rvNumber2.setVisibility(View.VISIBLE);
        rvNumber3.setVisibility(View.VISIBLE);
        mList1.clear();
        mList2.clear();
        mList3.clear();
        for (int i = 0; i <= 9; i++) {
            BetNumber number = new BetNumber(String.valueOf(i));
            mList1.add(number);
        }
        mList1.add(new BetNumber("-"));
        for (int i = 0; i <= 9; i++) {
            BetNumber number = new BetNumber(String.valueOf(i));
            mList2.add(number);
        }
        mList2.add(new BetNumber("-"));
        for (int i = 0; i <= 9; i++) {
            BetNumber number = new BetNumber(String.valueOf(i));
            mList3.add(number);
        }
        mList3.add(new BetNumber("-"));
        mAdapter1.notifyDataSetChanged();
        mAdapter2.notifyDataSetChanged();
        mAdapter3.notifyDataSetChanged();
    }

    @Override
    public int getLayoutResId() {
        return R.layout.fragment_3d;
    }

    @Override
    public void initData() {
        mList1 = new ArrayList<>();
        mList2 = new ArrayList<>();
        mList3 = new ArrayList<>();
    }

    @Override
    public void initAdapter() {
        rvNumber1.setLayoutManager(new GridLayoutManager(activity, 8));
        rvNumber1.addItemDecoration(new GridItemDecoration(20, 10));
        rvNumber2.setLayoutManager(new GridLayoutManager(activity, 8));
        rvNumber2.addItemDecoration(new GridItemDecoration(20, 10));
        rvNumber3.setLayoutManager(new GridLayoutManager(activity, 8));
        rvNumber3.addItemDecoration(new GridItemDecoration(20, 10));
        mAdapter1 = new NumberAdapter(R.layout.item_number, mList1);
        mAdapter2 = new NumberAdapter(R.layout.item_number, mList2);
        mAdapter3 = new NumberAdapter(R.layout.item_number, mList3);
        rvNumber1.setAdapter(mAdapter1);
        rvNumber2.setAdapter(mAdapter2);
        rvNumber3.setAdapter(mAdapter3);
        rvNumber1.addOnItemTouchListener(new OnItemClickListener() {
            @Override
            public void onSimpleItemClick(BaseQuickAdapter adapter, View view, int position) {
                BetNumber betNumber = mList1.get(position);
                onNumber1Click(betNumber);
            }
        });
        rvNumber2.addOnItemTouchListener(new OnItemClickListener() {
            @Override
            public void onSimpleItemClick(BaseQuickAdapter adapter, View view, int position) {
                BetNumber betNumber = mList2.get(position);
                onNumber2Click(betNumber);
            }
        });
        rvNumber3.addOnItemTouchListener(new OnItemClickListener() {
            @Override
            public void onSimpleItemClick(BaseQuickAdapter adapter, View view, int position) {
                BetNumber betNumber = mList3.get(position);
                onNumber3Click(betNumber);
            }
        });
    }

    @Override
    public void initViews() {
        if (!isFromCopy) {
            radio1.setChecked(true);
        }
    }

    private void singleClick(BetNumber number, int index) {
        int type = number.getType();
        SingleD3 bean = (SingleD3) ((SingleView) mBetView).getCurrentBet();
        if (type == BetNumber.NORMAL) {
            if (index == 0 && bean.mList1.size() == 1) {
                return;
            }
            if (index == 1 && bean.mList2.size() == 1) {
                return;
            }
            if (index == 2 && bean.mList3.size() == 1) {
                return;
            }
            number.setType(BetNumber.CHECKED);
            bean.add(number, index);
        }else {
            bean.remove(number, index);
            number.setType(BetNumber.NORMAL);
        }
        ((SingleView) mBetView).refreshRow(mBetView.mCurrentRow);
        if (bean.isFull() && mBetView.mCurrentRow < 4) {
            mBetView.rowChange(mBetView.mCurrentRow + 1);
            refreshAdapter(((SingleView) mBetView).getCurrentBet());
        }
    }

    private void boxClick(BetNumber number, int index) {
        int type = number.getType();
        String num = number.getNumber();
        ZuXuan bean = (ZuXuan) ((SingleView) mBetView).getCurrentBet();
        if (type == BetNumber.NORMAL) {
            if (index == 0) {
                if (bean.mList1.size() == 1) {
                    return;
                }
                if (bean.contains(bean.mList2, num) && bean.contains(bean.mList3, num)) {
                    showTips("该玩法不能3个号码相同");
                    return;
                }
            } else if (index == 1) {
                if (bean.mList2.size() == 1) {
                    return;
                }
                if (bean.contains(bean.mList1, num) && bean.contains(bean.mList3, num)) {
                    showTips("该玩法不能3个号码相同");
                    return;
                }
            } else {
                if (bean.mList3.size() == 1) {
                    return;
                }
                if (bean.contains(bean.mList1, num) && bean.contains(bean.mList2, num)) {
                    showTips("该玩法不能3个号码相同");
                    return;
                }
            }
            number.setType(BetNumber.CHECKED);
            bean.add(number, index);
        }else {
            bean.remove(number, index);
            number.setType(BetNumber.NORMAL);
        }
        ((SingleView) mBetView).refreshRow(mBetView.mCurrentRow);
        if (bean.isFull() && mBetView.mCurrentRow < 4) {
            mBetView.rowChange(mBetView.mCurrentRow + 1);
            refreshAdapter(((SingleView) mBetView).getCurrentBet());
        }
    }

    private void box3Click(BetNumber number, int index) {
        int type = number.getType();
        String num = number.getNumber();
        ZuXuan bean = (ZuXuan) ((SingleView) mBetView).getCurrentBet();
        if (type == BetNumber.NORMAL) {
            if (index == 0) {
                if (bean.mList1.size() == 1) {
                    return;
                }
                if (bean.contains(bean.mList2, num) && bean.contains(bean.mList3, num)) {
                    showTips("该玩法必须2个号码相同");
                    return;
                }
                if (bean.mList2.size() == 1 && bean.mList3.size() == 1
                        && !bean.mList2.get(0).getNumber().equals(bean.mList3.get(0).getNumber())
                        && !bean.contains(num)) {
                    showTips("该玩法必须2个号码相同");
                    return;
                }
            } else if (index == 1) {
                if (bean.mList2.size() == 1) {
                    return;
                }
                if (bean.contains(bean.mList1, num) && bean.contains(bean.mList3, num)) {
                    showTips("该玩法必须2个号码相同");
                    return;
                }
                if (bean.mList1.size() == 1 && bean.mList3.size() == 1
                        && !bean.mList1.get(0).getNumber().equals(bean.mList3.get(0).getNumber())
                        && !bean.contains(num)) {
                    showTips("该玩法必须2个号码相同");
                    return;
                }
            } else {
                if (bean.mList3.size() == 1) {
                    return;
                }
                if (bean.contains(bean.mList1, num) && bean.contains(bean.mList2, num)) {
                    showTips("该玩法必须2个号码相同");
                    return;
                }
                if (bean.mList2.size() == 1 && bean.mList1.size() == 1
                        && !bean.mList2.get(0).getNumber().equals(bean.mList1.get(0).getNumber())
                        && !bean.contains(num)) {
                    showTips("该玩法必须2个号码相同");
                    return;
                }
            }
            number.setType(BetNumber.CHECKED);
            bean.add(number, index);
        }else {
            bean.remove(number, index);
            number.setType(BetNumber.NORMAL);
        }
        ((SingleView) mBetView).refreshRow(mBetView.mCurrentRow);
        if (bean.isFull() && mBetView.mCurrentRow < 4) {
            mBetView.rowChange(mBetView.mCurrentRow + 1);
            refreshAdapter(((SingleView) mBetView).getCurrentBet());
        }
    }

    private void box6Click(BetNumber number, int index) {
        int type = number.getType();
        String num = number.getNumber();
        ZuXuan bean = (ZuXuan) ((SingleView) mBetView).getCurrentBet();
        if (type == BetNumber.NORMAL) {
            if (index == 0) {
                if (bean.mList1.size() == 1) {
                    return;
                }
            } else if (index == 1) {
                if (bean.mList2.size() == 1) {
                    return;
                }
            } else {
                if (bean.mList3.size() == 1) {
                    return;
                }
            }
            if (bean.contains(num)) {
                showTips("该玩法必须3个号码不同");
                return;
            }
            number.setType(BetNumber.CHECKED);
            bean.add(number, index);
        }else {
            bean.remove(number, index);
            number.setType(BetNumber.NORMAL);
        }
        ((SingleView) mBetView).refreshRow(mBetView.mCurrentRow);
        if (bean.isFull() && mBetView.mCurrentRow < 4) {
            mBetView.rowChange(mBetView.mCurrentRow + 1);
            refreshAdapter(((SingleView) mBetView).getCurrentBet());
        }
    }

    private void bitMultiClick(BetNumber number, int index) {
        int type = number.getType();
        String num = number.getNumber();
        BitMulti bitMulti = (BitMulti) ((OneRowView) mBetView).getCurrentBet();
        if (type == BetNumber.NORMAL) {
            if (index == 0) {
                if (bitMulti.mList1.size() == 1) {
                    return;
                }
                if (bitMulti.mList2.size() == 1 && bitMulti.mList3.size() == 1 && !num.equals("*") &&
                        !bitMulti.hasStar(bitMulti.mList2) && !bitMulti.hasStar(bitMulti.mList3)) {
                    showTips("该玩法必须有一位为*");
                    return;
                }
            } else if (index == 1) {
                if (bitMulti.mList2.size() == 1) {
                    return;
                }
                if (bitMulti.mList1.size() == 1 && bitMulti.mList3.size() == 1 && !num.equals("*") &&
                        !bitMulti.hasStar(bitMulti.mList1) && !bitMulti.hasStar(bitMulti.mList3)) {
                    showTips("该玩法必须有一位为*");
                    return;
                }
            } else {
                if (bitMulti.mList3.size() == 1) {
                    return;
                }
                if (bitMulti.mList1.size() == 1 && bitMulti.mList2.size() == 1 && !num.equals("*") &&
                        !bitMulti.hasStar(bitMulti.mList1) && !bitMulti.hasStar(bitMulti.mList2)) {
                    showTips("该玩法必须有一位为*");
                    return;
                }
            }

            number.setType(BetNumber.CHECKED);
            bitMulti.add(number, index);
        }else {
            bitMulti.remove(number, index);
            number.setType(BetNumber.NORMAL);
        }
        ((OneRowView) mBetView).refreshRow();
    }

    private void oneDClick(BetNumber number, int index) {
        int type = number.getType();
        String num = number.getNumber();
        OneD bean = (OneD) ((SingleView) mBetView).getCurrentBet();
        if (type == BetNumber.NORMAL) {
            if (index == 0) {
                if (bean.mList1.size() == 1) {
                    return;
                }
            } else if (index == 1) {
                if (bean.mList2.size() == 1) {
                    return;
                }
            } else {
                if (bean.mList3.size() == 1) {
                    return;
                }
            }
            //点击数字时 自动选择其余俩个-号码
            if (bean.getAllNumberList().size() <= 1 && !num.equals("-")) {
                int lineNumber = bean.getLineNumber();
                if (bean.getAllNumberList().size() == 1 && lineNumber == 0  ) {
                    showTips("该玩法只能有一位数字");
                    return;
                }
                if (index == 0) {
                    number.setType(BetNumber.CHECKED);
                    bean.add(number, index);
                    mList2.get(10).setType(BetNumber.CHECKED);
                    bean.add(mList2.get(10), 1);
                    mList3.get(10).setType(BetNumber.CHECKED);
                    bean.add(mList3.get(10), 2);
                    mAdapter2.notifyDataSetChanged();
                    mAdapter3.notifyDataSetChanged();
                } else if (index == 1) {
                    number.setType(BetNumber.CHECKED);
                    bean.add(number, index);
                    mList1.get(10).setType(BetNumber.CHECKED);
                    bean.add(mList1.get(10), 0);
                    mList3.get(10).setType(BetNumber.CHECKED);
                    bean.add(mList3.get(10), 2);
                    mAdapter1.notifyDataSetChanged();
                    mAdapter3.notifyDataSetChanged();
                } else if (index == 2) {
                    number.setType(BetNumber.CHECKED);
                    bean.add(number, index);
                    mList1.get(10).setType(BetNumber.CHECKED);
                    bean.add(mList1.get(10), 0);
                    mList2.get(10).setType(BetNumber.CHECKED);
                    bean.add(mList2.get(10), 1);
                    mAdapter1.notifyDataSetChanged();
                    mAdapter2.notifyDataSetChanged();
                }
            } else {
                int lineNumber = bean.getLineNumber();
                if (lineNumber == 2 && num.equals("-")) {
                    showTips("该玩法必须有一位数字");
                    return;
                }
                if (lineNumber == 1 && !num.equals("-")) {
                    showTips("该玩法只能有一位数字");
                    return;
                }
                number.setType(BetNumber.CHECKED);
                bean.add(number, index);
            }
        }else {
            bean.remove(number, index);
            number.setType(BetNumber.NORMAL);
        }
        ((SingleView) mBetView).refreshRow(mBetView.mCurrentRow);
        if (bean.isFull() && mBetView.mCurrentRow < 4) {
            mBetView.rowChange(mBetView.mCurrentRow + 1);
            refreshAdapter(((SingleView) mBetView).getCurrentBet());
        }
    }

    private void twoDClick(BetNumber number, int index) {
        int type = number.getType();
        String num = number.getNumber();
        TwoD bean = (TwoD) ((SingleView) mBetView).getCurrentBet();
        if (type == BetNumber.NORMAL) {
            int lineNumber = bean.getLineNumber();
            if (index == 0) {
                if (bean.mList1.size() == 1) {
                    return;
                }
            } else if (index == 1) {
                if (bean.mList2.size() == 1) {
                    return;
                }
            } else {
                if (bean.mList3.size() == 1) {
                    return;
                }
            }
            if (lineNumber == 1 && num.equals("-")) {
                showTips("该玩法必须有2个数字");
                return;
            }
            if (bean.getAllNumberList().size() == 2 && lineNumber == 0 && !num.equals("-")) {
                showTips("该玩法必须有1个-");
                return;
            }
            number.setType(BetNumber.CHECKED);
            bean.add(number, index);
        }else {
            bean.remove(number, index);
            number.setType(BetNumber.NORMAL);
        }
        ((SingleView) mBetView).refreshRow(mBetView.mCurrentRow);
        if (bean.isFull() && mBetView.mCurrentRow < 4) {
            mBetView.rowChange(mBetView.mCurrentRow + 1);
            refreshAdapter(((SingleView) mBetView).getCurrentBet());
        }
    }

    private void guess2DClick(BetNumber number, int index) {
        Guess2D bean = (Guess2D) ((SingleView) mBetView).getCurrentBet();
        if (number.getType() == BetNumber.NORMAL) {
            if (index == 0 && bean.mList1.size() == 1) {
                return;
            }
            if (index == 1 && bean.mList2.size() == 1) {
                return;
            }
            number.setType(BetNumber.CHECKED);
            bean.add(number, index);
        }else {
            bean.remove(number, index);
            number.setType(BetNumber.NORMAL);
        }
        ((SingleView) mBetView).refreshRow(mBetView.mCurrentRow);
        if (bean.isFull() && mBetView.mCurrentRow < 4) {
            mBetView.rowChange(mBetView.mCurrentRow + 1);
            refreshAdapter(((SingleView) mBetView).getCurrentBet());
        }
    }

    private void reverseBoxClick(BetNumber number, int index) {
        int type = number.getType();
        SingleD3 bean = (SingleD3) ((OneRowView) mBetView).getCurrentBet();
        if (type == BetNumber.NORMAL) {
            if (bean.mList1.size() ==1 && index == 0) {
                return;
            }
            if (bean.mList2.size() ==1 && index == 1) {
                return;
            }
            if (bean.mList3.size() ==1 && index == 2) {
                return;
            }
            number.setType(BetNumber.CHECKED);
            bean.add(number, index);
        } else {
            bean.remove(number, index);
            number.setType(BetNumber.NORMAL);
        }
        ((OneRowView) mBetView).refreshRow();
    }

    private void multiClick(BetNumber number, int index) {
        int type = number.getType();
        MultiD3 bean = (MultiD3) ((MultiD3View) mBetView).mBetList.get(0);
        if (type == BetNumber.NORMAL) {
            number.setType(BetNumber.CHECKED);
            bean.add(number, index);
        }else {
            bean.remove(number, index);
            number.setType(BetNumber.NORMAL);
        }
        if (index == 0) {
            ((MultiD3View) mBetView).refreshBai();
            if (mBetView.mCurrentRow != 0) {
                mBetView.rowChange(0);
            }
        } else if (index == 1) {
            ((MultiD3View) mBetView).refreshShi();
            if (mBetView.mCurrentRow != 1) {
                mBetView.rowChange(1);
            }
        } else {
            ((MultiD3View) mBetView).refreshGe();
            if (mBetView.mCurrentRow != 2) {
                mBetView.rowChange(2);
            }
        }
    }

    private void multiBoxClick(BetNumber number) {
        BoxSum bean = (BoxSum) ((MultiBoxView) mBetView).mBetList.get(0);
        if (number.getType() == BetNumber.NORMAL) {
            number.setType(BetNumber.CHECKED);
            bean.add(number);
        } else {
            bean.remove(number);
            number.setType(BetNumber.NORMAL);
        }
        ((MultiBoxView) mBetView).refreshRow();
    }

    private void stringClick(BetNumber number) {
        BoxSum bean = (BoxSum) ((MultiBoxView) mBetView).mBetList.get(0);
        if (number.getType() == BetNumber.NORMAL) {
            if (bean.mList.size() == 7) {
                return;
            }
            number.setType(BetNumber.CHECKED);
            bean.add(number);
        } else {
            bean.remove(number);
            number.setType(BetNumber.NORMAL);
        }
        ((MultiBoxView) mBetView).refreshRow();
    }

    private void baseClick(BetNumber number) {
        int type = number.getType();
        BaseD3 bean = (BaseD3) ((BaseD3View) mBetView).mBetList.get(0);
        if (mBetView.mCurrentRow == 0) {
            if (type == BetNumber.NORMAL || type == BetNumber.CHECKED) {
                if (bean.mDanList.size() == 2) {
                    return;
                }
                number.setType(BetNumber.DAN);
                if (type == BetNumber.NORMAL) {
                    bean.add(number);
                } else {
                    bean.change(number);
                }
                ((BaseD3View) mBetView).refreshDan();
                ((BaseD3View) mBetView).refreshTuo();
            } else {
                if (bean.mDanList.size() == 2) {
                    if (number.isBase()) {
                        bean.mDanList.clear();
                    } else {
                        bean.remove(number);
                    }
                    number.setType(BetNumber.NORMAL);
                    number.setBase(false);
                } else {
                    bean.add(number);
                    number.setBase(true);
                }
                ((BaseD3View) mBetView).refreshDan();
            }
        } else {
            if (type == BetNumber.NORMAL || type == BetNumber.DAN) {
                if (bean.mTuoList.size() == 9) {
                    return;
                }
                number.setType(BetNumber.CHECKED);
                if (type == BetNumber.NORMAL) {
                    bean.add(number);
                } else {
                    bean.change(number);
                    if (number.isBase()) {
                        bean.mDanList.clear();
                        number.setBase(false);
                    }
                }
                ((BaseD3View) mBetView).refreshDan();
                ((BaseD3View) mBetView).refreshTuo();
            } else {
                bean.remove(number);
                number.setType(BetNumber.NORMAL);
                ((BaseD3View) mBetView).refreshTuo();
            }
        }
    }

    private void baseBox3Click(BetNumber number) {
        int type = number.getType();
        BaseD3 bean = (BaseD3) ((BaseD3View) mBetView).mBetList.get(0);
        if (mBetView.mCurrentRow == 0) {
            //两胆必须相同
            if (type == BetNumber.NORMAL || type == BetNumber.CHECKED) {
                if (bean.mDanList.size() == 2) {
                    return;
                }
                if (bean.mDanList.size() == 1) {
                    showTips("该玩法两胆必须相同");
                    return;
                }
                number.setType(BetNumber.DAN);
                if (type == BetNumber.NORMAL) {
                    bean.add(number);
                } else {
                    bean.change(number);
                }
                ((BaseD3View) mBetView).refreshDan();
                ((BaseD3View) mBetView).refreshTuo();
            } else {
                if (bean.mDanList.size() == 2) {
                    if (number.isBase()) {
                        bean.mDanList.clear();
                    } else {
                        bean.remove(number);
                    }
                    number.setType(BetNumber.NORMAL);
                    number.setBase(false);
                } else {
                    bean.add(number);
                    number.setBase(true);
                }
                ((BaseD3View) mBetView).refreshDan();
            }
        } else {
            if (type == BetNumber.NORMAL || type == BetNumber.DAN) {
                if (bean.mTuoList.size() == 9) {
                    return;
                }
                number.setType(BetNumber.CHECKED);
                if (type == BetNumber.NORMAL) {
                    bean.add(number);
                } else {
                    bean.change(number);
                    if (number.isBase()) {
                        bean.mDanList.clear();
                        number.setBase(false);
                    }
                }
                ((BaseD3View) mBetView).refreshDan();
                ((BaseD3View) mBetView).refreshTuo();
            } else {
                bean.remove(number);
                number.setType(BetNumber.NORMAL);
                ((BaseD3View) mBetView).refreshTuo();
            }
        }
    }

    private void baseBox6Click(BetNumber number) {
        int type = number.getType();
        BaseD3 bean = (BaseD3) ((BaseD3View) mBetView).mBetList.get(0);
        if (mBetView.mCurrentRow == 0) {
            if (type == BetNumber.NORMAL || type == BetNumber.CHECKED) {
                if (bean.mDanList.size() == 2) {
                    return;
                }
                number.setType(BetNumber.DAN);
                if (type == BetNumber.NORMAL) {
                    bean.add(number);
                } else {
                    bean.change(number);
                }
                ((BaseD3View) mBetView).refreshDan();
                ((BaseD3View) mBetView).refreshTuo();
            } else {
                bean.remove(number);
                number.setType(BetNumber.NORMAL);
                ((BaseD3View) mBetView).refreshDan();
            }
        } else {
            if (type == BetNumber.NORMAL || type == BetNumber.DAN) {
                if (bean.mTuoList.size() == 9) {
                    return;
                }
                number.setType(BetNumber.CHECKED);
                if (type == BetNumber.NORMAL) {
                    bean.add(number);
                } else {
                    bean.change(number);
                }
                ((BaseD3View) mBetView).refreshDan();
                ((BaseD3View) mBetView).refreshTuo();
            } else {
                bean.remove(number);
                number.setType(BetNumber.NORMAL);
                ((BaseD3View) mBetView).refreshTuo();
            }
        }
    }

    private void onNumber1Click(BetNumber number) {
        switch (mPlayType) {
            case PlayTypeID.D3_ZHIXUAN_SINGLE:
            case PlayTypeID.D3_STRAIGHT_ALL:
                singleClick(number, 0);
                break;
            //组选 不能3个号相同
            case PlayTypeID.D3_ZUXUAN:
            case PlayTypeID.D3_PACK:
                boxClick(number, 0);
                break;
            case PlayTypeID.D3_ZUSAN:
            case PlayTypeID.D3_PACK3:
                box3Click(number, 0);
                break;
            case PlayTypeID.D3_ZULIU:
            case PlayTypeID.D3_PACK6:
                box6Click(number, 0);
                break;
            //包点玩法
            case PlayTypeID.D3_BOX_SUM:
            case PlayTypeID.D3_BOX3_SUM:
            case PlayTypeID.D3_BOX6_SUM:
            case PlayTypeID.D3_DIFFERENCE:
            case PlayTypeID.D3_DIFFERENCE_BOX3:
            case PlayTypeID.D3_DIFFERENCE_BOX6:
                BoxSum boxSumBean = (BoxSum) ((OneRowView) mBetView).getCurrentBet();
                if (number.getType() == BetNumber.NORMAL) {
                    if (boxSumBean.isFull()) {
                        return;
                    }
                    number.setType(BetNumber.CHECKED);
                    boxSumBean.add(number);
                } else {
                    boxSumBean.remove(number);
                    number.setType(BetNumber.NORMAL);
                }
                ((OneRowView) mBetView).refreshRow();
                break;
            //包号 必须有一个*
            case PlayTypeID.D3_ZHIXUAN_BIT_MULTI:
                bitMultiClick(number, 0);
                break;
            //旋转组合
            case PlayTypeID.D3_REVERSE_BOX:
                reverseBoxClick(number, 0);
                break;
            //包胆
            case PlayTypeID.D3_STRAIGHT_BASE:
                StraightBase straightBase = (StraightBase) ((OneRowView) mBetView).getCurrentBet();
                if (number.getType() == BetNumber.NORMAL) {
                    if (straightBase.mList.size() == 2) {
                        return;
                    }
                    number.setType(BetNumber.DAN);
                    straightBase.add(number);
                } else if (number.getType() == BetNumber.DAN) {
                    if (straightBase.mList.size() == 2) {
                        if (number.isBase()) {
                            straightBase.clear();
                        } else {
                            straightBase.remove(number);
                        }
                        number.setType(BetNumber.NORMAL);
                        number.setBase(false);
                    } else {
                        number.setBase(true);
                        straightBase.add(number);
                    }
                }
                ((OneRowView) mBetView).refreshRow();
                break;
            //猜大小 奇偶 1D 和数
            case PlayTypeID.D3_GUESS_BS:
            case PlayTypeID.D3_GUESS_OE:
            case PlayTypeID.D3_GUESS_1D:
            case PlayTypeID.D3_SUM:
                BoxSum guessBG = (BoxSum) ((SingleView) mBetView).getCurrentBet();
                if (number.getType() == BetNumber.NORMAL) {
                    if (guessBG.isFull()) {
                        return;
                    }
                    number.setType(BetNumber.CHECKED);
                    guessBG.add(number);
                } else {
                    guessBG.remove(number);
                    number.setType(BetNumber.NORMAL);
                }
                ((SingleView) mBetView).refreshRow(mBetView.mCurrentRow);
                if (guessBG.isFull() && mBetView.mCurrentRow < 4) {
                    mBetView.rowChange(mBetView.mCurrentRow + 1);
                    refreshAdapter(((SingleView) mBetView).getCurrentBet());
                }
                break;
            case PlayTypeID.D3_1D:
                oneDClick(number, 0);
                break;
            case PlayTypeID.D3_2D:
                twoDClick(number, 0);
                break;
            case PlayTypeID.D3_GUESS_2D:
                guess2DClick(number, 0);
                break;
            case PlayTypeID.D3_MULTI:
                multiClick(number, 0);
                break;
            case PlayTypeID.D3_MULTI_BOX3:
            case PlayTypeID.D3_MULTI_BOX6:
            case PlayTypeID.D3_MULTI_STRAIGHT_BOX3:
            case PlayTypeID.D3_MULTI_STRAIGHT_BOX6:
                multiBoxClick(number);
                break;
            case PlayTypeID.D3_STRING:
                stringClick(number);
                break;
            case PlayTypeID.D3_BASE:
            case PlayTypeID.D3_BASE_BOX:
                baseClick(number);
                break;
            case PlayTypeID.D3_BASE_BOX3:
                baseBox3Click(number);
                break;
            case PlayTypeID.D3_BASE_BOX6:
                baseBox6Click(number);
                break;
            default: break;
        }
        mAdapter1.notifyDataSetChanged();
        refreshMoney();
    }

    private void onNumber2Click(BetNumber number) {
        switch (mPlayType) {
            case PlayTypeID.D3_ZHIXUAN_SINGLE:
            case PlayTypeID.D3_STRAIGHT_ALL:
                singleClick(number, 1);
                break;
            //组选 不能3个号相同
            case PlayTypeID.D3_ZUXUAN:
            case PlayTypeID.D3_PACK:
                boxClick(number, 1);
                break;
            case PlayTypeID.D3_ZUSAN:
            case PlayTypeID.D3_PACK3:
                box3Click(number, 1);
                break;
            case PlayTypeID.D3_ZULIU:
            case PlayTypeID.D3_PACK6:
                box6Click(number, 1);
                break;
            //包号 必须有一个*
            case PlayTypeID.D3_ZHIXUAN_BIT_MULTI:
                bitMultiClick(number, 1);
                break;
            case PlayTypeID.D3_REVERSE_BOX:
                reverseBoxClick(number, 1);
                break;
            case PlayTypeID.D3_1D:
                oneDClick(number, 1);
                break;
            case PlayTypeID.D3_2D:
                twoDClick(number, 1);
                break;
            case PlayTypeID.D3_GUESS_2D:
                guess2DClick(number, 1);
                break;
            case PlayTypeID.D3_MULTI:
                multiClick(number, 1);
                break;
        }
        mAdapter2.notifyDataSetChanged();
        refreshMoney();
    }

    private void onNumber3Click(BetNumber number) {
        switch (mPlayType) {
            case PlayTypeID.D3_ZHIXUAN_SINGLE:
            case PlayTypeID.D3_STRAIGHT_ALL:
                singleClick(number, 2);
                break;
            //组选 不能3个号相同
            case PlayTypeID.D3_ZUXUAN:
            case PlayTypeID.D3_PACK:
                boxClick(number, 2);
                break;
            case PlayTypeID.D3_ZUSAN:
            case PlayTypeID.D3_PACK3:
                box3Click(number, 2);
                break;
            case PlayTypeID.D3_ZULIU:
            case PlayTypeID.D3_PACK6:
                box6Click(number, 2);
                break;
            //包号 必须有一个*
            case PlayTypeID.D3_ZHIXUAN_BIT_MULTI:
                bitMultiClick(number, 2);
                break;
            case PlayTypeID.D3_REVERSE_BOX:
                reverseBoxClick(number, 2);
                break;
            case PlayTypeID.D3_1D:
                oneDClick(number, 2);
                break;
            case PlayTypeID.D3_2D:
                twoDClick(number, 2);
                break;
            case PlayTypeID.D3_MULTI:
                multiClick(number, 2);
                break;
        }
        mAdapter3.notifyDataSetChanged();
        refreshMoney();
    }

    @Override
    public int getMaxTimes() {
        return D3Config.MAX_TIMES;
    }

    @Override
    public int getOneBetMoney() {
        return D3Config.MONEY_OF_BET;
    }

    @Override
    public long getValidBets() {
        long num = 0;
        switch (mPlayType) {
            case PlayTypeID.D3_ZHIXUAN_SINGLE:
            case PlayTypeID.D3_ZUXUAN:
            case PlayTypeID.D3_ZUSAN:
            case PlayTypeID.D3_ZULIU:
            case PlayTypeID.D3_STRAIGHT_ALL:
            case PlayTypeID.D3_GUESS_BS:
            case PlayTypeID.D3_GUESS_OE:
            case PlayTypeID.D3_1D:
            case PlayTypeID.D3_GUESS_1D:
            case PlayTypeID.D3_2D:
            case PlayTypeID.D3_GUESS_2D:
            case PlayTypeID.D3_PACK:
            case PlayTypeID.D3_PACK3:
            case PlayTypeID.D3_PACK6:
            case PlayTypeID.D3_SUM:
            case PlayTypeID.D3_GUESS_3SAME:
            case PlayTypeID.D3_TRACTOR:
                for (IBetBean bean : mBetView.mBetList) {
                    if (bean.isFull()) {
                        num++;
                    }
                }
                break;
            case PlayTypeID.D3_BOX_SUM:
                BoxSum boxSum = (BoxSum) mBetView.mBetList.get(0);
                if (boxSum.mList.size() == 1) {
                    int sum = Integer.parseInt(boxSum.mList.get(0).getNumber());
                    num = GameUtil.getBoxSumBets(sum);
                }
                break;
            case PlayTypeID.D3_BOX3_SUM:
                BoxSum box3Sum = (BoxSum) mBetView.mBetList.get(0);
                if (box3Sum.mList.size() == 1) {
                    int sum = Integer.parseInt(box3Sum.mList.get(0).getNumber());
                    num = GameUtil.getBox3SumBets(sum);
                }
                break;
            case PlayTypeID.D3_BOX6_SUM:
                BoxSum box6Sum = (BoxSum) mBetView.mBetList.get(0);
                if (box6Sum.mList.size() == 1) {
                    int sum = Integer.parseInt(box6Sum.mList.get(0).getNumber());
                    num = GameUtil.getBox6SumBets(sum);
                }
                break;
            case PlayTypeID.D3_ZHIXUAN_BIT_MULTI:
                BitMulti bitMulti = (BitMulti) mBetView.mBetList.get(0);
                if (bitMulti.isFull()) {
                    num = 1;
                    if (bitMulti.hasStar(bitMulti.mList1)) {
                        num *= 10;
                    }
                    if (bitMulti.hasStar(bitMulti.mList2)) {
                        num *= 10;
                    }
                    if (bitMulti.hasStar(bitMulti.mList3)) {
                        num *= 10;
                    }
                }
                break;
            case PlayTypeID.D3_REVERSE_BOX:
                SingleD3 reverseBox = (SingleD3) mBetView.mBetList.get(0);
                if (reverseBox.isFull()) {
                    int num1 = Integer.parseInt(reverseBox.mList1.get(0).getNumber());
                    int num2 = Integer.parseInt(reverseBox.mList2.get(0).getNumber());
                    int num3 = Integer.parseInt(reverseBox.mList3.get(0).getNumber());
                    if (num1 == num2 && num1 == num3) {
                        num = 1;
                    } else if (num1 == num2 || num1 == num3 || num2 == num3) {
                        num = 3;
                    } else {
                        num = 6;
                    }
                }
                break;
            case PlayTypeID.D3_STRAIGHT_BASE:
                StraightBase straightBase = (StraightBase) ((OneRowView) mBetView).getCurrentBet();
                if (straightBase.mList.size() == 1) {
                    num = 271;
                } else if (straightBase.mList.size() == 2) {
                    num = 54;
                }
                break;
            case PlayTypeID.D3_MULTI:
                MultiD3 multiD3 = (MultiD3) mBetView.mBetList.get(0);
                if (multiD3.isFull()) {
                    num = multiD3.mList1.size() * multiD3.mList2.size() * multiD3.mList3.size();
                }
                break;
            case PlayTypeID.D3_MULTI_BOX3:
                MultiBox3 multiBox3 = (MultiBox3) mBetView.mBetList.get(0);
                if (multiBox3.isFull()) {
                    num = 2 * GameUtil.C(multiBox3.mList.size(), 2);
                }
                break;
            case PlayTypeID.D3_MULTI_BOX6:
                MultiBox6 multiBox6 = (MultiBox6) mBetView.mBetList.get(0);
                if (multiBox6.isFull()) {
                    num = GameUtil.C(multiBox6.mList.size(), 3);
                }
                break;
            case PlayTypeID.D3_MULTI_STRAIGHT_BOX3:
                MultiBox3 multiStraightBox3 = (MultiBox3) mBetView.mBetList.get(0);
                if (multiStraightBox3.isFull()) {
                    num = 3 * 2 * GameUtil.C(multiStraightBox3.mList.size(), 2);
                }
                break;
            case PlayTypeID.D3_MULTI_STRAIGHT_BOX6:
                MultiBox6 multiStraightBox6 = (MultiBox6) mBetView.mBetList.get(0);
                if (multiStraightBox6.isFull()) {
                    num = 6 * GameUtil.C(multiStraightBox6.mList.size(), 3);
                }
                break;
            case PlayTypeID.D3_BASE:
                BaseD3 baseD3 = (BaseD3) mBetView.mBetList.get(0);
                if (baseD3.isFull()) {
                    int danSize = baseD3.mDanList.size();
                    int tuoSize = baseD3.mTuoList.size();
                    if (danSize == 1) {
                        num = 6 * GameUtil.C(tuoSize, 2) + 1 + 3 * 2 * tuoSize;
                    } else if (danSize == 2) {
                        if (baseD3.isSameDan()) {
                            num = 3 * tuoSize + 1;
                        } else {
                            num = 6 + 6 * tuoSize;
                        }
                    }
                }
                break;
            case PlayTypeID.D3_BASE_BOX:
                BaseD3 baseBox = (BaseD3) mBetView.mBetList.get(0);
                if (baseBox.isFull()) {
                    int danSize = baseBox.mDanList.size();
                    int tuoSize = baseBox.mTuoList.size();
                    if (danSize == 1) {
                        num = GameUtil.C(tuoSize, 2) + 1 + 2 * tuoSize;
                    } else if (danSize == 2) {
                        if (baseBox.isSameDan()) {
                            num = tuoSize + 1;
                        } else {
                            num = tuoSize + 2;
                        }
                    }
                }
                break;
            case PlayTypeID.D3_BASE_BOX3:
                BaseD3 baseBox3 = (BaseD3) mBetView.mBetList.get(0);
                if (baseBox3.isFull()) {
                    int danSize = baseBox3.mDanList.size();
                    int tuoSize = baseBox3.mTuoList.size();
                    if (danSize == 1) {
                        num = 2 * tuoSize;
                    } else if (danSize == 2) {
                        num = tuoSize;
                    }
                }
                break;
            case PlayTypeID.D3_BASE_BOX6:
                BaseD3 baseBox6 = (BaseD3) mBetView.mBetList.get(0);
                if (baseBox6.isFull()) {
                    int danSize = baseBox6.mDanList.size();
                    int tuoSize = baseBox6.mTuoList.size();
                    if (danSize == 1) {
                        num = GameUtil.C(tuoSize, 2);
                    } else if (danSize == 2) {
                        num = tuoSize;
                    }
                }
                break;
            case PlayTypeID.D3_DIFFERENCE:
                BoxSum difference = (BoxSum) mBetView.mBetList.get(0);
                if (difference.isFull()) {
                    int diff = Integer.parseInt(difference.mList.get(0).getNumber());
                    if (diff == 0) {
                        num = 10;
                    } else {
                        num = (9 - diff + 1) * (6 + 6 * (diff - 1));
                    }
                }
                break;
            case PlayTypeID.D3_DIFFERENCE_BOX3:
                BoxSum difference3 = (BoxSum) mBetView.mBetList.get(0);
                if (difference3.isFull()) {
                    int diff = Integer.parseInt(difference3.mList.get(0).getNumber());
                    num = (9 - diff + 1) * (2);
                }
                break;
            case PlayTypeID.D3_DIFFERENCE_BOX6:
                BoxSum difference6 = (BoxSum) mBetView.mBetList.get(0);
                if (difference6.isFull()) {
                    int diff = Integer.parseInt(difference6.mList.get(0).getNumber());
                    num = (9 - diff + 1) * (diff - 1);
                }
                break;
            case PlayTypeID.D3_STRAIGHT_ALL_BOX3:
                num = 270;
                break;
            case PlayTypeID.D3_STRING:
                StraightString straightString = (StraightString) mBetView.mBetList.get(0);
                if (straightString.isFull()) {
                    int size = straightString.mList.size();
                    num = size * size * size;
                }
                break;
            default: break;
        }
        return num;
    }

    @Override
    public void refreshAdapter(IBetBean betBean) {
        switch (mPlayType) {
            case PlayTypeID.D3_ZHIXUAN_SINGLE:
            case PlayTypeID.D3_ZUXUAN:
            case PlayTypeID.D3_ZUSAN:
            case PlayTypeID.D3_ZULIU:
            case PlayTypeID.D3_ZHIXUAN_BIT_MULTI:
            case PlayTypeID.D3_REVERSE_BOX:
            case PlayTypeID.D3_STRAIGHT_ALL:
            case PlayTypeID.D3_1D:
            case PlayTypeID.D3_2D:
            case PlayTypeID.D3_PACK:
            case PlayTypeID.D3_PACK3:
            case PlayTypeID.D3_PACK6:
            case PlayTypeID.D3_MULTI:
                mAdapter1.changeD3Bet(((BetD3) betBean).mList1, 0);
                mAdapter2.changeD3Bet(((BetD3) betBean).mList2, 0);
                mAdapter3.changeD3Bet(((BetD3) betBean).mList3, 0);
                break;
            case PlayTypeID.D3_BOX_SUM:
            case PlayTypeID.D3_GUESS_BS:
            case PlayTypeID.D3_GUESS_OE:
            case PlayTypeID.D3_GUESS_1D:
            case PlayTypeID.D3_SUM:
            case PlayTypeID.D3_MULTI_BOX3:
            case PlayTypeID.D3_MULTI_BOX6:
            case PlayTypeID.D3_MULTI_STRAIGHT_BOX3:
            case PlayTypeID.D3_MULTI_STRAIGHT_BOX6:
            case PlayTypeID.D3_STRING:
                mAdapter1.changeD3Bet(((BoxSum) betBean).mList, 0);
                break;
            case PlayTypeID.D3_BOX3_SUM:
            case PlayTypeID.D3_DIFFERENCE:
            case PlayTypeID.D3_DIFFERENCE_BOX3:
                mAdapter1.changeD3Bet(((BoxSum) betBean).mList, 1);
                break;
            case PlayTypeID.D3_DIFFERENCE_BOX6:
                mAdapter1.changeD3Bet(((BoxSum) betBean).mList, 2);
                break;
            case PlayTypeID.D3_BOX6_SUM:
                mAdapter1.changeD3Bet(((BoxSum) betBean).mList, 3);
                break;
            case PlayTypeID.D3_STRAIGHT_BASE:
                mAdapter1.changeD3StraightBase(((BoxSum) betBean).mList);
                break;
            case PlayTypeID.D3_GUESS_2D:
                mAdapter1.changeD3Bet(((Guess2D) betBean).mList1, 0);
                mAdapter2.changeD3Bet(((Guess2D) betBean).mList2, 0);
                break;
            case PlayTypeID.D3_BASE:
            case PlayTypeID.D3_BASE_BOX:
            case PlayTypeID.D3_BASE_BOX3:
            case PlayTypeID.D3_BASE_BOX6:
                mAdapter1.changeD3BaseBet(((BaseD3) betBean));
                break;
        }
    }

    @Override
    public void clearAdapter() {
        mAdapter1.clear();
        mAdapter2.clear();
        mAdapter3.clear();
    }

    @Override
    public void random() {
        switch (mPlayType) {
            case PlayTypeID.D3_ZHIXUAN_SINGLE:
            case PlayTypeID.D3_ZUXUAN:
            case PlayTypeID.D3_ZUSAN:
            case PlayTypeID.D3_ZULIU:
            case PlayTypeID.D3_STRAIGHT_ALL:
            case PlayTypeID.D3_GUESS_BS:
            case PlayTypeID.D3_GUESS_OE:
            case PlayTypeID.D3_1D:
            case PlayTypeID.D3_GUESS_1D:
            case PlayTypeID.D3_2D:
            case PlayTypeID.D3_GUESS_2D:
            case PlayTypeID.D3_PACK:
            case PlayTypeID.D3_PACK3:
            case PlayTypeID.D3_PACK6:
            case PlayTypeID.D3_SUM:
                if (isRandom) {
                    randomNum(mRandomNum);
                } else {
                    showSingleRandomDialog();
                }
                break;
            case PlayTypeID.D3_BOX_SUM:
            case PlayTypeID.D3_BOX3_SUM:
            case PlayTypeID.D3_BOX6_SUM:
            case PlayTypeID.D3_ZHIXUAN_BIT_MULTI:
            case PlayTypeID.D3_REVERSE_BOX:
            case PlayTypeID.D3_DIFFERENCE:
            case PlayTypeID.D3_DIFFERENCE_BOX3:
            case PlayTypeID.D3_DIFFERENCE_BOX6:
                IBetBean bean = mBetView.mBetList.get(0);
                bean.random();
                ((OneRowView) mBetView).refreshRow();
                refreshAdapter(bean);
                refreshMoney();
                break;
            case PlayTypeID.D3_STRAIGHT_BASE:
                if (isRandom) {
                    randomMulti();
                } else {
                    showStraightBaseRandomDialog();
                }
                break;
            case PlayTypeID.D3_MULTI_BOX3:
            case PlayTypeID.D3_MULTI_BOX6:
            case PlayTypeID.D3_MULTI_STRAIGHT_BOX3:
            case PlayTypeID.D3_MULTI_STRAIGHT_BOX6:
            case PlayTypeID.D3_STRING:
                if (isRandom) {
                    randomMulti();
                } else {
                    showMultiRandomDialog();
                }
                break;
            case PlayTypeID.D3_BASE:
            case PlayTypeID.D3_BASE_BOX:
            case PlayTypeID.D3_BASE_BOX3:
            case PlayTypeID.D3_BASE_BOX6:
                if (isRandom) {
                    randomBaseRound();
                } else {
                    showBaseRoundRandomDialog();
                }
                break;
        }
    }

    private void randomMulti() {
        IBetBean bean = mBetView.mBetList.get(0);
        bean.random(mRandomNum);
        ((MultiBoxView) mBetView).refreshRow();
        refreshAdapter(bean);
        refreshMoney();
    }

    private void randomBaseRound() {
        BaseD3 bean = (BaseD3) mBetView.mBetList.get(0);
        bean.random(mDanNum, mTuoNum);
        ((BaseD3View) mBetView).refreshDan();
        ((BaseD3View) mBetView).refreshTuo();
        refreshAdapter(bean);
        refreshMoney();
    }

    public void showBaseRoundRandomDialog() {
        CommonDialog.newInstance().setLayoutId(R.layout.dialog_random_comom)
                .setConvertListener((ViewConvertListener) (holder, dialog) -> {
                    holder.setViewVisibility(R.id.ll_random3, false);
                    KeyboardEditText etDan = holder.getView(R.id.et_dan);
                    KeyboardEditText etTuo= holder.getView(R.id.et_tuo);
                    holder.setOnClickListener(R.id.bt_cancel, v -> dialog.dismiss());
                    holder.setOnClickListener(R.id.bt_confirm, v -> {
                        String dan = etDan.getText().toString().trim();
                        String tuo = etTuo.getText().toString().trim();
                        BaseD3 bean = (BaseD3) mBetView.mBetList.get(0);
                        if (TextUtils.isEmpty(dan) || Integer.parseInt(dan) < bean.getMinDanSize()
                                || Integer.parseInt(dan) > bean.getMaxDanSize()) {
                            showTips(String.format(Locale.getDefault(),
                                    "胆个数超界 个数范围[%d-%d]", bean.getMinDanSize(), bean.getMaxDanSize()));
                            dialog.dismiss();
                            return;
                        }
                        if (TextUtils.isEmpty(tuo)|| Integer.parseInt(tuo) < bean.getMinTuoSize()
                                || Integer.parseInt(tuo) > bean.getMaxTuoSize()) {
                            showTips(String.format(Locale.getDefault(),
                                    "拖个数超界 个数范围[%d-%d]", bean.getMinTuoSize(), bean.getMaxTuoSize()));
                            dialog.dismiss();
                            return;
                        }
                        if ((Integer.parseInt(dan) + Integer.parseInt(tuo)) < bean.getMinSize()
                            ||(Integer.parseInt(dan) + Integer.parseInt(tuo)) > bean.getMaxSize()) {
                            showTips(String.format(Locale.getDefault(),
                                    "胆+拖个数超界 个数范围[%d-%d]", bean.getMinSize(), bean.getMaxSize()));
                            dialog.dismiss();
                            return;
                        }
                        isRandom = true;
                        mDanNum = Integer.parseInt(dan);
                        mTuoNum = Integer.parseInt(tuo);
                        randomBaseRound();
                        showTips("");
                        dialog.dismiss();
                    });
                })
                .setSize(ScreenUtils.getScreenWidth(), ScreenUtils.getScreenHeight())
                .setOutCancel(false)
                .show(activity.getSupportFragmentManager());
    }

    public void showMultiRandomDialog() {
        CommonDialog.newInstance().setLayoutId(R.layout.dialog_random_single)
                .setConvertListener((ViewConvertListener) (holder, dialog) -> {
                    holder.setViewVisibility(R.id.textView6, false);
                    holder.setText(R.id.textView5, "包号数");
                    KeyboardEditText etNum= holder.getView(R.id.et_bets);
                    etNum.setFilters(new InputFilter[]{new InputFilter.LengthFilter(2)});
                    holder.setOnClickListener(R.id.bt_cancel, v -> dialog.dismiss());
                    holder.setOnClickListener(R.id.bt_confirm, v -> {
                        String num = etNum.getText().toString().trim();
                        MultiBox3 bean = (MultiBox3) mBetView.mBetList.get(0);
                        if (TextUtils.isEmpty(num) || Integer.parseInt(num) < bean.getMinSize()
                                || Integer.parseInt(num) > bean.getMaxSize()) {
                            showTips(String.format(Locale.getDefault(),"包号号码个数范围[%d-%d]",bean.getMinSize(),bean.getMaxSize()));
                            dialog.dismiss();
                            return;
                        }
                        isRandom = true;
                        mRandomNum = Integer.parseInt(num);
                        randomMulti();
                        showTips("");
                        dialog.dismiss();
                    });
                })
                .setSize(ScreenUtils.getScreenWidth(), ScreenUtils.getScreenHeight())
                .setOutCancel(false)
                .show(activity.getSupportFragmentManager());
    }

    private void showStraightBaseRandomDialog() {
        CommonDialog.newInstance().setLayoutId(R.layout.dialog_random_single)
                .setConvertListener((ViewConvertListener) (holder, dialog) -> {
                    KeyboardEditText etBets = holder.getView(R.id.et_bets);
                    holder.setViewVisibility(R.id.textView6, false);
                    holder.setText(R.id.textView5, "胆数");
                    etBets.setFilters(new InputFilter[]{new InputFilter.LengthFilter(2)});
                    holder.setOnClickListener(R.id.bt_cancel, v -> dialog.dismiss());
                    holder.setOnClickListener(R.id.bt_confirm, v -> {
                        String bets = etBets.getText().toString().trim();
                        if (TextUtils.isEmpty(bets)) {
                            etBets.setError("胆数不能为空");
                            return;
                        }
                        if (Integer.parseInt(bets) > 2) {
                            showTips("胆数范围超界[1-2]");
                            dialog.dismiss();
                            return;
                        }
                        mRandomNum = Integer.parseInt(bets);
                        randomMulti();
                        isRandom = true;
                        dialog.dismiss();
                    });
                })
                .setSize(ScreenUtils.getScreenWidth(), ScreenUtils.getScreenHeight())
                .setOutCancel(false)
                .show(activity.getSupportFragmentManager());
    }

    @BindView(R.id.rv_number1)
    RecyclerView rvNumber1;
    @BindView(R.id.rv_number2)
    RecyclerView rvNumber2;
    @BindView(R.id.rv_number3)
    RecyclerView rvNumber3;
    @BindView(R.id.radio1)
    RadioButton radio1;
    @BindView(R.id.radio2)
    RadioButton radio2;
    @BindView(R.id.radio3)
    RadioButton radio3;
    @BindView(R.id.radio4)
    RadioButton radio4;
    @BindView(R.id.radio5)
    RadioButton radio5;
    @BindView(R.id.radio6)
    RadioButton radio6;
    @BindView(R.id.radio7)
    RadioButton radio7;
    @BindView(R.id.radio9)
    RadioButton radio9;
}
