mac
2023-12-25 0077e2137a77e6e671e95529165e10b3ed1289bb
app/src/main/java/com/hdl/photovoltaic/ui/MyPowerStationActivity.java
@@ -4,6 +4,7 @@
import androidx.appcompat.content.res.AppCompatResources;
import android.Manifest;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.os.Process;
@@ -16,9 +17,11 @@
import com.hdl.photovoltaic.R;
import com.hdl.photovoltaic.base.CustomBaseActivity;
import com.hdl.photovoltaic.bean.MqttInfo;
import com.hdl.photovoltaic.broadcast.NetworkChangeReceiver;
import com.hdl.photovoltaic.config.ConstantManage;
import com.hdl.photovoltaic.config.UserConfigManage;
import com.hdl.photovoltaic.databinding.ActivityMyPowerStationBinding;
import com.hdl.photovoltaic.enums.NetworkType;
import com.hdl.photovoltaic.listener.CloudCallBeak;
import com.hdl.photovoltaic.other.HdlCommonLogic;
import com.hdl.photovoltaic.other.HdlDeviceLogic;
@@ -47,7 +50,6 @@
import java.util.List;
/**
 * 我的电站界面
 */
@@ -60,6 +62,8 @@
    private int backPressTimes;
    private NetworkChangeReceiver networkChangeReceiver;
    @Override
    public Object getContentView() {
@@ -71,14 +75,38 @@
    public void onBindView(Bundle savedInstanceState) {
        setNotificationBarBackgroundColor(CustomColor.blue);
        //初始化
        initView();
        this.initView();
        //初始化界面监听器
        initEvent();
        this.initEvent();
        //注册监听
        registerAllTopicsListener();
        this.registerAllTopicsListener();
        //初始化mqtt客户端
        initMqttClient();
        this.initMqttClient();
        //监听网络状态变化
        this.networkMonitoring();
//        HdlOtaLogic.getInstance().startLocalService(new ServiceConnection() {
//            @Override
//            public void onServiceConnected(ComponentName name, IBinder service) {
//
//            }
//
//            @Override
//            public void onServiceDisconnected(ComponentName name) {
//
//            }
//        });
    }
    /**
     * 监听网络状态变化
     */
    private void networkMonitoring() {
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction("android.net.conn.CONNECTIVITY_CHANGE");
        networkChangeReceiver = new NetworkChangeReceiver();
        registerReceiver(networkChangeReceiver, intentFilter);
    }
    private void initEvent() {
@@ -116,11 +144,13 @@
        HdlUniLogic.getInstance().checkRemoveOtherUniMPEventCallBack();
        //移除监听
        HDLLinkLocalSdk.getInstance().removeAllTopicsListener(allTopicsListener);
        //移除监听网络状态变化
        unregisterReceiver(networkChangeReceiver);
    }
    private void initView() {
        viewBinding.myPowerStationBottomIl1.titleTv.setText(R.string.power_station);
        viewBinding.myPowerStationBottomIl1.titleTv.setText("首页");//
        viewBinding.myMessageBottomIl2.titleTv.setText(R.string.message);
        viewBinding.myMeBottomIl3.titleTv.setText(R.string.power_station_me);
        this.bottomViewChangeOfStyle();
@@ -250,7 +280,7 @@
                        uniCallBackBaseBean.setType(linkResponse.getTopic());
                        uniCallBackBaseBean.setData(linkResponse.getData());
                        HdlUniLogic.getInstance().sendUni(HDLUniMP.UNI_EVENT_REPLY_OTA_MODEL, uniCallBackBaseBean);
                        HdlLogLogic.print( linkResponse.getTopic() +  new Gson().toJson(linkResponse.getData()), true);
                        HdlLogLogic.print(linkResponse.getTopic() + new Gson().toJson(linkResponse.getData()), true);
                    }
                }
            }
@@ -327,13 +357,40 @@
            uniCallBackBaseBean.setType(event.getType());
            uniCallBackBaseBean.setData(event.getData());
            HdlUniLogic.getInstance().sendUni(HDLUniMP.UNI_EVENT_REPLY_OTA_MODEL, uniCallBackBaseBean);
            HdlLogLogic.print(  event.getTopic()  + new Gson().toJson(event.getData()), true);
            HdlLogLogic.print(event.getTopic() + new Gson().toJson(event.getData()), true);
        } else if (event.getTopic().contains(ConstantManage.network_change_post)) {
//            String wifi_ssid = WifiUtils.getInstance().getCurrentConnectWifiSsid();//获取WiFi的ssid需要位置权限的
            HdlLogLogic.print("监听网络状态--->" + event.getData().toString() + "(" + event.getType() + ")", true);
            //第一次启动App,以及切换网络的时候更新
            if (TextUtils.isEmpty(UserConfigManage.getInstance().getHomeId())) {
                return;
            }
            if (!event.getType().equals(NetworkType.no_network.toString())) {
//                AppManagerUtils.getAppManager().showLoading();
                HdlThreadLogic.runSubThread(new Runnable() {
                    @Override
                    public void run() {
                        HdlDeviceLogic.getInstance().getCurrentHomeLocalAndCloudGatewayList(UserConfigManage.getInstance().getHomeId(), new CloudCallBeak<List<GatewayBean>>() {
                            @Override
                            public void onSuccess(List<GatewayBean> obj) {
//                                AppManagerUtils.getAppManager().hideLoading();
                            }
                            @Override
                            public void onFailure(HDLException e) {
//                                AppManagerUtils.getAppManager().hideLoading();
                            }
                        });
                    }
                });
            }
        }
    }
    /**
     * 点击返回键的事件
     * 物理按键返回事件
     */
    @Override
    public void onBackPressed() {