From 48bd94f4e362c8a604017cbaf4c12e08be10c816 Mon Sep 17 00:00:00 2001
From: mac <user@users-MacBook-Pro.local>
Date: 星期五, 10 五月 2024 17:25:37 +0800
Subject: [PATCH] 2024年05月10日17:25:30

---
 app/src/main/java/com/hdl/photovoltaic/ui/MyPowerStationActivity.java |  141 ++++++++++++++++++++++++++++++++++++----------
 1 files changed, 110 insertions(+), 31 deletions(-)

diff --git a/app/src/main/java/com/hdl/photovoltaic/ui/MyPowerStationActivity.java b/app/src/main/java/com/hdl/photovoltaic/ui/MyPowerStationActivity.java
index e276732..936b0f0 100644
--- a/app/src/main/java/com/hdl/photovoltaic/ui/MyPowerStationActivity.java
+++ b/app/src/main/java/com/hdl/photovoltaic/ui/MyPowerStationActivity.java
@@ -2,14 +2,11 @@
 
 import androidx.annotation.NonNull;
 import androidx.appcompat.content.res.AppCompatResources;
-import androidx.core.app.ActivityCompat;
 
 import android.Manifest;
 import android.content.Context;
 import android.content.Intent;
 import android.content.pm.PackageManager;
-import android.location.Location;
-import android.location.LocationListener;
 import android.location.LocationManager;
 import android.os.Bundle;
 import android.os.Process;
@@ -18,7 +15,6 @@
 import android.text.TextUtils;
 import android.view.View;
 
-import com.alibaba.fastjson.JSONObject;
 import com.google.gson.Gson;
 import com.google.gson.reflect.TypeToken;
 import com.hdl.linkpm.sdk.core.exception.HDLException;
@@ -47,6 +43,7 @@
 import com.hdl.photovoltaic.utils.GPSManagerUtils;
 import com.hdl.photovoltaic.utils.PermissionUtils;
 import com.hdl.photovoltaic.widget.ConfirmationCancelDialog;
+import com.hdl.photovoltaic.widget.ConfirmationTipDialog;
 import com.hdl.sdk.link.HDLLinkLocalSdk;
 import com.hdl.sdk.link.common.event.EventListener;
 import com.hdl.sdk.link.core.bean.LinkResponse;
@@ -54,6 +51,7 @@
 import com.hdl.sdk.link.core.bean.eventbus.BaseEventBus;
 import com.hdl.sdk.link.core.bean.gateway.GatewayBean;
 import com.hdl.sdk.link.core.config.HDLLinkConfig;
+import com.hdl.sdk.link.core.connect.HDLUdpConnect;
 import com.hdl.sdk.link.core.utils.mqtt.MqttRecvClient;
 
 import org.greenrobot.eventbus.EventBus;
@@ -67,13 +65,13 @@
 
 
 /**
- * 鎴戠殑鐢电珯鐣岄潰
+ * B绔�-鐢电珯鐣岄潰
  */
 public class MyPowerStationActivity extends CustomBaseActivity {
 
 
     private ActivityMyPowerStationBinding viewBinding;
-    private int currentFragmentIndex = 1;
+    private int currentFragmentIndex = 0;
     private EventListener allTopicsListener;
     private int backPressTimes;
 
@@ -85,7 +83,8 @@
 
     @Override
     public void onBindView(Bundle savedInstanceState) {
-        setNotificationBarBackgroundColor(CustomColor.blue);
+//        setNotificationBarBackgroundColor(CustomColor.blue);
+        setStatusBarTranslucent();
         //鍒濆鍖�
         this.initView();
         //鍒濆鍖栫晫闈㈢洃鍚櫒
@@ -101,6 +100,21 @@
         //鍒濆鍖栨潈闄�
         this.requestPermissions();
 
+    }
+
+
+    @Override
+    protected void onResume() {
+        super.onResume();
+        //鍚姩椤典笌mainActivity鏍峰紡涓�鏍凤紝杩欐牱鍚姩椤靛拰mainActivity鐪嬩笂鍘绘槸涓�涓晫闈紝鐩殑鏄负浜唌ainActivity閬綇涓嬩竴椤碉紱
+//        AppManagerUtils.getAppManager().finishActivity(StartActivity.class);
+        portConflictDialog();
+//        Intent intent = new Intent(_mActivity, MyPowerStationActivity.class);
+//        intent.setFlags(Intent.Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
+//        intent.putExtra("skip", "skip");//閲岄潰鍒ゆ柇鏈夎繖涓爣璇嗗氨璺宠浆鍒版秷鎭腑蹇冪晫闈�
+//        _mActivity.startActivity(intent);
+        //鐐瑰嚮鏋佸厜閫氱煡鏍忔秷鎭繘鏉�
+//        this.clickJpushNotificationMessage();
     }
 
 
@@ -142,14 +156,14 @@
                                 UserConfigManage.getInstance().Save();
                             }
                             HDLApp.getInstance().setInfoMap(registrationId_tag, "true");//璁板綍涓�涓嬬姸鎬�,鍚庡彴鏉�姝籥pp浼氭竻绌�;
-                            HdlLogLogic.print("娣诲姞鏋佸厜ID鍒颁簯绔�--->registrationID:" + finalRegistrationID, true);
+                            HdlLogLogic.print("娣诲姞鏋佸厜ID鍒颁簯绔�--->registrationID:" + UserConfigManage.getInstance().getUserName() + "--->" + finalRegistrationID, true);
 
                         }
 
                         @Override
                         public void onFailure(HDLException e) {
                             HDLApp.getInstance().setInfoMap(registrationId_tag, "false");//璁板綍涓�涓嬬姸鎬�,鍚庡彴鏉�姝籥pp浼氭竻绌�;
-                            HdlLogLogic.print("娣诲姞鏋佸厜ID鍒颁簯绔け璐�--->registrationID:" + finalRegistrationID, true);
+                            HdlLogLogic.print("娣诲姞鏋佸厜ID鍒颁簯绔け璐�--->registrationID:" + UserConfigManage.getInstance().getUserName() + "--->" + finalRegistrationID, true);
                         }
                     });
 
@@ -191,9 +205,23 @@
 
 
     private void initEvent() {
+        viewBinding.myPowerStationBottomIl0.clickTv.setOnClickListener(new View.OnClickListener() {
+            @Override
+            public void onClick(View v) {
+                if (currentFragmentIndex == 0) {
+                    return;
+                }
+                currentFragmentIndex = 0;
+                bottomViewChangeOfStyle();
+                postEventBus(HomepageTitleTabSwitch.homepage);
+            }
+        });
         viewBinding.myPowerStationBottomIl1.clickTv.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
+                if (currentFragmentIndex == 1) {
+                    return;
+                }
                 currentFragmentIndex = 1;
                 bottomViewChangeOfStyle();
                 postEventBus(HomepageTitleTabSwitch.powerstation);
@@ -202,6 +230,9 @@
         viewBinding.myMessageBottomIl2.clickTv.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
+                if (currentFragmentIndex == 2) {
+                    return;
+                }
                 currentFragmentIndex = 2;
                 bottomViewChangeOfStyle();
                 postEventBus(HomepageTitleTabSwitch.message);
@@ -210,6 +241,9 @@
         viewBinding.myMeBottomIl3.clickTv.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
+                if (currentFragmentIndex == 3) {
+                    return;
+                }
                 currentFragmentIndex = 3;
                 bottomViewChangeOfStyle();
                 postEventBus(HomepageTitleTabSwitch.me);
@@ -229,43 +263,65 @@
     }
 
     private void initView() {
-        viewBinding.myPowerStationBottomIl1.titleTv.setText(R.string.power_shome_page);//
+        viewBinding.myPowerStationBottomIl0.titleTv.setText(R.string.power_shome_page);
+        viewBinding.myPowerStationBottomIl1.titleTv.setText(R.string.power_station);
         viewBinding.myMessageBottomIl2.titleTv.setText(R.string.message);
         viewBinding.myMeBottomIl3.titleTv.setText(R.string.power_station_me);
         this.bottomViewChangeOfStyle();
-
     }
 
     private void bottomViewChangeOfStyle() {
-        if (this.currentFragmentIndex == 1) {
+        if (this.currentFragmentIndex == 0) {
+            viewBinding.myHomePageFcv0.setVisibility(View.VISIBLE);//鏄剧ず棣栭〉鐣岄潰
+            viewBinding.myPowerStationFcv1.setVisibility(View.GONE);//鏄剧ず鐢电珯鐣岄潰
+            viewBinding.myMessageFcv2.setVisibility(View.GONE);//闅愯棌娑堟伅鐣岄潰
+            viewBinding.myMeFcv3.setVisibility(View.GONE);//闅愯棌鎴戠殑鐣岄潰
+            viewBinding.myPowerStationBottomIl0.iconIv.setImageDrawable(AppCompatResources.getDrawable(_mActivity, R.drawable.home_page_selected));
+            viewBinding.myPowerStationBottomIl0.titleTv.setTextColor(getColor(R.color.text_90000000));
+            viewBinding.myPowerStationBottomIl1.iconIv.setImageDrawable(AppCompatResources.getDrawable(_mActivity, R.drawable.power_station_unselected));
+            viewBinding.myPowerStationBottomIl1.titleTv.setTextColor(getColor(R.color.text_65000000));
+            viewBinding.myMessageBottomIl2.iconIv.setImageDrawable(AppCompatResources.getDrawable(_mActivity, R.drawable.message_unselected));
+            viewBinding.myMessageBottomIl2.titleTv.setTextColor(getColor(R.color.text_65000000));
+            viewBinding.myMeBottomIl3.iconIv.setImageDrawable(AppCompatResources.getDrawable(_mActivity, R.drawable.me_unselected));
+            viewBinding.myMeBottomIl3.titleTv.setTextColor(getColor(R.color.text_65000000));
+        } else if (this.currentFragmentIndex == 1) {
+            viewBinding.myHomePageFcv0.setVisibility(View.GONE);//闅愯棌棣栭〉鐣岄潰
             viewBinding.myPowerStationFcv1.setVisibility(View.VISIBLE);//鏄剧ず鐢电珯鐣岄潰
             viewBinding.myMessageFcv2.setVisibility(View.GONE);//闅愯棌娑堟伅鐣岄潰
             viewBinding.myMeFcv3.setVisibility(View.GONE);//闅愯棌鎴戠殑鐣岄潰
-            viewBinding.myPowerStationBottomIl1.iconIv.setImageDrawable(AppCompatResources.getDrawable(_mActivity, R.drawable.selectedpowerstation));
+            viewBinding.myPowerStationBottomIl0.iconIv.setImageDrawable(AppCompatResources.getDrawable(_mActivity, R.drawable.home_page_unselected));
+            viewBinding.myPowerStationBottomIl0.titleTv.setTextColor(getColor(R.color.text_65000000));
+            viewBinding.myPowerStationBottomIl1.iconIv.setImageDrawable(AppCompatResources.getDrawable(_mActivity, R.drawable.power_station_selected));
             viewBinding.myPowerStationBottomIl1.titleTv.setTextColor(getColor(R.color.text_90000000));
             viewBinding.myMessageBottomIl2.iconIv.setImageDrawable(AppCompatResources.getDrawable(_mActivity, R.drawable.message_unselected));
             viewBinding.myMessageBottomIl2.titleTv.setTextColor(getColor(R.color.text_65000000));
-            viewBinding.myMeBottomIl3.iconIv.setImageDrawable(AppCompatResources.getDrawable(_mActivity, R.drawable.unselectedme));
+            viewBinding.myMeBottomIl3.iconIv.setImageDrawable(AppCompatResources.getDrawable(_mActivity, R.drawable.me_unselected));
             viewBinding.myMeBottomIl3.titleTv.setTextColor(getColor(R.color.text_65000000));
         } else if (this.currentFragmentIndex == 2) {
+            viewBinding.myHomePageFcv0.setVisibility(View.GONE);//闅愯棌棣栭〉鐣岄潰
             viewBinding.myPowerStationFcv1.setVisibility(View.GONE);//闅愯棌鐢电珯鐣岄潰
             viewBinding.myMessageFcv2.setVisibility(View.VISIBLE);//鏄剧ず娑堟伅鐣岄潰
             viewBinding.myMeFcv3.setVisibility(View.GONE);//闅愯棌鎴戠殑鐣岄潰
-            viewBinding.myPowerStationBottomIl1.iconIv.setImageDrawable(AppCompatResources.getDrawable(_mActivity, R.drawable.unselectedpowerstation));
+            viewBinding.myPowerStationBottomIl0.iconIv.setImageDrawable(AppCompatResources.getDrawable(_mActivity, R.drawable.home_page_unselected));
+            viewBinding.myPowerStationBottomIl0.titleTv.setTextColor(getColor(R.color.text_65000000));
+            viewBinding.myPowerStationBottomIl1.iconIv.setImageDrawable(AppCompatResources.getDrawable(_mActivity, R.drawable.power_station_unselected));
             viewBinding.myPowerStationBottomIl1.titleTv.setTextColor(getColor(R.color.text_65000000));
             viewBinding.myMessageBottomIl2.iconIv.setImageDrawable(AppCompatResources.getDrawable(_mActivity, R.drawable.message_select));
             viewBinding.myMessageBottomIl2.titleTv.setTextColor(getColor(R.color.text_90000000));
-            viewBinding.myMeBottomIl3.iconIv.setImageDrawable(AppCompatResources.getDrawable(_mActivity, R.drawable.unselectedme));
+            viewBinding.myMeBottomIl3.iconIv.setImageDrawable(AppCompatResources.getDrawable(_mActivity, R.drawable.me_unselected));
             viewBinding.myMeBottomIl3.titleTv.setTextColor(getColor(R.color.text_65000000));
         } else if (this.currentFragmentIndex == 3) {
+            viewBinding.myHomePageFcv0.setVisibility(View.GONE);//闅愯棌棣栭〉鐣岄潰
             viewBinding.myPowerStationFcv1.setVisibility(View.GONE);//闅愯棌鐢电珯鐣岄潰
             viewBinding.myMessageFcv2.setVisibility(View.GONE);//闅愯棌娑堟伅鐣岄潰
             viewBinding.myMeFcv3.setVisibility(View.VISIBLE);//鏄剧ず鎴戠殑鐣岄潰
-            viewBinding.myPowerStationBottomIl1.iconIv.setImageDrawable(AppCompatResources.getDrawable(_mActivity, R.drawable.unselectedpowerstation));
+            viewBinding.myPowerStationBottomIl0.iconIv.setImageDrawable(AppCompatResources.getDrawable(_mActivity, R.drawable.home_page_unselected));
+            viewBinding.myPowerStationBottomIl0.titleTv.setTextColor(getColor(R.color.text_65000000));
+            viewBinding.myPowerStationBottomIl1.iconIv.setImageDrawable(AppCompatResources.getDrawable(_mActivity, R.drawable.power_station_unselected));
             viewBinding.myPowerStationBottomIl1.titleTv.setTextColor(getColor(R.color.text_65000000));
             viewBinding.myMessageBottomIl2.iconIv.setImageDrawable(AppCompatResources.getDrawable(_mActivity, R.drawable.message_unselected));
             viewBinding.myMessageBottomIl2.titleTv.setTextColor(getColor(R.color.text_65000000));
-            viewBinding.myMeBottomIl3.iconIv.setImageDrawable(AppCompatResources.getDrawable(_mActivity, R.drawable.selectedme));
+            viewBinding.myMeBottomIl3.iconIv.setImageDrawable(AppCompatResources.getDrawable(_mActivity, R.drawable.me_selected));
             viewBinding.myMeBottomIl3.titleTv.setTextColor(getColor(R.color.text_90000000));
         }
     }
@@ -285,7 +341,6 @@
     public void requestPermissions() {
         //娑堟伅閫氱煡闄愭潈
         this.notificationSet();
-        //Manifest.permission.ACCESS_COARSE_LOCATION
         //ACCESS_FINE_LOCATION	鍏佽浣跨敤GPS瀹氫綅
         //ACCESS_COARSE_LOCATION	鍏佽浣跨敤WIFI鐑偣鎴栧熀绔欐潵鑾峰彇绮楃暐鐨勫畾浣�
         String[] ary = PermissionUtils.checkPermission(_mActivity, new String[]{Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION});
@@ -389,19 +444,22 @@
      * 鍒濆鍖杕qtt瀹㈡埛绔�
      */
     public void initMqttClient() {
-        HdlMqttLogic.getInstance().getMqttRemoteInfo(HomeType.A, new CloudCallBeak<MqttInfo>() {
-            @Override
-            public void onSuccess(MqttInfo info) {
-                if (info != null) {
-                    MqttRecvClient.init(_mActivity, info.getUrl(), info.getClientId(), info.getUserName(), info.getPassWord());
+        if (!MqttRecvClient.getInstance().isInit()) {
+            HdlMqttLogic.getInstance().getMqttRemoteInfo(HomeType.A, new CloudCallBeak<MqttInfo>() {
+                @Override
+                public void onSuccess(MqttInfo info) {
+                    if (info != null) {
+                        MqttRecvClient.getInstance().setConnectParam(info.getUrl(), info.getClientId(), info.getUserName(), info.getPassWord(), null);
+                        MqttRecvClient.getInstance().connect();
+                    }
                 }
-            }
 
-            @Override
-            public void onFailure(HDLException e) {
-                HdlLogLogic.print("璇诲彇mqtt杩滅▼淇℃伅澶辫触--->" + e.getMessage(), e.getCode(), true);
-            }
-        });
+                @Override
+                public void onFailure(HDLException e) {
+                    HdlLogLogic.print("璇诲彇mqtt杩滅▼淇℃伅澶辫触--->" + e.getMessage(), e.getCode(), true);
+                }
+            });
+        }
     }
 
     @Subscribe(threadMode = ThreadMode.MAIN)
@@ -467,6 +525,8 @@
                 HdlThreadLogic.runSubThread(new Runnable() {
                     @Override
                     public void run() {
+                        //闃叉app鍚姩鐨勬椂鍊欐病鏈夌綉缁�(app涔熺櫥褰曚笉浜�),瀵艰嚧鑾峰彇涓嶄簡mqtt杩滅▼杩炴帴淇℃伅;
+                        initMqttClient();
                         HdlDeviceLogic.getInstance().getCurrentHomeLocalAndCloudGatewayList(UserConfigManage.getInstance().getHomeId(), new CloudCallBeak<List<GatewayBean>>() {
                             @Override
                             public void onSuccess(List<GatewayBean> obj) {
@@ -500,7 +560,7 @@
 
 
     /**
-     * 鐗╃悊鎸夐敭杩斿洖浜嬩欢
+     * 鐗╃悊鎸夐敭杩斿洖浜嬩欢(鍖呮嫭宸︽粦绉婚櫎浜嬩欢)
      */
     @Override
     public void onBackPressed() {
@@ -566,4 +626,23 @@
 
     }
 
+    /**
+     * 绔彛鍐茬獊
+     */
+    private void portConflictDialog() {
+        if (!HDLUdpConnect.getInstance().isBindSuccess()) {
+            ConfirmationTipDialog dialog = new ConfirmationTipDialog(_mActivity);
+            dialog.show();
+            dialog.setTitle(getString(R.string.loading_title_tip));
+            dialog.setContent(getString(R.string.port_conflict));
+            dialog.setConfirmation(getString(R.string.home_login_affirm));
+            dialog.setYesOnclickListener(new ConfirmationCancelDialog.onYesOnclickListener() {
+                @Override
+                public void Confirm() {
+                    dialog.dismiss();
+                }
+            });
+        }
+    }
+
 }
\ No newline at end of file

--
Gitblit v1.8.0