You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
65 lines
2.3 KiB
65 lines
2.3 KiB
package com.community.pocket.ui.main.ui.info;
|
|
|
|
import androidx.lifecycle.MutableLiveData;
|
|
|
|
import com.community.pocket.R;
|
|
import com.community.pocket.data.main.info.InfoRequest;
|
|
import com.community.pocket.ui.main.ui.share.BaseViewModel;
|
|
import com.community.pocket.util.ValidUtil;
|
|
|
|
//个人信息UI数据管理
|
|
public class InfoViewModel extends BaseViewModel<InfoRequest> {
|
|
|
|
//修改密码表单校验状态
|
|
private MutableLiveData<InfoFormState> modifyFormState = new MutableLiveData<>();
|
|
|
|
//修改密码请求状态
|
|
private MutableLiveData<InfoResponse> modifyResponse = new MutableLiveData<>();
|
|
|
|
//个人信息请求状态
|
|
private MutableLiveData<InfoResponse> infoResponse = new MutableLiveData<>();
|
|
|
|
MutableLiveData<InfoFormState> getModifyFormState() {
|
|
return modifyFormState;
|
|
}
|
|
|
|
MutableLiveData<InfoResponse> getModifyResponse() {
|
|
return modifyResponse;
|
|
}
|
|
|
|
MutableLiveData<InfoResponse> getInfoResponse() {
|
|
return infoResponse;
|
|
}
|
|
|
|
//修改密码表单校验状态
|
|
void modifyPwdChanged(String oldpwd, String newpwd, String confirmNewPwd) {
|
|
if (!ValidUtil.passwordvalid(oldpwd)) {
|
|
modifyFormState.setValue(new InfoFormState(R.string.invalid_password, null, null));
|
|
} else if (!ValidUtil.passwordvalid(newpwd)) {
|
|
modifyFormState.setValue(new InfoFormState(null, R.string.invalid_password, null));
|
|
} else if (oldpwd.equals(newpwd)) {
|
|
modifyFormState.setValue(new InfoFormState(null, R.string.password_diff, null));
|
|
} else if (!ValidUtil.passwordvalid(confirmNewPwd)) {
|
|
modifyFormState.setValue(new InfoFormState(null, null, R.string.invalid_password));
|
|
} else if (!newpwd.equals(confirmNewPwd)) {
|
|
modifyFormState.setValue(new InfoFormState(null, null, R.string.invalid_confirm_password));
|
|
} else {
|
|
modifyFormState.setValue(new InfoFormState(true));
|
|
}
|
|
}
|
|
|
|
//修改密码
|
|
void modifyPwd(String oldpwd, String newpwd) {
|
|
getRequest().modifyPwd(modifyResponse, oldpwd, newpwd);
|
|
}
|
|
|
|
//获取个人信息
|
|
void loadInfo() {
|
|
getRequest().loadInfo(infoResponse);
|
|
}
|
|
|
|
@Override
|
|
protected InfoRequest getRequest() {
|
|
return InfoRequest.getInstance();
|
|
}
|
|
}
|
|
|