wjc
19 小时以前 2f5411b86c59706d31f6ec7de629d8f860725e46
app/src/main/java/com/hdl/photovoltaic/ui/CPowerStationActivity.java
@@ -6,11 +6,14 @@
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Process;
import android.os.SystemClock;
import android.text.TextUtils;
import android.util.Log;
import com.alibaba.fastjson.JSONObject;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken;
@@ -32,18 +35,23 @@
import com.hdl.photovoltaic.other.HdlLogLogic;
import com.hdl.photovoltaic.other.HdlMqttLogic;
import com.hdl.photovoltaic.other.HdlOtaLogic;
import com.hdl.photovoltaic.other.HdlPushLogic;
import com.hdl.photovoltaic.other.HdlResidenceLogic;
import com.hdl.photovoltaic.other.HdlThreadLogic;
import com.hdl.photovoltaic.other.HdlUniLogic;
import com.hdl.photovoltaic.push.PushMessageInfoBean;
import com.hdl.photovoltaic.services.ForeService;
import com.hdl.photovoltaic.ui.bean.DeviceRemoteInfo;
import com.hdl.photovoltaic.ui.bean.HouseIdBean;
import com.hdl.photovoltaic.ui.bean.MessageBean;
import com.hdl.photovoltaic.ui.bean.OidBean;
import com.hdl.photovoltaic.ui.message.MessageInfoActivity;
import com.hdl.photovoltaic.ui.newC.PowerStationsListActivity;
import com.hdl.photovoltaic.ui.newC.PowerStationsMoveActivity;
import com.hdl.photovoltaic.uni.HDLUniMP;
import com.hdl.photovoltaic.uni.HDLUniMPSDKManager;
import com.hdl.photovoltaic.utils.AppManagerUtils;
import com.hdl.photovoltaic.utils.BadgeUtils;
import com.hdl.sdk.link.HDLLinkLocalSdk;
import com.hdl.sdk.link.common.event.EventListener;
import com.hdl.sdk.link.core.bean.LinkResponse;
@@ -59,6 +67,7 @@
import java.lang.reflect.Type;
import java.util.List;
import java.util.Objects;
import cn.jpush.android.api.JPushInterface;
@@ -71,6 +80,8 @@
    private EventListener allTopicsListener;
    private int backPressTimes;
    private volatile boolean isRunning = false;
    @Override
    public Object getContentView() {
@@ -88,8 +99,12 @@
        this.registerAllTopicsListener();
        //初始化mqtt客户端
        this.initMqttClient();
        //上传极光注册ID到云端
        this.pushTokens();
//        //上传极光注册ID到云端
//        this.pushTokens();
        //上传推动令牌到云端(谷歌FCM推送)
        this.sendPushTokenToServer(UserConfigManage.getInstance().getPushToken());
        //点击通知栏消息进来
        this.OpenSpecifiedPage(getIntent(), "onBindView");
        //获取云端脚本
        HdlESLocalJsonLogic.getInstance().getAllHdlESLocalJson();
//        mForegroundService= new Intent(this, ForeService.class);
@@ -115,6 +130,44 @@
//        this.portConflictDialog();
    }
    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        //AndroidManifest.xml 需要添加启动模式android:launchMode="singleTask"才执行这个方法
        OpenSpecifiedPage(intent, "onNewIntent");
    }
    /**
     * 点击通知栏消息进来
     */
    private void OpenSpecifiedPage(Intent intent, String tag) {
        Log.d("==========", tag);
        try {
            String data = getIntentExpantData(intent);
            if (TextUtils.isEmpty(data)) {
                return;
            }
            PushMessageInfoBean pushMessageInfoBean = HdlPushLogic.getInstance().pushDataProcessing("", "", data);
            if (TextUtils.isEmpty(pushMessageInfoBean.getMsgId())) {
                return;
            }
            HDLUniMPSDKManager.uinEnabled = false;
            if (tag.equals("onNewIntent")) {
                HDLUniMPSDKManager.uinEnabled = false;
                //C端启动App自动打开小程序电站详情界面
                if (null != HDLUniMPSDKManager.getInstance().getUniMP()) {
                    HDLUniMPSDKManager.getInstance().getUniMP().closeUniMP();
                }
                startAppAutomaticallyOpenUni();
            }
            CheckUniOn(pushMessageInfoBean);
        } catch (Exception e) {
            Log.d("错误", " " + e.getMessage());
        }
    }
    public void startAppAutomaticallyOpenUni() {
        new Thread(new Runnable() {
            @Override
@@ -132,6 +185,42 @@
//                        }
                    }
                });
            }
        }).start();
    }
    /**
     * 检测uni是否打开,检测最长时间为5s,检测成功后打开原生消息界面,关闭返回主界面
     */
    public void CheckUniOn(PushMessageInfoBean pushMessageInfoBean) {
        if (pushMessageInfoBean == null) return;
        final long startTime = System.currentTimeMillis();
        new Thread(new Runnable() {
            @Override
            public void run() {
                while (System.currentTimeMillis() - startTime < 5 * 1000) {
                    if (HDLUniMPSDKManager.uinEnabled) {
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                if (pushMessageInfoBean.isAiPrompt()) {
                                    HdlUniLogic.getInstance().sendUni(HDLUniMP.UNI_EVENT_NOTIFICATION_DEVICE_open_ai_push_message, new HDLUniMP.UniCallBackBaseBean());
                                } else {
                                    MessageBean messageBean = new MessageBean();
                                    messageBean.setMsgId(Long.valueOf(pushMessageInfoBean.getMsgId()));
                                    Intent intentMessageInfoActivity = new Intent();
                                    intentMessageInfoActivity.setClass(_mActivity, MessageInfoActivity.class);
                                    intentMessageInfoActivity.putExtra("messageBean", JSONObject.toJSONString(messageBean));
                                    startActivity(intentMessageInfoActivity);
                                }
                            }
                        });
                        break;
                    }
                    SystemClock.sleep(1000);
                }
            }
        }).start();
    }
@@ -239,6 +328,9 @@
            MqttRecvClient.getInstance().checkAndsubscribeAllTopics(topicHome);//订阅【电站】消息
        } else if (event.getTopic().contains(ConstantManage.refresh_push_token)) {
            //pushToken更新
            sendPushTokenToServer(UserConfigManage.getInstance().getPushToken());
        }
    }
@@ -259,15 +351,16 @@
        UserConfigManage.getInstance().setUniBottomSafeDistanceBackgroundColor(0);
        List<HouseIdBean> HouseIdList = HdlResidenceLogic.getInstance().getHouseIdList();
        if (HouseIdList.isEmpty()) {
            if (TextUtils.isEmpty(UserConfigManage.getInstance().getHomeId())) {
                String path = HDLUniMP.UNI_EVENT_OPEN_HOME_Null_C;
                HdlUniLogic.getInstance().openUniMP(path, null);
            } else {
                //1,解决手机没有外网,获取不到电站列表,自动登录进来,默认传上一次的住宅id;
                //2,之前电站列表只有一个电站,然后删除掉电站,这时住宅id还缓存着,再一次进来,默认传上一次的住宅id;
                String path = HDLUniMP.UNI_EVENT_OPEN_HOME_DETAILS_C + "?homeId=" + UserConfigManage.getInstance().getHomeId() + "&homeName=" + UserConfigManage.getInstance().getHomeName();
                HdlUniLogic.getInstance().openUniMP(path, null);
            }
//            if (TextUtils.isEmpty(UserConfigManage.getInstance().getHomeId())) {
            String path = HDLUniMP.UNI_EVENT_OPEN_HOME_Null_C;
            HdlUniLogic.getInstance().openUniMP(path, null);
//            } else {
//                //暂时不考虑这种情况
//                //1,解决手机没有外网,获取不到电站列表,自动登录进来,默认传上一次的住宅id;
//                //2,之前电站列表只有一个电站,然后删除掉电站,这时住宅id还缓存着,再一次进来,默认传上一次的住宅id;
//                String path = HDLUniMP.UNI_EVENT_OPEN_HOME_DETAILS_C + "?homeId=" + UserConfigManage.getInstance().getHomeId() + "&homeName=" + UserConfigManage.getInstance().getHomeName();
//                HdlUniLogic.getInstance().openUniMP(path, null);
//            }
        } else {
            int select_home = 0;
@@ -333,7 +426,7 @@
    @Override
    protected void onDestroy() {
        super.onDestroy();
        HdlUniLogic.getInstance().checkRemoveOtherUniMPEventCallBack();
//        HdlUniLogic.getInstance().checkRemoveOtherUniMPEventCallBack();
        //移除监听
        HDLLinkLocalSdk.getInstance().removeAllTopicsListener(allTopicsListener);
//        stopService(mForegroundService);
@@ -373,7 +466,7 @@
                        public void onSuccess(String pushId) {
                            if (!TextUtils.isEmpty(pushId)) {
                                UserConfigManage.getInstance().setRegistrationID(finalRegistrationID);
                                UserConfigManage.getInstance().setPushToken(finalRegistrationID);
                                UserConfigManage.getInstance().setPushId(pushId);
                                UserConfigManage.getInstance().Save();
                            }
@@ -392,6 +485,34 @@
                }
            }
        });
    }
    /**
     * 上传 token 到服务器
     *
     * @param token 令牌
     */
    private void sendPushTokenToServer(final String token) {
        if (TextUtils.isEmpty(token)) {
            return;
        }
        HdlResidenceLogic.getInstance().pushAdd(new CloudCallBeak<String>() {
            @Override
            public void onSuccess(String pushId) {
                if (!TextUtils.isEmpty(pushId)) {
                    UserConfigManage.getInstance().setToken(token);
                    UserConfigManage.getInstance().setPushId(pushId);
                    UserConfigManage.getInstance().Save();
                }
                HdlLogLogic.print("添加令牌到云端 PushToken:" + UserConfigManage.getInstance().getPushToken() + " pushId:" + pushId, true);
            }
            @Override
            public void onFailure(HDLException e) {
                HdlLogLogic.print("添加令牌到云端失败 PushToken:" + UserConfigManage.getInstance().getPushToken() + " 错误:" + e.getMessage(), true);
            }
        });
    }
@@ -502,14 +623,14 @@
//                        HdlUniLogic.getInstance().sendUni(HDLUniMP.UNI_EVENT_NOTIFICATION_DEVICE_MODEL, uniCallBackBaseBean);
                        HdlLogLogic.print(linkResponse.getTopic() + new Gson().toJson(linkResponse.getData()), true);
//                        HdlDeviceLogic.getInstance().searchAllNetworkGateway(null);//逆变器wifi状态-重新搜索一下逆变器-重新更新连接状态
                    } else if (linkResponse.getTopic().endsWith("/app/thing/event/appHomeRefresh/up")) {
                    } else if (linkResponse.getTopic().endsWith("/app/thing/event/appHomeDeliverRollbackRefresh/up")) {
                        try {
                            //住宅交付状态回滚通知
                            String[] topicArray = linkResponse.getTopic().split("/");
                            if (topicArray.length < 2) {
                                return;
                            }
                            final String HomeId = topicArray[1];
                            final String HomeId = topicArray[2];
                            //先删除电站
                            HdlResidenceLogic.getInstance().delHouseId(HomeId);
                            List<HouseIdBean> localHouseIdList = HdlResidenceLogic.getInstance().getHouseIdList();
@@ -520,6 +641,8 @@
                                uniCallBackBaseBean.setType(HDLUniMP.UNI_EVENT_NOTIFICATION_DEVICE_REFRESH_DETAILS);
                                uniCallBackBaseBean.setData(jsonObject);
                                HdlUniLogic.getInstance().sendUni(HDLUniMP.UNI_EVENT_NOTIFICATION_DEVICE_MODEL, uniCallBackBaseBean);
                                UserConfigManage.getInstance().setHomeId("");
                                UserConfigManage.getInstance().Save();
                            } else {
                                if (HomeId.equals(UserConfigManage.getInstance().getHomeId()) || TextUtils.isEmpty(UserConfigManage.getInstance().getHomeId())) {
                                    HouseIdBean houseIdBean = localHouseIdList.get(0);
@@ -534,7 +657,9 @@
                                    HdlUniLogic.getInstance().sendUni(HDLUniMP.UNI_EVENT_NOTIFICATION_DEVICE_MODEL, uniCallBackBaseBean);
                                }
                            }
                        } catch (Exception e) {
                            HdlLogLogic.print("回滚异常", false);
                        }
                        if (AppManagerUtils.getAppManager().existsTopActivity(PowerStationsListActivity.class, PowerStationsMoveActivity.class)) {
                            //存在栈里再通知更新
@@ -549,5 +674,27 @@
        HDLLinkLocalSdk.getInstance().registerAllTopicsListener(allTopicsListener);
    }
    /**
     * 处理从通知点击带来的数据,这里获取数据,然后透传给主界面做处理
     *
     * @return 返回附加数据
     */
    private String getIntentExpantData(Intent intent) {
        try {
            if (intent == null) {
                return "";
            }
            // 处理从通知点击带来的数据,这里获取数据,然后透传给主界面做处理
            if (intent.getExtras() != null) {
                for (String key : intent.getExtras().keySet()) {
                    if (key.equals("pushData")) {
                        return Objects.requireNonNull(intent.getExtras().get(key)).toString();
                    }
                }
            }
        } catch (Exception e) {
            return "";
        }
        return "";
    }
}