wjc
2024-12-05 d07814fd6d289487769bbe44b5d805d67c969944
app/src/main/java/com/hdl/photovoltaic/ui/account/RegisterAccountActivity.java
@@ -20,16 +20,21 @@
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.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.widget.ConfirmationCancelDialog;
import com.hdl.photovoltaic.widget.ConfirmationTipDialog;
import com.hdl.photovoltaic.widget.ListDialog;
import com.hdl.sdk.link.common.utils.ThreadToolUtils;
import com.hdl.photovoltaic.widget.ListStaticDialog;
import com.sahooz.library.countrypicker.Country;
import com.sahooz.library.countrypicker.CountryPickerFragment;
import com.sahooz.library.countrypicker.PickCountryCallback;
/**
 * 注册账号界面
@@ -61,6 +66,7 @@
    @Override
    public void onBindView(Bundle savedInstanceState) {
        setStatusBarTranslucent();
        //初始化
        initView();
        //初始化界面监听器
@@ -70,8 +76,7 @@
            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.connect(viewBinding.registerConfirmPswEt.getId(), ConstraintSet.BOTTOM, ConstraintSet.PARENT_ID, ConstraintSet.BOTTOM, px2dip(h));//
                //应用约束
                cs.applyTo(viewBinding.parentCl);
            }
@@ -91,7 +96,22 @@
    private void initView() {
        switchPhoneOrMailView();
        //根据app语言默认服务器地址
        if (UserConfigManage.getInstance().isZh()) {
            mUrl = "https://china-gateway.hdlcontrol.com";
            viewBinding.regionTv.setText("HDL China");
        } else {
            viewBinding.regionTv.setText("HDL Bahrain");
            mUrl = "https://bahrain-gateway.hdlcontrol.com";
        }
        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() {
@@ -102,35 +122,46 @@
                finish();
            }
        });
        //服务器选择
        viewBinding.registerRegionServerRl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ListDialog listDialog = new ListDialog(_mActivity);
                ListStaticDialog listDialog = new ListStaticDialog(_mActivity);
                listDialog.show();
                listDialog.setOnHDLChinaOnListener(new ListDialog.onHDLChinaListener() {
                listDialog.setOnHDLChinaOnListener(new ListStaticDialog.onHDLChinaListener() {
                    @Override
                    public void HDLChina() {
                        mUrl = "https://china-gateway.hdlcontrol.com";
                        viewBinding.regionTv.setText(listDialog.geHDLChinaText());
                        listDialog.dismiss();
                    }
                });
                listDialog.setOnHDLBahrainListener(new ListDialog.onHDLBahrainListener() {
                listDialog.setOnHDLBahrainListener(new ListStaticDialog.onHDLBahrainListener() {
                    @Override
                    public void HDLBahrain() {
                        mUrl = "https://bahrain-gateway.hdlcontrol.com";
                        viewBinding.regionTv.setText(listDialog.getHDLBahrainText());
                        listDialog.dismiss();
                    }
                });
            }
        });
        //手机区号选择
        viewBinding.registerRegionAccountRl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                selectArea();
            }
        });
        //切换手机号
        viewBinding.registerPhoneTitleIc.underlineCl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                isPhoneType = true;
                switchPhoneOrMailView();
                switchPhoneOrEmailStyleView();
            }
        });
        //切换邮箱
@@ -138,27 +169,12 @@
            @Override
            public void onClick(View v) {
                isPhoneType = false;
                switchPhoneOrMailView();
                switchPhoneOrEmailStyleView();
            }
        });
        //输入密码
        viewBinding.registerPswEt.addTextChangedListener(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) {
                isCompleteEnabled();
            }
            @Override
            public void afterTextChanged(Editable s) {
            }
        });
        viewBinding.registerPswEt.addTextChangedListener(changePswTextWatcher);
        //密码显示或者隐藏
        viewBinding.registerPswHideIv.setOnClickListener(new View.OnClickListener() {
            @Override
@@ -180,22 +196,7 @@
            }
        });
        //输入确认密码
        viewBinding.registerConfirmPswEt.addTextChangedListener(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) {
                isCompleteEnabled();
            }
            @Override
            public void afterTextChanged(Editable s) {
            }
        });
        viewBinding.registerConfirmPswEt.addTextChangedListener(changeConfirmPswTextWatcher);
        //确认密码显示或者隐藏
        viewBinding.registerConfirmPswHideIv.setOnClickListener(new View.OnClickListener() {
            @Override
@@ -216,22 +217,7 @@
            }
        });
        //输入手机号或者邮箱
        viewBinding.registerAccountEt.addTextChangedListener(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) {
                isCompleteEnabled();
            }
            @Override
            public void afterTextChanged(Editable s) {
            }
        });
        viewBinding.registerAccountEt.addTextChangedListener(accountTextWatcher);
        //手机号获取验证码
        viewBinding.registerPhoneVerificationTv.setOnClickListener(new View.OnClickListener() {
            @Override
@@ -241,22 +227,7 @@
            }
        });
        //输入手机验证码
        viewBinding.registerPhoneVerificationEt.addTextChangedListener(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) {
                isCompleteEnabled();
            }
            @Override
            public void afterTextChanged(Editable s) {
            }
        });
        viewBinding.registerPhoneVerificationEt.addTextChangedListener(phoneVerificationTextWatcher);
        //邮箱获取验证码
        viewBinding.registerMailVerificationTv.setOnClickListener(new View.OnClickListener() {
            @Override
@@ -266,22 +237,7 @@
            }
        });
        //输入邮箱验证码
        viewBinding.registerMailVerificationEt.addTextChangedListener(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) {
                isCompleteEnabled();
            }
            @Override
            public void afterTextChanged(Editable s) {
            }
        });
        viewBinding.registerMailVerificationEt.addTextChangedListener(mailVerificationTextWatcher);
        //注册账号
        viewBinding.registerCompleteTv.setOnClickListener(new View.OnClickListener() {
            @Override
@@ -289,6 +245,9 @@
                if (!isLocalCheckAccountAndPassword()) {
                    return;
                }
                //
                viewBinding.textErrorTv.setText("");
                String account = viewBinding.registerAccountEt.getText().toString();
                String psw = viewBinding.registerConfirmPswEt.getText().toString();
                String verification_code;
@@ -297,14 +256,17 @@
                } else {
                    verification_code = viewBinding.registerMailVerificationEt.getText().toString();
                }
                HdlAccountLogic.getInstance().registerAccount(isPhoneType, account, psw, verification_code, new CloudCallBeak<Boolean>() {
                showLoading();
                HdlAccountLogic.getInstance().registerAccount_C(isPhoneType, account, psw, verification_code, 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() {
@@ -318,13 +280,15 @@
                    @Override
                    public void onFailure(HDLException e) {
                        hideLoading();
                        HdlThreadLogic.tipFlashingBox(_mActivity, false, e.getMsg(), e.getCode());
                    }
                });
            }
        });
    }
    /**
     * 发送验证码指令
@@ -346,9 +310,8 @@
        HdlAccountLogic.getInstance().regionByAccount(account, new CloudCallBeak<HDLUserRegionBean>() {
            @Override
            public void onSuccess(HDLUserRegionBean obj) {
                //发送消息验证码
                HdlThreadLogic.toast(RegisterAccountActivity.this, getString(R.string.home_login_already_exists));
                HdlLogLogic.print("regionByAccount onSuccess==" + obj);
                HdlLogLogic.print("获取账号区域信息--->" + obj, false);
            }
            @Override
@@ -362,7 +325,7 @@
                        mUrl = "https://test-gz.hdlcontrol.com";
                    }
                    HDLLinkPMUser.getInstance().setUserRegionUrl(mUrl);
                    HdlAccountLogic.getInstance().sendVerifyCode(isPhoneType, account, "86", 1, new CloudCallBeak<Boolean>() {
                    HdlAccountLogic.getInstance().sendVerifyCode(isPhoneType, account, viewBinding.regionAccountNumberTv.getText().toString(), 1, new CloudCallBeak<Boolean>() {
                        @Override
                        public void onSuccess(Boolean obj) {
                            if (isPhoneType) {
@@ -374,15 +337,19 @@
                        @Override
                        public void onFailure(HDLException e) {
                            HdlThreadLogic.toast(_mActivity, e);
                        }
                    });
                } else {
                    HdlThreadLogic.toast(_mActivity, e);
                }
            }
        });
    }
    /**
     * 初始化手机号计时器
@@ -393,7 +360,7 @@
            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));
            viewBinding.registerPhoneVerificationTv.setTextColor(getResources().getColor(R.color.text_25000000, null));
            viewBinding.registerPhoneVerificationTv.setEnabled(false);
        }
@@ -401,7 +368,7 @@
        @Override
        public void onFinish() {
            viewBinding.registerPhoneVerificationTv.setText(getString(R.string.home_login_verification_regain));
            viewBinding.registerPhoneVerificationTv.setTextColor(getResources().getColor(R.color.text_245EC3));
            viewBinding.registerPhoneVerificationTv.setTextColor(getResources().getColor(R.color.text_245EC3, null));
            viewBinding.registerPhoneVerificationTv.setEnabled(true);
@@ -417,7 +384,7 @@
            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));
//            viewBinding.registerMailVerificationTv.setTextColor(getResources().getColor(R.color.text_E6FFFFFF, null));
            viewBinding.registerMailVerificationTv.setEnabled(false);
        }
@@ -425,31 +392,49 @@
        @Override
        public void onFinish() {
            viewBinding.registerMailVerificationTv.setText(getString(R.string.home_login_verification_regain));
            viewBinding.registerMailVerificationTv.setTextColor(getResources().getColor(R.color.text_245EC3));
//            viewBinding.registerMailVerificationTv.setTextColor(getResources().getColor(R.color.text_E6FFFFFF, null));
            viewBinding.registerMailVerificationTv.setEnabled(true);
        }
    };
    /**
     * 国家手机号区号弹窗
     */
    private void selectArea() {
        CountryPickerFragment dialog = new CountryPickerFragment(this, new PickCountryCallback() {
            @Override
            public void onPick(Country country) {
                if (country.flag != 0) viewBinding.regionAccountTv.setText(country.name);
                viewBinding.regionAccountNumberTv.setText("+" + country.code);
            }
        });
        dialog.show();
        dialog.setDialogSize();
    }
    /**
     * 切换手机号或者邮箱的样式
     */
    private void switchPhoneOrMailView() {
    private void switchPhoneOrEmailStyleView() {
        if (isPhoneType) {
            //手机号
            viewBinding.registerPhoneTitleIc.accountTitleTv.setText(R.string.home_login_手机号);
            viewBinding.registerPhoneTitleIc.accountTitleTv.setTextSize(20);
            viewBinding.registerPhoneTitleIc.accountTitleTv.setTextColor(getResources().getColor(R.color.text_90000000));
            viewBinding.registerPhoneTitleIc.lineV.setVisibility(View.VISIBLE);
            viewBinding.registerPhoneTitleIc.accountTitleTv.setText(R.string.home_login_phone);
            viewBinding.registerPhoneTitleIc.accountTitleTv.setTextSize(18);
            viewBinding.registerPhoneTitleIc.accountTitleTv.setTextColor(getResources().getColor(R.color.text_E6FFFFFF, null));
            viewBinding.registerPhoneTitleIc.lineV.setVisibility(View.GONE);
            viewBinding.registerMailTitleIc.accountTitleTv.setText(R.string.home_login_邮箱);
            viewBinding.registerMailTitleIc.accountTitleTv.setTextSize(16);
            viewBinding.registerMailTitleIc.accountTitleTv.setTextColor(getResources().getColor(R.color.text_40000000));
            viewBinding.registerMailTitleIc.accountTitleTv.setText(R.string.home_login_email);
            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_请输入手机号);
            viewBinding.registerAccountEt.setHint(R.string.home_login_input_phone);
            //显示手机号验证码,隐藏邮箱验证码,
            viewBinding.registerPhoneVerificationCodeRl.setVisibility(View.VISIBLE);
            viewBinding.registerMailVerificationCodeRl.setVisibility(View.GONE);
@@ -467,15 +452,18 @@
        } else {
            //邮箱
            viewBinding.registerPhoneTitleIc.accountTitleTv.setText(R.string.home_login_手机号);
            viewBinding.registerPhoneTitleIc.accountTitleTv.setText(R.string.home_login_phone);
            viewBinding.registerPhoneTitleIc.accountTitleTv.setTextSize(16);
            viewBinding.registerPhoneTitleIc.accountTitleTv.setTextColor(getResources().getColor(R.color.text_40000000));
            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_邮箱);
            viewBinding.registerMailTitleIc.accountTitleTv.setTextSize(20);
            viewBinding.registerMailTitleIc.accountTitleTv.setTextColor(getResources().getColor(R.color.text_90000000));
            viewBinding.registerMailTitleIc.lineV.setVisibility(View.VISIBLE);
            viewBinding.registerMailTitleIc.accountTitleTv.setText(R.string.home_login_email);
            viewBinding.registerMailTitleIc.accountTitleTv.setTextSize(18);
            viewBinding.registerMailTitleIc.accountTitleTv.setTextColor(getResources().getColor(R.color.text_E6FFFFFF, null));
            viewBinding.registerMailTitleIc.lineV.setVisibility(View.GONE);
            //隐藏区号
            viewBinding.registerRegionAccountRl.setVisibility(View.GONE);
            //输入邮箱
            viewBinding.registerAccountEt.setInputType(InputType.TYPE_CLASS_TEXT);
            viewBinding.registerAccountEt.setHint(R.string.home_login_input_mail);
@@ -496,7 +484,7 @@
            viewBinding.registerConfirmPswEt.setText(mMailConfirmPsw);
        }
        isCompleteEnabled();
    }
@@ -514,6 +502,11 @@
            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);
    }
@@ -543,6 +536,7 @@
    @Override
    protected void onDestroy() {
        super.onDestroy();
        Country.destroy();
        if (phoneCountDownTimer != null) {
            phoneCountDownTimer.cancel();
            phoneCountDownTimer = null;
@@ -551,5 +545,110 @@
            mailCountDownTimer.cancel();
            mailCountDownTimer = null;
        }
        viewBinding.registerAccountEt.removeTextChangedListener(accountTextWatcher);
        viewBinding.registerPhoneVerificationEt.removeTextChangedListener(phoneVerificationTextWatcher);
        viewBinding.registerMailVerificationEt.removeTextChangedListener(mailVerificationTextWatcher);
        viewBinding.registerPswEt.removeTextChangedListener(changePswTextWatcher);
        viewBinding.registerConfirmPswEt.removeTextChangedListener(changeConfirmPswTextWatcher);
    }
    /**
     * 输入手机号或者邮箱
     */
    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) {
            isCompleteEnabled();
        }
        @Override
        public void afterTextChanged(Editable s) {
        }
    };
    /**
     * 输入手机验证码
     */
    private final TextWatcher phoneVerificationTextWatcher = 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) {
            isCompleteEnabled();
        }
        @Override
        public void afterTextChanged(Editable s) {
        }
    };
    /**
     * 邮箱获取验证码
     */
    private final TextWatcher mailVerificationTextWatcher = 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) {
            isCompleteEnabled();
        }
        @Override
        public void afterTextChanged(Editable s) {
        }
    };
    /**
     * 输入密码
     */
    private final TextWatcher changePswTextWatcher = 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) {
            isCompleteEnabled();
        }
        @Override
        public void afterTextChanged(Editable s) {
        }
    };
    /**
     * 输入确认密码
     */
    private final TextWatcher changeConfirmPswTextWatcher = 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) {
            isCompleteEnabled();
        }
        @Override
        public void afterTextChanged(Editable s) {
        }
    };
}