1.修改播放礼物特效代码
2:修改从房间进入其他页面出现不能回到房间的问题
This commit is contained in:
@@ -14,13 +14,14 @@
|
||||
|
||||
<activity
|
||||
android:name=".activity.RoomActivity"
|
||||
android:exported="false"
|
||||
android:launchMode="singleInstance"
|
||||
android:launchMode="singleTask"
|
||||
android:windowSoftInputMode="adjustPan"
|
||||
android:enableOnBackInvokedCallback="false"
|
||||
android:theme="@style/TransparentActivityTheme"
|
||||
android:configChanges="orientation|screenSize|keyboardHidden"
|
||||
android:screenOrientation="portrait" />
|
||||
android:screenOrientation="portrait"
|
||||
android:exported="true"
|
||||
/>
|
||||
|
||||
<service
|
||||
android:name=".service.MediaProjectionService"
|
||||
|
||||
@@ -10,17 +10,21 @@ import static com.liulishuo.okdownload.OkDownloadProvider.context;
|
||||
import android.Manifest;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.app.ActivityManager;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.content.res.Configuration;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.os.Bundle;
|
||||
import android.os.CountDownTimer;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.os.Message;
|
||||
import android.os.StrictMode;
|
||||
import android.text.Spannable;
|
||||
import android.text.SpannableStringBuilder;
|
||||
@@ -93,6 +97,7 @@ import com.petterp.floatingx.assist.helper.FxScopeHelper;
|
||||
import com.petterp.floatingx.listener.control.IFxControl;
|
||||
import com.tencent.imsdk.v2.V2TIMValueCallback;
|
||||
import com.xscm.moduleutil.base.CommonAppContext;
|
||||
import com.xscm.moduleutil.bean.GiftAvatarBean;
|
||||
import com.xscm.moduleutil.bean.GiftBean;
|
||||
import com.xscm.moduleutil.bean.HeadlineBean;
|
||||
import com.xscm.moduleutil.bean.RoomInputEvent;
|
||||
@@ -146,6 +151,7 @@ import com.xscm.moduleutil.utils.ColorManager;
|
||||
import com.xscm.moduleutil.utils.ImageUtils;
|
||||
import com.xscm.moduleutil.utils.SpUtil;
|
||||
import com.xscm.moduleutil.utils.SystemUtils;
|
||||
import com.xscm.moduleutil.widget.AvatarFrameView;
|
||||
import com.xscm.moduleutil.widget.CircularProgressView;
|
||||
import com.xscm.moduleutil.widget.CustomMusicFloatingView;
|
||||
import com.xscm.moduleutil.widget.SilentCountDownTimer;
|
||||
@@ -164,12 +170,15 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Queue;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import io.agora.musiccontentcenter.Music;
|
||||
import io.reactivex.disposables.Disposable;
|
||||
import lombok.Synchronized;
|
||||
import pub.devrel.easypermissions.AppSettingsDialog;
|
||||
import pub.devrel.easypermissions.EasyPermissions;
|
||||
|
||||
@@ -221,6 +230,10 @@ public class RoomActivity extends BaseMvpActivity<RoomPresenter, ActivityRoomBin
|
||||
private List<DialogInterface> activeDialogs = new ArrayList<>();
|
||||
private List<Fragment> activeDialogFragments = new ArrayList<>();
|
||||
|
||||
private boolean isMinimized = false;
|
||||
private static final String PREF_MINIMIZED_ROOM = "minimized_room_id";
|
||||
private static final String PREF_MINIMIZED_TIME = "minimized_time";
|
||||
|
||||
// 添加弹框到管理列表
|
||||
public void addActiveDialog(DialogInterface dialog) {
|
||||
activeDialogs.add(dialog);
|
||||
@@ -249,44 +262,115 @@ public class RoomActivity extends BaseMvpActivity<RoomPresenter, ActivityRoomBin
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
// 处理从桌面重新启动的情况
|
||||
// @Override
|
||||
// public boolean dispatchTouchEvent(MotionEvent ev) {
|
||||
// // 获取触摸位置的坐标
|
||||
// float x = ev.getX();
|
||||
// float y = ev.getY();
|
||||
// protected void onNewIntent(Intent intent) {
|
||||
// super.onNewIntent(intent);
|
||||
// setIntent(intent);
|
||||
//
|
||||
// // 找到 BFragment
|
||||
// Fragment fragment = getSupportFragmentManager().findFragmentByTag("RoomKtvFragment");
|
||||
// if (fragment instanceof RoomKtvFragment) {
|
||||
// // 获取负 margin 的视图
|
||||
// View negativeMarginView = ((RoomKtvFragment) fragment).getNegativeMarginView();
|
||||
// if (negativeMarginView != null) {
|
||||
// // 计算视图在屏幕上的位置
|
||||
// int[] location = new int[2];
|
||||
// negativeMarginView.getLocationOnScreen(location);
|
||||
// int viewX = location[0];
|
||||
// int viewY = location[1];
|
||||
// int viewWidth = negativeMarginView.getWidth();
|
||||
// int viewHeight = negativeMarginView.getHeight();
|
||||
// // 检查是否应该恢复最小化的房间
|
||||
// handleRestoreFromMinimize(intent);
|
||||
// }
|
||||
|
||||
private void handleRestoreFromMinimize(Intent intent) {
|
||||
// 如果是从桌面启动且之前有最小化的房间
|
||||
// if (Intent.ACTION_MAIN.equals(intent.getAction())
|
||||
// && intent.hasCategory(Intent.CATEGORY_LAUNCHER)) {
|
||||
//
|
||||
// // 检查触摸点是否在视图范围内
|
||||
// if (x >= viewX && x <= viewX + viewWidth &&
|
||||
// y >= viewY && y <= viewY + viewHeight) {
|
||||
// // 将事件传递给该视图
|
||||
// return negativeMarginView.dispatchTouchEvent(ev);
|
||||
// SharedPreferences prefs = getSharedPreferences("room_minimize_state", Context.MODE_PRIVATE);
|
||||
// boolean isMinimized = prefs.getBoolean("is_minimized", false);
|
||||
//
|
||||
// if (isMinimized) {
|
||||
// // 恢复到最小化的房间
|
||||
// String minimizedRoomId = prefs.getString(PREF_MINIMIZED_ROOM, null);
|
||||
// if (minimizedRoomId != null && minimizedRoomId.equals(roomId)) {
|
||||
// // 当前就是最小化的房间,直接恢复
|
||||
// resumeRoomFromMinimize();
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return super.dispatchTouchEvent(ev);
|
||||
// }
|
||||
|
||||
// 其他情况按正常流程处理
|
||||
String newRoomId = intent.getStringExtra("roomId");
|
||||
String newPassword = intent.getStringExtra("password");
|
||||
|
||||
if (!TextUtils.isEmpty(newRoomId) && !newRoomId.equals(roomId)) {
|
||||
// switchToRoom(newRoomId, newPassword);
|
||||
releaseRoom();
|
||||
startActivity(intent);
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
private void resumeRoomFromMinimize() {
|
||||
// 从最小化状态恢复房间
|
||||
isMinimized = false;
|
||||
clearMinimizeState();
|
||||
|
||||
// 恢复房间状态
|
||||
resumeRoomState();
|
||||
|
||||
// 确保UI正确显示
|
||||
if (mBinding != null) {
|
||||
// 恢复UI状态
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
||||
// 拦截返回键,显示退出对话框而不是直接退出
|
||||
showExitRoomDialog();
|
||||
return true;
|
||||
}
|
||||
// else if (keyCode == KeyEvent.KEYCODE_HOME) {
|
||||
// // Home 键按下时,保存状态但不特殊处理
|
||||
// // 系统会自动将应用最小化
|
||||
//// saveMinimizeState();
|
||||
// return super.onKeyDown(keyCode, event);
|
||||
// }
|
||||
return false;
|
||||
}
|
||||
|
||||
private void showExitRoomDialog() {
|
||||
ExitRoomBottomSheet bottomSheet = ExitRoomBottomSheet.newInstance();
|
||||
bottomSheet.setOnOptionSelectedListener(new ExitRoomBottomSheet.OnOptionSelectedListener() {
|
||||
@Override
|
||||
public void onMinimize() {
|
||||
// 处理最小化逻辑,比如不销毁 Activity,仅移至后台
|
||||
// CommonAppContext.getInstance().isShow = false;
|
||||
// ARouter.getInstance().build(ARouteConstants.ME).navigation();//栈顶复用
|
||||
// moveTaskToBack(true);
|
||||
|
||||
CommonAppContext.getInstance().isShow = false;
|
||||
ARouter.getInstance().build(ARouteConstants.ME)
|
||||
.withFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
.navigation();
|
||||
// moveTaskToBack(true);
|
||||
|
||||
// 处理最小化逻辑
|
||||
minimizeToBackground();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onExitRoom() {
|
||||
// 调用退出房间方法
|
||||
MvpPre.quitRoom(roomId, SpUtil.getUserId() + "");
|
||||
|
||||
// 真正退出房间
|
||||
performExitRoom();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCancel() {
|
||||
// 用户点击取消,不做任何事
|
||||
}
|
||||
});
|
||||
bottomSheet.show(getSupportFragmentManager(), "ExitRoomBottomSheet");
|
||||
addActiveDialogFragment(bottomSheet);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConfigurationChanged(@NonNull Configuration newConfig) {
|
||||
@@ -371,6 +455,9 @@ public class RoomActivity extends BaseMvpActivity<RoomPresenter, ActivityRoomBin
|
||||
// () -> EventBus.getDefault().post(new ShowOnWheatDialogEvent()),
|
||||
// 10000);
|
||||
|
||||
isSave = false;
|
||||
sDestroied = false;
|
||||
isMinimized = false;
|
||||
|
||||
overridePendingTransition(0, 0); // 关闭转场动画
|
||||
|
||||
@@ -380,8 +467,11 @@ public class RoomActivity extends BaseMvpActivity<RoomPresenter, ActivityRoomBin
|
||||
|
||||
SpUtil.saveMyRoomId(roomId);
|
||||
MessageListenerSingleton.getInstance().joinGroup(roomId);
|
||||
// MvpPre.getRoomIn(roomId, password);
|
||||
// MvpPre.getRoomOnline(roomId, "1", "10");
|
||||
|
||||
|
||||
// 检查是否有保存的最小化状态
|
||||
checkAndRestoreMinimizeState();
|
||||
|
||||
// 在子线程中执行网络请求
|
||||
performNetworkRequestsAsync();
|
||||
|
||||
@@ -395,7 +485,22 @@ public class RoomActivity extends BaseMvpActivity<RoomPresenter, ActivityRoomBin
|
||||
// }
|
||||
|
||||
}
|
||||
private void checkAndRestoreMinimizeState() {
|
||||
SharedPreferences prefs = getSharedPreferences("room_minimize_state", Context.MODE_PRIVATE);
|
||||
boolean isMinimized = prefs.getBoolean("is_minimized", false);
|
||||
|
||||
if (isMinimized) {
|
||||
// 检查最小化时间,如果太久可能需要重新登录
|
||||
long minimizeTime = prefs.getLong(PREF_MINIMIZED_TIME, 0);
|
||||
long currentTime = System.currentTimeMillis();
|
||||
|
||||
// 如果最小化超过一定时间(如30分钟),可能需要重新验证
|
||||
if (currentTime - minimizeTime > 30 * 60 * 1000) {
|
||||
// 清理过期的最小化状态
|
||||
clearMinimizeState();
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 在子线程中执行网络请求,避免阻塞主线程
|
||||
*/
|
||||
@@ -989,7 +1094,7 @@ public class RoomActivity extends BaseMvpActivity<RoomPresenter, ActivityRoomBin
|
||||
}
|
||||
roomFragment.updateSeatViewExchangedWithPitArray(mRoomInfoResp);
|
||||
}
|
||||
|
||||
private List<GiftBean> playQueue = new ArrayList();
|
||||
|
||||
private void handleMsgType1005(RoomMessageEvent messageEvent, RoomMessageEvent.T text) {
|
||||
if (text == null || mRoomInfoResp == null || mRoomInfoResp.getRoom_info() == null) return;
|
||||
@@ -998,32 +1103,42 @@ public class RoomActivity extends BaseMvpActivity<RoomPresenter, ActivityRoomBin
|
||||
UserInfo toUserInfo = text.getToUserInfo();
|
||||
if (giftInfo == null || toUserInfo == null) return;
|
||||
|
||||
// mBinding.svgaGift.setSource(giftInfo.getPlay_image(), 2);
|
||||
if (SpUtil.getOpenEffect() == 1) {
|
||||
// 特效关闭时清空队列并停止播放
|
||||
mBinding.svgaGift.setSource(giftInfo.getPlay_image(), 2);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 在子线程中处理礼物特效播放
|
||||
ThreadUtils.executeByIo(new ThreadUtils.SimpleTask<Void>() {
|
||||
@Override
|
||||
public Void doInBackground() throws Throwable {
|
||||
// 预处理礼物数据(如果需要)
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(Void result) {
|
||||
// 在主线程中更新UI
|
||||
runOnUiThread(() -> {
|
||||
try {
|
||||
// 使用post方法确保在下一个消息循环中执行
|
||||
mBinding.svgaGift.post(() -> {
|
||||
mBinding.svgaGift.setSource(giftInfo.getPlay_image(), 2);
|
||||
});
|
||||
} catch (Exception e) {
|
||||
LogUtils.e("Error setting gift source: " + e.getMessage());
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
// ThreadUtils.executeBySingle(new ThreadUtils.SimpleTask<Void>() {
|
||||
// @Override
|
||||
// public Void doInBackground() throws Throwable {
|
||||
// // 预处理礼物数据(如果需要)
|
||||
// LogUtils.d("@@@@doInBackground",Thread.currentThread().getName());
|
||||
// if ("mp4".equals(mBinding.svgaGift.getFileExtension(giftInfo.getPlay_image()))) {
|
||||
// mBinding.svgaGift.downloadAndPlayMp4(giftInfo.getPlay_image());
|
||||
// }
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onSuccess(Void result) {
|
||||
// LogUtils.d("@@@@",Thread.currentThread().getName());
|
||||
//
|
||||
// // 在主线程中更新UI
|
||||
//// runOnUiThread(() -> {
|
||||
//// try {
|
||||
//// // 使用post方法确保在下一个消息循环中执行
|
||||
//// mBinding.svgaGift.post(() -> {
|
||||
//// mBinding.svgaGift.setSource(giftInfo.getPlay_image(), 2);
|
||||
//// });
|
||||
//// } catch (Exception e) {
|
||||
//// LogUtils.e("Error setting gift source: " + e.getMessage());
|
||||
//// }
|
||||
//// });
|
||||
// }
|
||||
// });
|
||||
|
||||
List<RoomPitBean> pitList = mRoomInfoResp.getRoom_info().getPit_list();
|
||||
if (pitList == null) return;
|
||||
@@ -1056,6 +1171,21 @@ public class RoomActivity extends BaseMvpActivity<RoomPresenter, ActivityRoomBin
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// @Subscribe(threadMode = ThreadMode.MAIN)
|
||||
// public void handleGiftAvatarBean(GiftAvatarBean giftAvatarBean) {
|
||||
// LogUtils.e("@@@@" + "EventBus2222222"+"playQueue.size()===="+playQueue.size());
|
||||
//
|
||||
// for (GiftBean giftBean : playQueue) {
|
||||
// if(!giftBean.is_paly()){
|
||||
// mBinding.svgaGift.setSource(giftBean.getPlay_image(), 2);
|
||||
// giftBean.set_paly( true);
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// }
|
||||
|
||||
private void handleMsgType1014(RoomMessageEvent messageEvent, RoomMessageEvent.T text) {
|
||||
if (text == null) return;
|
||||
|
||||
@@ -1792,36 +1922,44 @@ public class RoomActivity extends BaseMvpActivity<RoomPresenter, ActivityRoomBin
|
||||
fragment.show(getSupportFragmentManager(), "RoomChartsFragment");
|
||||
addActiveDialogFragment(fragment);
|
||||
} else if (id == R.id.btn_close_live) {
|
||||
showExitRoomDialog();
|
||||
|
||||
//最小化
|
||||
ExitRoomBottomSheet bottomSheet = ExitRoomBottomSheet.newInstance();
|
||||
bottomSheet.setOnOptionSelectedListener(new ExitRoomBottomSheet.OnOptionSelectedListener() {
|
||||
@Override
|
||||
public void onMinimize() {
|
||||
// 处理最小化逻辑,比如不销毁 Activity,仅移至后台
|
||||
// ExitRoomBottomSheet bottomSheet = ExitRoomBottomSheet.newInstance();
|
||||
// bottomSheet.setOnOptionSelectedListener(new ExitRoomBottomSheet.OnOptionSelectedListener() {
|
||||
// @Override
|
||||
// public void onMinimize() {
|
||||
// // 处理最小化逻辑,比如不销毁 Activity,仅移至后台
|
||||
//// CommonAppContext.getInstance().isShow = false;
|
||||
//// ARouter.getInstance().build(ARouteConstants.ME).navigation();//栈顶复用
|
||||
//// moveTaskToBack(true);
|
||||
//
|
||||
// CommonAppContext.getInstance().isShow = false;
|
||||
// ARouter.getInstance().build(ARouteConstants.ME).navigation();//栈顶复用
|
||||
// moveTaskToBack(true);
|
||||
|
||||
CommonAppContext.getInstance().isShow = false;
|
||||
ARouter.getInstance().build(ARouteConstants.ME)
|
||||
.withFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
.navigation();
|
||||
// moveTaskToBack(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onExitRoom() {
|
||||
// 调用退出房间方法
|
||||
MvpPre.quitRoom(roomId, SpUtil.getUserId() + "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCancel() {
|
||||
// 用户点击取消,不做任何事
|
||||
}
|
||||
});
|
||||
bottomSheet.show(getSupportFragmentManager(), "ExitRoomBottomSheet");
|
||||
addActiveDialogFragment(bottomSheet);
|
||||
// ARouter.getInstance().build(ARouteConstants.ME)
|
||||
// .withFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
// .navigation();
|
||||
//// moveTaskToBack(true);
|
||||
//
|
||||
// // 处理最小化逻辑
|
||||
// minimizeToBackground();
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onExitRoom() {
|
||||
// // 调用退出房间方法
|
||||
// MvpPre.quitRoom(roomId, SpUtil.getUserId() + "");
|
||||
//
|
||||
// // 真正退出房间
|
||||
// performExitRoom();
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onCancel() {
|
||||
// // 用户点击取消,不做任何事
|
||||
// }
|
||||
// });
|
||||
// bottomSheet.show(getSupportFragmentManager(), "ExitRoomBottomSheet");
|
||||
// addActiveDialogFragment(bottomSheet);
|
||||
} else if (id == R.id.tv_num) {
|
||||
// RoomOnlineDialogFragment.show(roomId, "", mRoomUserBean, mRoomInfoResp, getSupportFragmentManager());
|
||||
RoomOnlineDialogFragment fragment = RoomOnlineDialogFragment.show(roomId, "", mRoomUserBean, mRoomInfoResp, getSupportFragmentManager());
|
||||
@@ -1930,6 +2068,97 @@ public class RoomActivity extends BaseMvpActivity<RoomPresenter, ActivityRoomBin
|
||||
}
|
||||
}
|
||||
|
||||
public void performExitRoom() {
|
||||
// 清理最小化状态
|
||||
clearMinimizeState();
|
||||
isMinimized = false;
|
||||
|
||||
// 执行退出房间逻辑
|
||||
CommonAppContext.getInstance().isPlaying = false;
|
||||
CommonAppContext.getInstance().isShow = false;
|
||||
|
||||
// 停止屏幕捕获和其他资源
|
||||
AgoraManager.getInstance(this).stopScreenCapture();
|
||||
AgoraManager.getInstance(this).leaveRoom();
|
||||
AgoraManager.getInstance(this).cleanup();
|
||||
|
||||
MyRoomSingleton.getInstance().onExitRoom();
|
||||
MessageListenerSingleton.reset(roomId);
|
||||
|
||||
// 清理资源
|
||||
cleanupResources();
|
||||
|
||||
// 导航到首页
|
||||
navigateToMainPage();
|
||||
|
||||
finish();
|
||||
}
|
||||
// 添加前后台状态检测
|
||||
private boolean isAppInForeground() {
|
||||
ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
|
||||
List<ActivityManager.RunningAppProcessInfo> appProcesses = activityManager.getRunningAppProcesses();
|
||||
if (appProcesses == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final String packageName = getPackageName();
|
||||
for (ActivityManager.RunningAppProcessInfo appProcess : appProcesses) {
|
||||
if (appProcess.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND
|
||||
&& appProcess.processName.equals(packageName)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
private void navigateToMainPage() {
|
||||
ARouter.getInstance()
|
||||
.build(ARouteConstants.ME)
|
||||
.withFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
.navigation();
|
||||
|
||||
// 添加转场动画
|
||||
overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
|
||||
}
|
||||
|
||||
|
||||
private void minimizeToBackground() {
|
||||
isMinimized = true;
|
||||
|
||||
// 保存最小化状态和房间ID
|
||||
saveMinimizeState();
|
||||
|
||||
// 设置应用状态
|
||||
CommonAppContext.getInstance().isShow = false;
|
||||
|
||||
// 使用 moveTaskToBack 将应用最小化
|
||||
// moveTaskToBack(true);
|
||||
}
|
||||
|
||||
private void saveMinimizeState() {
|
||||
SharedPreferences prefs = getSharedPreferences("room_minimize_state", Context.MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = prefs.edit();
|
||||
editor.putString(PREF_MINIMIZED_ROOM, roomId);
|
||||
editor.putLong(PREF_MINIMIZED_TIME, System.currentTimeMillis());
|
||||
editor.putBoolean("is_minimized", true);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
private void clearMinimizeState() {
|
||||
SharedPreferences prefs = getSharedPreferences("room_minimize_state", Context.MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = prefs.edit();
|
||||
editor.remove(PREF_MINIMIZED_ROOM);
|
||||
editor.remove(PREF_MINIMIZED_TIME);
|
||||
editor.putBoolean("is_minimized", false);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
private boolean wasMinimized() {
|
||||
SharedPreferences prefs = getSharedPreferences("room_minimize_state", Context.MODE_PRIVATE);
|
||||
return prefs.getBoolean("is_minimized", false);
|
||||
}
|
||||
|
||||
private void queren() {
|
||||
// 创建并显示确认对话框
|
||||
ConfirmDialog dialog = new ConfirmDialog(this,
|
||||
@@ -2635,25 +2864,65 @@ public class RoomActivity extends BaseMvpActivity<RoomPresenter, ActivityRoomBin
|
||||
super.onResume();
|
||||
CommonAppContext.getInstance().isShow = true;
|
||||
CommonAppContext.getInstance().isPlaying = true;
|
||||
|
||||
// 检查是否是从最小化状态恢复
|
||||
// if (wasMinimized()) {
|
||||
// // 从最小化状态恢复,保持当前房间
|
||||
// clearMinimizeState();
|
||||
// isMinimized = false;
|
||||
//
|
||||
// // 恢复房间状态
|
||||
// resumeRoomState();
|
||||
// } else {
|
||||
// 正常启动或从后台恢复
|
||||
if (isInBackground) {
|
||||
isInBackground = false;
|
||||
// 从后台回到前台时调用
|
||||
if (MvpPre != null && roomId != null) {
|
||||
MvpPre.postRoomInfo(roomId);
|
||||
}
|
||||
}
|
||||
// }
|
||||
|
||||
// 延迟调整布局,确保视图已经完全加载
|
||||
mBinding.mainContentContainer.post(this::adjustLayoutHeights);
|
||||
// MvpPre.postRoomInfo(roomId);
|
||||
// 检查是否从后台返回
|
||||
if (isInBackground) {
|
||||
isInBackground = false;
|
||||
// 从后台回到前台时调用
|
||||
if (MvpPre != null && roomId != null) {
|
||||
MvpPre.postRoomInfo(roomId);
|
||||
}
|
||||
|
||||
// // 延迟调整布局,确保视图已经完全加载
|
||||
// mBinding.mainContentContainer.post(this::adjustLayoutHeights);
|
||||
//// MvpPre.postRoomInfo(roomId);
|
||||
// // 检查是否从后台返回
|
||||
// if (isInBackground) {
|
||||
// isInBackground = false;
|
||||
// // 从后台回到前台时调用
|
||||
// if (MvpPre != null && roomId != null) {
|
||||
// MvpPre.postRoomInfo(roomId);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
private void resumeRoomState() {
|
||||
// 恢复房间相关状态
|
||||
if (MvpPre != null && roomId != null) {
|
||||
MvpPre.postRoomInfo(roomId);
|
||||
}
|
||||
|
||||
// 重新连接房间相关服务
|
||||
if (MessageListenerSingleton.getInstance() != null) {
|
||||
MessageListenerSingleton.getInstance().joinGroup(roomId);
|
||||
}
|
||||
|
||||
// 恢复音频状态
|
||||
if (AgoraManager.getInstance(this) != null) {
|
||||
AgoraManager.getInstance(this).resumeMusic();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
super.onStop();
|
||||
// 判断应用是否进入后台
|
||||
isInBackground = true;
|
||||
// 只有在真正进入后台时才标记
|
||||
if (!isAppInForeground()) {
|
||||
isInBackground = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -2888,17 +3157,17 @@ public class RoomActivity extends BaseMvpActivity<RoomPresenter, ActivityRoomBin
|
||||
|
||||
@Override
|
||||
public void quitRoom() {
|
||||
CommonAppContext.getInstance().isPlaying = false;
|
||||
CommonAppContext.getInstance().isShow = false;
|
||||
// AgoraManager.getInstance(this).destroy();
|
||||
AgoraManager.getInstance(this).stopScreenCapture();
|
||||
AgoraManager.getInstance(this).leaveRoom();
|
||||
AgoraManager.getInstance(this).cleanup();
|
||||
MyRoomSingleton.getInstance().onExitRoom();
|
||||
MessageListenerSingleton.reset(roomId);
|
||||
ARouter.getInstance().build(ARouteConstants.ME).navigation();//栈顶复用
|
||||
cleanupResources();
|
||||
finish();
|
||||
// CommonAppContext.getInstance().isPlaying = false;
|
||||
// CommonAppContext.getInstance().isShow = false;
|
||||
//// AgoraManager.getInstance(this).destroy();
|
||||
// AgoraManager.getInstance(this).stopScreenCapture();
|
||||
// AgoraManager.getInstance(this).leaveRoom();
|
||||
// AgoraManager.getInstance(this).cleanup();
|
||||
// MyRoomSingleton.getInstance().onExitRoom();
|
||||
// MessageListenerSingleton.reset(roomId);
|
||||
// ARouter.getInstance().build(ARouteConstants.ME).navigation();//栈顶复用
|
||||
// cleanupResources();
|
||||
// finish();
|
||||
}
|
||||
|
||||
public void quit(){
|
||||
@@ -2997,6 +3266,11 @@ public class RoomActivity extends BaseMvpActivity<RoomPresenter, ActivityRoomBin
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
// 只有在真正退出房间时才清理最小化状态
|
||||
if (!isMinimized) {
|
||||
clearMinimizeState();
|
||||
}
|
||||
|
||||
// 清理所有可能的内存泄漏点
|
||||
cleanupResources();
|
||||
|
||||
|
||||
@@ -4,6 +4,9 @@ import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.os.CountDownTimer;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.os.Message;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
@@ -44,6 +47,8 @@ import org.greenrobot.eventbus.Subscribe;
|
||||
import org.greenrobot.eventbus.ThreadMode;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author qx
|
||||
@@ -513,150 +518,405 @@ public class PublicScreenEaseChatFragment extends BaseMvpFragment<PublicScreenEa
|
||||
});
|
||||
}
|
||||
|
||||
// public void handleRoomMessage(RoomMessageEvent message) {
|
||||
// LogUtils.e("@@@", "handleRoomMessage: " + message);
|
||||
// LogUtils.e("@@@", "handleRoomMessage: roomId" + roomId);
|
||||
// if (easeChatAdapter==null){
|
||||
// easeChatAdapter=new EaseChatAdapter();
|
||||
// }
|
||||
// if (message.getRoomId() == null){
|
||||
// return;
|
||||
// }
|
||||
// if (!message.getRoomId().contains(roomId)) {
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// if (message.getMsgType() == 1001) {
|
||||
// RoomJoinMountModel roomJoinMountModel = new RoomJoinMountModel(message.getRoomId(), message.getText().getJia_jia(), 2);
|
||||
// EventBus.getDefault().post(roomJoinMountModel);
|
||||
// EventBus.getDefault().post(message);
|
||||
// easeChatAdapter.addData(new EMMessageInfo(message));
|
||||
// scrollToBottomIfNeed();
|
||||
// return;
|
||||
// } else if (message.getMsgType() == 1002) {
|
||||
// EventBus.getDefault().post(message);
|
||||
// easeChatAdapter.addData(new EMMessageInfo(message));
|
||||
// scrollToBottomIfNeed();
|
||||
// return;
|
||||
// } else if (message.getMsgType() == 123) {
|
||||
// easeChatAdapter.clearData();
|
||||
// EventBus.getDefault().post(message);
|
||||
// easeChatAdapter.addData(new EMMessageInfo(message));
|
||||
// scrollToBottomIfNeed();
|
||||
// return;
|
||||
// } else if (message.getMsgType() == 1012) {
|
||||
// EventBus.getDefault().post(message);
|
||||
//// easeChatAdapter.addData(new EMMessageInfo(message));
|
||||
//// scrollToBottomIfNeed();
|
||||
// return;
|
||||
// } else if (message.getMsgType() == 1014) {
|
||||
// EventBus.getDefault().post(message);
|
||||
// return;
|
||||
// } else if (message.getMsgType() == 1013) {
|
||||
// EventBus.getDefault().post(message);
|
||||
// return;
|
||||
// } else if (message.getMsgType() == 124) {
|
||||
// RoomMessageEvent.text text = GsonUtils.fromJson(message.getText().getText(), RoomMessageEvent.text.class);
|
||||
// MusicPlayBean musicPlayBean = new MusicPlayBean();
|
||||
// musicPlayBean.setPosition(text.getPosition());
|
||||
// EventBus.getDefault().post(musicPlayBean);
|
||||
// return;
|
||||
// } else if (message.getMsgType() == 1007 || message.getMsgType() == 1018 || message.getMsgType() == 1006 || message.getMsgType() == 1017) {
|
||||
// if (message.getText().getFromUserInfo().getUser_id() == SpUtil.getUserId()) {
|
||||
// easeChatAdapter.addData(new EMMessageInfo(message));
|
||||
// }
|
||||
// EventBus.getDefault().post(message);
|
||||
// return;
|
||||
// } else if (message.getMsgType() == 1016) {
|
||||
// if (message.getText().getFromUserInfo().getUser_id() == SpUtil.getUserId()) {
|
||||
// easeChatAdapter.addData(new EMMessageInfo(message));
|
||||
// }
|
||||
// EventBus.getDefault().post(message);
|
||||
// return;
|
||||
// } else if (message.getMsgType() == 1026) {
|
||||
// EventBus.getDefault().post(message);
|
||||
// return;
|
||||
// } else if (message.getMsgType() == 1003 || message.getMsgType() == 1004) {
|
||||
// EventBus.getDefault().post(message);
|
||||
// easeChatAdapter.addData(new EMMessageInfo(message));
|
||||
// scrollToBottomIfNeed();
|
||||
// return;
|
||||
// } else if (message.getMsgType() == 1015) {
|
||||
// EventBus.getDefault().post(message);
|
||||
// return;
|
||||
// } else if (message.getMsgType() == 1021) {
|
||||
// EventBus.getDefault().post(message);
|
||||
// return;
|
||||
// } else if (message.getMsgType() == 1034) {
|
||||
// EventBus.getDefault().post(message);
|
||||
// return;
|
||||
// } else if (message.getMsgType() == 1000) {
|
||||
// EventBus.getDefault().post(message);
|
||||
// easeChatAdapter.addData(new EMMessageInfo(message));
|
||||
// scrollToBottomIfNeed();
|
||||
// return;
|
||||
// } else if (message.getMsgType() == 1036 || message.getMsgType() == 1037) {
|
||||
// EventBus.getDefault().post(message);
|
||||
// return;
|
||||
// } else if (message.getMsgType() == 1005) {
|
||||
// EventBus.getDefault().post(message);
|
||||
// if (message.getText().getText() == null) {
|
||||
// return;
|
||||
// } else {
|
||||
// easeChatAdapter.addData(new EMMessageInfo(message));
|
||||
// scrollToBottomIfNeed();
|
||||
// return;
|
||||
// }
|
||||
// } else if (message.getMsgType() == 1035) {
|
||||
// EventBus.getDefault().post(message);
|
||||
// return;
|
||||
// } else if (message.getMsgType() == 1) {
|
||||
// EventBus.getDefault().post(message);
|
||||
// easeChatAdapter.addData(new EMMessageInfo(message));
|
||||
// scrollToBottomIfNeed();
|
||||
// return;
|
||||
// } else if (message.getMsgType() == 1030 || message.getMsgType() == 1033 || message.getMsgType() == 1032) {
|
||||
// EventBus.getDefault().post(message);
|
||||
// easeChatAdapter.addData(new EMMessageInfo(message));
|
||||
// scrollToBottomIfNeed();
|
||||
// return;
|
||||
// } else if (message.getMsgType() == 1038) {
|
||||
// easeChatAdapter.addData(new EMMessageInfo(message));
|
||||
// scrollToBottomIfNeed();
|
||||
// return;
|
||||
// } else if (message.getMsgType() == 1049) {
|
||||
// if (message.getText().getStep()!=3) {
|
||||
// EventBus.getDefault().post(message);
|
||||
// easeChatAdapter.addData(new EMMessageInfo(message));
|
||||
// scrollToBottomIfNeed();
|
||||
// }
|
||||
// return;
|
||||
// } else if (message.getMsgType() == 1050 || message.getMsgType() == 1054 || message.getMsgType() == 1051 || message.getMsgType() == 1052) {
|
||||
// EventBus.getDefault().post(message);
|
||||
// return;
|
||||
// } else if (message.getMsgType() == 1053) {
|
||||
// EventBus.getDefault().post(message);
|
||||
// return;
|
||||
// } else if (message.getMsgType() == 1055) {
|
||||
// EventBus.getDefault().post(message);
|
||||
// return;
|
||||
// }else if (message.getMsgType()==1056 || message.getMsgType()==1057 || message.getMsgType()==1059){
|
||||
// EventBus.getDefault().post(message);
|
||||
// return;
|
||||
// }else if (message.getMsgType() == 1025){
|
||||
// EventBus.getDefault().post(message);
|
||||
// return;
|
||||
// }else if (message.getMsgType() == 1039){
|
||||
// EventBus.getDefault().post(message);
|
||||
// easeChatAdapter.addData(new EMMessageInfo(message));
|
||||
// scrollToBottomIfNeed();
|
||||
// return;
|
||||
// }else if (message.getMsgType() == 1058){
|
||||
// EventBus.getDefault().post(message);
|
||||
// return;
|
||||
// }
|
||||
// EventBus.getDefault().post(message);
|
||||
//// easeChatAdapter.addData(new EMMessageInfo(message));
|
||||
//// scrollToBottomIfNeed();
|
||||
// }
|
||||
|
||||
|
||||
public void handleRoomMessage(RoomMessageEvent message) {
|
||||
LogUtils.e("@@@", "handleRoomMessage: " + message);
|
||||
LogUtils.e("@@@", "handleRoomMessage: roomId" + roomId);
|
||||
if (easeChatAdapter==null){
|
||||
easeChatAdapter=new EaseChatAdapter();
|
||||
if (message == null) return;
|
||||
|
||||
if (easeChatAdapter == null) {
|
||||
easeChatAdapter = new EaseChatAdapter();
|
||||
}
|
||||
if (message.getRoomId() == null){
|
||||
return;
|
||||
}
|
||||
if (!message.getRoomId().contains(roomId)) {
|
||||
|
||||
if (message.getRoomId() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (message.getMsgType() == 1001) {
|
||||
RoomJoinMountModel roomJoinMountModel = new RoomJoinMountModel(message.getRoomId(), message.getText().getJia_jia(), 2);
|
||||
EventBus.getDefault().post(roomJoinMountModel);
|
||||
EventBus.getDefault().post(message);
|
||||
easeChatAdapter.addData(new EMMessageInfo(message));
|
||||
scrollToBottomIfNeed();
|
||||
return;
|
||||
} else if (message.getMsgType() == 1002) {
|
||||
EventBus.getDefault().post(message);
|
||||
easeChatAdapter.addData(new EMMessageInfo(message));
|
||||
scrollToBottomIfNeed();
|
||||
return;
|
||||
} else if (message.getMsgType() == 123) {
|
||||
easeChatAdapter.clearData();
|
||||
EventBus.getDefault().post(message);
|
||||
easeChatAdapter.addData(new EMMessageInfo(message));
|
||||
scrollToBottomIfNeed();
|
||||
return;
|
||||
} else if (message.getMsgType() == 1012) {
|
||||
EventBus.getDefault().post(message);
|
||||
// easeChatAdapter.addData(new EMMessageInfo(message));
|
||||
// scrollToBottomIfNeed();
|
||||
return;
|
||||
} else if (message.getMsgType() == 1014) {
|
||||
EventBus.getDefault().post(message);
|
||||
return;
|
||||
} else if (message.getMsgType() == 1013) {
|
||||
EventBus.getDefault().post(message);
|
||||
return;
|
||||
} else if (message.getMsgType() == 124) {
|
||||
RoomMessageEvent.text text = GsonUtils.fromJson(message.getText().getText(), RoomMessageEvent.text.class);
|
||||
MusicPlayBean musicPlayBean = new MusicPlayBean();
|
||||
musicPlayBean.setPosition(text.getPosition());
|
||||
EventBus.getDefault().post(musicPlayBean);
|
||||
return;
|
||||
} else if (message.getMsgType() == 1007 || message.getMsgType() == 1018 || message.getMsgType() == 1006 || message.getMsgType() == 1017) {
|
||||
if (message.getText().getFromUserInfo().getUser_id() == SpUtil.getUserId()) {
|
||||
easeChatAdapter.addData(new EMMessageInfo(message));
|
||||
}
|
||||
EventBus.getDefault().post(message);
|
||||
return;
|
||||
} else if (message.getMsgType() == 1016) {
|
||||
if (message.getText().getFromUserInfo().getUser_id() == SpUtil.getUserId()) {
|
||||
easeChatAdapter.addData(new EMMessageInfo(message));
|
||||
}
|
||||
EventBus.getDefault().post(message);
|
||||
return;
|
||||
} else if (message.getMsgType() == 1026) {
|
||||
EventBus.getDefault().post(message);
|
||||
return;
|
||||
} else if (message.getMsgType() == 1003 || message.getMsgType() == 1004) {
|
||||
EventBus.getDefault().post(message);
|
||||
easeChatAdapter.addData(new EMMessageInfo(message));
|
||||
scrollToBottomIfNeed();
|
||||
return;
|
||||
} else if (message.getMsgType() == 1015) {
|
||||
EventBus.getDefault().post(message);
|
||||
return;
|
||||
} else if (message.getMsgType() == 1021) {
|
||||
EventBus.getDefault().post(message);
|
||||
return;
|
||||
} else if (message.getMsgType() == 1034) {
|
||||
EventBus.getDefault().post(message);
|
||||
return;
|
||||
} else if (message.getMsgType() == 1000) {
|
||||
EventBus.getDefault().post(message);
|
||||
easeChatAdapter.addData(new EMMessageInfo(message));
|
||||
scrollToBottomIfNeed();
|
||||
return;
|
||||
} else if (message.getMsgType() == 1036 || message.getMsgType() == 1037) {
|
||||
EventBus.getDefault().post(message);
|
||||
return;
|
||||
} else if (message.getMsgType() == 1005) {
|
||||
EventBus.getDefault().post(message);
|
||||
if (message.getText().getText() == null) {
|
||||
return;
|
||||
} else {
|
||||
easeChatAdapter.addData(new EMMessageInfo(message));
|
||||
scrollToBottomIfNeed();
|
||||
return;
|
||||
}
|
||||
} else if (message.getMsgType() == 1035) {
|
||||
EventBus.getDefault().post(message);
|
||||
return;
|
||||
} else if (message.getMsgType() == 1) {
|
||||
EventBus.getDefault().post(message);
|
||||
easeChatAdapter.addData(new EMMessageInfo(message));
|
||||
scrollToBottomIfNeed();
|
||||
return;
|
||||
} else if (message.getMsgType() == 1030 || message.getMsgType() == 1033 || message.getMsgType() == 1032) {
|
||||
EventBus.getDefault().post(message);
|
||||
easeChatAdapter.addData(new EMMessageInfo(message));
|
||||
scrollToBottomIfNeed();
|
||||
return;
|
||||
} else if (message.getMsgType() == 1038) {
|
||||
easeChatAdapter.addData(new EMMessageInfo(message));
|
||||
scrollToBottomIfNeed();
|
||||
return;
|
||||
} else if (message.getMsgType() == 1049) {
|
||||
if (message.getText().getStep()!=3) {
|
||||
EventBus.getDefault().post(message);
|
||||
easeChatAdapter.addData(new EMMessageInfo(message));
|
||||
scrollToBottomIfNeed();
|
||||
}
|
||||
return;
|
||||
} else if (message.getMsgType() == 1050 || message.getMsgType() == 1054 || message.getMsgType() == 1051 || message.getMsgType() == 1052) {
|
||||
EventBus.getDefault().post(message);
|
||||
return;
|
||||
} else if (message.getMsgType() == 1053) {
|
||||
EventBus.getDefault().post(message);
|
||||
return;
|
||||
} else if (message.getMsgType() == 1055) {
|
||||
EventBus.getDefault().post(message);
|
||||
return;
|
||||
}else if (message.getMsgType()==1056 || message.getMsgType()==1057 || message.getMsgType()==1059){
|
||||
EventBus.getDefault().post(message);
|
||||
return;
|
||||
}else if (message.getMsgType() == 1025){
|
||||
EventBus.getDefault().post(message);
|
||||
return;
|
||||
}else if (message.getMsgType() == 1039){
|
||||
EventBus.getDefault().post(message);
|
||||
easeChatAdapter.addData(new EMMessageInfo(message));
|
||||
scrollToBottomIfNeed();
|
||||
if (roomId == null || !message.getRoomId().contains(roomId)) {
|
||||
return;
|
||||
}
|
||||
EventBus.getDefault().post(message);
|
||||
// easeChatAdapter.addData(new EMMessageInfo(message));
|
||||
// scrollToBottomIfNeed();
|
||||
|
||||
// 使用Handler将消息处理放到消息队列中,避免阻塞
|
||||
if (messageHandler.hasMessages(MSG_HANDLE_ROOM_MESSAGE)) {
|
||||
// 如果队列中已有待处理消息,将当前消息加入队列
|
||||
Message msg = Message.obtain();
|
||||
msg.what = MSG_HANDLE_ROOM_MESSAGE;
|
||||
msg.obj = message;
|
||||
messageHandler.sendMessage(msg);
|
||||
} else {
|
||||
// 立即处理第一条消息
|
||||
processRoomMessage(message);
|
||||
// 标记有待处理消息
|
||||
messageHandler.sendEmptyMessageDelayed(MSG_HANDLE_ROOM_MESSAGE, 100);
|
||||
}
|
||||
}
|
||||
|
||||
private static final int MSG_HANDLE_ROOM_MESSAGE = 1001;
|
||||
private final Handler messageHandler = new Handler(Looper.getMainLooper()) {
|
||||
private List<RoomMessageEvent> messageQueue = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public void handleMessage(@NonNull Message msg) {
|
||||
if (msg.what == MSG_HANDLE_ROOM_MESSAGE) {
|
||||
if (!messageQueue.isEmpty()) {
|
||||
// 批量处理消息
|
||||
processBatchMessages(messageQueue);
|
||||
messageQueue.clear();
|
||||
} else if (msg.obj instanceof RoomMessageEvent) {
|
||||
// 处理单条消息
|
||||
processRoomMessage((RoomMessageEvent) msg.obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private void processBatchMessages(List<RoomMessageEvent> messages) {
|
||||
if (messages.isEmpty() || easeChatAdapter == null) return;
|
||||
|
||||
List<EMMessageInfo> messageInfos = new ArrayList<>();
|
||||
for (RoomMessageEvent message : messages) {
|
||||
EMMessageInfo info = createMessageInfoIfNeeded(message);
|
||||
if (info != null) {
|
||||
messageInfos.add(info);
|
||||
}
|
||||
// 发送事件总线消息
|
||||
EventBus.getDefault().post(message);
|
||||
}
|
||||
|
||||
if (!messageInfos.isEmpty()) {
|
||||
easeChatAdapter.addData(messageInfos);
|
||||
scrollToBottomIfNeed();
|
||||
}
|
||||
}
|
||||
|
||||
private void processRoomMessage(RoomMessageEvent message) {
|
||||
if (message == null) return;
|
||||
|
||||
int msgType = message.getMsgType();
|
||||
RoomMessageEvent.T text = message.getText();
|
||||
|
||||
switch (msgType) {
|
||||
case 1001:
|
||||
if (text != null) {
|
||||
RoomJoinMountModel roomJoinMountModel = new RoomJoinMountModel(
|
||||
message.getRoomId(), text.getJia_jia(), 2);
|
||||
EventBus.getDefault().post(roomJoinMountModel);
|
||||
}
|
||||
postAndAddMessage(message);
|
||||
break;
|
||||
|
||||
case 1002:
|
||||
postAndAddMessage(message);
|
||||
break;
|
||||
|
||||
case 123:
|
||||
easeChatAdapter.clearData();
|
||||
postAndAddMessage(message);
|
||||
break;
|
||||
|
||||
case 1012:
|
||||
case 1014:
|
||||
case 1013:
|
||||
case 1026:
|
||||
case 1015:
|
||||
case 1021:
|
||||
case 1034:
|
||||
case 1035:
|
||||
case 1050:
|
||||
case 1054:
|
||||
case 1051:
|
||||
case 1052:
|
||||
case 1053:
|
||||
case 1055:
|
||||
case 1056:
|
||||
case 1057:
|
||||
case 1059:
|
||||
case 1025:
|
||||
case 1058:
|
||||
EventBus.getDefault().post(message);
|
||||
break;
|
||||
|
||||
case 124:
|
||||
if (text != null && text.getText() != null) {
|
||||
try {
|
||||
RoomMessageEvent.text parsedText = GsonUtils.fromJson(
|
||||
text.getText(), RoomMessageEvent.text.class);
|
||||
if (parsedText != null) {
|
||||
MusicPlayBean musicPlayBean = new MusicPlayBean();
|
||||
musicPlayBean.setPosition(parsedText.getPosition());
|
||||
EventBus.getDefault().post(musicPlayBean);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LogUtils.e("解析音乐播放消息失败", e);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 1007:
|
||||
case 1018:
|
||||
case 1006:
|
||||
case 1017:
|
||||
case 1016:
|
||||
if (text != null && text.getFromUserInfo() != null &&
|
||||
text.getFromUserInfo().getUser_id() == SpUtil.getUserId()) {
|
||||
EMMessageInfo info = new EMMessageInfo(message);
|
||||
easeChatAdapter.addData(info);
|
||||
scrollToBottomIfNeed();
|
||||
}
|
||||
EventBus.getDefault().post(message);
|
||||
break;
|
||||
|
||||
case 1003:
|
||||
case 1004:
|
||||
case 1000:
|
||||
case 1:
|
||||
case 1030:
|
||||
case 1033:
|
||||
case 1032:
|
||||
case 1039:
|
||||
postAndAddMessage(message);
|
||||
break;
|
||||
|
||||
case 1038:
|
||||
addSingleMessage(message);
|
||||
break;
|
||||
|
||||
case 1049:
|
||||
if (text != null && text.getStep() != 3) {
|
||||
postAndAddMessage(message);
|
||||
}
|
||||
break;
|
||||
|
||||
case 1005:
|
||||
EventBus.getDefault().post(message);
|
||||
if (text != null && text.getText() != null) {
|
||||
addSingleMessage(message);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
EventBus.getDefault().post(message);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private EMMessageInfo createMessageInfoIfNeeded(RoomMessageEvent message) {
|
||||
int msgType = message.getMsgType();
|
||||
RoomMessageEvent.T text = message.getText();
|
||||
|
||||
switch (msgType) {
|
||||
case 1001:
|
||||
case 1002:
|
||||
case 123:
|
||||
case 1003:
|
||||
case 1004:
|
||||
case 1000:
|
||||
case 1:
|
||||
case 1030:
|
||||
case 1033:
|
||||
case 1032:
|
||||
case 1039:
|
||||
case 1049:
|
||||
return new EMMessageInfo(message);
|
||||
|
||||
case 1005:
|
||||
if (text != null && text.getText() != null) {
|
||||
return new EMMessageInfo(message);
|
||||
}
|
||||
break;
|
||||
|
||||
case 1038:
|
||||
return new EMMessageInfo(message);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private void addSingleMessage(RoomMessageEvent message) {
|
||||
if (easeChatAdapter != null) {
|
||||
easeChatAdapter.addData(new EMMessageInfo(message));
|
||||
scrollToBottomIfNeed();
|
||||
}
|
||||
}
|
||||
|
||||
private void postAndAddMessage(RoomMessageEvent message) {
|
||||
EventBus.getDefault().post(message);
|
||||
addSingleMessage(message);
|
||||
}
|
||||
|
||||
// 在类的字段部分添加以下内容
|
||||
private static final int MAX_MESSAGE_COUNT = 500; // 限制最大消息数
|
||||
|
||||
// 优化 scrollToBottomIfNeed 方法
|
||||
private void scrollToBottomIfNeed() {
|
||||
if (isBottom && mBinding.recycleView != null && easeChatAdapter != null) {
|
||||
int itemCount = easeChatAdapter.getItemCount();
|
||||
if (itemCount > 0) {
|
||||
mBinding.recycleView.scrollToPosition(itemCount - 1);
|
||||
}
|
||||
} else {
|
||||
count++;
|
||||
if (mBinding.tvCount != null) {
|
||||
mBinding.tvCount.setText(count + "条新消息");
|
||||
mBinding.tvCount.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
// 当未读消息过多时,限制数量显示
|
||||
if (count > 99) {
|
||||
if (mBinding.tvCount != null) {
|
||||
mBinding.tvCount.setText("99+条新消息");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void roomJoinMount(RoomSettingEvent roomSetting) {
|
||||
if (roomSetting == null) {
|
||||
@@ -664,15 +924,15 @@ public class PublicScreenEaseChatFragment extends BaseMvpFragment<PublicScreenEa
|
||||
}
|
||||
}
|
||||
|
||||
private void scrollToBottomIfNeed() {
|
||||
if (isBottom && mBinding.recycleView != null) {
|
||||
mBinding.recycleView.scrollToPosition(easeChatAdapter.getItemCount() - 1);
|
||||
} else {
|
||||
count++;
|
||||
mBinding.tvCount.setText(count + "条新消息");
|
||||
mBinding.tvCount.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
// private void scrollToBottomIfNeed() {
|
||||
// if (isBottom && mBinding.recycleView != null) {
|
||||
// mBinding.recycleView.scrollToPosition(easeChatAdapter.getItemCount() - 1);
|
||||
// } else {
|
||||
// count++;
|
||||
// mBinding.tvCount.setText(count + "条新消息");
|
||||
// mBinding.tvCount.setVisibility(View.VISIBLE);
|
||||
// }
|
||||
// }
|
||||
|
||||
/**
|
||||
* 房间信息
|
||||
|
||||
@@ -614,7 +614,7 @@ public class RoomCabinFragment extends BaseRoomFragment<RoomCabinPresenter, Room
|
||||
// ARouter.getInstance().build(ARouteConstants.ROOM_DETAILS).withString("from", "我的界面").withString("roomId", AgoraManager.getInstance(getActivity()).getLastRoomId()).navigation();
|
||||
return;
|
||||
}else {
|
||||
((RoomActivity) getActivity()).quitRoom();
|
||||
((RoomActivity) getActivity()).performExitRoom();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user