From b75795836a851a13e54cc4efb597262fb448217c Mon Sep 17 00:00:00 2001
From: mac <user@users-MacBook-Pro.local>
Date: 星期三, 08 五月 2024 15:22:01 +0800
Subject: [PATCH] 2024年05月08日15:21:54

---
 app/src/main/java/com/hdl/photovoltaic/ui/me/MeFragment.java |   87 ++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 77 insertions(+), 10 deletions(-)

diff --git a/app/src/main/java/com/hdl/photovoltaic/ui/me/MeFragment.java b/app/src/main/java/com/hdl/photovoltaic/ui/me/MeFragment.java
index edc24a2..bde7be6 100644
--- a/app/src/main/java/com/hdl/photovoltaic/ui/me/MeFragment.java
+++ b/app/src/main/java/com/hdl/photovoltaic/ui/me/MeFragment.java
@@ -2,12 +2,14 @@
 
 import android.content.Intent;
 import android.os.Bundle;
+import android.text.TextUtils;
 import android.view.View;
 
 
 import androidx.annotation.Nullable;
 
-import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
+import com.alibaba.fastjson.JSONObject;
+import com.google.gson.Gson;
 import com.hdl.linkpm.sdk.core.exception.HDLException;
 import com.hdl.photovoltaic.R;
 import com.hdl.photovoltaic.base.CustomBaseFragment;
@@ -18,12 +20,15 @@
 import com.hdl.photovoltaic.listener.CloudCallBeak;
 import com.hdl.photovoltaic.other.HdlAccountLogic;
 import com.hdl.photovoltaic.other.HdlLogLogic;
+import com.hdl.photovoltaic.other.HdlResidenceLogic;
 import com.hdl.photovoltaic.other.HdlThreadLogic;
 import com.hdl.photovoltaic.ui.bean.BUserInfo;
 import com.hdl.photovoltaic.ui.bean.CUserInfo;
 import com.hdl.photovoltaic.ui.test.TestMainActivity;
 import com.hdl.photovoltaic.utils.GlideUtils;
 import com.hdl.sdk.link.core.bean.eventbus.BaseEventBus;
+
+import org.greenrobot.eventbus.EventBus;
 
 /**
  * 鎴戠殑-鐣岄潰
@@ -49,6 +54,7 @@
         initEvent();
         //鍒濆鍖栨暟鎹�
         initData();
+
     }
 
     /**
@@ -56,11 +62,13 @@
      */
     private void initData() {
 //        showLoading();
-        if (UserConfigManage.getInstance().isBAccount()) {
-            this.getBUserInfo();
-        } else {
-            this.getCMemberInfo();
-        }
+//        if (UserConfigManage.getInstance().isBAccount()) {
+//            this.getBUserInfo();
+//        } else {
+//            this.getCMemberInfo();
+//        }
+        //鍥犱负uni閭h竟闇�瑕侊紝鍚姩鐨勬椂鍊欏氨璇诲彇鍟�
+        this.getResidenceTemperatureUnit();
     }
 
 
@@ -131,7 +139,6 @@
             public void onSuccess(BUserInfo bUserInfo) {
                 mB_UserInfo = bUserInfo;
 //                hideLoading();
-
                 setMemberName(bUserInfo.getUserName());
             }
 
@@ -152,6 +159,11 @@
         viewBinding.fragmentMeIconParentCl.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
+                if (UserConfigManage.getInstance().isBAccount()) {
+                    //todo B绔笉鏀寔鏇存敼鏄电О
+                    HdlThreadLogic.toast(_mActivity, R.string.loading_not_supported);
+                    return;
+                }
                 Intent intent = new Intent();
                 intent.setClass(_mActivity, PersonalDataActivity.class);
                 if (mC_UserInfo == null) {
@@ -207,6 +219,8 @@
 
         viewBinding.fragmentMeLineAsregardsIl.fragmentMeLineLeftIconIv.setImageResource(R.drawable.asregards);
         viewBinding.fragmentMeLineAsregardsIl.fragmentMeLineTitleIv.setText(R.string.me_regard);
+        setMemberName(UserConfigManage.getInstance().getUserName());
+//        setMemberHeadIcon(UserConfigManage.getInstance().getUserImageUrl());
 
 
     }
@@ -230,10 +244,14 @@
      * 鏄剧ず鐢ㄦ埛澶村儚
      */
     private void setMemberHeadIcon(String memberHeadIconUrl) {
+        if (TextUtils.isEmpty(memberHeadIconUrl)) {
+            return;
+        }
         if (mC_UserInfo != null) {
             mC_UserInfo.setMemberHeadIcon(memberHeadIconUrl);
         }
-        GlideUtils.getRoundedCornersImage(_mActivity, memberHeadIconUrl, viewBinding.fragmentMeIconIv, new RoundedCorners(4));
+        GlideUtils.getCircleCropImage(_mActivity, memberHeadIconUrl, viewBinding.fragmentMeIconIv, true);
+//        GlideUtils.getRoundedCornersImage(_mActivity, memberHeadIconUrl, viewBinding.fragmentMeIconIv, new RoundedCorners(4), true);
 
     }
 
@@ -241,6 +259,9 @@
      * 鏄剧ず鐢ㄦ埛鍚嶇О
      */
     private void setMemberName(String userName) {
+        if (TextUtils.isEmpty(userName)) {
+            return;
+        }
         viewBinding.fragmentMeUserNameIv.setText(userName);
         UserConfigManage.getInstance().setUserName(userName);
         UserConfigManage.getInstance().Save();
@@ -250,12 +271,58 @@
     @Override
     public void onEventMessage(BaseEventBus eventBus) {
         super.onEventMessage(eventBus);
+        if (eventBus == null) {
+            return;
+        }
         //鎺ユ敹澶栭儴鐐瑰嚮浜嬩欢
         if (eventBus.getTopic().equals(ConstantManage.homepage_title_tab_switch)) {
             if (eventBus.getType().equals(HomepageTitleTabSwitch.me.toString())) {
-                //
-                HdlLogLogic.print("姝e湪鐐瑰嚮銆愭垜鐨勩��");
+                //璇诲彇澶村儚
+                if (UserConfigManage.getInstance().isBAccount()) {
+                    this.getBUserInfo();
+                } else {
+                    this.getCMemberInfo();
+                }
+                // 鍙栨秷绮樻�т簨浠�
+                EventBus.getDefault().removeStickyEvent(eventBus);
             }
+
         }
+
+    }
+
+    /**
+     * 鑾峰彇鐢ㄦ埛鑷畾涔夐厤缃俯搴﹀崟浣嶈鎯�(app鍚姩鐨勬椂鍊欒鑾峰彇)
+     */
+    private void getResidenceTemperatureUnit() {
+        HdlResidenceLogic.getInstance().getResidenceTemperatureUnit(new CloudCallBeak<String>() {
+            @Override
+            public void onSuccess(String json) {
+                try {
+                    if (TextUtils.isEmpty(json) || json.equals("{}")) {
+                        return;
+                    }
+                    JSONObject jsonObject = new Gson().fromJson(json, JSONObject.class);
+                    if (jsonObject.containsKey("tempType")) {
+                        String unit = jsonObject.getString("tempType");
+                        if (unit.contains("C")) {
+                            unit = "鈩�";
+                        } else {
+                            unit = "鈩�";
+                        }
+                        UserConfigManage.getInstance().setTemperature_unit(unit);
+                        UserConfigManage.getInstance().Save();
+                    }
+                } catch (Exception ignored) {
+                }
+
+            }
+
+            @Override
+            public void onFailure(HDLException e) {
+                HdlLogLogic.print("鑾峰彇鐢ㄦ埛鑷畾涔夐厤缃俯搴﹀崟浣嶈鎯�--->" + e.getMsg() + "(" + e.getCode() + ")", true);
+//                HdlThreadLogic.toast(_mActivity, e);
+            }
+        });
     }
 }

--
Gitblit v1.8.0