| | |
| | | package com.hdl.photovoltaic.ui; |
| | | |
| | | |
| | | import android.content.Intent; |
| | | import android.os.Bundle; |
| | | import android.text.Editable; |
| | | import android.text.Spannable; |
| | |
| | | import android.text.method.HideReturnsTransformationMethod; |
| | | import android.text.method.PasswordTransformationMethod; |
| | | import android.text.style.ForegroundColorSpan; |
| | | import android.util.Log; |
| | | import android.view.View; |
| | | import android.widget.TextView; |
| | | |
| | | |
| | | import androidx.appcompat.content.res.AppCompatResources; |
| | | |
| | | import com.hdl.linkpm.sdk.core.exception.HDLException; |
| | | import com.hdl.linkpm.sdk.user.HDLLinkPMUser; |
| | | import com.hdl.linkpm.sdk.user.bean.HDLLoginBean; |
| | | import com.hdl.linkpm.sdk.user.bean.HDLUserRegionBean; |
| | | import com.hdl.linkpm.sdk.user.callback.ILoginCallBack; |
| | | import com.hdl.photovoltaic.R; |
| | | import com.hdl.photovoltaic.base.CustomBaseActivity; |
| | | import com.hdl.photovoltaic.config.UserConfigManage; |
| | | import com.hdl.photovoltaic.other.HdlFileLogic; |
| | | import com.hdl.photovoltaic.other.HdlResidenceLogic; |
| | | import com.hdl.photovoltaic.ui.bean.LoginUserBean; |
| | | import com.hdl.photovoltaic.ui.bean.LoginUserRegionBean; |
| | | import com.hdl.photovoltaic.ui.account.ChangePassword; |
| | | import com.hdl.photovoltaic.ui.account.RegisterAccountActivity; |
| | | import com.hdl.photovoltaic.ui.bean.HouseIdBean; |
| | | import com.hdl.photovoltaic.config.AppConfigManage; |
| | | import com.hdl.photovoltaic.databinding.ActivityHomeLoginBinding; |
| | | import com.hdl.photovoltaic.listener.CloudCallBeak; |
| | | import com.hdl.photovoltaic.other.HdlAccountLogic; |
| | | import com.hdl.photovoltaic.other.HdlThreadLogic; |
| | | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * 登录的界面 |
| | | */ |
| | | public class HomeLoginActivity extends CustomBaseActivity { |
| | | |
| | | private ActivityHomeLoginBinding viewBinding; |
| | |
| | | private void initView() { |
| | | setStringDifferentColors(viewBinding.homeLoginPrivacyTv); |
| | | //测试用 |
| | | viewBinding.homeLoginAccountEt.setText("18402017839"); |
| | | viewBinding.homeLoginAccountEt.setText("13375012441"); |
| | | viewBinding.homeLoginPasswordEt.setText("123456"); |
| | | isLoginTextViewEnabled(); |
| | | } |
| | | |
| | | private void initEvent() { |
| | | |
| | | viewBinding.homeLoginAccountEt.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) { |
| | | Log.d("HomeLoginActivity2", String.format("CharSequence=%s,start=%s,before=%s,count=%s", s, start, before, count)); |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void afterTextChanged(Editable s) { |
| | | if (s.length() > 0) { |
| | | if (viewBinding.homeLoginClearContentsIv.getVisibility() == View.GONE) { |
| | | viewBinding.homeLoginClearContentsIv.setVisibility(View.VISIBLE); |
| | | } |
| | | } else { |
| | | if (viewBinding.homeLoginClearContentsIv.getVisibility() == View.VISIBLE) { |
| | | viewBinding.homeLoginClearContentsIv.setVisibility(View.GONE); |
| | | } |
| | | } |
| | | isLoginTextViewEnabled(); |
| | | |
| | | } |
| | | }); |
| | | viewBinding.homeLoginAccountEt.addTextChangedListener(accountTextWatcher); |
| | | viewBinding.homeLoginClearContentsIv.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | |
| | | } |
| | | }); |
| | | |
| | | viewBinding.homeLoginPasswordEt.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) { |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void afterTextChanged(Editable s) { |
| | | isLoginTextViewEnabled(); |
| | | } |
| | | }); |
| | | viewBinding.homeLoginPasswordEt.addTextChangedListener(passwordTextWatcher); |
| | | viewBinding.homeLoginHideIv.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | |
| | | } |
| | | }); |
| | | |
| | | |
| | | //选择b端,c端 |
| | | viewBinding.homeLoginInstallUserTv.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | v.setSelected(!v.isSelected()); |
| | | UserConfigManage.getInstance().setBAccount(v.isSelected()); |
| | | viewBinding.homeLoginCheckIv.setSelected(UserConfigManage.getInstance().isBAccount()); |
| | | if (UserConfigManage.getInstance().isBAccount()) { |
| | | viewBinding.homeLoginRegisterTv.setVisibility(View.GONE); |
| | | } else { |
| | | viewBinding.homeLoginRegisterTv.setVisibility(View.VISIBLE); |
| | | } |
| | | } |
| | | }); |
| | | //选择b端,c端 |
| | | viewBinding.homeLoginCheckIv.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | v.setSelected(!v.isSelected()); |
| | | UserConfigManage.getInstance().setBAccount(v.isSelected()); |
| | | if (UserConfigManage.getInstance().isBAccount()) { |
| | | viewBinding.homeLoginRegisterTv.setVisibility(View.GONE); |
| | | } else { |
| | | viewBinding.homeLoginRegisterTv.setVisibility(View.VISIBLE); |
| | | } |
| | | } |
| | | }); |
| | | viewBinding.homeLoginPrivacyCheckIv.setOnClickListener(new View.OnClickListener() { |
| | |
| | | // //隐私协议提示 |
| | | // return; |
| | | // } |
| | | showLoading(getString(R.string.home_login_登录中)); |
| | | HdlAccountLogic.getInstance().regionByAccount(account, new CloudCallBeak<LoginUserRegionBean>() { |
| | | showLoading(getString(R.string.home_login_be_logging_in)); |
| | | HdlAccountLogic.getInstance().regionByAccount(account, new CloudCallBeak<HDLUserRegionBean>() { |
| | | @Override |
| | | public void onSuccess(LoginUserRegionBean obj) { |
| | | public void onSuccess(HDLUserRegionBean obj) { |
| | | AppConfigManage.setUserRegionUrl(obj.getRegionUrl()); |
| | | HdlAccountLogic.getInstance().loginByPassword(account, password, new CloudCallBeak<LoginUserBean>() { |
| | | HDLLinkPMUser.getInstance().setUserRegionUrl(AppConfigManage.getUserRegionUrl()); |
| | | HdlAccountLogic.getInstance().loginByPassword(account, password, new ILoginCallBack() { |
| | | @Override |
| | | public void onSuccess(LoginUserBean obj) { |
| | | HdlThreadLogic.runMainThread(new Runnable() { |
| | | public void onSuccess(HDLLoginBean obj) { |
| | | HdlResidenceLogic.getInstance().getResidenceIdList("", "", new CloudCallBeak<List<HouseIdBean>>() { |
| | | @Override |
| | | public void run() { |
| | | HdlResidenceLogic.getInstance().getResidenceList(1, 100, new CloudCallBeak<Boolean>() { |
| | | @Override |
| | | public void onSuccess(Boolean obj) { |
| | | public void onSuccess(List<HouseIdBean> obj) { |
| | | hideLoading(); |
| | | HdlResidenceLogic.getInstance().setHouseIdList(obj); |
| | | restoreButtonStyleToInitializeState(); |
| | | startActivity(MyPowerStationActivity.class); |
| | | } |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(Exception exception) { |
| | | |
| | | } |
| | | }); |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | hideLoading(); |
| | | restoreButtonStyleToInitializeState(); |
| | | startActivity(MyPowerStationActivity.class); |
| | | |
| | | } |
| | | }, null, null); |
| | | |
| | | }); |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(Exception exception) { |
| | | public void onFailure(HDLException exception) { |
| | | hideLoading(); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(Exception exception) { |
| | | public void onFailure(HDLException e) { |
| | | hideLoading(); |
| | | } |
| | | }); |
| | |
| | | viewBinding.homeLoginExperienceTv.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | startActivity(MyPowerStationActivity.class); |
| | | v.setSelected(!v.isSelected()); |
| | | UserConfigManage.getInstance().setUserExperience(v.isSelected()); |
| | | // requestPermissions(); |
| | | // startActivity(MyPowerStationActivity.class); |
| | | HdlFileLogic.getInstance().deleteDirectory(HdlFileLogic.getInstance().getCurrentHomeRootPath()); |
| | | } |
| | | }); |
| | | //注册 |
| | | viewBinding.homeLoginRegisterTv.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | Intent intent = new Intent(); |
| | | intent.setClass(HomeLoginActivity.this, RegisterAccountActivity.class); |
| | | startActivity(intent); |
| | | } |
| | | }); |
| | | //忘记密码 |
| | | viewBinding.homeLoginForgetPasswordTv.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | Intent intent = new Intent(); |
| | | intent.setClass(HomeLoginActivity.this, ChangePassword.class); |
| | | startActivity(intent); |
| | | } |
| | | }); |
| | | |
| | |
| | | private boolean isLocalCheckAccountAndPassword(String account, String password) { |
| | | if (TextUtils.isEmpty(account)) { |
| | | viewBinding.homeLoginLine1V.setBackgroundColor(getColor(R.color.text_D34545)); |
| | | viewBinding.homeLoginAccountTextErrorTv.setText(R.string.home_login_error_账号不能为空); |
| | | viewBinding.homeLoginAccountTextErrorTv.setText(R.string.home_login_error_account_null); |
| | | return false; |
| | | } |
| | | if (TextUtils.isEmpty(password)) { |
| | | viewBinding.homeLoginLine2V.setBackgroundColor(getColor(R.color.text_D34545)); |
| | | viewBinding.homeLoginPasswordTextErrorTv.setText(R.string.home_login_error_密码不能为空); |
| | | viewBinding.homeLoginPasswordTextErrorTv.setText(R.string.home_login_error_password_null); |
| | | return false; |
| | | } |
| | | |
| | | |
| | | if (password.length() < 6 || password.length() > 16) { |
| | | viewBinding.homeLoginLine2V.setBackgroundColor(getColor(R.color.text_D34545)); |
| | | viewBinding.homeLoginPasswordTextErrorTv.setText(R.string.home_login_error_最少6_16个字符); |
| | | viewBinding.homeLoginPasswordTextErrorTv.setText(R.string.home_login_error_6_16_str); |
| | | return false; |
| | | } |
| | | return true; |
| | |
| | | * 恢复组件样式到初始化状态 |
| | | */ |
| | | private void restoreButtonStyleToInitializeState() { |
| | | viewBinding.homeLoginLine1V.setBackgroundColor(getColor(R.color.text_E1E1E1)); |
| | | viewBinding.homeLoginAccountTextErrorTv.setText(""); |
| | | viewBinding.homeLoginLine2V.setBackgroundColor(getColor(R.color.text_E1E1E1)); |
| | | viewBinding.homeLoginPasswordTextErrorTv.setText(""); |
| | | HdlThreadLogic.runMainThread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | viewBinding.homeLoginLine1V.setBackgroundColor(getColor(R.color.text_E1E1E1)); |
| | | viewBinding.homeLoginAccountTextErrorTv.setText(""); |
| | | viewBinding.homeLoginLine2V.setBackgroundColor(getColor(R.color.text_E1E1E1)); |
| | | viewBinding.homeLoginPasswordTextErrorTv.setText(""); |
| | | } |
| | | }, null, null); |
| | | } |
| | | |
| | | /** |
| | |
| | | view.setText(spannable); |
| | | } |
| | | |
| | | /** |
| | | * 输入账号 |
| | | */ |
| | | 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) { |
| | | if (s.length() > 0) { |
| | | if (viewBinding.homeLoginClearContentsIv.getVisibility() == View.GONE) { |
| | | viewBinding.homeLoginClearContentsIv.setVisibility(View.VISIBLE); |
| | | } |
| | | } else { |
| | | if (viewBinding.homeLoginClearContentsIv.getVisibility() == View.VISIBLE) { |
| | | viewBinding.homeLoginClearContentsIv.setVisibility(View.GONE); |
| | | } |
| | | } |
| | | isLoginTextViewEnabled(); |
| | | } |
| | | }; |
| | | /** |
| | | * 输入密码 |
| | | */ |
| | | private final TextWatcher passwordTextWatcher = 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) { |
| | | isLoginTextViewEnabled(); |
| | | } |
| | | }; |
| | | |
| | | @Override |
| | | protected void onDestroy() { |
| | | super.onDestroy(); |
| | | viewBinding.homeLoginAccountEt.removeTextChangedListener(accountTextWatcher); |
| | | viewBinding.homeLoginPasswordEt.removeTextChangedListener(passwordTextWatcher); |
| | | } |
| | | } |