package com.hdl.photovoltaic.ui.me; import android.os.Bundle; import android.os.CountDownTimer; import android.text.TextUtils; 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.ActivityBindPhoneBinding; import com.hdl.photovoltaic.listener.CloudCallBeak; import com.hdl.photovoltaic.other.HdlAccountLogic; import com.hdl.photovoltaic.other.HdlLogLogic; import com.hdl.photovoltaic.other.HdlThreadLogic; import com.sahooz.library.countrypicker.Country; import com.sahooz.library.countrypicker.CountryPickerFragment; import com.sahooz.library.countrypicker.PickCountryCallback; /** * 修改绑定手机号的界面 */ public class BindPhoneActivity extends CustomBaseActivity { private ActivityBindPhoneBinding viewBinding; @Override public Object getContentView() { viewBinding = ActivityBindPhoneBinding.inflate(getLayoutInflater()); return viewBinding.getRoot(); } @Override public void onBindView(Bundle savedInstanceState) { setNotificationBarBackgroundColor(CustomColor.white); setStatusBarTextColor(); //初始化 initView(); //初始化界面监听器 initEvent(); } private void initEvent() { viewBinding.toolbarTopFragmentHouseListRl.topBackLl.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { setResult(20); finish(); } }); viewBinding.bindAreaParentRl.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { selectArea(); } }); viewBinding.bindPhoneVerificationCodeRl.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { sendVerification(); } }); viewBinding.bindPhoneClearIv.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { viewBinding.bindPhoneEt.setText(""); } }); viewBinding.bindPhoneTv.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (isLocalCheck()) { String phoneStr = viewBinding.bindPhoneEt.getText().toString(); String verificationStr = viewBinding.changePhoneVerificationEt.getText().toString(); HdlAccountLogic.getInstance().bindingAccount_C(phoneStr, "", verificationStr, new CloudCallBeak() { @Override public void onSuccess(Boolean obj) { UserConfigManage.getInstance().setBingPhone(phoneStr); UserConfigManage.getInstance().Save(); setResult(20); finish(); } @Override public void onFailure(HDLException e) { HdlThreadLogic.tipFlashingBox(_mActivity, false, e.getMsg(), e.getCode()); } }); } } }); } private void initView() { viewBinding.toolbarTopFragmentHouseListRl.topTitleTv.setText(R.string.set_change_bind_phone_number); viewBinding.toolbarTopFragmentHouseListRl.topTitleTv.setTextColor(getResources().getColor(R.color.text_030D1C, null)); viewBinding.toolbarTopFragmentHouseListRl.topBackLl.setVisibility(View.VISIBLE); viewBinding.toolbarTopFragmentHouseListRl.topBarView.setBackgroundColor(getResources().getColor(R.color.text_FFFFFFFF, null)); try { Country.load(this); } catch (Exception e) { e.printStackTrace(); } } /** * 国家手机号区号弹窗 */ private void selectArea() { CountryPickerFragment dialog = new CountryPickerFragment(this, new PickCountryCallback() { @Override public void onPick(Country country) { if (country.flag != 0) viewBinding.bindAreaTv.setText(country.name); String code = "+" + country.code; viewBinding.bindAreaNumberTv.setText(code); } }); dialog.show(); dialog.setDialogSize(); } /** * 发送验证码指令 */ private void sendVerification() { String account = viewBinding.bindPhoneEt.getText().toString(); if (TextUtils.isEmpty(account)) { HdlThreadLogic.tipFlashingBox(this, false, getString(R.string.home_login_phone_null), -1); return; } HdlAccountLogic.getInstance().sendVerifyCode(true, account, viewBinding.bindAreaNumberTv.getText().toString(), 3, new CloudCallBeak() { @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.bindPhoneVerificationTv.setText(str); viewBinding.bindPhoneVerificationTv.setTextColor(getResources().getColor(R.color.text_25000000, null)); viewBinding.bindPhoneVerificationTv.setEnabled(false); } @Override public void onFinish() { viewBinding.bindPhoneVerificationTv.setText(getString(R.string.home_login_verification_regain)); viewBinding.bindPhoneVerificationTv.setTextColor(getResources().getColor(R.color.text_245EC3, null)); viewBinding.bindPhoneVerificationTv.setEnabled(true); } }; /** * 本地校验 */ private boolean isLocalCheck() { String phoneStr = viewBinding.bindPhoneEt.getText().toString(); String verificationStr = viewBinding.changePhoneVerificationEt.getText().toString(); if (TextUtils.isEmpty(phoneStr)) { HdlThreadLogic.tipFlashingBox(this, false, getString(R.string.home_login_phone_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; } @Override protected void onDestroy() { super.onDestroy(); Country.destroy(); if (countDownTimer != null) { countDownTimer.cancel(); countDownTimer = null; } } /** * 物理按键返回事件 */ @Override public void onBackPressed() { setResult(20); super.onBackPressed(); } }