|
|
@@ -1,15 +1,19 @@
|
|
|
package com.sheep.gamegroup.view.activity;
|
|
|
|
|
|
+import android.app.Activity;
|
|
|
import android.os.Bundle;
|
|
|
import android.os.Handler;
|
|
|
import android.os.Message;
|
|
|
import android.support.v7.widget.AppCompatEditText;
|
|
|
import android.text.TextUtils;
|
|
|
+import android.util.Log;
|
|
|
import android.view.View;
|
|
|
import android.widget.LinearLayout;
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.sheep.gamegroup.absBase.BaseActivity;
|
|
|
+import com.sheep.gamegroup.di.components.DaggerChangePhoneComponent;
|
|
|
import com.sheep.gamegroup.di.components.DaggerPhoneComponent;
|
|
|
import com.sheep.gamegroup.di.modules.PhoneModule;
|
|
|
import com.sheep.gamegroup.model.entity.BaseMessage;
|
|
|
@@ -20,6 +24,7 @@ import com.sheep.gamegroup.util.Jump2View;
|
|
|
import com.sheep.gamegroup.util.MyDbManager;
|
|
|
import com.sheep.jiuyan.samllsheep.R;
|
|
|
import com.sheep.jiuyan.samllsheep.SheepApp;
|
|
|
+import com.sheep.jiuyan.samllsheep.utils.G;
|
|
|
import com.sheep.jiuyan.samllsheep.utils.TitleBarUtils;
|
|
|
|
|
|
import org.xutils.ex.DbException;
|
|
|
@@ -37,8 +42,6 @@ import butterknife.OnClick;
|
|
|
public class ChangeTelAct extends BaseActivity implements PhoneContract.View{
|
|
|
@BindView(R.id.tel_tv)
|
|
|
TextView telTv;
|
|
|
- @BindView(R.id.change_sure_tv)
|
|
|
- TextView change_sure_tv;
|
|
|
@BindView(R.id.sure_change_tv)
|
|
|
TextView sureTv;
|
|
|
@BindView(R.id.show_change_layout)
|
|
|
@@ -63,14 +66,20 @@ public class ChangeTelAct extends BaseActivity implements PhoneContract.View{
|
|
|
@Inject
|
|
|
PhonePresenter presenter;
|
|
|
|
|
|
+ private Activity activity;
|
|
|
private final int CHANGGE_CLICK = 0;//切换手机按钮点击后
|
|
|
private final int OLD_PHONE_CLICK = 1;//旧手机获取验证码后
|
|
|
|
|
|
private int oldOrNew; //1,绑定过 0,未绑定过
|
|
|
|
|
|
+ private int step = 1; //1、获取旧手机验证码 2、提交旧手机验证码 3、提交新手机号码 4、提交新手机获取的验证码
|
|
|
+ private String sec_code;
|
|
|
+ private String auth_code;
|
|
|
+ private String mobile;
|
|
|
+
|
|
|
private String hitStr = "请输入手机号";
|
|
|
private String noticeStr = "绑定手机号";
|
|
|
- UserEntity userEntity = null;
|
|
|
+ private UserEntity userEntity = null;
|
|
|
|
|
|
Handler handler = new Handler(){
|
|
|
@Override
|
|
|
@@ -95,13 +104,16 @@ public class ChangeTelAct extends BaseActivity implements PhoneContract.View{
|
|
|
@Override
|
|
|
public void initView() {
|
|
|
ButterKnife.bind(this);
|
|
|
+ activity = this;
|
|
|
+ DaggerChangePhoneComponent.builder()
|
|
|
+ .netComponent(SheepApp.get(activity).getNetComponent())
|
|
|
+ .phoneModule(new PhoneModule(this))
|
|
|
+ .build()
|
|
|
+ .inject(this);
|
|
|
|
|
|
-// DaggerPhoneComponent.builder()
|
|
|
-// .netComponent(SheepApp.get(this).getNetComponent())
|
|
|
-// .phoneModule(new PhoneModule(this))
|
|
|
-// .build()
|
|
|
-// .inject(this);
|
|
|
- oldOrNew = 0;
|
|
|
+ TitleBarUtils.getInstance()
|
|
|
+ .setTitle(this, noticeStr)
|
|
|
+ .setTitleFinish(this);
|
|
|
try {
|
|
|
userEntity = MyDbManager.getInstance()
|
|
|
.dbFindUser();
|
|
|
@@ -109,10 +121,7 @@ public class ChangeTelAct extends BaseActivity implements PhoneContract.View{
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
if(userEntity != null && !TextUtils.isEmpty(userEntity.getMobile())){//提示
|
|
|
-
|
|
|
- TitleBarUtils.getInstance()
|
|
|
- .setTitle(this, noticeStr)
|
|
|
- .setTitleFinish(this);
|
|
|
+ oldOrNew = 1;
|
|
|
showChangeLayout.setVisibility(View.VISIBLE);
|
|
|
changePhoneLayout.setVisibility(View.GONE);
|
|
|
telTv.setText(userEntity.getMobile()+"");
|
|
|
@@ -144,45 +153,99 @@ public class ChangeTelAct extends BaseActivity implements PhoneContract.View{
|
|
|
phoneEtAccount.setHint(hitStr+"");
|
|
|
phoneEtAccount.setText(userEntity.getMobile()+"");
|
|
|
}else{
|
|
|
- hitStr = "请输入原手机号码";
|
|
|
- noticeStr = "更换手机号";
|
|
|
+ step = 0;
|
|
|
+ hitStr = "请输入手机号码";
|
|
|
+ noticeStr = "绑定手机号";
|
|
|
phoneEtAccount.setHint(hitStr+"");
|
|
|
+ TitleBarUtils.getInstance()
|
|
|
+ .setTitle(this, noticeStr)
|
|
|
+ .setTitleFinish(this);
|
|
|
}
|
|
|
- TitleBarUtils.getInstance()
|
|
|
- .setTitle(this, noticeStr)
|
|
|
- .setTitleFinish(this);
|
|
|
}
|
|
|
|
|
|
- @OnClick({R.id.change_sure_tv, R.id.phone_btn_code, R.id.phone_sure_tv, R.id.sure_change_tv, R.id.phone_btn_code_old})
|
|
|
+ @OnClick({ R.id.phone_btn_code, R.id.phone_sure_tv, R.id.sure_change_tv, R.id.phone_btn_code_old})
|
|
|
public void onViewClicked(View view) {
|
|
|
switch (view.getId()) {
|
|
|
- case R.id.change_sure_tv:
|
|
|
- break;
|
|
|
case R.id.phone_btn_code:
|
|
|
+ sec_code = null;
|
|
|
+ mobile = phoneEtAccount.getText().toString() +"";
|
|
|
+ if(!checkPhoneInput(mobile)){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(oldOrNew == 0){
|
|
|
+ presenter.getCaptcha(mobile);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ step = 3;
|
|
|
break;
|
|
|
- case R.id.phone_sure_tv:
|
|
|
+ case R.id.phone_sure_tv://更换手机号
|
|
|
+ sec_code = phoneEtCode.getText().toString()+"";
|
|
|
+ if(!checkCodeInput(sec_code)){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if(oldOrNew == 0){
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ jsonObject.put("mobile", mobile+"");
|
|
|
+ jsonObject.put("sec_code", sec_code+"");
|
|
|
+ presenter.bindPhone(jsonObject);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ step = 4;
|
|
|
+ submit();
|
|
|
break;
|
|
|
case R.id.sure_change_tv:
|
|
|
oldOrNew = 1;
|
|
|
handler.sendEmptyMessage(CHANGGE_CLICK);
|
|
|
- if(!checkCodeInput(phone_et_code_old.getText().toString() +"")){
|
|
|
+ sec_code = phone_et_code_old.getText().toString()+"";
|
|
|
+ if(!checkCodeInput(sec_code)){
|
|
|
return;
|
|
|
}
|
|
|
+ step = 2;
|
|
|
+ submit();
|
|
|
// Jump2View.getInstance().goPhoneLoginView(ChangeTelAct.this, 1);
|
|
|
break;
|
|
|
case R.id.phone_btn_code_old://旧手机获取验证码
|
|
|
+ sec_code = null;
|
|
|
+ step = 1;
|
|
|
+ submit();
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 提交
|
|
|
+ */
|
|
|
+ private void submit(){
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ jsonObject.put("step", step+"");
|
|
|
+ switch (step){
|
|
|
+ case 1:
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ jsonObject.put("sec_code", sec_code+"");
|
|
|
+ break;
|
|
|
+ case 3:
|
|
|
+ jsonObject.put("auth_code", auth_code+"");
|
|
|
+ jsonObject.put("mobile", mobile+"");
|
|
|
+ break;
|
|
|
+ case 4:
|
|
|
+ jsonObject.put("sec_code", sec_code+"");
|
|
|
+ jsonObject.put("auth_code", auth_code+"");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ presenter.switchPhone(jsonObject);
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public void returnGaptcha(Object o) {
|
|
|
-
|
|
|
+ Log.e("---Gaptcha-", o.toString());
|
|
|
+// G.showToast(o.getMsg() + "");
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void gaptchaFail(BaseMessage o) {
|
|
|
-
|
|
|
+ G.showToast(o.getMsg() + "");
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -197,12 +260,47 @@ public class ChangeTelAct extends BaseActivity implements PhoneContract.View{
|
|
|
|
|
|
@Override
|
|
|
public void changeTelSuccess(BaseMessage o) {
|
|
|
-
|
|
|
+ try{
|
|
|
+ if(step == 2){
|
|
|
+ refreshData();
|
|
|
+ }else if(step == 4){
|
|
|
+ G.showToast(o.getMsg()+"");
|
|
|
+ finish();
|
|
|
+ }
|
|
|
+ if(o == null){
|
|
|
+ G.showToast("网络错误");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if(o.getData() == null || o.getData().equals("")){
|
|
|
+ G.showToast(o.getMsg()+"");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ G.showToast(o.getMsg()+"");
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(JSONObject.toJSONString(o.getData()));
|
|
|
+ auth_code = jsonObject.getString("auth_code");
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void changeTelFail(BaseMessage o) {
|
|
|
+ if(o == null){
|
|
|
+ G.showToast("网络错误");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ G.showToast(o.getMsg()+"");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void bindTelSuccess(BaseMessage o) {
|
|
|
+ G.showToast(o.getMsg()+"");
|
|
|
+ finish();
|
|
|
+ }
|
|
|
|
|
|
+ @Override
|
|
|
+ public void bindTelFail(BaseMessage o) {
|
|
|
+ G.showToast(o.getMsg()+"");
|
|
|
}
|
|
|
|
|
|
|