ChangePwdActivity.java
2.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package com.hjx.parent;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import com.prws.common.base.BaseActivity;
import com.prws.common.base.BasePresenter;
import com.prws.common.net.NetWorks;
import com.prws.common.utils.LogUtil;
import com.prws.common.utils.SharedPreferencesUtil;
import org.json.JSONObject;
import java.util.HashMap;
import java.util.Map;
import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;
import okhttp3.ResponseBody;
public class ChangePwdActivity extends BaseActivity {
@Override
protected int layoutResId() {
return R.layout.activity_changem;
}
@Override
public Object getContract() {
return null;
}
@Override
public BasePresenter getPresenter() {
return null;
}
EditText et_pwd;
@Override
protected void initView() {
et_pwd = findViewById(R.id.et_pwd);
}
@Override
protected void initListener() {
findViewById(R.id.iv_back).setOnClickListener(view -> onBackPressed());
findViewById(R.id.btn_next).setOnClickListener(view -> {
String pwd = et_pwd.getText().toString().trim();
if (pwd == null || pwd.length() == 0){
Toast.makeText(this,"密码不能为空",Toast.LENGTH_SHORT).show();
return;
}
changePwd(pwd);
});
}
public void changePwd(String pwd){
String userId = (String) SharedPreferencesUtil.getData("userId", "");
Map map = new HashMap();
map.put("userId",userId);
map.put("password",pwd);
NetWorks.changePassword(NetWorks.getMapRequestBody(map), new Observer<ResponseBody>() {
@Override
public void onSubscribe(Disposable d) {
}
@Override
public void onNext(ResponseBody responseBody) {
try {
String str = responseBody.string().toString();
LogUtil.e(TAG,"----"+str);
JSONObject jo = new JSONObject(str);
boolean isSucceed = jo.getBoolean("success");
if (isSucceed){
Toast.makeText(ChangePwdActivity.this, "修改成功", Toast.LENGTH_SHORT).show();
finish();
}else {
Toast.makeText(ChangePwdActivity.this, jo.getString("msg"), Toast.LENGTH_SHORT).show();
}
}catch (Exception e){
e.printStackTrace();
Toast.makeText(ChangePwdActivity.this,"服务繁忙,请重试",Toast.LENGTH_SHORT).show();
}
}
@Override
public void onError(Throwable e) {
}
@Override
public void onComplete() {
}
});
}
@Override
protected void initData() {
}
@Override
public void onNetChanged(int netWorkState) {
}
}