1:修改当在游戏房间的时候,不能点击其他房间进入,

2:在进入房间后,退出上一个房间的各种调用
This commit is contained in:
2025-12-01 18:41:14 +08:00
parent be60810221
commit 980ec43e6c
7 changed files with 150 additions and 52 deletions

View File

@@ -1,5 +1,7 @@
package com.xscm.modulemain.manager;
import static com.liulishuo.okdownload.OkDownloadProvider.context;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
@@ -19,6 +21,7 @@ import com.xscm.moduleutil.base.CommonAppContext;
import com.xscm.moduleutil.bean.room.RoomInfoResp;
import com.xscm.moduleutil.bean.room.RoomOnline;
import com.xscm.moduleutil.bean.room.RoomOnlineBean;
import com.xscm.moduleutil.dialog.ConfirmDialog;
import com.xscm.moduleutil.event.RoomOutEvent;
import com.xscm.moduleutil.http.BaseObserver;
import com.xscm.moduleutil.http.RetrofitClient;
@@ -49,6 +52,8 @@ public class RoomManager {
// 房间数据缓存
private Map<String, RoomInfoResp> roomDataCache = new ConcurrentHashMap<>();
private Map<String, Long> cacheTimestamps = new ConcurrentHashMap<>();
private String taskId;
private Context context;
// 缓存有效期5分钟
private static final long CACHE_DURATION = 5 * 60 * 1000;
@@ -71,6 +76,8 @@ public class RoomManager {
* @param password 房间密码
*/
public void fetchRoomDataAndEnter(Context context, String roomId, String password, String taskId) {
this.taskId=taskId;
this.context=context;
// 显示加载提示
// 这里可以根据需要添加加载对话框
if (CommonAppContext.getInstance().isRoomJoininj) {
@@ -85,12 +92,15 @@ public class RoomManager {
fetchAndJoinRoom(context, roomId, password, taskId);
} else {
if (!CommonAppContext.getInstance().playId.equals(roomId)) {
MessageListenerSingleton.getInstance().joinGroup(roomId);
exitRoom(CommonAppContext.getInstance().playId);
CommonAppContext.getInstance().isShow = false;
CommonAppContext.getInstance().isPlaying = false;
CommonAppContext.getInstance().isRoomJoininj = false;
EventBus.getDefault().post(new RoomOutEvent());
// MessageListenerSingleton.getInstance().joinGroup(roomId);
// exitRoom(CommonAppContext.getInstance().playId);
// CommonAppContext.getInstance().isShow = false;
// CommonAppContext.getInstance().isPlaying = false;
// CommonAppContext.getInstance().isRoomJoininj = false;
// EventBus.getDefault().post(new RoomOutEvent());
fetchAndJoinRoom(context, roomId, password, taskId);
return;
} else if (CommonAppContext.getInstance().lable_id.equals("6")) {
upInfo(context, roomId, password, true, roomInfo, true, taskId);
return;
@@ -136,24 +146,42 @@ public class RoomManager {
@Override
public void onNext(RoomInfoResp resp) {
if (resp != null) {
String appId = CommonAppContext.getInstance().getCurrentEnvironment().getSwSdkAppId();
String token = resp.getUser_info().getAgora_token(); // 如果启用了鉴权才需要
String roomId = resp.getRoom_info().getRoom_id(); // 房间 ID
String rtm_token = resp.getUser_info().getAgora_rtm_token();
SpUtil.setRtmToken(rtm_token);
int uid = SpUtil.getUserId(); // 0 表示由 Agora 自动生成 UID
boolean enableMic = false; // 是否开启麦克风
boolean enableJs = false; // 是否开启角色
if (resp.getUser_info().getPit_number() != 0) {
enableJs = true;
if (ActivityUtils.getTopActivity() instanceof MainActivity){
((MainActivity) ActivityUtils.getTopActivity()).isShowLoading(false);
}
if (!resp.getRoom_id().isEmpty()){
if(CommonAppContext.getInstance().playId==null){
CommonAppContext.getInstance().playId="";
}
queren(resp.getRoom_id(),resp.getMsg());
}else {
MessageListenerSingleton.getInstance().joinGroup(roomId);
exitRoom(CommonAppContext.getInstance().playId);
CommonAppContext.getInstance().isShow = false;
CommonAppContext.getInstance().isPlaying = false;
CommonAppContext.getInstance().isRoomJoininj = false;
EventBus.getDefault().post(new RoomOutEvent());
String appId = CommonAppContext.getInstance().getCurrentEnvironment().getSwSdkAppId();
String token = resp.getUser_info().getAgora_token(); // 如果启用了鉴权才需要
String roomId = resp.getRoom_info().getRoom_id(); // 房间 ID
String rtm_token = resp.getUser_info().getAgora_rtm_token();
SpUtil.setRtmToken(rtm_token);
int uid = SpUtil.getUserId(); // 0 表示由 Agora 自动生成 UID
boolean enableMic = false; // 是否开启麦克风
boolean enableJs = false; // 是否开启角色
if (resp.getUser_info().getPit_number() != 0) {
enableJs = true;
}
LogUtils.e("token", token);
LogUtils.e("roomId:", roomId);
// 初始化 Agora 并加入房间
AgoraManager.getInstance()
.joinRoom(token, roomId, uid, enableMic, enableJs);
cacheRoomData(roomId, resp);
navigateToRoom(context, roomId, password, resp, false, taskId);
}
LogUtils.e("token", token);
LogUtils.e("roomId:", roomId);
// 初始化 Agora 并加入房间
AgoraManager.getInstance()
.joinRoom(token, roomId, uid, enableMic, enableJs);
cacheRoomData(roomId, resp);
navigateToRoom(context, roomId, password, resp, false, taskId);
}else {
if (ActivityUtils.getTopActivity() instanceof MainActivity){
((MainActivity) ActivityUtils.getTopActivity()).isShowLoading(false);
@@ -342,4 +370,25 @@ public class RoomManager {
Logger.d(TAG, "退出房间: " + roomId);
}
private void queren(String roomId,String msg){
// 检查context是否有效避免在Activity销毁后显示对话框
// if (context == null || (context instanceof Activity && ((Activity)context).isFinishing())) {
// Logger.d(TAG, "Context is null or Activity is finishing, cannot show dialog");
// return;
// }
new ConfirmDialog(ActivityUtils.getTopActivity(),
"提示",
msg,
CommonAppContext.getInstance().playId.equals(roomId) ?"":"去上一个房间",
CommonAppContext.getInstance().playId.equals(roomId) ?"取消":"在想想",
v -> {
// 点击“确认”按钮时执行删除操作
// MvpPre.deleteComment(String.valueOf(commentId));
fetchRoomDataAndEnter(ActivityUtils.getTopActivity(),roomId,"",taskId);
},
v -> {
// 点击“取消”按钮时什么都不做
}, false, 0).show();
}
}