package com.hdl.photovoltaic.ui.me;
|
|
|
import android.os.Bundle;
|
import android.os.CountDownTimer;
|
import android.text.Editable;
|
import android.text.TextUtils;
|
import android.text.TextWatcher;
|
import android.view.View;
|
|
import com.hdl.linkpm.sdk.core.exception.HDLException;
|
import com.hdl.photovoltaic.R;
|
import com.hdl.photovoltaic.base.CustomBaseActivity;
|
import com.hdl.photovoltaic.config.UserConfigManage;
|
import com.hdl.photovoltaic.databinding.ActivityBindMailBinding;
|
import com.hdl.photovoltaic.listener.CloudCallBeak;
|
import com.hdl.photovoltaic.other.HdlAccountLogic;
|
import com.hdl.photovoltaic.other.HdlLogLogic;
|
import com.hdl.photovoltaic.other.HdlThreadLogic;
|
|
/**
|
* 修改绑定邮箱的界面
|
*/
|
public class BindMailActivity extends CustomBaseActivity {
|
|
private ActivityBindMailBinding viewBinding;
|
|
@Override
|
public Object getContentView() {
|
viewBinding = ActivityBindMailBinding.inflate(getLayoutInflater());
|
return viewBinding.getRoot();
|
}
|
|
@Override
|
public void onBindView(Bundle savedInstanceState) {
|
setStatusBarTranslucent();
|
//初始化
|
initView();
|
//初始化界面监听器
|
initEvent();
|
|
}
|
|
private void initEvent() {
|
|
viewBinding.toolbarTopRl.topBackLl.setOnClickListener(new View.OnClickListener() {
|
@Override
|
public void onClick(View v) {
|
setResult(20);
|
finish();
|
}
|
});
|
|
viewBinding.bindMailVerificationCodeRl.setOnClickListener(new View.OnClickListener() {
|
@Override
|
public void onClick(View v) {
|
sendVerification();
|
}
|
});
|
|
viewBinding.bindMailClearIv.setOnClickListener(new View.OnClickListener() {
|
@Override
|
public void onClick(View v) {
|
viewBinding.bindMailEt.setText("");
|
}
|
});
|
//输入账号
|
viewBinding.bindMailEt.addTextChangedListener(accountTextWatcher);
|
//输入验证码
|
viewBinding.changeMailVerificationEt.addTextChangedListener(verificationCodeTextWatcher);
|
viewBinding.bindPhoneTv.setOnClickListener(new View.OnClickListener() {
|
@Override
|
public void onClick(View v) {
|
if (isEnabled()) {
|
String mailStr = viewBinding.bindMailEt.getText().toString();
|
String verificationStr = viewBinding.changeMailVerificationEt.getText().toString();
|
HdlAccountLogic.getInstance().bindingAccount_C("", mailStr, verificationStr, new CloudCallBeak<Boolean>() {
|
@Override
|
public void onSuccess(Boolean obj) {
|
UserConfigManage.getInstance().setBingEmail(mailStr);
|
UserConfigManage.getInstance().Save();
|
setResult(20);
|
finish();
|
}
|
|
@Override
|
public void onFailure(HDLException e) {
|
HdlThreadLogic.tipFlashingBox(_mActivity, false, e.getMsg(), e.getCode());
|
}
|
});
|
}
|
}
|
});
|
|
}
|
|
private void initView() {
|
viewBinding.toolbarTopRl.topTitleTv.setText(R.string.set_change_bind_mail);
|
viewBinding.toolbarTopRl.topBackLl.setVisibility(View.VISIBLE);
|
checkClearIconShowOrNot(viewBinding.bindMailEt.getText().toString());
|
}
|
|
/**
|
* 发送验证码指令
|
*/
|
private void sendVerification() {
|
|
String account = viewBinding.bindMailEt.getText().toString();
|
if (TextUtils.isEmpty(account)) {
|
HdlThreadLogic.tipFlashingBox(this, false, getString(R.string.home_login_mail_null), -1);
|
return;
|
}
|
HdlAccountLogic.getInstance().sendVerifyCode(false, account, "86", 3, new CloudCallBeak<Boolean>() {
|
@Override
|
public void onSuccess(Boolean obj) {
|
countDownTimer.start();
|
}
|
|
@Override
|
public void onFailure(HDLException e) {
|
HdlThreadLogic.tipFlashingBox(_mActivity, false, e.getMsg(), e.getCode());
|
HdlLogLogic.print(e.getMessage(), e.getCode(), true);
|
}
|
});
|
|
}
|
|
/**
|
* 初始化手机号计时器
|
*/
|
CountDownTimer countDownTimer = new CountDownTimer(60 * 1000, 1000) {
|
@Override
|
public void onTick(long millisUntilFinished) {
|
long time = (millisUntilFinished / 1000);
|
String str = time + "s" + getString(R.string.home_login_psw_verification_repeater);
|
viewBinding.bindMailVerificationTv.setText(str);
|
viewBinding.bindMailVerificationTv.setTextColor(getResources().getColor(R.color.text_25000000, null));
|
viewBinding.bindMailVerificationTv.setEnabled(false);
|
|
}
|
|
@Override
|
public void onFinish() {
|
viewBinding.bindMailVerificationTv.setText(getString(R.string.home_login_verification_regain));
|
viewBinding.bindMailVerificationTv.setTextColor(getResources().getColor(R.color.text_245EC3, null));
|
viewBinding.bindMailVerificationTv.setEnabled(true);
|
|
|
}
|
};
|
|
/**
|
* 本地校验
|
*/
|
private boolean isLocalCheck() {
|
String phoneStr = viewBinding.bindMailEt.getText().toString();
|
String verificationStr = viewBinding.changeMailVerificationEt.getText().toString();
|
if (TextUtils.isEmpty(phoneStr)) {
|
HdlThreadLogic.tipFlashingBox(this, false, getString(R.string.home_login_mail_null), -1);
|
return false;
|
}
|
if (TextUtils.isEmpty(verificationStr)) {
|
HdlThreadLogic.tipFlashingBox(this, false, getString(R.string.home_login_null_verification_code), -1);
|
return false;
|
}
|
|
return true;
|
|
}
|
|
/**
|
* 检测清除图标是否显示
|
*/
|
private void checkClearIconShowOrNot(String s) {
|
if (s.replace(" ", "").length() > 0) {
|
if (viewBinding.bindMailClearIv.getVisibility() == View.GONE) {
|
viewBinding.bindMailClearIv.setVisibility(View.VISIBLE);
|
}
|
} else {
|
if (viewBinding.bindMailClearIv.getVisibility() == View.VISIBLE) {
|
viewBinding.bindMailClearIv.setVisibility(View.GONE);
|
}
|
}
|
}
|
|
/**
|
* 校验确认按钮是否启用
|
*/
|
private boolean isEnabled() {
|
String account = viewBinding.bindMailEt.getText().toString().replace(" ", "");
|
String verificationCode = viewBinding.changeMailVerificationEt.getText().toString().replace(" ", "");
|
boolean isEnabled = account.length() > 0 && verificationCode.length() > 0;
|
if (isEnabled) {
|
viewBinding.bindPhoneTv.setTextColor(getColor(R.color.text_E6FFFFFF));
|
} else {
|
viewBinding.bindPhoneTv.setTextColor(getColor(R.color.text_66FFFFFF));
|
}
|
viewBinding.bindPhoneTv.setEnabled(isEnabled);
|
return isEnabled;
|
|
}
|
|
/**
|
* 输入账号
|
*/
|
private final TextWatcher accountTextWatcher = 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) {
|
checkClearIconShowOrNot(s.toString());
|
isEnabled();
|
}
|
};
|
|
/**
|
* 输入验证码
|
*/
|
private final TextWatcher verificationCodeTextWatcher = 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) {
|
isEnabled();
|
}
|
};
|
|
@Override
|
protected void onDestroy() {
|
super.onDestroy();
|
|
if (countDownTimer != null) {
|
countDownTimer.cancel();
|
countDownTimer = null;
|
}
|
viewBinding.bindMailEt.removeTextChangedListener(accountTextWatcher);
|
viewBinding.changeMailVerificationEt.removeTextChangedListener(verificationCodeTextWatcher);
|
}
|
|
|
/**
|
* 物理按键返回事件
|
*/
|
@Override
|
public void onBackPressed() {
|
setResult(20);
|
super.onBackPressed();
|
}
|
|
}
|