From 30859ca8f2175475d2c666353bc27f3b2ceede53 Mon Sep 17 00:00:00 2001
From: mac <user@users-MacBook-Pro.local>
Date: 星期四, 22 八月 2024 13:43:47 +0800
Subject: [PATCH] 2024年08月22日13:43:45

---
 app/src/main/java/com/hdl/photovoltaic/ui/me/MeChangePasswordActivity.java |  217 +++++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 181 insertions(+), 36 deletions(-)

diff --git a/app/src/main/java/com/hdl/photovoltaic/ui/me/MeChangePasswordActivity.java b/app/src/main/java/com/hdl/photovoltaic/ui/me/MeChangePasswordActivity.java
index bec2e0b..c693283 100644
--- a/app/src/main/java/com/hdl/photovoltaic/ui/me/MeChangePasswordActivity.java
+++ b/app/src/main/java/com/hdl/photovoltaic/ui/me/MeChangePasswordActivity.java
@@ -1,6 +1,5 @@
 package com.hdl.photovoltaic.ui.me;
 
-import androidx.appcompat.app.AppCompatActivity;
 import androidx.appcompat.content.res.AppCompatResources;
 
 import android.os.Bundle;
@@ -13,11 +12,21 @@
 import android.widget.EditText;
 import android.widget.ImageView;
 
+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.BaseActivity;
+import com.hdl.photovoltaic.base.CustomBaseActivity;
+import com.hdl.photovoltaic.config.UserConfigManage;
 import com.hdl.photovoltaic.databinding.ActivityMeChangePasswordBinding;
+import com.hdl.photovoltaic.listener.CloudCallBeak;
+import com.hdl.photovoltaic.other.HdlAccountLogic;
+import com.hdl.photovoltaic.other.HdlThreadLogic;
+import com.hdl.photovoltaic.widget.ConfirmationCancelDialog;
 
-public class MeChangePasswordActivity extends BaseActivity implements View.OnClickListener {
+/**
+ * 鎴戠殑-淇敼瀵嗙爜-鐣岄潰
+ */
+public class MeChangePasswordActivity extends CustomBaseActivity {
 
     private ActivityMeChangePasswordBinding viewBinding;
 
@@ -29,54 +38,185 @@
 
     @Override
     public void onBindView(Bundle savedInstanceState) {
+        setNotificationBarBackgroundColor(CustomColor.white);
+        setStatusBarTextColor();
         //鍒濆鍖�
         initView();
         //鍒濆鍖栫晫闈㈢洃鍚櫒
         initEvent();
+
     }
 
     /**
      * 鍒濆鍖栫晫闈㈢洃鍚櫒
      */
     private void initEvent() {
-        viewBinding.toolbarTopFragmentHouseListRl.topBackBtn.setOnClickListener(this);
-        viewBinding.meChangePasswordOldIc.mePswEt.addTextChangedListener(textWatcher1);
-        viewBinding.meChangePasswordOldIc.mePswHideIv.setOnClickListener(this);
-        viewBinding.meChangePasswordNewIc.mePswEt.addTextChangedListener(textWatcher2);
-        viewBinding.meChangePasswordNewIc.mePswHideIv.setOnClickListener(this);
-        viewBinding.meChangePasswordAffirmIc.mePswEt.addTextChangedListener(textWatcher3);
-        viewBinding.meChangePasswordAffirmIc.mePswHideIv.setOnClickListener(this);
+        viewBinding.toolbarTopFragmentHouseListRl.topBackLl.setOnClickListener(new View.OnClickListener() {
+            @Override
+            public void onClick(View v) {
+                finish();
+            }
+        });
+        //鍘熷瘑鐮佽緭鍏ユ
+        viewBinding.meChangePasswordOldIc.mePswEt.addTextChangedListener(oldPswTextWatcher);
+        //鏄剧ず鍘熷瘑鐮佸浘鏍�
+        viewBinding.meChangePasswordOldIc.mePswHideIv.setOnClickListener(new View.OnClickListener() {
+            @Override
+            public void onClick(View v) {
+                setEditTextStyle(viewBinding.meChangePasswordOldIc.mePswEt, viewBinding.meChangePasswordOldIc.mePswHideIv);
+            }
+        });
+        //鏂板瘑鐮佽緭鍏ユ
+        viewBinding.meChangePasswordNewIc.mePswEt.addTextChangedListener(newPswTextWatcher);
+        //鏄剧ず鏂板瘑鐮佸浘鏍�
+        viewBinding.meChangePasswordNewIc.mePswHideIv.setOnClickListener(new View.OnClickListener() {
+            @Override
+            public void onClick(View v) {
+                setEditTextStyle(viewBinding.meChangePasswordNewIc.mePswEt, viewBinding.meChangePasswordNewIc.mePswHideIv);
+            }
+        });
+        //鍐嶆杈撳叆鏂板瘑鐮佽緭鍏ユ
+        viewBinding.meChangePasswordAffirmIc.mePswEt.addTextChangedListener(confirmPswTextWatcher);
+        //鏄剧ず鍐嶆杈撳叆鏂板瘑鐮佸浘鏍�
+        viewBinding.meChangePasswordAffirmIc.mePswHideIv.setOnClickListener(new View.OnClickListener() {
+            @Override
+            public void onClick(View v) {
+                setEditTextStyle(viewBinding.meChangePasswordAffirmIc.mePswEt, viewBinding.meChangePasswordAffirmIc.mePswHideIv);
+            }
+        });
+        //纭淇敼
+        viewBinding.homeAffirmTv.setOnClickListener(new View.OnClickListener() {
+            @Override
+            public void onClick(View v) {
+                String oldPsw = viewBinding.meChangePasswordOldIc.mePswEt.getText().toString().replaceAll(" ", "");
+                String newPsw = viewBinding.meChangePasswordNewIc.mePswEt.getText().toString().replaceAll(" ", "");
+                String affirmPsw = viewBinding.meChangePasswordAffirmIc.mePswEt.getText().toString().replaceAll(" ", "");
+                if (!isEditTextPassword(oldPsw, newPsw, affirmPsw)) {
+                    return;
+                }
+                // 浜屾纭鎻愮ず妗�
+                ConfirmationCancelDialog dialog = new ConfirmationCancelDialog(_mActivity);
+                dialog.setTitle(getString(R.string.loading_title_tip));
+                dialog.setContent(_mActivity.getString(R.string.home_password_changed_successfully_log_in));
+                dialog.show();
+                dialog.setYesOnclickListener(new ConfirmationCancelDialog.onYesOnclickListener() {
+                    @Override
+                    public void Confirm() {
+                        sendChangePassword(oldPsw, newPsw);
+                    }
+                });
+                dialog.setNoOnclickListener(new ConfirmationCancelDialog.onNoOnclickListener() {
+                    @Override
+                    public void Cancel() {
+                        dialog.dismiss();
+                    }
+                });
+
+            }
+        });
     }
+
+    /**
+     * 鍙戦�佹洿鏀逛釜浜哄瘑鐮佹寚浠�
+     *
+     * @param oldPsw 鍘熸潵瀵嗙爜
+     * @param newPsw 鏂板瘑鐮�
+     */
+    private void sendChangePassword(String oldPsw, String newPsw) {
+
+        if (UserConfigManage.getInstance().isBAccount()) {
+            //B绔洿鏀逛釜浜哄瘑鐮�
+            HdlAccountLogic.getInstance().updatePassword_B(oldPsw, newPsw, new CloudCallBeak<String>() {
+                @Override
+                public void onSuccess(String str) {
+//                    HdlThreadLogic.tipFlashingBox(_mActivity, true, getString(R.string.home_login_pws_reset_succeeded), 0);
+                    HDLLinkPMUser.getInstance().logout(0);
+                }
+
+                @Override
+                public void onFailure(HDLException e) {
+                    HdlThreadLogic.tipFlashingBox(_mActivity, false, e.getMsg(), e.getCode());
+                }
+            });
+        } else {
+            //C绔洿鏀逛釜浜哄瘑鐮�
+            HdlAccountLogic.getInstance().updatePassword_C(oldPsw, newPsw, new CloudCallBeak<String>() {
+                @Override
+                public void onSuccess(String obj) {
+
+                    HDLLinkPMUser.getInstance().logout(0);
+
+
+                }
+
+                @Override
+                public void onFailure(HDLException e) {
+                    HdlThreadLogic.tipFlashingBox(_mActivity, false, e.getMsg(), e.getCode());
+                }
+            });
+
+        }
+    }
+
 
     /**
      * 鍒濆鍖�
      */
     private void initView() {
-        viewBinding.toolbarTopFragmentHouseListRl.topBarView.setBackgroundColor(getResources().getColor(R.color.text_FFFFFFFF));
+        viewBinding.toolbarTopFragmentHouseListRl.topBarView.setBackgroundColor(getResources().getColor(R.color.text_FFFFFFFF, null));
         viewBinding.toolbarTopFragmentHouseListRl.topTitleTv.setText(R.string.home_login_change_password);
-        viewBinding.toolbarTopFragmentHouseListRl.topTitleTv.setTextColor(getResources().getColor(R.color.text_030D1C));
-        viewBinding.toolbarTopFragmentHouseListRl.topBackBtn.setVisibility(View.VISIBLE);
+        viewBinding.toolbarTopFragmentHouseListRl.topTitleTv.setTextColor(getResources().getColor(R.color.text_030D1C, null));
+        viewBinding.toolbarTopFragmentHouseListRl.topBackLl.setVisibility(View.VISIBLE);
+        viewBinding.toolbarTopFragmentHouseListRl.topLeftIv.setImageResource(R.drawable.back_c);
         viewBinding.meChangePasswordOldIc.mePswTitleTv.setText(R.string.home_login_old_pws);
         viewBinding.meChangePasswordOldIc.mePswEt.setHint(R.string.home_login_input_old_pws);
+        viewBinding.meChangePasswordOldIc.lineV.setVisibility(View.GONE);
         viewBinding.meChangePasswordNewIc.mePswTitleTv.setText(R.string.home_login_new_pws);
         viewBinding.meChangePasswordNewIc.mePswEt.setHint(R.string.home_login_input_new_pws);
+        viewBinding.meChangePasswordNewIc.lineV.setVisibility(View.GONE);
         viewBinding.meChangePasswordAffirmIc.mePswTitleTv.setText(R.string.home_login_affirm_psw);
         viewBinding.meChangePasswordAffirmIc.mePswEt.setHint(R.string.home_login_input_affirm_psw);
+        viewBinding.meChangePasswordAffirmIc.lineV.setVisibility(View.GONE);
 
 
     }
 
-    @Override
-    public void onClick(View v) {
-        if (v.getId() == viewBinding.toolbarTopFragmentHouseListRl.topBackBtn.getId()) {
-            finish();
-        } else if (v.getId() == viewBinding.meChangePasswordOldIc.mePswHideIv.getId()) {
-            setEditTextStyle(viewBinding.meChangePasswordOldIc.mePswEt, viewBinding.meChangePasswordOldIc.mePswHideIv);
-        } else if (v.getId() == viewBinding.meChangePasswordNewIc.mePswHideIv.getId()) {
-            setEditTextStyle(viewBinding.meChangePasswordNewIc.mePswEt, viewBinding.meChangePasswordNewIc.mePswHideIv);
-        } else if (v.getId() == viewBinding.meChangePasswordAffirmIc.mePswHideIv.getId()) {
-            setEditTextStyle(viewBinding.meChangePasswordAffirmIc.mePswEt, viewBinding.meChangePasswordAffirmIc.mePswHideIv);
+
+    /**
+     * 鏍¢獙鎸夐挳鏄惁鍚敤
+     */
+    private void isCompleteEnabled() {
+        String oldPsw = viewBinding.meChangePasswordOldIc.mePswEt.getText().toString();
+        String newPsw = viewBinding.meChangePasswordNewIc.mePswEt.getText().toString();
+        String affirmPsw = viewBinding.meChangePasswordAffirmIc.mePswEt.getText().toString();
+        boolean isEnabled = oldPsw.length() > 0 && newPsw.length() > 0 && affirmPsw.length() > 0;
+        viewBinding.homeAffirmTv.setEnabled(isEnabled);
+    }
+
+    /**
+     * 鏈湴鏍¢獙瀵嗙爜鏄惁姝g‘
+     *
+     * @param oldPsw    鍘熸潵瀵嗙爜
+     * @param newPsw    鏂板瘑鐮�
+     * @param affirmPsw 鍐嶆纭鏂板瘑鐮�
+     * @return 涓�鏍疯繑鍥瀟rue锛屽惁鑰協alse
+     */
+    private boolean isEditTextPassword(String oldPsw, String newPsw, String affirmPsw) {
+        if (newPsw.length() < 6 || affirmPsw.length() < 6) {
+            HdlThreadLogic.tipFlashingBox(_mActivity, true, getString(R.string.home_login_least6), -1);
+            return false;
         }
+        if (!newPsw.equals(affirmPsw)) {
+            //鏂板瘑鐮佸拰纭瀵嗙爜涓嶄竴鏍�
+            HdlThreadLogic.tipFlashingBox(_mActivity, true, getString(R.string.home_login_input_unlike_psw), -1);
+            return false;
+        }
+        if (oldPsw.equals(newPsw)) {
+            HdlThreadLogic.tipFlashingBox(_mActivity, true, getString(R.string.home_old_password_not_new_password), -1);
+            return false;
+        }
+        return true;
+
     }
 
     private void setEditTextStyle(EditText editText, ImageView imageView) {
@@ -99,12 +239,15 @@
     @Override
     protected void onDestroy() {
         super.onDestroy();
-        viewBinding.meChangePasswordOldIc.mePswEt.removeTextChangedListener(textWatcher1);
-        viewBinding.meChangePasswordNewIc.mePswEt.removeTextChangedListener(textWatcher2);
-        viewBinding.meChangePasswordAffirmIc.mePswEt.removeTextChangedListener(textWatcher3);
+        viewBinding.meChangePasswordOldIc.mePswEt.removeTextChangedListener(oldPswTextWatcher);
+        viewBinding.meChangePasswordNewIc.mePswEt.removeTextChangedListener(newPswTextWatcher);
+        viewBinding.meChangePasswordAffirmIc.mePswEt.removeTextChangedListener(confirmPswTextWatcher);
     }
 
-    private final TextWatcher textWatcher1 = new TextWatcher() {
+    /**
+     * 杈撳叆鍘熷瘑鐮�
+     */
+    private final TextWatcher oldPswTextWatcher = new TextWatcher() {
         @Override
         public void beforeTextChanged(CharSequence s, int start, int count, int after) {
 
@@ -112,16 +255,18 @@
 
         @Override
         public void onTextChanged(CharSequence s, int start, int before, int count) {
-
         }
 
         @Override
         public void afterTextChanged(Editable s) {
-
+            isCompleteEnabled();
         }
     };
 
-    private final TextWatcher textWatcher2 = new TextWatcher() {
+    /**
+     * 杈撳叆鏂板瘑鐮�
+     */
+    private final TextWatcher newPswTextWatcher = new TextWatcher() {
         @Override
         public void beforeTextChanged(CharSequence s, int start, int count, int after) {
 
@@ -129,16 +274,17 @@
 
         @Override
         public void onTextChanged(CharSequence s, int start, int before, int count) {
-
         }
 
         @Override
         public void afterTextChanged(Editable s) {
-
+            isCompleteEnabled();
         }
     };
-
-    private final TextWatcher textWatcher3 = new TextWatcher() {
+    /**
+     * 鍐嶆纭瀵嗙爜
+     */
+    private final TextWatcher confirmPswTextWatcher = new TextWatcher() {
         @Override
         public void beforeTextChanged(CharSequence s, int start, int count, int after) {
 
@@ -146,12 +292,11 @@
 
         @Override
         public void onTextChanged(CharSequence s, int start, int before, int count) {
-
         }
 
         @Override
         public void afterTextChanged(Editable s) {
-
+            isCompleteEnabled();
         }
     };
 

--
Gitblit v1.8.0