package com.hdl.photovoltaic.ui.me;
|
|
import androidx.appcompat.content.res.AppCompatResources;
|
|
import android.graphics.drawable.Drawable;
|
import android.os.Bundle;
|
import android.text.Editable;
|
import android.text.TextUtils;
|
import android.text.TextWatcher;
|
import android.text.method.HideReturnsTransformationMethod;
|
import android.text.method.PasswordTransformationMethod;
|
import android.view.View;
|
import android.widget.EditText;
|
import android.widget.ImageView;
|
|
import com.hdl.linkpm.sdk.core.exception.HDLException;
|
import com.hdl.photovoltaic.R;
|
import com.hdl.photovoltaic.base.BaseActivity;
|
import com.hdl.photovoltaic.config.UserConfigManage;
|
import com.hdl.photovoltaic.databinding.ActivityMeChangePasswordBinding;
|
import com.hdl.photovoltaic.listener.CloudCallBeak;
|
import com.hdl.photovoltaic.other.HdlAccountLogic;
|
import com.hdl.photovoltaic.other.HdlThreadLogic;
|
import com.hdl.photovoltaic.widget.FlashingBoxDialog;
|
|
/**
|
* 我的-修改密码-界面
|
*/
|
public class MeChangePasswordActivity extends BaseActivity {
|
|
private ActivityMeChangePasswordBinding viewBinding;
|
|
@Override
|
public Object getContentView() {
|
viewBinding = ActivityMeChangePasswordBinding.inflate(getLayoutInflater());
|
return viewBinding.getRoot();
|
}
|
|
@Override
|
public void onBindView(Bundle savedInstanceState) {
|
//初始化
|
initView();
|
//初始化界面监听器
|
initEvent();
|
|
}
|
|
/**
|
* 初始化界面监听器
|
*/
|
private void initEvent() {
|
viewBinding.toolbarTopFragmentHouseListRl.topBackBtn.setOnClickListener(new View.OnClickListener() {
|
@Override
|
public void onClick(View v) {
|
finish();
|
}
|
});
|
//原密码输入框
|
viewBinding.meChangePasswordOldIc.mePswEt.addTextChangedListener(oldPswTextWatcher);
|
//显示原密码图标
|
viewBinding.meChangePasswordOldIc.mePswHideIv.setOnClickListener(new View.OnClickListener() {
|
@Override
|
public void onClick(View v) {
|
setEditTextStyle(viewBinding.meChangePasswordOldIc.mePswEt, viewBinding.meChangePasswordOldIc.mePswHideIv);
|
}
|
});
|
//新密码输入框
|
viewBinding.meChangePasswordNewIc.mePswEt.addTextChangedListener(newPswTextWatcher);
|
//显示新密码图标
|
viewBinding.meChangePasswordNewIc.mePswHideIv.setOnClickListener(new View.OnClickListener() {
|
@Override
|
public void onClick(View v) {
|
setEditTextStyle(viewBinding.meChangePasswordNewIc.mePswEt, viewBinding.meChangePasswordNewIc.mePswHideIv);
|
}
|
});
|
//再次输入新密码输入框
|
viewBinding.meChangePasswordAffirmIc.mePswEt.addTextChangedListener(confirmPswTextWatcher);
|
//显示再次输入新密码图标
|
viewBinding.meChangePasswordAffirmIc.mePswHideIv.setOnClickListener(new View.OnClickListener() {
|
@Override
|
public void onClick(View v) {
|
setEditTextStyle(viewBinding.meChangePasswordAffirmIc.mePswEt, viewBinding.meChangePasswordAffirmIc.mePswHideIv);
|
}
|
});
|
//确认修改
|
viewBinding.homeAffirmTv.setOnClickListener(new View.OnClickListener() {
|
@Override
|
public void onClick(View v) {
|
sendChangePassword();
|
}
|
});
|
}
|
|
/**
|
* 发送更改个人密码指令
|
*/
|
private void sendChangePassword() {
|
String oldPsw = viewBinding.meChangePasswordOldIc.mePswEt.getText().toString().replaceAll(" +", "");
|
String newPsw = viewBinding.meChangePasswordNewIc.mePswEt.getText().toString().replaceAll(" +", "");
|
String affirmPsw = viewBinding.meChangePasswordAffirmIc.mePswEt.getText().toString().replaceAll(" +", "");
|
if (!isEditTextPassword(newPsw, affirmPsw)) {
|
tipFlashingBox(AppCompatResources.getDrawable(_mActivity, R.drawable.tip_fail), getString(R.string.home_login_input_unlike_psw), -1);
|
return;
|
}
|
if (UserConfigManage.getInstance().isBAccount()) {
|
//B端更改个人密码
|
HdlAccountLogic.getInstance().updateBPassword(oldPsw, newPsw, new CloudCallBeak<String>() {
|
@Override
|
public void onSuccess(String str) {
|
tipFlashingBox(AppCompatResources.getDrawable(_mActivity, R.drawable.tip_succeed), getString(R.string.home_login_pws_reset_succeeded), 0);
|
}
|
|
@Override
|
public void onFailure(HDLException e) {
|
tipFlashingBox(AppCompatResources.getDrawable(_mActivity, R.drawable.tip_fail), e.getMsg(), e.getCode());
|
}
|
});
|
} else {
|
//C端更改个人密码
|
HdlAccountLogic.getInstance().updateCPassword(oldPsw, newPsw, new CloudCallBeak<String>() {
|
@Override
|
public void onSuccess(String obj) {
|
tipFlashingBox(AppCompatResources.getDrawable(_mActivity, R.drawable.tip_succeed), getString(R.string.home_login_pws_reset_succeeded), 0);
|
}
|
|
@Override
|
public void onFailure(HDLException e) {
|
tipFlashingBox(AppCompatResources.getDrawable(_mActivity, R.drawable.tip_fail), e.getMsg(), e.getCode());
|
}
|
});
|
|
}
|
}
|
|
|
/**
|
* 提示框
|
*
|
* @param drawable 图标
|
* @param msg 信息
|
* @param code 状态
|
*/
|
private void tipFlashingBox(Drawable drawable, String msg, int code) {
|
HdlThreadLogic.runMainThread(new Runnable() {
|
@Override
|
public void run() {
|
FlashingBoxDialog flashingBoxDialog = new FlashingBoxDialog(_mActivity);
|
flashingBoxDialog.setImage(drawable);
|
flashingBoxDialog.setContent(msg + "\r\n(" + code + ")");
|
flashingBoxDialog.show();
|
}
|
}, null, null);
|
}
|
|
/**
|
* 初始化
|
*/
|
private void initView() {
|
viewBinding.toolbarTopFragmentHouseListRl.topBarView.setBackgroundColor(getResources().getColor(R.color.text_FFFFFFFF));
|
viewBinding.toolbarTopFragmentHouseListRl.topTitleTv.setText(R.string.home_login_change_password);
|
viewBinding.toolbarTopFragmentHouseListRl.topTitleTv.setTextColor(getResources().getColor(R.color.text_030D1C));
|
viewBinding.toolbarTopFragmentHouseListRl.topBackBtn.setVisibility(View.VISIBLE);
|
viewBinding.meChangePasswordOldIc.mePswTitleTv.setText(R.string.home_login_old_pws);
|
viewBinding.meChangePasswordOldIc.mePswEt.setHint(R.string.home_login_input_old_pws);
|
viewBinding.meChangePasswordOldIc.lineV.setVisibility(View.GONE);
|
viewBinding.meChangePasswordNewIc.mePswTitleTv.setText(R.string.home_login_new_pws);
|
viewBinding.meChangePasswordNewIc.mePswEt.setHint(R.string.home_login_input_new_pws);
|
viewBinding.meChangePasswordNewIc.lineV.setVisibility(View.GONE);
|
viewBinding.meChangePasswordAffirmIc.mePswTitleTv.setText(R.string.home_login_affirm_psw);
|
viewBinding.meChangePasswordAffirmIc.mePswEt.setHint(R.string.home_login_input_affirm_psw);
|
viewBinding.meChangePasswordAffirmIc.lineV.setVisibility(View.GONE);
|
|
|
}
|
|
|
/**
|
* 校验按钮是否启用
|
*/
|
private void isCompleteEnabled() {
|
String oldPsw = viewBinding.meChangePasswordOldIc.mePswEt.getText().toString();
|
String newPsw = viewBinding.meChangePasswordNewIc.mePswEt.getText().toString();
|
String affirmPsw = viewBinding.meChangePasswordAffirmIc.mePswEt.getText().toString();
|
boolean isEnabled = oldPsw.length() > 0 && newPsw.length() > 0 && affirmPsw.length() > 0;
|
viewBinding.homeAffirmTv.setEnabled(isEnabled);
|
}
|
|
/**
|
* 本地校验密码是否正确
|
*
|
* @param newPsw 新密码
|
* @param affirmPsw 再次确认新密码
|
* @return 一样返回true,否者false
|
*/
|
private boolean isEditTextPassword(String newPsw, String affirmPsw) {
|
//新密码和确认密码不一样
|
return newPsw.equals(affirmPsw);
|
|
}
|
|
private void setEditTextStyle(EditText editText, ImageView imageView) {
|
if (imageView.isSelected()) {
|
imageView.setSelected(false);
|
imageView.setImageDrawable(AppCompatResources.getDrawable(_mActivity, R.drawable.hide));
|
editText.setTransformationMethod(PasswordTransformationMethod.getInstance());
|
} else {
|
imageView.setSelected(true);
|
imageView.setImageDrawable(AppCompatResources.getDrawable(_mActivity, R.drawable.show));
|
editText.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
|
}
|
//设置光标位置
|
if (!TextUtils.isEmpty(editText.getText())) {
|
editText.setSelection(editText.length());
|
}
|
}
|
|
|
@Override
|
protected void onDestroy() {
|
super.onDestroy();
|
viewBinding.meChangePasswordOldIc.mePswEt.removeTextChangedListener(oldPswTextWatcher);
|
viewBinding.meChangePasswordNewIc.mePswEt.removeTextChangedListener(newPswTextWatcher);
|
viewBinding.meChangePasswordAffirmIc.mePswEt.removeTextChangedListener(confirmPswTextWatcher);
|
}
|
|
/**
|
* 输入原密码
|
*/
|
private final TextWatcher oldPswTextWatcher = new TextWatcher() {
|
@Override
|
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
|
}
|
|
@Override
|
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
}
|
|
@Override
|
public void afterTextChanged(Editable s) {
|
isCompleteEnabled();
|
}
|
};
|
|
/**
|
* 输入新密码
|
*/
|
private final TextWatcher newPswTextWatcher = new TextWatcher() {
|
@Override
|
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
|
}
|
|
@Override
|
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
}
|
|
@Override
|
public void afterTextChanged(Editable s) {
|
isCompleteEnabled();
|
}
|
};
|
/**
|
* 再次确认密码
|
*/
|
private final TextWatcher confirmPswTextWatcher = new TextWatcher() {
|
@Override
|
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
|
}
|
|
@Override
|
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
}
|
|
@Override
|
public void afterTextChanged(Editable s) {
|
isCompleteEnabled();
|
}
|
};
|
|
|
}
|