From 8814f3f0828e6ac652a29cc9de9f971fd55bca5b Mon Sep 17 00:00:00 2001 From: wjc <1243177876@qq.com> Date: 星期三, 07 五月 2025 14:54:42 +0800 Subject: [PATCH] 2025年05月07日14:54:39 --- app/src/main/java/com/hdl/photovoltaic/ui/me/BindPhoneActivity.java | 174 +++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 160 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/com/hdl/photovoltaic/ui/me/BindPhoneActivity.java b/app/src/main/java/com/hdl/photovoltaic/ui/me/BindPhoneActivity.java index 9a3e08c..cb5864d 100644 --- a/app/src/main/java/com/hdl/photovoltaic/ui/me/BindPhoneActivity.java +++ b/app/src/main/java/com/hdl/photovoltaic/ui/me/BindPhoneActivity.java @@ -3,17 +3,26 @@ 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.ActivityBindPhoneBinding; +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.GPSManagerUtils; +import com.sahooz.library.countrypicker.Country; +import com.sahooz.library.countrypicker.CountryPickerFragment; +import com.sahooz.library.countrypicker.PickCountryCallback; /** * 淇敼缁戝畾鎵嬫満鍙风殑鐣岄潰 @@ -30,8 +39,8 @@ @Override public void onBindView(Bundle savedInstanceState) { - setNotificationBarBackgroundColor(CustomColor.white); - setStatusBarTextColor(); + setStatusBarTranslucent(); + getWindow().setNavigationBarColor(getColor(R.color.text_FF000000)); //鍒濆鍖� initView(); //鍒濆鍖栫晫闈㈢洃鍚櫒 @@ -41,10 +50,17 @@ private void initEvent() { - viewBinding.toolbarTopFragmentHouseListRl.topBackBtn.setOnClickListener(new View.OnClickListener() { + viewBinding.toolbarTopRl.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(); } }); @@ -61,16 +77,24 @@ viewBinding.bindPhoneEt.setText(""); } }); + + //杈撳叆璐﹀彿 + viewBinding.bindPhoneEt.addTextChangedListener(accountTextWatcher); + //杈撳叆楠岃瘉鐮� + viewBinding.changePhoneVerificationEt.addTextChangedListener(verificationCodeTextWatcher); viewBinding.bindPhoneTv.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - if (isLocalCheck()) { + if (isEnabled()) { String phoneStr = viewBinding.bindPhoneEt.getText().toString(); String verificationStr = viewBinding.changePhoneVerificationEt.getText().toString(); - HdlAccountLogic.getInstance().bindingAccount_C(phoneStr, "", verificationStr, new CloudCallBeak<Boolean>() { + HdlAccountLogic.getInstance().bindingAccount_C(phoneStr, "", verificationStr, viewBinding.bindAreaNumberTv.getText().toString(), new CloudCallBeak<Boolean>() { @Override public void onSuccess(Boolean obj) { - HdlThreadLogic.tipFlashingBox(_mActivity, true, getString(R.string.set_bind_phone_succeed), 0); + UserConfigManage.getInstance().setBingPhone(phoneStr); + UserConfigManage.getInstance().Save(); + setResult(20); + finish(); } @Override @@ -85,10 +109,51 @@ } 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.topBackBtn.setVisibility(View.VISIBLE); - viewBinding.toolbarTopFragmentHouseListRl.topBarView.setBackgroundColor(getResources().getColor(R.color.text_FFFFFFFF, null)); + if (UserConfigManage.getInstance().isZh()) { + viewBinding.bindAreaTv.setText(getText(R.string.home_chinese_mainland)); + viewBinding.bindAreaNumberTv.setText("+86"); + } else { + viewBinding.bindAreaTv.setText(getText(R.string.iraq)); + viewBinding.bindAreaNumberTv.setText("+964"); + } + viewBinding.toolbarTopRl.topTitleTv.setText(R.string.set_change_bind_phone_number); + viewBinding.toolbarTopRl.topBackLl.setVisibility(View.VISIBLE); + checkClearIconShowOrNot(viewBinding.bindPhoneEt.getText().toString()); + try { + Country.load(this); + Country country = null; + if (TextUtils.isEmpty(GPSManagerUtils.getInstance().getCountryCode(this))) { + //鍐嶆牴鎹郴缁熻瑷� + country = Country.getCountryInfo(); + } else { + //鍏堟牴鎹畾浣� + country = Country.getLocationCountryInfo(GPSManagerUtils.getInstance().getCountryCode(this)); + } + if (country != null) { + viewBinding.bindAreaTv.setText(country.translate); + viewBinding.bindAreaNumberTv.setText("+" + country.code); + } + } catch (Exception e) { + e.printStackTrace(); + } + HdlCommonLogic.getInstance().setSpan(viewBinding.bindPhoneVerificationTv, viewBinding.bindPhoneVerificationTv.getText().toString(), true, null); + } + + /** + * 鍥藉鎵嬫満鍙峰尯鍙峰脊绐� + */ + private void selectArea() { + CountryPickerFragment dialog = new CountryPickerFragment(this, new PickCountryCallback() { + @Override + public void onPick(Country country) { + if (country.flag != 0) + viewBinding.bindAreaTv.setText(country.translate); + String code = "+" + country.code; + viewBinding.bindAreaNumberTv.setText(code); + } + }); + dialog.show(); + dialog.setDialogSize(); } /** @@ -101,7 +166,7 @@ HdlThreadLogic.tipFlashingBox(this, false, getString(R.string.home_login_phone_null), -1); return; } - HdlAccountLogic.getInstance().sendVerifyCode(true, account, "86", 3, new CloudCallBeak<Boolean>() { + HdlAccountLogic.getInstance().sendVerifyCode_C(true, account, viewBinding.bindAreaNumberTv.getText().toString(), VerifyType.VerifyType_3, new CloudCallBeak<Boolean>() { @Override public void onSuccess(Boolean obj) { countDownTimer.start(); @@ -125,7 +190,6 @@ 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); } @@ -133,12 +197,44 @@ @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 void checkClearIconShowOrNot(String s) { + if (s.replace(" ", "").length() > 0) { + if (viewBinding.bindPhoneClearIv.getVisibility() == View.GONE) { + viewBinding.bindPhoneClearIv.setVisibility(View.VISIBLE); + } + } else { + if (viewBinding.bindPhoneClearIv.getVisibility() == View.VISIBLE) { + viewBinding.bindPhoneClearIv.setVisibility(View.GONE); + } + } + } + + /** + * 鏍¢獙纭鎸夐挳鏄惁鍚敤 + */ + private boolean isEnabled() { + String account = viewBinding.bindPhoneEt.getText().toString().replace(" ", ""); + String verificationCode = viewBinding.changePhoneVerificationEt.getText().toString().replace(" ", ""); + boolean isEnabled = account.length() > 0 && verificationCode.length() > 0; + if (isEnabled) { + viewBinding.bindPhoneTv.setTextColor(getColor(R.color.text_FFACACAC)); + } else { + viewBinding.bindPhoneTv.setTextColor(getColor(R.color.text_FF5B5B5B)); + } + viewBinding.bindPhoneTv.setEnabled(isEnabled); + return isEnabled; + + } + /** * 鏈湴鏍¢獙 @@ -154,18 +250,68 @@ HdlThreadLogic.tipFlashingBox(this, false, getString(R.string.home_login_null_verification_code), -1); return false; } - return true; } + /** + * 杈撳叆璐﹀彿 + */ + 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(); + Country.destroy(); if (countDownTimer != null) { countDownTimer.cancel(); countDownTimer = null; } + viewBinding.bindPhoneEt.removeTextChangedListener(accountTextWatcher); + viewBinding.changePhoneVerificationEt.removeTextChangedListener(verificationCodeTextWatcher); } + + /** + * 鐗╃悊鎸夐敭杩斿洖浜嬩欢 + */ + @Override + public void onBackPressed() { + setResult(20); + super.onBackPressed(); + } } \ No newline at end of file -- Gitblit v1.8.0