| | |
| | | package com.hdl.photovoltaic.ui.account; |
| | | |
| | | |
| | | import android.Manifest; |
| | | import android.content.Context; |
| | | import android.content.pm.PackageManager; |
| | | import android.os.Bundle; |
| | | import android.os.CountDownTimer; |
| | | import android.telephony.TelephonyManager; |
| | | import android.text.Editable; |
| | | import android.text.InputType; |
| | | import android.text.TextUtils; |
| | |
| | | |
| | | import androidx.appcompat.content.res.AppCompatResources; |
| | | import androidx.constraintlayout.widget.ConstraintSet; |
| | | import androidx.core.content.ContextCompat; |
| | | |
| | | import com.hdl.linkpm.sdk.core.exception.HDLException; |
| | | import com.hdl.linkpm.sdk.user.HDLLinkPMUser; |
| | |
| | | import com.hdl.photovoltaic.R; |
| | | import com.hdl.photovoltaic.base.CustomBaseActivity; |
| | | import com.hdl.photovoltaic.config.AppConfigManage; |
| | | import com.hdl.photovoltaic.config.UserConfigManage; |
| | | import com.hdl.photovoltaic.databinding.ActivityRegisterAccountBinding; |
| | | import com.hdl.photovoltaic.enums.VerifyType; |
| | | import com.hdl.photovoltaic.listener.CloudCallBeak; |
| | | import com.hdl.photovoltaic.other.HdlAccountLogic; |
| | | import com.hdl.photovoltaic.other.HdlCommonLogic; |
| | | import com.hdl.photovoltaic.other.HdlLogLogic; |
| | | import com.hdl.photovoltaic.other.HdlThreadLogic; |
| | | import com.hdl.photovoltaic.utils.KeyboardStateObserverUtils; |
| | | import com.hdl.photovoltaic.utils.LocalManageUtil; |
| | | import com.hdl.photovoltaic.widget.ConfirmationCancelDialog; |
| | | import com.hdl.photovoltaic.widget.ConfirmationTipDialog; |
| | | import com.hdl.photovoltaic.widget.ListStaticDialog; |
| | |
| | | import com.sahooz.library.countrypicker.CountryPickerFragment; |
| | | import com.sahooz.library.countrypicker.PickCountryCallback; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Locale; |
| | | |
| | | /** |
| | | * 注册账号界面 |
| | |
| | | |
| | | @Override |
| | | public void onBindView(Bundle savedInstanceState) { |
| | | setStatusBarTranslucent(); |
| | | getWindow().setNavigationBarColor(getColor(R.color.text_00000000)); |
| | | //初始化 |
| | | initView(); |
| | | //初始化界面监听器 |
| | | initEvent(); |
| | | KeyboardStateObserverUtils.getKeyboardStateObserver(_mActivity).setKeyboardVisibilityListener(new KeyboardStateObserverUtils.OnKeyboardVisibilityListener() { |
| | | @Override |
| | | public void onKeyboardShow(int h) { |
| | | ConstraintSet cs = new ConstraintSet(); |
| | | cs.clone(viewBinding.parentCl); |
| | | cs.connect(viewBinding.registerConfirmPswEt.getId(), ConstraintSet.BOTTOM, ConstraintSet.PARENT_ID, ConstraintSet.BOTTOM, px2dip(h)) |
| | | ;// |
| | | //应用约束 |
| | | cs.applyTo(viewBinding.parentCl); |
| | | } |
| | | |
| | | @Override |
| | | |
| | | public void onKeyboardHide(int h) { |
| | | ConstraintSet cs = new ConstraintSet(); |
| | | cs.clone(viewBinding.parentCl); |
| | | cs.connect(viewBinding.registerConfirmPswEt.getId(), ConstraintSet.BOTTOM, ConstraintSet.PARENT_ID, ConstraintSet.BOTTOM, px2dip(h));// |
| | | //应用约束 |
| | | cs.applyTo(viewBinding.parentCl); |
| | | } |
| | | |
| | | }); |
| | | // KeyboardStateObserverUtils.getKeyboardStateObserver(_mActivity).setKeyboardVisibilityListener(new KeyboardStateObserverUtils.OnKeyboardVisibilityListener() { |
| | | // @Override |
| | | // public void onKeyboardShow(int h) { |
| | | // ConstraintSet cs = new ConstraintSet(); |
| | | // cs.clone(viewBinding.parentCl); |
| | | // cs.connect(viewBinding.registerConfirmPswEt.getId(), ConstraintSet.BOTTOM, ConstraintSet.PARENT_ID, ConstraintSet.BOTTOM, px2dip(h));// |
| | | // //应用约束 |
| | | // cs.applyTo(viewBinding.parentCl); |
| | | // } |
| | | // |
| | | // @Override |
| | | // |
| | | // public void onKeyboardHide(int h) { |
| | | // ConstraintSet cs = new ConstraintSet(); |
| | | // cs.clone(viewBinding.parentCl); |
| | | // cs.connect(viewBinding.registerConfirmPswEt.getId(), ConstraintSet.BOTTOM, ConstraintSet.PARENT_ID, ConstraintSet.BOTTOM, px2dip(h));// |
| | | // //应用约束 |
| | | // cs.applyTo(viewBinding.parentCl); |
| | | // } |
| | | // |
| | | // }); |
| | | } |
| | | |
| | | |
| | | private void initView() { |
| | | //根据app语言默认服务器地址 |
| | | if (UserConfigManage.getInstance().isZh()) { |
| | | mUrl = "https://china-gateway.hdlcontrol.com"; |
| | | viewBinding.regionTv.setText("HDL China"); |
| | | viewBinding.regionAccountTv.setText(getText(R.string.home_chinese_mainland)); |
| | | viewBinding.regionAccountNumberTv.setText("+86"); |
| | | } else { |
| | | viewBinding.regionTv.setText("HDL Bahrain"); |
| | | mUrl = "https://bahrain-gateway.hdlcontrol.com"; |
| | | viewBinding.regionAccountTv.setText(getText(R.string.iraq)); |
| | | viewBinding.regionAccountNumberTv.setText("+964"); |
| | | } |
| | | switchPhoneOrEmailStyleView(); |
| | | try { |
| | | Country.load(this); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | HdlCommonLogic.getInstance().setSpan(viewBinding.registerPhoneVerificationTv, viewBinding.registerPhoneVerificationTv.getText().toString(), true, null); |
| | | HdlCommonLogic.getInstance().setSpan(viewBinding.registerMailVerificationTv, viewBinding.registerMailVerificationTv.getText().toString(), true, null); |
| | | |
| | | |
| | | } |
| | | |
| | | private void initEvent() { |
| | |
| | | if (!isLocalCheckAccountAndPassword()) { |
| | | return; |
| | | } |
| | | // |
| | | viewBinding.textErrorTv.setText(""); |
| | | |
| | | String account = viewBinding.registerAccountEt.getText().toString(); |
| | | String psw = viewBinding.registerConfirmPswEt.getText().toString(); |
| | | String verification_code; |
| | |
| | | } else { |
| | | verification_code = viewBinding.registerMailVerificationEt.getText().toString(); |
| | | } |
| | | HdlAccountLogic.getInstance().registerAccount_C(isPhoneType, account, psw, verification_code, new CloudCallBeak<Boolean>() { |
| | | showLoading(); |
| | | HdlAccountLogic.getInstance().registerAccount_C(isPhoneType, account, psw, verification_code, viewBinding.regionAccountNumberTv.getText().toString(), new CloudCallBeak<Boolean>() { |
| | | @Override |
| | | public void onSuccess(Boolean obj) { |
| | | HdlThreadLogic.runMainThread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | hideLoading(); |
| | | ConfirmationTipDialog dialog = new ConfirmationTipDialog(_mActivity); |
| | | dialog.show(); |
| | | dialog.setTitle(getString(R.string.home_account_registered_successfully)); |
| | | dialog.setYesOnclickListener(new ConfirmationCancelDialog.onYesOnclickListener() { |
| | | @Override |
| | | public void Confirm() { |
| | |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | |
| | | hideLoading(); |
| | | HdlThreadLogic.tipFlashingBox(_mActivity, false, e.getMsg(), e.getCode()); |
| | | } |
| | | }); |
| | | } |
| | |
| | | @Override |
| | | public void onSuccess(HDLUserRegionBean obj) { |
| | | HdlThreadLogic.toast(RegisterAccountActivity.this, getString(R.string.home_login_already_exists)); |
| | | HdlLogLogic.print("获取账号区域信息===" + obj, false); |
| | | HdlLogLogic.print("获取账号区域信息--->" + obj, false); |
| | | } |
| | | |
| | | @Override |
| | |
| | | mUrl = "https://test-gz.hdlcontrol.com"; |
| | | } |
| | | HDLLinkPMUser.getInstance().setUserRegionUrl(mUrl); |
| | | HdlAccountLogic.getInstance().sendVerifyCode(isPhoneType, account, viewBinding.regionAccountNumberTv.getText().toString(), 1, new CloudCallBeak<Boolean>() { |
| | | HdlAccountLogic.getInstance().sendVerifyCode_C(isPhoneType, account, viewBinding.regionAccountNumberTv.getText().toString(), VerifyType.VerifyType_1, new CloudCallBeak<Boolean>() { |
| | | @Override |
| | | public void onSuccess(Boolean obj) { |
| | | if (isPhoneType) { |
| | |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | |
| | | HdlThreadLogic.toast(_mActivity, e); |
| | | } |
| | | }); |
| | | } else { |
| | | HdlThreadLogic.toast(_mActivity, e); |
| | | } |
| | | |
| | | |
| | | } |
| | | }); |
| | |
| | | long time = (millisUntilFinished / 1000); |
| | | String str = time + "s" + getString(R.string.home_login_psw_verification_repeater); |
| | | viewBinding.registerPhoneVerificationTv.setText(str); |
| | | viewBinding.registerPhoneVerificationTv.setTextColor(getResources().getColor(R.color.text_25000000, null)); |
| | | // viewBinding.registerPhoneVerificationTv.setTextColor(getResources().getColor(R.color.text_25000000, null)); |
| | | viewBinding.registerPhoneVerificationTv.setEnabled(false); |
| | | |
| | | } |
| | |
| | | @Override |
| | | public void onFinish() { |
| | | viewBinding.registerPhoneVerificationTv.setText(getString(R.string.home_login_verification_regain)); |
| | | viewBinding.registerPhoneVerificationTv.setTextColor(getResources().getColor(R.color.text_245EC3, null)); |
| | | // viewBinding.registerPhoneVerificationTv.setTextColor(getResources().getColor(R.color.text_245EC3, null)); |
| | | viewBinding.registerPhoneVerificationTv.setEnabled(true); |
| | | |
| | | |
| | |
| | | String str = time + "s" + getString(R.string.home_login_psw_verification_repeater); |
| | | |
| | | viewBinding.registerMailVerificationTv.setText(str); |
| | | viewBinding.registerMailVerificationTv.setTextColor(getResources().getColor(R.color.text_25000000, null)); |
| | | // viewBinding.registerMailVerificationTv.setTextColor(getResources().getColor(R.color.text_E6FFFFFF, null)); |
| | | viewBinding.registerMailVerificationTv.setEnabled(false); |
| | | |
| | | } |
| | |
| | | @Override |
| | | public void onFinish() { |
| | | viewBinding.registerMailVerificationTv.setText(getString(R.string.home_login_verification_regain)); |
| | | viewBinding.registerMailVerificationTv.setTextColor(getResources().getColor(R.color.text_245EC3, null)); |
| | | // viewBinding.registerMailVerificationTv.setTextColor(getResources().getColor(R.color.text_E6FFFFFF, null)); |
| | | viewBinding.registerMailVerificationTv.setEnabled(true); |
| | | |
| | | } |
| | |
| | | CountryPickerFragment dialog = new CountryPickerFragment(this, new PickCountryCallback() { |
| | | @Override |
| | | public void onPick(Country country) { |
| | | if (country.flag != 0) |
| | | viewBinding.regionAccountTv.setText(country.name); |
| | | if (country.flag != 0) viewBinding.regionAccountTv.setText(country.translate); |
| | | viewBinding.regionAccountNumberTv.setText("+" + country.code); |
| | | } |
| | | }); |
| | |
| | | * 切换手机号或者邮箱的样式 |
| | | */ |
| | | private void switchPhoneOrEmailStyleView() { |
| | | |
| | | |
| | | if (isPhoneType) { |
| | | //手机号 |
| | | viewBinding.registerPhoneTitleIc.accountTitleTv.setText(R.string.home_login_phone); |
| | | viewBinding.registerPhoneTitleIc.accountTitleTv.setTextSize(20); |
| | | viewBinding.registerPhoneTitleIc.accountTitleTv.setTextColor(getResources().getColor(R.color.text_90000000, null)); |
| | | viewBinding.registerPhoneTitleIc.accountTitleTv.setTextSize(18); |
| | | viewBinding.registerPhoneTitleIc.accountTitleTv.setTextColor(getResources().getColor(R.color.text_E6FFFFFF, null)); |
| | | viewBinding.registerPhoneTitleIc.lineV.setVisibility(View.VISIBLE); |
| | | |
| | | viewBinding.registerMailTitleIc.accountTitleTv.setText(R.string.home_login_email); |
| | | viewBinding.registerMailTitleIc.accountTitleTv.setTextSize(16); |
| | | viewBinding.registerMailTitleIc.accountTitleTv.setTextColor(getResources().getColor(R.color.text_40000000, null)); |
| | | viewBinding.registerMailTitleIc.accountTitleTv.setTextSize(14); |
| | | viewBinding.registerMailTitleIc.accountTitleTv.setTextColor(getResources().getColor(R.color.text_66FFFFFF, null)); |
| | | viewBinding.registerMailTitleIc.lineV.setVisibility(View.GONE); |
| | | |
| | | //显示区号 |
| | | viewBinding.registerRegionAccountRl.setVisibility(View.VISIBLE); |
| | | //输入手机号 |
| | | viewBinding.registerAccountEt.setInputType(InputType.TYPE_CLASS_NUMBER); |
| | | viewBinding.registerAccountEt.setHint(R.string.home_login_input_phone); |
| | |
| | | //邮箱 |
| | | viewBinding.registerPhoneTitleIc.accountTitleTv.setText(R.string.home_login_phone); |
| | | viewBinding.registerPhoneTitleIc.accountTitleTv.setTextSize(16); |
| | | viewBinding.registerPhoneTitleIc.accountTitleTv.setTextColor(getResources().getColor(R.color.text_40000000, null)); |
| | | viewBinding.registerPhoneTitleIc.accountTitleTv.setTextColor(getResources().getColor(R.color.text_66FFFFFF, null)); |
| | | viewBinding.registerPhoneTitleIc.lineV.setVisibility(View.GONE); |
| | | |
| | | viewBinding.registerMailTitleIc.accountTitleTv.setText(R.string.home_login_email); |
| | | viewBinding.registerMailTitleIc.accountTitleTv.setTextSize(20); |
| | | viewBinding.registerMailTitleIc.accountTitleTv.setTextColor(getResources().getColor(R.color.text_90000000, null)); |
| | | viewBinding.registerMailTitleIc.accountTitleTv.setTextSize(18); |
| | | viewBinding.registerMailTitleIc.accountTitleTv.setTextColor(getResources().getColor(R.color.text_E6FFFFFF, null)); |
| | | viewBinding.registerMailTitleIc.lineV.setVisibility(View.VISIBLE); |
| | | |
| | | //隐藏区号 |
| | | viewBinding.registerRegionAccountRl.setVisibility(View.GONE); |
| | | //输入邮箱 |
| | | viewBinding.registerAccountEt.setInputType(InputType.TYPE_CLASS_TEXT); |
| | | viewBinding.registerAccountEt.setHint(R.string.home_login_input_mail); |
| | |
| | | viewBinding.registerConfirmPswEt.setText(mMailConfirmPsw); |
| | | |
| | | } |
| | | isCompleteEnabled(); |
| | | try { |
| | | Country.load(this); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | |
| | | verification_code = viewBinding.registerMailVerificationEt.getText().toString(); |
| | | } |
| | | boolean isEnabled = account.length() > 0 && psw1.length() > 0 && psw2.length() > 0 && verification_code.length() > 0; |
| | | if (isEnabled) { |
| | | viewBinding.registerCompleteTv.setTextColor(getColor(R.color.text_E6FFFFFF)); |
| | | } else { |
| | | viewBinding.registerCompleteTv.setTextColor(getColor(R.color.text_66FFFFFF)); |
| | | } |
| | | viewBinding.registerCompleteTv.setEnabled(isEnabled); |
| | | } |
| | | |