|
|
@@ -0,0 +1,144 @@
|
|
|
+package com.sheep.gamegroup.module.game.util;
|
|
|
+
|
|
|
+import android.app.Dialog;
|
|
|
+import android.content.Context;
|
|
|
+import android.text.TextUtils;
|
|
|
+import android.view.LayoutInflater;
|
|
|
+import android.view.View;
|
|
|
+import android.widget.TextView;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.sheep.gamegroup.model.entity.BaseMessage;
|
|
|
+import com.sheep.gamegroup.model.entity.GameEntity;
|
|
|
+import com.sheep.gamegroup.model.entity.UserEntity;
|
|
|
+import com.sheep.gamegroup.model.util.SheepSubscriber;
|
|
|
+import com.sheep.gamegroup.util.DataUtil;
|
|
|
+import com.sheep.gamegroup.util.RxjavaCountDownTimer;
|
|
|
+import com.sheep.gamegroup.util.ViewUtil;
|
|
|
+import com.sheep.groups.creditcard.RegexUtils;
|
|
|
+import com.sheep.jiuyan.samllsheep.R;
|
|
|
+import com.sheep.jiuyan.samllsheep.SheepApp;
|
|
|
+import com.sheep.jiuyan.samllsheep.utils.G;
|
|
|
+
|
|
|
+import butterknife.BindView;
|
|
|
+import butterknife.ButterKnife;
|
|
|
+import butterknife.OnClick;
|
|
|
+import io.reactivex.android.schedulers.AndroidSchedulers;
|
|
|
+import io.reactivex.schedulers.Schedulers;
|
|
|
+
|
|
|
+public class GameAppointHelper {
|
|
|
+
|
|
|
+ private GameEntity game;
|
|
|
+
|
|
|
+ private Context context;
|
|
|
+
|
|
|
+ @BindView(R.id.mobile_view)
|
|
|
+ TextView mobile_view;
|
|
|
+ @BindView(R.id.code_view)
|
|
|
+ TextView code_view;
|
|
|
+ @BindView(R.id.get_code_btn)
|
|
|
+ TextView get_code_btn;
|
|
|
+
|
|
|
+ boolean hasMobile = false;
|
|
|
+
|
|
|
+ public GameAppointHelper(Context context, GameEntity game) {
|
|
|
+ this.context = context;
|
|
|
+ this.game = game;
|
|
|
+ hasMobile = DataUtil.getInstance().getUserEntity().isBindMobile();
|
|
|
+ }
|
|
|
+
|
|
|
+ public void showAppointDialog() {
|
|
|
+ View content = bindView();
|
|
|
+ ViewUtil.showConfirmDialog(context, "请输入手机号", content, "取消", "提交预约", false, (dialog) -> {
|
|
|
+ if (!RegexUtils.isMobileSimple(mobile_view.getText().toString())) {
|
|
|
+ G.showToast("请输入正确的手机号");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (!hasMobile) {
|
|
|
+ if (TextUtils.isEmpty(code_view.getText().toString())) {
|
|
|
+ G.showToast("请输入验证码");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ appoint(dialog);
|
|
|
+ }).show();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void appoint(Dialog dialog) {
|
|
|
+ JSONObject json = new JSONObject();
|
|
|
+ json.put("app_id", game.getApp().getId());
|
|
|
+ json.put("mobile", mobile_view.getText().toString());
|
|
|
+ if (!hasMobile) {
|
|
|
+ json.put("captcha", code_view.getText().toString());
|
|
|
+ }
|
|
|
+ SheepApp.getInstance()
|
|
|
+ .getNetComponent()
|
|
|
+ .getApiService()
|
|
|
+ .appointGame(json)
|
|
|
+ .subscribeOn(Schedulers.io())
|
|
|
+ .observeOn(AndroidSchedulers.mainThread())
|
|
|
+ .subscribe(new SheepSubscriber<BaseMessage>(context) {
|
|
|
+ @Override
|
|
|
+ public void onError(BaseMessage baseMessage) {
|
|
|
+ G.showToast(baseMessage);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onNext(BaseMessage baseMessage) {
|
|
|
+ G.showToast("预约成功");
|
|
|
+ dialog.dismiss();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private View bindView() {
|
|
|
+ View view = LayoutInflater.from(context).inflate(R.layout.dialog_game_appoint, null, false);
|
|
|
+ ButterKnife.bind(this, view);
|
|
|
+ if (hasMobile) {
|
|
|
+ ViewUtil.setVisibility(code_view, !hasMobile);
|
|
|
+ ViewUtil.setVisibility(get_code_btn, !hasMobile);
|
|
|
+ }
|
|
|
+ return view;
|
|
|
+ }
|
|
|
+
|
|
|
+ @OnClick(R.id.get_code_btn)
|
|
|
+ void getCode() {
|
|
|
+ if (!RegexUtils.isMobileSimple(mobile_view.getText().toString())) {
|
|
|
+ G.showToast("请输入正确的手机号");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ JSONObject json = new JSONObject();
|
|
|
+ json.put("mobile", mobile_view.getText().toString());
|
|
|
+ SheepApp.getInstance().getNetComponent().getApiService().sendCommonCaptcha(json)
|
|
|
+ .subscribeOn(Schedulers.io())
|
|
|
+ .observeOn(AndroidSchedulers.mainThread())
|
|
|
+ .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.getInstance()) {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onNext(BaseMessage baseMessage) {
|
|
|
+ ViewUtil.setEnabled(get_code_btn, false);
|
|
|
+ G.shortToast("验证码已发送");
|
|
|
+ RxjavaCountDownTimer.getInstance(60)
|
|
|
+ .setOnTickListener(new RxjavaCountDownTimer.OnTickListener() {
|
|
|
+ @Override
|
|
|
+ public void onFinish() {
|
|
|
+ ViewUtil.setEnabled(get_code_btn, true);
|
|
|
+ ViewUtil.setText(get_code_btn, "获取验证码");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onTicker(long time) {
|
|
|
+ ViewUtil.setText(get_code_btn, (time / 1000) + "秒");
|
|
|
+ }
|
|
|
+ }).start();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onError(BaseMessage baseMessage) {
|
|
|
+ G.showToast(baseMessage);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+}
|