|
|
@@ -1,9 +1,12 @@
|
|
|
package com.sheep.gamegroup.module.login;
|
|
|
|
|
|
import android.app.Activity;
|
|
|
+import android.content.Context;
|
|
|
+import android.content.Intent;
|
|
|
import android.os.Bundle;
|
|
|
import android.support.v4.app.Fragment;
|
|
|
import android.support.v4.app.FragmentTransaction;
|
|
|
+import android.text.TextUtils;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.sheep.gamegroup.absBase.BaseActivity;
|
|
|
@@ -12,7 +15,9 @@ import com.sheep.gamegroup.model.entity.UserEntity;
|
|
|
import com.sheep.gamegroup.model.util.SheepSubscriber;
|
|
|
import com.sheep.gamegroup.module.login.controller.ChangePasswordController;
|
|
|
import com.sheep.gamegroup.module.login.fragments.BindAccountFgt;
|
|
|
+import com.sheep.gamegroup.module.login.fragments.Captcha4ForgetFgt;
|
|
|
import com.sheep.gamegroup.module.login.fragments.NewPasswordFgt;
|
|
|
+import com.sheep.gamegroup.module.login.fragments.NoPhoneTipFgt;
|
|
|
import com.sheep.gamegroup.module.login.fragments.OldPasswordFgt;
|
|
|
import com.sheep.gamegroup.module.login.fragments.SignInFgt;
|
|
|
import com.sheep.gamegroup.util.DataUtil;
|
|
|
@@ -26,8 +31,14 @@ import io.reactivex.schedulers.Schedulers;
|
|
|
|
|
|
public class ChangePasswordAct extends BaseActivity implements ChangePasswordController {
|
|
|
|
|
|
+ public final static int MODE_CHANGE = 0;
|
|
|
+ public final static int MODE_FORGET = 1;
|
|
|
+
|
|
|
private String newPwd, oldPwd;
|
|
|
|
|
|
+ private int mode;
|
|
|
+ private UserEntity user;
|
|
|
+
|
|
|
@Override
|
|
|
protected int getLayoutId() {
|
|
|
return R.layout.activity_login;
|
|
|
@@ -37,13 +48,24 @@ public class ChangePasswordAct extends BaseActivity implements ChangePasswordCon
|
|
|
public void initView() {
|
|
|
TitleBarUtils.getInstance().setShowOrHide(this, true);
|
|
|
TitleBarUtils.getInstance().setTitleBack(this).setTitle(this, "设置密码");
|
|
|
- UserEntity user = DataUtil.getInstance().getUserEntity();
|
|
|
- if(user.getSet_password()==0){
|
|
|
- BindAccountFgt fgt = BindAccountFgt.newInstance(this);
|
|
|
- showFragment("绑定登录名密码", fgt);
|
|
|
- } else {
|
|
|
- OldPasswordFgt fgt = OldPasswordFgt.newInstance(this);
|
|
|
- showFragment("设置密码", fgt);
|
|
|
+ user = DataUtil.getInstance().getUserEntity();
|
|
|
+ mode = getIntent().getIntExtra("mode", -1);
|
|
|
+ if (mode == MODE_CHANGE) {
|
|
|
+ if (user.getSet_password() == 0) {
|
|
|
+ BindAccountFgt fgt = BindAccountFgt.newInstance(this);
|
|
|
+ showFragment("绑定登录名密码", fgt);
|
|
|
+ } else {
|
|
|
+ OldPasswordFgt fgt = OldPasswordFgt.newInstance(this);
|
|
|
+ showFragment("设置密码", fgt);
|
|
|
+ }
|
|
|
+ } else if (mode == MODE_FORGET) {
|
|
|
+ if (TextUtils.isEmpty(user.getMobile())) {
|
|
|
+ NoPhoneTipFgt fgt = NoPhoneTipFgt.newInstance(this);
|
|
|
+ showFragment("忘记密码", fgt);
|
|
|
+ } else {
|
|
|
+ Captcha4ForgetFgt fgt = Captcha4ForgetFgt.newInstance(this);
|
|
|
+ showFragment("输入验证码", fgt);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -66,33 +88,58 @@ public class ChangePasswordAct extends BaseActivity implements ChangePasswordCon
|
|
|
@Override
|
|
|
public void whenComplete(String newPwd) {
|
|
|
this.newPwd = newPwd;
|
|
|
-
|
|
|
showProgress();
|
|
|
JSONObject json = new JSONObject();
|
|
|
- json.put("old_password", oldPwd);
|
|
|
- json.put("new_password", newPwd);
|
|
|
- SheepApp.getInstance().getNetComponent().getApiService().changePassword(json)
|
|
|
- .subscribeOn(Schedulers.io())
|
|
|
- .observeOn(AndroidSchedulers.mainThread())
|
|
|
- .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.getInstance()) {
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onNext(BaseMessage baseMessage) {
|
|
|
- hideProgress();
|
|
|
- G.shortToast("密码修改成功");
|
|
|
- finish();
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onError(BaseMessage baseMessage) {
|
|
|
- hideProgress();
|
|
|
- if (baseMessage != null) {
|
|
|
- G.shortToast(baseMessage);
|
|
|
- } else {
|
|
|
- G.shortToast("修改密码出错");
|
|
|
+ if (mode == 0) {
|
|
|
+ json.put("old_password", oldPwd);
|
|
|
+ json.put("new_password", newPwd);
|
|
|
+ SheepApp.getInstance().getNetComponent().getApiService().changePassword(json)
|
|
|
+ .subscribeOn(Schedulers.io())
|
|
|
+ .observeOn(AndroidSchedulers.mainThread())
|
|
|
+ .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.getInstance()) {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onNext(BaseMessage baseMessage) {
|
|
|
+ hideProgress();
|
|
|
+ G.shortToast("密码修改成功");
|
|
|
+ finish();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onError(BaseMessage baseMessage) {
|
|
|
+ hideProgress();
|
|
|
+ if (baseMessage != null) {
|
|
|
+ G.shortToast(baseMessage);
|
|
|
+ } else {
|
|
|
+ G.shortToast("修改密码出错");
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- });
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ json.put("password", newPwd);
|
|
|
+ SheepApp.getInstance().getNetComponent().getApiService().resetPass4New(json)
|
|
|
+ .subscribeOn(Schedulers.io())
|
|
|
+ .observeOn(AndroidSchedulers.mainThread())
|
|
|
+ .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.getInstance()){
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onNext(BaseMessage baseMessage) {
|
|
|
+ hideProgress();
|
|
|
+ G.shortToast("密码重置成功");
|
|
|
+ finish();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onError(BaseMessage baseMessage) {
|
|
|
+ hideProgress();
|
|
|
+ if (baseMessage != null) {
|
|
|
+ G.shortToast(baseMessage);
|
|
|
+ } else {
|
|
|
+ G.shortToast("修改密码出错");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -101,6 +148,24 @@ public class ChangePasswordAct extends BaseActivity implements ChangePasswordCon
|
|
|
finish();
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void whenCaptcha(String code) {
|
|
|
+ NewPasswordFgt fgt = NewPasswordFgt.newInstance(this);
|
|
|
+ showFragment("重置密码", fgt);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void whenForget() {
|
|
|
+ mode = MODE_FORGET;
|
|
|
+ if (TextUtils.isEmpty(user.getMobile())) {
|
|
|
+ NoPhoneTipFgt fgt = NoPhoneTipFgt.newInstance(this);
|
|
|
+ showFragment("忘记密码", fgt);
|
|
|
+ } else {
|
|
|
+ Captcha4ForgetFgt fgt = Captcha4ForgetFgt.newInstance(this);
|
|
|
+ showFragment("输入验证码", fgt);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private void showFragment(String tag, Fragment fragment) {
|
|
|
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
|
|
|
transaction.replace(R.id.fragment_container, fragment, tag);
|
|
|
@@ -108,4 +173,11 @@ public class ChangePasswordAct extends BaseActivity implements ChangePasswordCon
|
|
|
transaction.addToBackStack(null);
|
|
|
transaction.commitAllowingStateLoss();
|
|
|
}
|
|
|
+
|
|
|
+ public static void changePassword(Context context) {
|
|
|
+ Intent intent = new Intent(context, ChangePasswordAct.class);
|
|
|
+ intent.putExtra("mode", MODE_CHANGE);
|
|
|
+ context.startActivity(intent);
|
|
|
+ }
|
|
|
+
|
|
|
}
|