Merge branch 'branch_new' into branch_new_69
This commit is contained in:
@@ -161,7 +161,7 @@ public class CommonAppContext extends MultiDexApplication implements Applicatio
|
||||
//设置mqtt环境 false 测试环境 true 正式环境
|
||||
// ExternalResConstants.INSTANCE.setIS_MQTT_RELEASE(false);
|
||||
//设置http环境 false 测试环境 true 正式环境
|
||||
ExternalResConstants.INSTANCE.setIS_HTTP_RELEASE(true);
|
||||
ExternalResConstants.INSTANCE.setIS_HTTP_RELEASE(false);
|
||||
currentEnvironment = ExternalResConstants.INSTANCE.HTTP_PATH();
|
||||
|
||||
initialization();
|
||||
|
||||
@@ -9,4 +9,5 @@ public class RoomOnline {
|
||||
|
||||
private List<RoomOnlineBean> on_pit;//麦上用户
|
||||
private List<RoomOnlineBean> off_pit;//麦下用户
|
||||
private int count;//在线人数
|
||||
}
|
||||
|
||||
@@ -2402,6 +2402,8 @@ public class RetrofitClient {
|
||||
BaseModel<RoomOnline> roomOnlineBaseModel = response.body();
|
||||
if (roomOnlineBaseModel.getCode() == 1) {
|
||||
observer.onNext(roomOnlineBaseModel.getData());
|
||||
}else if (roomOnlineBaseModel.getCode() == 0) {
|
||||
ToastUtils.showLong(roomOnlineBaseModel.getMsg());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -212,135 +212,106 @@ public class RoomOnlineDialogFragment extends BaseMvpDialogFragment<RoomPresente
|
||||
|
||||
@Override
|
||||
public void getRoomOnline(RoomOnline onlineBean) {
|
||||
if (!isValidContext()) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// 确保在主线程中执行UI操作
|
||||
if (getActivity() == null || mBinding == null) {
|
||||
getActivity().runOnUiThread(() -> {
|
||||
finishRefreshOrLoad();
|
||||
|
||||
if (onlineBean == null) {
|
||||
handleEmptyData();
|
||||
return;
|
||||
}
|
||||
|
||||
getActivity().runOnUiThread(() -> {
|
||||
// 完成刷新或加载更多操作
|
||||
if (mBinding.srl != null) {
|
||||
if (page <= 1) {
|
||||
mBinding.srl.finishRefresh();
|
||||
} else {
|
||||
mBinding.srl.finishLoadMore();
|
||||
}
|
||||
}
|
||||
List<RoomOnlineBean> roomOnlineBeanList = processOnlineData(onlineBean);
|
||||
updateAdapterData(roomOnlineBeanList);
|
||||
updateUserCount(onlineBean.getCount());
|
||||
});
|
||||
}
|
||||
|
||||
List<RoomOnlineBean> roomOnlineBeanList = new ArrayList<>();
|
||||
// 处理第一页数据(刷新操作)
|
||||
if (page <= 1) {
|
||||
// 清空之前的数据
|
||||
roomOnlineAdapter.setNewData(new ArrayList<>());
|
||||
}
|
||||
private boolean isValidContext() {
|
||||
return getActivity() != null && mBinding != null;
|
||||
}
|
||||
|
||||
int type_pit;
|
||||
if (pit_number.isEmpty()) {
|
||||
type_pit = 1;
|
||||
} else {
|
||||
type_pit = 2;
|
||||
}
|
||||
if (onlineBean.getOn_pit() != null && onlineBean.getOn_pit().size() > 0) {
|
||||
RoomOnlineBean roomOnlineBean = new RoomOnlineBean();
|
||||
roomOnlineBean.setItemViewType(1);
|
||||
roomOnlineBean.setTypeNames("麦上用户");
|
||||
roomOnlineBeanList.add(roomOnlineBean);
|
||||
for (RoomOnlineBean roomOnlineBean1 : onlineBean.getOn_pit()) {
|
||||
roomOnlineBean1.setType(1);
|
||||
roomOnlineBean1.setType_pit(0);
|
||||
roomOnlineBean1.setItemViewType(2);
|
||||
roomOnlineBeanList.add(roomOnlineBean1);
|
||||
}
|
||||
private void finishRefreshOrLoad() {
|
||||
if (mBinding.srl == null) return;
|
||||
|
||||
}
|
||||
if (onlineBean.getOff_pit() != null && onlineBean.getOff_pit().size() > 0) {
|
||||
RoomOnlineBean roomOnlineBean = new RoomOnlineBean();
|
||||
roomOnlineBean.setItemViewType(1);
|
||||
roomOnlineBean.setTypeNames("麦下用户");
|
||||
roomOnlineBeanList.add(roomOnlineBean);
|
||||
for (RoomOnlineBean roomOnlineBean2 : onlineBean.getOff_pit()) {
|
||||
roomOnlineBean2.setType(2);
|
||||
roomOnlineBean2.setType_pit(type_pit);
|
||||
roomOnlineBean2.setItemViewType(2);
|
||||
roomOnlineBeanList.add(roomOnlineBean2);
|
||||
}
|
||||
}
|
||||
if (page <= 1) {
|
||||
mBinding.srl.finishRefresh();
|
||||
} else {
|
||||
mBinding.srl.finishLoadMore();
|
||||
}
|
||||
}
|
||||
|
||||
// 根据是刷新还是加载更多来处理数据
|
||||
if (page <= 1) {
|
||||
// 刷新操作,设置新数据
|
||||
roomOnlineAdapter.setNewData(roomOnlineBeanList);
|
||||
} else {
|
||||
// 加载更多操作,添加数据
|
||||
if (roomOnlineBeanList.size() > 0) {
|
||||
roomOnlineAdapter.addData(roomOnlineBeanList);
|
||||
} else {
|
||||
// 没有更多数据了
|
||||
if (mBinding.srl != null) {
|
||||
mBinding.srl.finishLoadMoreWithNoMoreData();
|
||||
}
|
||||
}
|
||||
}
|
||||
private void handleEmptyData() {
|
||||
if (page <= 1) {
|
||||
roomOnlineAdapter.setNewData(new ArrayList<>());
|
||||
} else if (mBinding.srl != null) {
|
||||
mBinding.srl.finishLoadMoreWithNoMoreData();
|
||||
}
|
||||
}
|
||||
|
||||
// 更新用户总数
|
||||
// 更新用户总数 - 仅在第一页刷新时更新总数
|
||||
if (page <= 1) {
|
||||
int total = 0;
|
||||
if (onlineBean.getOn_pit() != null) {
|
||||
total += onlineBean.getOn_pit().size();
|
||||
}
|
||||
if (onlineBean.getOff_pit() != null) {
|
||||
total += onlineBean.getOff_pit().size();
|
||||
}
|
||||
private List<RoomOnlineBean> processOnlineData(RoomOnline onlineBean) {
|
||||
List<RoomOnlineBean> result = new ArrayList<>();
|
||||
boolean isFirstPage = page <= 1;
|
||||
int typePit = pit_number.isEmpty() ? 1 : 2;
|
||||
|
||||
// 只有当获取到有效数据时才更新总数显示
|
||||
if (onlineBean.getOn_pit() != null || onlineBean.getOff_pit() != null) {
|
||||
mBinding.tvNum.setText("用户列表(" + total + ")人");
|
||||
if (getActivity() instanceof RoomActivity) {
|
||||
((RoomActivity) getActivity()).setOnlineNumber(total);
|
||||
}
|
||||
}
|
||||
// 如果两个列表都为null,保持之前的总数显示不变
|
||||
} else {
|
||||
// 加载更多时,更新总数显示
|
||||
int currentTotal = 0;
|
||||
List<RoomOnlineBean> currentData = roomOnlineAdapter.getData();
|
||||
for (RoomOnlineBean bean : currentData) {
|
||||
if (bean.getItemViewType() == 2) { // 只统计用户项,不统计标题项
|
||||
currentTotal++;
|
||||
}
|
||||
}
|
||||
// 处理麦上用户
|
||||
processUserList(onlineBean.getOn_pit(), result, "麦上用户",
|
||||
isFirstPage, 1, 0);
|
||||
|
||||
mBinding.tvNum.setText("用户列表(" + currentTotal + ")人");
|
||||
if (getActivity() instanceof RoomActivity) {
|
||||
((RoomActivity) getActivity()).setOnlineNumber(currentTotal);
|
||||
}
|
||||
}
|
||||
// 处理麦下用户
|
||||
processUserList(onlineBean.getOff_pit(), result, "麦下用户",
|
||||
isFirstPage, 2, typePit);
|
||||
|
||||
// 检查是否需要禁用加载更多(如果当前页数据少于预期)
|
||||
if (onlineBean.getOn_pit() != null && onlineBean.getOff_pit() != null) {
|
||||
int currentCount = onlineBean.getOn_pit().size() + onlineBean.getOff_pit().size();
|
||||
if (currentCount < 10 && page > 1) { // 每页预期10条数据
|
||||
if (mBinding.srl != null) {
|
||||
mBinding.srl.finishLoadMoreWithNoMoreData();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
// 确保在异常情况下也能完成刷新操作
|
||||
if (getActivity() != null && mBinding != null && mBinding.srl != null) {
|
||||
getActivity().runOnUiThread(() -> {
|
||||
if (page <= 1) {
|
||||
mBinding.srl.finishRefresh(false);
|
||||
} else {
|
||||
mBinding.srl.finishLoadMore(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
e.printStackTrace();
|
||||
return result;
|
||||
}
|
||||
|
||||
private void processUserList(List<RoomOnlineBean> userList,
|
||||
List<RoomOnlineBean> result, String title,
|
||||
boolean addTitle, int type, int typePit) {
|
||||
if (userList == null || userList.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (addTitle) {
|
||||
RoomOnlineBean titleBean = createTitleBean(title);
|
||||
result.add(titleBean);
|
||||
}
|
||||
|
||||
for (RoomOnlineBean userBean : userList) {
|
||||
userBean.setType(type);
|
||||
userBean.setType_pit(typePit);
|
||||
userBean.setItemViewType(2);
|
||||
result.add(userBean);
|
||||
}
|
||||
}
|
||||
|
||||
private RoomOnlineBean createTitleBean(String title) {
|
||||
RoomOnlineBean titleBean = new RoomOnlineBean();
|
||||
titleBean.setItemViewType(1);
|
||||
titleBean.setTypeNames(title);
|
||||
return titleBean;
|
||||
}
|
||||
|
||||
private void updateAdapterData(List<RoomOnlineBean> newData) {
|
||||
if (page <= 1) {
|
||||
roomOnlineAdapter.setNewData(newData);
|
||||
} else if (!newData.isEmpty()) {
|
||||
roomOnlineAdapter.addData(newData);
|
||||
} else if (mBinding.srl != null) {
|
||||
mBinding.srl.finishLoadMoreWithNoMoreData();
|
||||
}
|
||||
}
|
||||
|
||||
private void updateUserCount(int count) {
|
||||
if (mBinding.tvNum != null) {
|
||||
mBinding.tvNum.setText(String.format("用户列表(%d)人", count));
|
||||
}
|
||||
|
||||
if (getActivity() instanceof RoomActivity) {
|
||||
((RoomActivity) getActivity()).setOnlineNumber(count);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -94,20 +94,23 @@ public class RoomManager {
|
||||
if (CommonAppContext.getInstance().playId == null) {
|
||||
fetchAndJoinRoom(context, roomId, password, taskId);
|
||||
} else {
|
||||
if (!CommonAppContext.getInstance().playId.equals(roomId)) {
|
||||
if (!CommonAppContext.getInstance().playId.equals(roomId)) {//这是判断点击的和存储的roomId是否相同,不相同就退出记录的id,然后加入新的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());
|
||||
|
||||
//2025年12月9日17:39:21 修改,将获取在线用户判断是否在房间进行关闭,原因是:服务端不在踢人了,所以点击最小化的时候,就直接走room_info接口
|
||||
upInfo(context, roomId, password, false, roomInfo, true, taskId);
|
||||
return;
|
||||
// fetchAndJoinRoom(context, roomId, password, taskId);
|
||||
// return;
|
||||
} else if (CommonAppContext.getInstance().lable_id.equals("6")) {
|
||||
} else if (CommonAppContext.getInstance().lable_id.equals("6")) {//这是判断是否是小黑屋,是小黑屋进行更新,走room_info接口
|
||||
upInfo(context, roomId, password, true, roomInfo, true, taskId);
|
||||
return;
|
||||
}
|
||||
//这里是点击的roomId和存错的id是同一个的时候,就走的是更新,roomInfo接口
|
||||
isUserOnline(context, roomId, password, roomInfo, taskId);
|
||||
}
|
||||
}
|
||||
@@ -293,47 +296,48 @@ public class RoomManager {
|
||||
// 可以通过检查Agora是否还在房间中,或者通过服务端接口查询用户状态等方式实现
|
||||
// 目前返回false,需要根据实际需求实现具体逻辑
|
||||
|
||||
final boolean[] isOnline = {false};
|
||||
RetrofitClient.getInstance().getRoomOnline(roomId, "1", "50", new BaseObserver<RoomOnline>() {
|
||||
@Override
|
||||
public void onSubscribe(Disposable d) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(RoomOnline roomOnline) {
|
||||
try {
|
||||
if (roomOnline != null) {
|
||||
if (roomOnline.getOn_pit() != null) {
|
||||
for (RoomOnlineBean roomOnlineBean : roomOnline.getOn_pit()) {
|
||||
if (roomOnlineBean.getUser_id() == SpUtil.getUserId()) {
|
||||
isOnline[0] = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (roomOnline.getOff_pit() != null) {
|
||||
for (RoomOnlineBean roomOnlineBean : roomOnline.getOff_pit()) {
|
||||
if (roomOnlineBean.getUser_id() == SpUtil.getUserId()) {
|
||||
isOnline[0] = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
upInfo(context, roomId, password, isOnline[0], roomInfo, true, taskId);
|
||||
|
||||
} else {
|
||||
isOnline[0] = false;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// 捕获所有可能的异常,避免崩溃
|
||||
e.printStackTrace();
|
||||
isOnline[0] = false;
|
||||
// 即使出现异常也继续执行
|
||||
upInfo(context, roomId, password, isOnline[0], roomInfo, true, taskId);
|
||||
}
|
||||
}
|
||||
});
|
||||
// final boolean[] isOnline = {false};
|
||||
// RetrofitClient.getInstance().getRoomOnline(roomId, "1", "50", new BaseObserver<RoomOnline>() {
|
||||
// @Override
|
||||
// public void onSubscribe(Disposable d) {
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onNext(RoomOnline roomOnline) {
|
||||
// try {
|
||||
// if (roomOnline != null) {
|
||||
// if (roomOnline.getOn_pit() != null) {
|
||||
// for (RoomOnlineBean roomOnlineBean : roomOnline.getOn_pit()) {
|
||||
// if (roomOnlineBean.getUser_id() == SpUtil.getUserId()) {
|
||||
// isOnline[0] = true;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// if (roomOnline.getOff_pit() != null) {
|
||||
// for (RoomOnlineBean roomOnlineBean : roomOnline.getOff_pit()) {
|
||||
// if (roomOnlineBean.getUser_id() == SpUtil.getUserId()) {
|
||||
// isOnline[0] = true;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// upInfo(context, roomId, password, isOnline[0], roomInfo, true, taskId);
|
||||
//
|
||||
// } else {
|
||||
// isOnline[0] = false;
|
||||
// }
|
||||
// } catch (Exception e) {
|
||||
// // 捕获所有可能的异常,避免崩溃
|
||||
// e.printStackTrace();
|
||||
// isOnline[0] = false;
|
||||
// // 即使出现异常也继续执行
|
||||
// upInfo(context, roomId, password, isOnline[0], roomInfo, true, taskId);
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
upInfo(context, roomId, password, true, roomInfo, true, taskId);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user