| | |
| | | import android.view.View; |
| | | import android.widget.TextView; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.google.gson.Gson; |
| | | import com.google.gson.reflect.TypeToken; |
| | |
| | | import com.hdl.photovoltaic.enums.LowerTagType; |
| | | import com.hdl.photovoltaic.enums.NetworkType; |
| | | import com.hdl.photovoltaic.listener.CloudCallBeak; |
| | | import com.hdl.photovoltaic.other.HdlAiLogic; |
| | | import com.hdl.photovoltaic.other.HdlCommonLogic; |
| | | import com.hdl.photovoltaic.other.HdlDeviceLogic; |
| | | import com.hdl.photovoltaic.other.HdlESLocalJsonLogic; |
| | |
| | | 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.ui.bean.ChatInfoBean; |
| | | import com.hdl.photovoltaic.ui.bean.ChatMessagePageBean; |
| | | import com.hdl.photovoltaic.ui.bean.DeviceRemoteInfo; |
| | | import com.hdl.photovoltaic.ui.bean.MessageBean; |
| | | import com.hdl.photovoltaic.ui.bean.OidBean; |
| | |
| | | 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 com.petterp.floatingx.FloatingX; |
| | | import com.petterp.floatingx.assist.FxGravity; |
| | | import com.petterp.floatingx.assist.FxScopeType; |
| | | import com.petterp.floatingx.assist.helper.FxAppHelper; |
| | | import com.petterp.floatingx.listener.control.IFxAppControl; |
| | | import com.umeng.analytics.MobclickAgent; |
| | | |
| | | import org.greenrobot.eventbus.Subscribe; |
| | |
| | | private ActivityMyPowerStationBinding viewBinding; |
| | | private EventListener allTopicsListener; |
| | | private int backPressTimes; |
| | | public IFxAppControl iFxAppControl; |
| | | |
| | | @Override |
| | | public Object getContentView() { |
| | |
| | | |
| | | @Override |
| | | public void onBindView(Bundle savedInstanceState) { |
| | | //// //通知栏点击进来,防止应用在后台时被重复启动,阿里云推动通知指定打开某个Activity,没有设置Flags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);默认启动新实例,导致多个实例 |
| | | // if (!isTaskRoot()) { |
| | | // finish(); |
| | | // } |
| | | setStatusBarTranslucent(); |
| | | getWindow().setNavigationBarColor(getColor(R.color.text_FF1C1C1E)); |
| | | //初始化碎片 |
| | |
| | | this.getUnreadCount(); |
| | | //获取云端脚本 |
| | | HdlESLocalJsonLogic.getInstance().getAllHdlESLocalJson(); |
| | | |
| | | this.getChatInfo(); |
| | | this.createAppFloatWindow(); |
| | | |
| | | } |
| | | |
| | |
| | | if (TextUtils.isEmpty(data)) { |
| | | return; |
| | | } |
| | | // PushMessageInfoBean pushMessageInfoBean = new Gson().fromJson(data, PushMessageInfoBean.class); |
| | | PushMessageInfoBean pushMessageInfoBean = HdlPushLogic.getInstance().pushDataProcessing("", "", data); |
| | | if (TextUtils.isEmpty(pushMessageInfoBean.getMsgId())) { |
| | | return; |
| | |
| | | //启动页与mainActivity样式一样,这样启动页和mainActivity看上去是一个界面,目的是为了mainActivity遮住下一页; |
| | | // AppManagerUtils.getAppManager().finishActivity(StartActivity.class); |
| | | portConflictDialog(); |
| | | // Intent intent = new Intent(_mActivity, BPowerStationActivity.class); |
| | | // intent.setFlags(Intent.Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); |
| | | // intent.putExtra("skip", "skip");//里面判断有这个标识就跳转到消息中心界面 |
| | | // _mActivity.startActivity(intent); |
| | | //点击极光通知栏消息进来 |
| | | // this.clickJpushNotificationMessage(); |
| | | } |
| | | |
| | | |
| | |
| | | // UserConfigManage.getInstance().setRegistrationID(registrationID); |
| | | // UserConfigManage.getInstance().Save(); |
| | | String finalRegistrationID = registrationID; |
| | | HdlResidenceLogic.getInstance().pushAdd(new CloudCallBeak<String>() { |
| | | HdlPushLogic.getInstance().pushAdd(new CloudCallBeak<String>() { |
| | | @Override |
| | | public void onSuccess(String pushId) { |
| | | |
| | |
| | | * @param token 令牌 |
| | | */ |
| | | private void sendPushTokenToServer(final String token) { |
| | | |
| | | if (TextUtils.isEmpty(token)) { |
| | | return; |
| | | } |
| | | HdlResidenceLogic.getInstance().pushAdd(new CloudCallBeak<String>() { |
| | | HdlPushLogic.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); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | /** |
| | | * 查看智能体详情 |
| | | * |
| | | */ |
| | | private void getChatInfo() { |
| | | HdlAiLogic.getInstance().getChatInfo(new CloudCallBeak<ChatInfoBean>() { |
| | | @Override |
| | | public void onSuccess(ChatInfoBean chatInfoBean) { |
| | | UserConfigManage.getInstance().setAgentSecret(chatInfoBean.getAgentSecret()); |
| | | UserConfigManage.getInstance().setAgentUrl(chatInfoBean.getAgentUrl()); |
| | | UserConfigManage.getInstance().Save(); |
| | | HdlAiLogic.getInstance().chatMessagesList(new CloudCallBeak<ChatMessagePageBean>() { |
| | | @Override |
| | | public void onSuccess(ChatMessagePageBean obj) { |
| | | if (obj != null && !obj.getData().isEmpty()) { |
| | | UserConfigManage.getInstance().setConversationId(obj.getData().get(0).getId()); |
| | | UserConfigManage.getInstance().Save(); |
| | | } else { |
| | | //没有拿到对话列表,把旧的当前会话ID清空 |
| | | UserConfigManage.getInstance().setConversationId(""); |
| | | HdlLogLogic.print("没有拿到对话列表,把旧的当前会话ID清空 ", true); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | |
| | | } |
| | | }); |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | HdlLogLogic.print("获取智能体AppKey失败 " + e.getMessage(), true); |
| | | } |
| | | }); |
| | | } |
| | |
| | | HdlUniLogic.getInstance().checkRemoveOtherUniMPEventCallBack(); |
| | | //移除监听 |
| | | HDLLinkLocalSdk.getInstance().removeAllTopicsListener(allTopicsListener); |
| | | |
| | | if (this.iFxAppControl != null) { |
| | | this.iFxAppControl.cancel(); |
| | | } |
| | | |
| | | } |
| | | |
| | |
| | | public void run() { |
| | | //防止app启动的时候没有网络(app也登录不了),导致获取不了mqtt远程连接信息; |
| | | initMqttClient(); |
| | | HdlDeviceLogic.getInstance().getCurrentHomeLocalAndCloudGatewayList(UserConfigManage.getInstance().getHomeId(), new CloudCallBeak<List<GatewayBean>>() { |
| | | HdlDeviceLogic.getInstance().getCurrentHomeLocalAndCloudGatewayList(UserConfigManage.getInstance().getHomeId(), UserConfigManage.getInstance().getPowerStationType(), new CloudCallBeak<List<GatewayBean>>() { |
| | | @Override |
| | | public void onSuccess(List<GatewayBean> obj) { |
| | | // AppManagerUtils.getAppManager().hideLoading(); |
| | |
| | | showFragment(); |
| | | } |
| | | } else if (event.getTopic().contains(ConstantManage.refresh_push_token)) { |
| | | String token = event.getType(); |
| | | UserConfigManage.getInstance().setPushToken(token); |
| | | UserConfigManage.getInstance().Save(); |
| | | //pushToken更新 |
| | | sendPushTokenToServer(UserConfigManage.getInstance().getPushToken()); |
| | | } |
| | |
| | | //触发消息点击事件 |
| | | viewBinding.myMessageBottomIl2.clickTv.performClick(); |
| | | // if (currentFragmentIndex == 2) { |
| | | // HdlCommonLogic.getInstance().postEventBusSticky(ConstantManage.refresh_message_house, ConstantManage.refresh_message_house); |
| | | // return; |
| | | // } |
| | | // currentFragmentIndex = 2; |
| | | // bottomViewChangeOfStyle(); |
| | | // showFragment(); |
| | | // HdlCommonLogic.lowerTagType = LowerTagType.message; |
| | | // HdlCommonLogic.getInstance().postEventBusSticky(ConstantManage.homepage_title_tab_switch, HomepageTitleTabSwitch.message.toString()); |
| | | // HdlCommonLogic.getInstance().postEventBusSticky(ConstantManage.refresh_message_house, ConstantManage.refresh_message_house); |
| | | } |
| | | |
| | | |
| | |
| | | return ""; |
| | | } |
| | | |
| | | /** |
| | | * 创建应用级AI小组件悬浮窗 |
| | | */ |
| | | private void createAppFloatWindow() { |
| | | if (this.iFxAppControl != null) { |
| | | //彻底销毁悬浮窗(会从界面上移除) |
| | | this.iFxAppControl.cancel(); |
| | | } |
| | | FxAppHelper helper = FxAppHelper.builder() |
| | | .setContext(_mActivity) // 设置上下文 |
| | | .setLayout(R.layout.item_ai) // 设置悬浮窗布局 |
| | | .setScopeType(FxScopeType.APP) // 设置为应用内悬浮窗类型,无需权限 |
| | | .setEnableEdgeAdsorption(true)// 开启边缘吸附 |
| | | // .setEnableHalfHide(true) // 开启半隐藏模式(实现“靠边隐藏”) |
| | | // 1. 设置重力为右下角 |
| | | .setGravity(FxGravity.RIGHT_OR_BOTTOM) |
| | | // 2. 设置底部边界边距,确保浮窗不被拖拽到边界以下,留出空间 |
| | | .setBottomBorderMargin(230f) |
| | | .setRightBorderMargin(40f) |
| | | .setTopBorderMargin(250f) |
| | | .build(); // 最后调用 build() 完成构建 |
| | | // 获取控制对象 |
| | | this.iFxAppControl = FloatingX.install(helper); |
| | | this.iFxAppControl.show(); |
| | | this.iFxAppControl.setClickListener(300, new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | HdlUniLogic.getInstance().openUniMP(HDLUniMP.UNI_EVENT_OPEN_AIChatBox, null); |
| | | } |
| | | }); |
| | | |
| | | } |
| | | |
| | | } |