From 41874a5073cd9f4fef663afb303f990dca690d92 Mon Sep 17 00:00:00 2001 From: zlzw <583819556@qq.com> Date: Tue, 2 Apr 2024 13:19:23 +0800 Subject: [PATCH] =?UTF-8?q?fix=20[=E6=89=BE=E5=9B=9E=E5=AF=86=E7=A0=81?= =?UTF-8?q?=E6=97=A0=E6=B3=95=E7=99=BB=E9=99=86=E9=97=AE=E9=A2=98]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/shayu/phonelive/AppContext.java | 3 +-- .../manager/imrongcloud/MessageIMManager.java | 22 +++++++++++++++++++ .../com/yunbao/common/utils/AppManager.java | 9 ++++++++ .../utils/MessageChatNotifyManager.java | 3 +-- .../yunbao/main/activity/FindPwdActivity.java | 1 + .../yunbao/main/activity/MainActivity.java | 1 - .../main/views/MainMessageViewHolder.java | 2 +- 7 files changed, 35 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/shayu/phonelive/AppContext.java b/app/src/main/java/com/shayu/phonelive/AppContext.java index f37ac80..d22f81d 100644 --- a/app/src/main/java/com/shayu/phonelive/AppContext.java +++ b/app/src/main/java/com/shayu/phonelive/AppContext.java @@ -39,7 +39,6 @@ import com.yunbao.common.CommonAppContext; import com.yunbao.common.Constants; import com.yunbao.common.bean.AnchorStartLiveBean; import com.yunbao.common.bean.CrashSaveBean; -import com.yunbao.common.dialog.DebugDialog; import com.yunbao.common.event.SudGameSocketImEvent; import com.yunbao.common.manager.imrongcloud.InstructorSendReward; import com.yunbao.common.manager.imrongcloud.InstructorSendRewardProvider; @@ -297,6 +296,7 @@ public class AppContext extends CommonAppContext { } else if (message.getConversationType() == Conversation.ConversationType.PRIVATE) {//私聊信息 EventBus.getDefault().post(message); + MessageIMManager.get(sInstance).resetImUnReadMessageCount(sInstance); if (AppManager.getInstance().getLastActivity() instanceof CompleteUserInfoActivity) { return false; } @@ -307,7 +307,6 @@ public class AppContext extends CommonAppContext { RongIMClient.getInstance().getUnreadCount(Conversation.ConversationType.PRIVATE, message.getTargetId(), new RongIMClient.ResultCallback() { @Override public void onSuccess(Integer integer) { - DebugDialog.getInstance(AppManager.getActivity(MainActivity.class)).setParams("推送" + message.getTargetId(), "是否已读:" + message.getReceivedStatus().isRead() + "|未读数" + integer); if (integer > 0) { Log.i("聊天推送", message.getTargetId() + "是否已读:" + message.getReceivedStatus().isRead() + "|未读数" + integer); MessageChatNotifyManager.getInstance().push(AppManager.getInstance().getLastActivity() diff --git a/common/src/main/java/com/yunbao/common/manager/imrongcloud/MessageIMManager.java b/common/src/main/java/com/yunbao/common/manager/imrongcloud/MessageIMManager.java index 734cae4..d430a08 100644 --- a/common/src/main/java/com/yunbao/common/manager/imrongcloud/MessageIMManager.java +++ b/common/src/main/java/com/yunbao/common/manager/imrongcloud/MessageIMManager.java @@ -11,11 +11,13 @@ import com.alibaba.fastjson.JSON; import com.google.gson.Gson; import com.yunbao.common.bean.IMLoginModel; import com.yunbao.common.bean.ImUserInfoModel; +import com.yunbao.common.dialog.DebugDialog; import com.yunbao.common.dialog.MessageLongClickPopuwindow; import com.yunbao.common.event.MessageIMEvent; import com.yunbao.common.http.HttpCallback; import com.yunbao.common.http.HttpClient; import com.yunbao.common.manager.IMLoginManager; +import com.yunbao.common.utils.AppManager; import com.yunbao.common.utils.RouteUtil; import org.greenrobot.eventbus.EventBus; @@ -26,6 +28,7 @@ import java.util.List; import io.rong.imkit.IMCenter; import io.rong.imkit.config.ConversationClickListener; import io.rong.imkit.manager.UnReadMessageManager; +import io.rong.imlib.RongIMClient; import io.rong.imlib.model.Conversation; import io.rong.imlib.model.Message; import io.rong.imlib.model.UserInfo; @@ -74,6 +77,7 @@ public class MessageIMManager { UnReadMessageManager.getInstance().addObserver(conversationTypes, new UnReadMessageManager.IUnReadMessageObserver() { @Override public void onCountChanged(int integer) { + if (!IMLoginManager.get(mContext).hintChat()) { imNumber = integer; //发送通知 @@ -83,6 +87,24 @@ public class MessageIMManager { } }); + } + public void resetImUnReadMessageCount(Context mContext){ + RongIMClient.getInstance().getUnreadCount(new Conversation.ConversationType[]{ + Conversation.ConversationType.PRIVATE + }, new RongIMClient.ResultCallback() { + @Override + public void onSuccess(Integer integer) { + imNumber = integer; + //发送通知 + unreadMessagesHandler.post(essagesRunnable); + } + + @Override + public void onError(RongIMClient.ErrorCode e) { + + } + }); + } public MessageIMManager setSystemNumber(int systemNumber) { diff --git a/common/src/main/java/com/yunbao/common/utils/AppManager.java b/common/src/main/java/com/yunbao/common/utils/AppManager.java index 24f0c47..f1a0703 100644 --- a/common/src/main/java/com/yunbao/common/utils/AppManager.java +++ b/common/src/main/java/com/yunbao/common/utils/AppManager.java @@ -20,6 +20,15 @@ public class AppManager { return SingleApp.INSTANCE; } + public Activity getMainActivity() { + for (Activity activity : activityStack) { + if(activity.getClass().getSimpleName().contains("MainActivity")){ + return activity; + } + } + return getLastActivity(); + } + public static class SingleApp { public static AppManager INSTANCE = new AppManager(); } diff --git a/common/src/main/java/com/yunbao/common/utils/MessageChatNotifyManager.java b/common/src/main/java/com/yunbao/common/utils/MessageChatNotifyManager.java index 3c6a677..fcdb8cf 100644 --- a/common/src/main/java/com/yunbao/common/utils/MessageChatNotifyManager.java +++ b/common/src/main/java/com/yunbao/common/utils/MessageChatNotifyManager.java @@ -55,10 +55,9 @@ public class MessageChatNotifyManager { private synchronized void notifyLiveFlot(Context mContext) { String simpleName = AppManager.getInstance().getLastActivity().getClass().getSimpleName(); if (clazzList.contains(simpleName)) { - ToastUtil.showDebug("屏蔽类,不展示"); + // ToastUtil.showDebug("屏蔽类,不展示"); return; } - DebugDialog.getInstance((Activity) mContext).setParams("待推送通知数", startListNotifyList.size() + ""); if (startListNotifyList.iterator().hasNext()) { MessageUserInfoBean bean = startListNotifyList.iterator().next(); RongIMClient.getInstance().getUnreadCount(Conversation.ConversationType.PRIVATE, bean.getUser().getId() + "", new RongIMClient.ResultCallback() { diff --git a/main/src/main/java/com/yunbao/main/activity/FindPwdActivity.java b/main/src/main/java/com/yunbao/main/activity/FindPwdActivity.java index 260b051..b87d2ee 100644 --- a/main/src/main/java/com/yunbao/main/activity/FindPwdActivity.java +++ b/main/src/main/java/com/yunbao/main/activity/FindPwdActivity.java @@ -368,6 +368,7 @@ public class FindPwdActivity extends AbsActivity { String uid = obj.getString("id"); String token = obj.getString("token"); IMLoginModel model = GsonUtils.fromJson(info[0], IMLoginModel.class); + IMLoginManager.get(mContext).setupLoginUser(model); CommonAppConfig.getInstance().setLoginInfo(uid, token, true); getBaseUserInfo(); } else { diff --git a/main/src/main/java/com/yunbao/main/activity/MainActivity.java b/main/src/main/java/com/yunbao/main/activity/MainActivity.java index 255f08c..d6c7dce 100644 --- a/main/src/main/java/com/yunbao/main/activity/MainActivity.java +++ b/main/src/main/java/com/yunbao/main/activity/MainActivity.java @@ -234,7 +234,6 @@ public class MainActivity extends AbsActivity implements MainAppBarLayoutListene .postDelayed(new Runnable() { @Override public void run() { - DebugDialog.getInstance(mContext).setParams("Debug", "悬浮层"); } }, 1000); UserInfoManager.updateMyInfo(this, null); diff --git a/main/src/main/java/com/yunbao/main/views/MainMessageViewHolder.java b/main/src/main/java/com/yunbao/main/views/MainMessageViewHolder.java index 3eb16e9..2ff440a 100644 --- a/main/src/main/java/com/yunbao/main/views/MainMessageViewHolder.java +++ b/main/src/main/java/com/yunbao/main/views/MainMessageViewHolder.java @@ -113,6 +113,7 @@ public class MainMessageViewHolder extends AbsMainViewHolder { public void onResume() { super.onResume(); initData(); + MessageIMManager.get(mContext).resetImUnReadMessageCount(mContext); search.setText(""); } @@ -230,7 +231,6 @@ public class MainMessageViewHolder extends AbsMainViewHolder { @Override public void run() { netHandler.post(imUserInfoRunnable); - IMLoginManager.get(mContext).initChat("1"); if (IMLoginManager.get(mContext).hintChat()) { container.setVisibility(View.GONE); ltNodataMsg.setVisibility(View.VISIBLE);