1.修改播放礼物特效代码
2:修改从房间进入其他页面出现不能回到房间的问题
This commit is contained in:
@@ -55,7 +55,7 @@ android {
|
|||||||
}
|
}
|
||||||
buildTypes {
|
buildTypes {
|
||||||
release {
|
release {
|
||||||
minifyEnabled true
|
minifyEnabled false
|
||||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||||
signingConfig signingConfigs.release
|
signingConfig signingConfigs.release
|
||||||
|
|
||||||
@@ -77,7 +77,7 @@ android {
|
|||||||
|
|
||||||
debug {
|
debug {
|
||||||
debuggable true
|
debuggable true
|
||||||
minifyEnabled true
|
minifyEnabled false
|
||||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||||
signingConfig signingConfigs.debug
|
signingConfig signingConfigs.debug
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ isBuildModule=false
|
|||||||
android.injected.testOnly=false
|
android.injected.testOnly=false
|
||||||
|
|
||||||
APP_VERSION_NAME=1.0.0
|
APP_VERSION_NAME=1.0.0
|
||||||
APP_VERSION_CODE=120
|
APP_VERSION_CODE=121
|
||||||
|
|
||||||
org.gradle.jvm.toolchain.useLegacyAdapters=false
|
org.gradle.jvm.toolchain.useLegacyAdapters=false
|
||||||
#org.gradle.java.home=C\:\\Users\\qx\\.jdks\\ms-17.0.15
|
#org.gradle.java.home=C\:\\Users\\qx\\.jdks\\ms-17.0.15
|
||||||
|
|||||||
@@ -91,6 +91,23 @@ public class CommonAppContext extends MultiDexApplication {
|
|||||||
private final ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(1);
|
private final ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(1);
|
||||||
private ScheduledExecutorService scheduledExecutorServiceRoom = null;
|
private ScheduledExecutorService scheduledExecutorServiceRoom = null;
|
||||||
private MqttConnect mqttConnect=null;
|
private MqttConnect mqttConnect=null;
|
||||||
|
|
||||||
|
// 添加后台状态标记
|
||||||
|
private boolean wasInBackground = false;
|
||||||
|
|
||||||
|
public void onAppBackground() {
|
||||||
|
wasInBackground = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onAppForeground() {
|
||||||
|
wasInBackground = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean wasInBackground() {
|
||||||
|
return wasInBackground;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate() {
|
public void onCreate() {
|
||||||
super.onCreate();
|
super.onCreate();
|
||||||
|
|||||||
@@ -24,4 +24,5 @@ public class GiftBean {
|
|||||||
private int count;
|
private int count;
|
||||||
private String user_id;
|
private String user_id;
|
||||||
private int num;
|
private int num;
|
||||||
|
private boolean is_paly =false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -158,11 +158,11 @@ public class EMMessageInfo implements MultiItemEntity {
|
|||||||
case QXRoomMessageTypeRoomDress:
|
case QXRoomMessageTypeRoomDress:
|
||||||
case QXRoomMessageTypeRoomOnline:
|
case QXRoomMessageTypeRoomOnline:
|
||||||
case QXRoomMessageTypeRoomOPK:
|
case QXRoomMessageTypeRoomOPK:
|
||||||
case QXRoomMessageTypeRoomOMh:
|
|
||||||
case QXRoomMessageTypeRoomFriendPartDidChanged:
|
case QXRoomMessageTypeRoomFriendPartDidChanged:
|
||||||
case QXRoomMessageTypeSeatDidChanged:
|
case QXRoomMessageTypeSeatDidChanged:
|
||||||
case QXRoomMessageTypehm:
|
case QXRoomMessageTypehm:
|
||||||
return 1;
|
return 1;
|
||||||
|
case QXRoomMessageTypeRoomOMh:
|
||||||
case QXRoomMessageTypeGift:
|
case QXRoomMessageTypeGift:
|
||||||
return 3;
|
return 3;
|
||||||
case 1:
|
case 1:
|
||||||
|
|||||||
@@ -322,7 +322,7 @@ public class GiftLotteryDialog extends BaseMvpDialogFragment<GiftLotteryPresente
|
|||||||
isDrawing = true;
|
isDrawing = true;
|
||||||
// init(2);
|
// init(2);
|
||||||
startType = 2;
|
startType = 2;
|
||||||
MvpPre.drawGiftList(giftBagId, userIds, roomId, "10",heart_id);
|
MvpPre.drawGiftList(giftBagId, userIds, roomId, "6",heart_id);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
com.hjq.toast.ToastUtils.show("正在抽奖中...");
|
com.hjq.toast.ToastUtils.show("正在抽奖中...");
|
||||||
@@ -332,7 +332,7 @@ public class GiftLotteryDialog extends BaseMvpDialogFragment<GiftLotteryPresente
|
|||||||
isDrawing = true;
|
isDrawing = true;
|
||||||
// init(3);
|
// init(3);
|
||||||
startType = 3;
|
startType = 3;
|
||||||
MvpPre.drawGiftList(giftBagId, userIds, roomId, "100",heart_id);
|
MvpPre.drawGiftList(giftBagId, userIds, roomId, "9",heart_id);
|
||||||
} else {
|
} else {
|
||||||
com.hjq.toast.ToastUtils.show("正在抽奖中...");
|
com.hjq.toast.ToastUtils.show("正在抽奖中...");
|
||||||
}
|
}
|
||||||
@@ -390,16 +390,16 @@ public class GiftLotteryDialog extends BaseMvpDialogFragment<GiftLotteryPresente
|
|||||||
if (icon > 0 && box_price > 0) {
|
if (icon > 0 && box_price > 0) {
|
||||||
if (type == 10) {
|
if (type == 10) {
|
||||||
updateBackground(mBinding.mirroeSky.llOne, icon > box_price, drawableX, drawableW);
|
updateBackground(mBinding.mirroeSky.llOne, icon > box_price, drawableX, drawableW);
|
||||||
updateBackground(mBinding.mirroeSky.llTen, icon > box_price * 10, drawableX, drawableW);
|
updateBackground(mBinding.mirroeSky.llTen, icon > box_price * 6, drawableX, drawableW);
|
||||||
updateBackground(mBinding.mirroeSky.llHundred, icon > box_price * 100, drawableX, drawableW);
|
updateBackground(mBinding.mirroeSky.llHundred, icon > box_price * 9, drawableX, drawableW);
|
||||||
} else if (type == 11) {
|
} else if (type == 11) {
|
||||||
updateBackground(mBinding.cityTime.llOne, icon > box_price, drawableX, drawableW);
|
updateBackground(mBinding.cityTime.llOne, icon > box_price, drawableX, drawableW);
|
||||||
updateBackground(mBinding.cityTime.llTen, icon > box_price * 10, drawableX, drawableW);
|
updateBackground(mBinding.cityTime.llTen, icon > box_price * 6, drawableX, drawableW);
|
||||||
updateBackground(mBinding.cityTime.llHundred, icon > box_price * 100, drawableX, drawableW);
|
updateBackground(mBinding.cityTime.llHundred, icon > box_price * 9, drawableX, drawableW);
|
||||||
} else if (type == 12) {
|
} else if (type == 12) {
|
||||||
updateBackground(mBinding.pinnacleTime.llOne, icon > box_price, drawableX, drawableW);
|
updateBackground(mBinding.pinnacleTime.llOne, icon > box_price, drawableX, drawableW);
|
||||||
updateBackground(mBinding.pinnacleTime.llTen, icon > box_price * 10, drawableX, drawableW);
|
updateBackground(mBinding.pinnacleTime.llTen, icon > box_price * 6, drawableX, drawableW);
|
||||||
updateBackground(mBinding.pinnacleTime.llHundred, icon > box_price * 100, drawableX, drawableW);
|
updateBackground(mBinding.pinnacleTime.llHundred, icon > box_price * 9, drawableX, drawableW);
|
||||||
} else {
|
} else {
|
||||||
// 兜底处理:未知 type 时全部设为不可点击 + 默认背景
|
// 兜底处理:未知 type 时全部设为不可点击 + 默认背景
|
||||||
setAllBackgroundToDefault(drawableW);
|
setAllBackgroundToDefault(drawableW);
|
||||||
@@ -725,17 +725,17 @@ public class GiftLotteryDialog extends BaseMvpDialogFragment<GiftLotteryPresente
|
|||||||
private void upTitle(int boxPrice) {
|
private void upTitle(int boxPrice) {
|
||||||
if (type == 10) {
|
if (type == 10) {
|
||||||
mBinding.mirroeSky.oneTitle.setText(boxPrice + "币一次");
|
mBinding.mirroeSky.oneTitle.setText(boxPrice + "币一次");
|
||||||
mBinding.mirroeSky.tenTitle.setText((boxPrice * 10) + "币十次");
|
mBinding.mirroeSky.tenTitle.setText((boxPrice * 6) + "币六次");
|
||||||
mBinding.mirroeSky.hundredTitle.setText((boxPrice * 100) + "币百次");
|
mBinding.mirroeSky.hundredTitle.setText((boxPrice * 9) + "币九次");
|
||||||
} else if (type == 11) {
|
} else if (type == 11) {
|
||||||
mBinding.cityTime.oneTitle.setText(boxPrice + "币一次");
|
mBinding.cityTime.oneTitle.setText(boxPrice + "币一次");
|
||||||
mBinding.cityTime.tenTitle.setText((boxPrice * 10) + "币十次");
|
mBinding.cityTime.tenTitle.setText((boxPrice * 6) + "币六次");
|
||||||
mBinding.cityTime.hundredTitle.setText((boxPrice * 100) + "币百次");
|
mBinding.cityTime.hundredTitle.setText((boxPrice * 9) + "币九次");
|
||||||
|
|
||||||
} else if (type == 12) {
|
} else if (type == 12) {
|
||||||
mBinding.pinnacleTime.oneTitle.setText(boxPrice + "币一次");
|
mBinding.pinnacleTime.oneTitle.setText(boxPrice + "币一次");
|
||||||
mBinding.pinnacleTime.tenTitle.setText((boxPrice * 10) + "币十次");
|
mBinding.pinnacleTime.tenTitle.setText((boxPrice * 6) + "币六次");
|
||||||
mBinding.pinnacleTime.hundredTitle.setText((boxPrice * 100) + "币百次");
|
mBinding.pinnacleTime.hundredTitle.setText((boxPrice * 9) + "币九次");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -38,19 +38,24 @@ import com.opensource.svgaplayer.SVGADynamicEntity;
|
|||||||
import com.opensource.svgaplayer.SVGAImageView;
|
import com.opensource.svgaplayer.SVGAImageView;
|
||||||
import com.opensource.svgaplayer.SVGAParser;
|
import com.opensource.svgaplayer.SVGAParser;
|
||||||
import com.opensource.svgaplayer.SVGAVideoEntity;
|
import com.opensource.svgaplayer.SVGAVideoEntity;
|
||||||
|
import com.tencent.imsdk.v2.V2TIMSimpleMsgListener;
|
||||||
import com.tencent.qgame.animplayer.AnimConfig;
|
import com.tencent.qgame.animplayer.AnimConfig;
|
||||||
import com.tencent.qgame.animplayer.inter.IAnimListener;
|
import com.tencent.qgame.animplayer.inter.IAnimListener;
|
||||||
import com.tencent.qgame.animplayer.inter.IFetchResource;
|
import com.tencent.qgame.animplayer.inter.IFetchResource;
|
||||||
import com.xscm.moduleutil.R;
|
import com.xscm.moduleutil.R;
|
||||||
|
import com.xscm.moduleutil.bean.GiftAvatarBean;
|
||||||
import com.xscm.moduleutil.databinding.RoomViewSvgaAnimBinding;
|
import com.xscm.moduleutil.databinding.RoomViewSvgaAnimBinding;
|
||||||
import com.xscm.moduleutil.utils.Md5Utils;
|
import com.xscm.moduleutil.utils.Md5Utils;
|
||||||
import com.xscm.moduleutil.utils.MemoryOptimizationUtils;
|
import com.xscm.moduleutil.utils.MemoryOptimizationUtils;
|
||||||
import com.xscm.moduleutil.utils.SpUtil;
|
import com.xscm.moduleutil.utils.SpUtil;
|
||||||
import com.xscm.moduleutil.utils.logger.Logger;
|
import com.xscm.moduleutil.utils.logger.Logger;
|
||||||
|
|
||||||
|
import org.greenrobot.eventbus.EventBus;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.lang.ref.WeakReference;
|
import java.lang.ref.WeakReference;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@@ -73,7 +78,7 @@ public class AvatarFrameView extends FrameLayout implements IAnimListener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailed(int i, @Nullable String s) {
|
public void onFailed(int i, @Nullable String s) {
|
||||||
|
LogUtils.e("@@@@" + "onFailed");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -83,12 +88,11 @@ public class AvatarFrameView extends FrameLayout implements IAnimListener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onVideoStart() {
|
public void onVideoStart() {
|
||||||
|
LogUtils.e("@@@@" + "onVideoStart");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onVideoRender(int i, @Nullable AnimConfig animConfig) {
|
public void onVideoRender(int i, @Nullable AnimConfig animConfig) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -102,15 +106,17 @@ public class AvatarFrameView extends FrameLayout implements IAnimListener {
|
|||||||
// if (isDestroyed) return;
|
// if (isDestroyed) return;
|
||||||
|
|
||||||
// 确保在主线程中执行
|
// 确保在主线程中执行
|
||||||
if (Looper.myLooper() == Looper.getMainLooper()) {
|
// EventBus.getDefault().post(new GiftAvatarBean());
|
||||||
handleVideoComplete();
|
LogUtils.e("@@@@" + "EventBus onVideoComplete");
|
||||||
} else {
|
// if (Looper.myLooper() == Looper.getMainLooper()) {
|
||||||
mainHandler.post(() -> {
|
// handleVideoComplete();
|
||||||
// if (!isDestroyed) {
|
// } else {
|
||||||
handleVideoComplete();
|
// mainHandler.post(() -> {
|
||||||
|
//// if (!isDestroyed) {
|
||||||
|
// handleVideoComplete();
|
||||||
|
//// }
|
||||||
|
// });
|
||||||
// }
|
// }
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleVideoComplete() {
|
private void handleVideoComplete() {
|
||||||
@@ -209,6 +215,7 @@ public class AvatarFrameView extends FrameLayout implements IAnimListener {
|
|||||||
super(context, attrs, defStyleAttr);
|
super(context, attrs, defStyleAttr);
|
||||||
mBinding = DataBindingUtil.inflate(LayoutInflater.from(context), R.layout.room_view_svga_anim, this, true);
|
mBinding = DataBindingUtil.inflate(LayoutInflater.from(context), R.layout.room_view_svga_anim, this, true);
|
||||||
initViews();
|
initViews();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initViews() {
|
private void initViews() {
|
||||||
@@ -231,9 +238,49 @@ public class AvatarFrameView extends FrameLayout implements IAnimListener {
|
|||||||
// 初始化播放管理器
|
// 初始化播放管理器
|
||||||
playbackManager = new PlaybackManager(mainHandler);
|
playbackManager = new PlaybackManager(mainHandler);
|
||||||
|
|
||||||
if (mBinding != null) {
|
// 获取 MP4PlaybackCallback 单例实例并设置引用
|
||||||
mBinding.playView.setAnimListener(this);
|
MP4PlaybackCallback callback = MP4PlaybackCallback.getInstance();
|
||||||
}
|
callback.setAvatarFrameView(this);
|
||||||
|
// 设置播放完成监听
|
||||||
|
mBinding.playView.setAnimListener(callback);
|
||||||
|
|
||||||
|
// if (mBinding != null) {
|
||||||
|
// mBinding.playView.setAnimListener(this);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// MP4PlaybackCallback = new IAnimListener() {
|
||||||
|
// @Override
|
||||||
|
// public boolean onVideoConfigReady(@NonNull AnimConfig animConfig) {
|
||||||
|
// return false;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// @Override
|
||||||
|
// public void onVideoStart() {
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// @Override
|
||||||
|
// public void onVideoRender(int i, @Nullable AnimConfig animConfig) {
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// @Override
|
||||||
|
// public void onVideoComplete() {
|
||||||
|
// onPlaybackComplete();
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// @Override
|
||||||
|
// public void onVideoDestroy() {
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// @Override
|
||||||
|
// public void onFailed(int i, @Nullable String s) {
|
||||||
|
// onPlaybackComplete();
|
||||||
|
// }
|
||||||
|
// };
|
||||||
|
// // 设置播放完成监听
|
||||||
|
// mBinding.playView.setAnimListener(MP4PlaybackCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getFileExtension(String url) {
|
private String getFileExtension(String url) {
|
||||||
@@ -264,11 +311,6 @@ public class AvatarFrameView extends FrameLayout implements IAnimListener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 关键:即使 isPlaying 为 true,也要检查实际播放状态
|
|
||||||
// if (isPlaying && isActuallyPlaying()) {
|
|
||||||
// Logger.d("AvatarFrameView", "Already playing, skip");
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
PlayItem item = playQueue.poll();
|
PlayItem item = playQueue.poll();
|
||||||
if (item != null) {
|
if (item != null) {
|
||||||
// 通知开始播放
|
// 通知开始播放
|
||||||
@@ -278,42 +320,12 @@ public class AvatarFrameView extends FrameLayout implements IAnimListener {
|
|||||||
// 处理播放项目
|
// 处理播放项目
|
||||||
processPlayItem(item);
|
processPlayItem(item);
|
||||||
|
|
||||||
// isPlaying = true;
|
|
||||||
// Logger.d("AvatarFrameView", "Playing item, remaining queue size: " + playQueue.size());
|
|
||||||
// RenderType type = null;
|
|
||||||
// String ext = getFileExtension(item.url);
|
|
||||||
// if ("svga".equalsIgnoreCase(ext)) {
|
|
||||||
// type = RenderType.SVGA;
|
|
||||||
// } else if ("mp4".equalsIgnoreCase(ext)) {
|
|
||||||
// type = RenderType.MP4;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// if (type == null) {
|
|
||||||
// isPlaying = false;
|
|
||||||
// playNextFromQueue(); // 跳过无效项
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// clearPrevious();
|
|
||||||
// renderType = type;
|
|
||||||
// mType = item.type;
|
|
||||||
//
|
|
||||||
// switch (type) {
|
|
||||||
// case SVGA:
|
|
||||||
// mBinding.playView.stopPlay();
|
|
||||||
// mBinding.playView.setVisibility(View.GONE);
|
|
||||||
// loadSVGA(item.url);
|
|
||||||
// break;
|
|
||||||
// case MP4:
|
|
||||||
// mBinding.playView.setVisibility(View.VISIBLE);
|
|
||||||
// downloadAndPlayMp4(item.url);
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
} else {
|
} else {
|
||||||
isPlaying = false;
|
isPlaying = false;
|
||||||
Logger.d("AvatarFrameView", "Queue is empty, stop playing");
|
Logger.d("AvatarFrameView", "Queue is empty, stop playing");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 添加统一的播放完成处理方法
|
// 添加统一的播放完成处理方法
|
||||||
private void onPlaybackComplete() {
|
private void onPlaybackComplete() {
|
||||||
mainHandler.post(() -> {
|
mainHandler.post(() -> {
|
||||||
@@ -329,7 +341,6 @@ public class AvatarFrameView extends FrameLayout implements IAnimListener {
|
|||||||
if (playQueue.size() % 5 == 0) {
|
if (playQueue.size() % 5 == 0) {
|
||||||
performLightMemoryCleanup();
|
performLightMemoryCleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 继续处理队列中的下一个项目
|
// 继续处理队列中的下一个项目
|
||||||
playNextFromQueue();
|
playNextFromQueue();
|
||||||
});
|
});
|
||||||
@@ -492,14 +503,17 @@ public class AvatarFrameView extends FrameLayout implements IAnimListener {
|
|||||||
|
|
||||||
boolean isTxk = false;
|
boolean isTxk = false;
|
||||||
|
|
||||||
private void downloadAndPlayMp4(String url) {
|
public void downloadAndPlayMp4(String url) {
|
||||||
|
|
||||||
// 提取文件名
|
// 提取文件名
|
||||||
String fileName = url.substring(url.lastIndexOf("/"));
|
String fileName = url.substring(url.lastIndexOf("/"));
|
||||||
String filePath = getContext().getCacheDir().getAbsolutePath() + fileName;
|
String filePath = getContext().getCacheDir().getAbsolutePath() + fileName;
|
||||||
|
|
||||||
|
LogUtils.e("@@@@@filePath: " + filePath.toString());
|
||||||
File file = new File(filePath);
|
File file = new File(filePath);
|
||||||
|
|
||||||
if (!file.exists()) {
|
if (!file.exists()) {
|
||||||
|
|
||||||
LogUtils.e("无缓存");
|
LogUtils.e("无缓存");
|
||||||
// 使用OkHttp进行下载
|
// 使用OkHttp进行下载
|
||||||
OkHttpClient client = new OkHttpClient();
|
OkHttpClient client = new OkHttpClient();
|
||||||
@@ -514,25 +528,43 @@ public class AvatarFrameView extends FrameLayout implements IAnimListener {
|
|||||||
onPlaybackComplete();
|
onPlaybackComplete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 更简单的优化版本
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(Call call, Response response) throws IOException {
|
public void onResponse(Call call, Response response) throws IOException {
|
||||||
|
LogUtils.d("@@@@", "onResponse" + Thread.currentThread().getName());
|
||||||
if (response.isSuccessful()) {
|
if (response.isSuccessful()) {
|
||||||
// 保存文件到缓存目录
|
|
||||||
try (ResponseBody responseBody = response.body()) {
|
try (ResponseBody responseBody = response.body()) {
|
||||||
if (responseBody != null) {
|
if (responseBody != null) {
|
||||||
|
// 在后台线程处理文件保存
|
||||||
|
|
||||||
|
String fileName = url.substring(url.lastIndexOf("/"));
|
||||||
|
String filePath = getContext().getCacheDir().getAbsolutePath() + fileName;
|
||||||
File downloadedFile = new File(filePath);
|
File downloadedFile = new File(filePath);
|
||||||
FileOutputStream fos = new FileOutputStream(downloadedFile);
|
|
||||||
fos.write(responseBody.bytes());
|
// 使用流式传输避免大文件卡顿
|
||||||
fos.close();
|
try (InputStream inputStream = responseBody.byteStream();
|
||||||
|
FileOutputStream fos = new FileOutputStream(downloadedFile)) {
|
||||||
|
|
||||||
|
// 定义缓冲区大小(8KB)
|
||||||
|
byte[] buffer = new byte[1024 * 1024];
|
||||||
|
int bytesRead;
|
||||||
|
|
||||||
|
// 流式读取并写入文件
|
||||||
|
while ((bytesRead = inputStream.read(buffer)) != -1) {
|
||||||
|
fos.write(buffer, 0, bytesRead);
|
||||||
|
}
|
||||||
|
|
||||||
|
fos.flush();
|
||||||
isTxk = true;
|
isTxk = true;
|
||||||
// 在主线程中播放动画
|
|
||||||
mainHandler.post(() -> {
|
mainHandler.post(() -> {
|
||||||
playMp4File(downloadedFile);
|
LogUtils.d("@@@@Thread", Thread.currentThread().getName());
|
||||||
// if (isTxk) {
|
playMp4File(file);
|
||||||
// mBinding.playView.setLoop(1);
|
|
||||||
// }
|
|
||||||
mBinding.playView.startPlay(downloadedFile);
|
|
||||||
});
|
});
|
||||||
|
} catch (IOException e) {
|
||||||
|
LogUtils.e("MP4文件保存失败: " + e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
mainHandler.post(() -> onPlaybackComplete());
|
mainHandler.post(() -> onPlaybackComplete());
|
||||||
}
|
}
|
||||||
@@ -561,9 +593,7 @@ public class AvatarFrameView extends FrameLayout implements IAnimListener {
|
|||||||
private void playMp4File(File file) {
|
private void playMp4File(File file) {
|
||||||
try {
|
try {
|
||||||
if (mBinding != null && file != null && file.exists()) {
|
if (mBinding != null && file != null && file.exists()) {
|
||||||
// 设置播放完成监听
|
// mBinding.playView.setAnimListener(new MP4PlaybackCallback());
|
||||||
mBinding.playView.setAnimListener(new MP4PlaybackCallback());
|
|
||||||
|
|
||||||
// 设置循环次数(根据mType决定)
|
// 设置循环次数(根据mType决定)
|
||||||
if (mType == 1) {
|
if (mType == 1) {
|
||||||
mBinding.playView.setLoop(0); // 无限循环
|
mBinding.playView.setLoop(0); // 无限循环
|
||||||
@@ -1233,6 +1263,7 @@ public class AvatarFrameView extends FrameLayout implements IAnimListener {
|
|||||||
// 清理当前正在播放的内容
|
// 清理当前正在播放的内容
|
||||||
clearPrevious();
|
clearPrevious();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 在类成员变量中添加
|
// 在类成员变量中添加
|
||||||
private static final int PLAYBACK_TIMEOUT = 10000; // 10秒超时
|
private static final int PLAYBACK_TIMEOUT = 10000; // 10秒超时
|
||||||
private Map<String, Long> playbackStartTimeMap = new HashMap<>();
|
private Map<String, Long> playbackStartTimeMap = new HashMap<>();
|
||||||
@@ -1375,12 +1406,40 @@ public class AvatarFrameView extends FrameLayout implements IAnimListener {
|
|||||||
}
|
}
|
||||||
// 在 AvatarFrameView 类中添加以下代码
|
// 在 AvatarFrameView 类中添加以下代码
|
||||||
|
|
||||||
// MP4播放完成监听器
|
// private IAnimListener MP4PlaybackCallback;
|
||||||
private class MP4PlaybackCallback implements IAnimListener {
|
// 在 AvatarFrameView 类的成员变量区域添加单例实例
|
||||||
|
private static volatile MP4PlaybackCallback sInstance;
|
||||||
|
|
||||||
|
private static class MP4PlaybackCallback implements IAnimListener {
|
||||||
|
private AvatarFrameView avatarFrameView;
|
||||||
|
|
||||||
|
private MP4PlaybackCallback() {
|
||||||
|
// 私有构造函数
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取单例实例的方法
|
||||||
|
public static MP4PlaybackCallback getInstance() {
|
||||||
|
if (sInstance == null) {
|
||||||
|
synchronized (MP4PlaybackCallback.class) {
|
||||||
|
if (sInstance == null) {
|
||||||
|
sInstance = new MP4PlaybackCallback();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sInstance;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 设置外部引用的方法
|
||||||
|
public void setAvatarFrameView(AvatarFrameView view) {
|
||||||
|
this.avatarFrameView = view;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailed(int i, @Nullable String s) {
|
public void onFailed(int i, @Nullable String s) {
|
||||||
LogUtils.e(TAG, "MP4 playback failed: " + s);
|
LogUtils.e(AvatarFrameView.TAG, "MP4 playback failed: " + s);
|
||||||
onPlaybackComplete();
|
if (avatarFrameView != null) {
|
||||||
|
avatarFrameView.onPlaybackComplete();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -1400,7 +1459,9 @@ public class AvatarFrameView extends FrameLayout implements IAnimListener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onVideoComplete() {
|
public void onVideoComplete() {
|
||||||
onPlaybackComplete();
|
if (avatarFrameView != null) {
|
||||||
|
avatarFrameView.onPlaybackComplete();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import com.opensource.svgaplayer.SVGAImageView;
|
|||||||
import com.xscm.moduleutil.R;
|
import com.xscm.moduleutil.R;
|
||||||
import com.xscm.moduleutil.base.RoomRollModel;
|
import com.xscm.moduleutil.base.RoomRollModel;
|
||||||
import com.xscm.moduleutil.bean.FaceBean;
|
import com.xscm.moduleutil.bean.FaceBean;
|
||||||
|
import com.xscm.moduleutil.bean.RoomMessageEvent;
|
||||||
import com.xscm.moduleutil.bean.UserOnlineStatusBean;
|
import com.xscm.moduleutil.bean.UserOnlineStatusBean;
|
||||||
import com.xscm.moduleutil.bean.room.ClosePhone;
|
import com.xscm.moduleutil.bean.room.ClosePhone;
|
||||||
import com.xscm.moduleutil.bean.room.RoomClearCardiacAllModel;
|
import com.xscm.moduleutil.bean.room.RoomClearCardiacAllModel;
|
||||||
@@ -272,7 +273,7 @@ public abstract class BaseWheatView extends ConstraintLayout implements IBaseWhe
|
|||||||
public void userJoined(int userId, int elapsd) {
|
public void userJoined(int userId, int elapsd) {
|
||||||
if (pitBean != null && pitBean.getUser_id() != null && !pitBean.getUser_id().equals("0")) {
|
if (pitBean != null && pitBean.getUser_id() != null && !pitBean.getUser_id().equals("0")) {
|
||||||
if (pitBean.getUser_id().equals(userId + "")) {
|
if (pitBean.getUser_id().equals(userId + "")) {
|
||||||
iv_on_line.setVisibility(GONE);
|
// iv_on_line.setVisibility(GONE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -295,6 +296,19 @@ public abstract class BaseWheatView extends ConstraintLayout implements IBaseWhe
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||||
|
public void subscribeMessages(RoomMessageEvent roomMessageEvent) {
|
||||||
|
if(roomMessageEvent.getMsgType()==1058){
|
||||||
|
if (roomMessageEvent.getText().getUser_id().equals(pitBean.getUser_id())){
|
||||||
|
if (roomMessageEvent.getText().getType()==1){
|
||||||
|
iv_on_line.setVisibility(GONE);
|
||||||
|
}else {
|
||||||
|
iv_on_line.setVisibility(VISIBLE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 开始倒计时
|
* 开始倒计时
|
||||||
|
|||||||
@@ -65,7 +65,7 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="@dimen/dp_3"
|
android:layout_marginTop="@dimen/dp_3"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:text="抽十次"
|
android:text="抽六次"
|
||||||
android:textSize="@dimen/sp_12" />
|
android:textSize="@dimen/sp_12" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
@@ -94,7 +94,7 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="@dimen/dp_3"
|
android:layout_marginTop="@dimen/dp_3"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:text="抽百次"
|
android:text="抽九次"
|
||||||
android:textSize="@dimen/sp_12" />
|
android:textSize="@dimen/sp_12" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
|
|||||||
@@ -68,7 +68,7 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="@dimen/dp_3"
|
android:layout_marginTop="@dimen/dp_3"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:text="抽十次"
|
android:text="抽六次"
|
||||||
android:textSize="@dimen/sp_12" />
|
android:textSize="@dimen/sp_12" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
@@ -97,7 +97,7 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="@dimen/dp_3"
|
android:layout_marginTop="@dimen/dp_3"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:text="抽百次"
|
android:text="抽九次"
|
||||||
android:textSize="@dimen/sp_12" />
|
android:textSize="@dimen/sp_12" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
|
|||||||
@@ -65,7 +65,7 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="@dimen/dp_3"
|
android:layout_marginTop="@dimen/dp_3"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:text="抽十次"
|
android:text="抽六次"
|
||||||
android:textSize="@dimen/sp_12" />
|
android:textSize="@dimen/sp_12" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
@@ -94,7 +94,7 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="@dimen/dp_3"
|
android:layout_marginTop="@dimen/dp_3"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:text="抽百次"
|
android:text="抽九次"
|
||||||
android:textSize="@dimen/sp_12" />
|
android:textSize="@dimen/sp_12" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".activity.MainActivity"
|
android:name=".activity.MainActivity"
|
||||||
android:launchMode="singleTop"
|
android:launchMode="singleTask"
|
||||||
android:exported="true"
|
android:exported="true"
|
||||||
/>
|
/>
|
||||||
</application>
|
</application>
|
||||||
|
|||||||
@@ -363,12 +363,35 @@ public class MainActivity extends BaseMvpActivity<HomePresenter, ActivityMainBin
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean shouldRestoreRoom() {
|
||||||
|
// 检查是否应该恢复房间:
|
||||||
|
// 1. 应用有正在播放的房间
|
||||||
|
// 2. 应用应该显示房间
|
||||||
|
// 3. 应用是从后台恢复的(通过检查 CommonAppContext 状态)
|
||||||
|
return CommonAppContext.getInstance().isPlaying
|
||||||
|
&& CommonAppContext.getInstance().isShow
|
||||||
|
&& CommonAppContext.getInstance().wasInBackground();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
|
|
||||||
if (isTaskRoot() &&CommonAppContext.getInstance().isPlaying && CommonAppContext.getInstance().isShow) {
|
LogUtils.e("isShow", CommonAppContext.getInstance().isShow ,CommonAppContext.getInstance().isPlaying,isTaskRoot());
|
||||||
ARouter.getInstance().build(ARouteConstants.ROOM_DETAILS).withString("form", "首页").withString("roomId", CommonAppContext.getInstance().playId).navigation();
|
// if (isTaskRoot() &&CommonAppContext.getInstance().isPlaying && CommonAppContext.getInstance().isShow) {
|
||||||
|
// ARouter.getInstance().build(ARouteConstants.ROOM_DETAILS).withString("form", "首页").withString("roomId", CommonAppContext.getInstance().playId).navigation();
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
// 修改判断条件:不仅检查 isTaskRoot,还要检查是否是从后台恢复
|
||||||
|
if (shouldRestoreRoom()) {
|
||||||
|
ARouter.getInstance().build(ARouteConstants.ROOM_DETAILS)
|
||||||
|
.withString("form", "首页")
|
||||||
|
.withString("roomId", CommonAppContext.getInstance().playId)
|
||||||
|
.navigation();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
MvpPre.loginIm();
|
MvpPre.loginIm();
|
||||||
@@ -425,12 +448,14 @@ public class MainActivity extends BaseMvpActivity<HomePresenter, ActivityMainBin
|
|||||||
super.onStop();
|
super.onStop();
|
||||||
// mBinding.riv.removeCallbacks(mRivAnimationTask);
|
// mBinding.riv.removeCallbacks(mRivAnimationTask);
|
||||||
// mBinding.riv.clearAnimation();
|
// mBinding.riv.clearAnimation();
|
||||||
|
CommonAppContext.getInstance().onAppBackground();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onStart() {
|
protected void onStart() {
|
||||||
super.onStart();
|
super.onStart();
|
||||||
// LogUtils.d(BaseApplication.getInstance().getToken());
|
// LogUtils.d(BaseApplication.getInstance().getToken());
|
||||||
|
CommonAppContext.getInstance().onAppForeground();
|
||||||
}
|
}
|
||||||
|
|
||||||
private final Runnable mRivAnimationTask = () -> {
|
private final Runnable mRivAnimationTask = () -> {
|
||||||
|
|||||||
@@ -14,13 +14,14 @@
|
|||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".activity.RoomActivity"
|
android:name=".activity.RoomActivity"
|
||||||
android:exported="false"
|
android:launchMode="singleTask"
|
||||||
android:launchMode="singleInstance"
|
|
||||||
android:windowSoftInputMode="adjustPan"
|
android:windowSoftInputMode="adjustPan"
|
||||||
android:enableOnBackInvokedCallback="false"
|
android:enableOnBackInvokedCallback="false"
|
||||||
android:theme="@style/TransparentActivityTheme"
|
android:theme="@style/TransparentActivityTheme"
|
||||||
android:configChanges="orientation|screenSize|keyboardHidden"
|
android:configChanges="orientation|screenSize|keyboardHidden"
|
||||||
android:screenOrientation="portrait" />
|
android:screenOrientation="portrait"
|
||||||
|
android:exported="true"
|
||||||
|
/>
|
||||||
|
|
||||||
<service
|
<service
|
||||||
android:name=".service.MediaProjectionService"
|
android:name=".service.MediaProjectionService"
|
||||||
|
|||||||
@@ -10,17 +10,21 @@ import static com.liulishuo.okdownload.OkDownloadProvider.context;
|
|||||||
import android.Manifest;
|
import android.Manifest;
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
import android.app.ActivityManager;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
import android.content.pm.ActivityInfo;
|
import android.content.pm.ActivityInfo;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.graphics.drawable.ColorDrawable;
|
import android.graphics.drawable.ColorDrawable;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.CountDownTimer;
|
import android.os.CountDownTimer;
|
||||||
|
import android.os.Handler;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
|
import android.os.Message;
|
||||||
import android.os.StrictMode;
|
import android.os.StrictMode;
|
||||||
import android.text.Spannable;
|
import android.text.Spannable;
|
||||||
import android.text.SpannableStringBuilder;
|
import android.text.SpannableStringBuilder;
|
||||||
@@ -93,6 +97,7 @@ import com.petterp.floatingx.assist.helper.FxScopeHelper;
|
|||||||
import com.petterp.floatingx.listener.control.IFxControl;
|
import com.petterp.floatingx.listener.control.IFxControl;
|
||||||
import com.tencent.imsdk.v2.V2TIMValueCallback;
|
import com.tencent.imsdk.v2.V2TIMValueCallback;
|
||||||
import com.xscm.moduleutil.base.CommonAppContext;
|
import com.xscm.moduleutil.base.CommonAppContext;
|
||||||
|
import com.xscm.moduleutil.bean.GiftAvatarBean;
|
||||||
import com.xscm.moduleutil.bean.GiftBean;
|
import com.xscm.moduleutil.bean.GiftBean;
|
||||||
import com.xscm.moduleutil.bean.HeadlineBean;
|
import com.xscm.moduleutil.bean.HeadlineBean;
|
||||||
import com.xscm.moduleutil.bean.RoomInputEvent;
|
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.ImageUtils;
|
||||||
import com.xscm.moduleutil.utils.SpUtil;
|
import com.xscm.moduleutil.utils.SpUtil;
|
||||||
import com.xscm.moduleutil.utils.SystemUtils;
|
import com.xscm.moduleutil.utils.SystemUtils;
|
||||||
|
import com.xscm.moduleutil.widget.AvatarFrameView;
|
||||||
import com.xscm.moduleutil.widget.CircularProgressView;
|
import com.xscm.moduleutil.widget.CircularProgressView;
|
||||||
import com.xscm.moduleutil.widget.CustomMusicFloatingView;
|
import com.xscm.moduleutil.widget.CustomMusicFloatingView;
|
||||||
import com.xscm.moduleutil.widget.SilentCountDownTimer;
|
import com.xscm.moduleutil.widget.SilentCountDownTimer;
|
||||||
@@ -164,12 +170,15 @@ import java.util.ArrayList;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Queue;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import io.agora.musiccontentcenter.Music;
|
import io.agora.musiccontentcenter.Music;
|
||||||
import io.reactivex.disposables.Disposable;
|
import io.reactivex.disposables.Disposable;
|
||||||
|
import lombok.Synchronized;
|
||||||
import pub.devrel.easypermissions.AppSettingsDialog;
|
import pub.devrel.easypermissions.AppSettingsDialog;
|
||||||
import pub.devrel.easypermissions.EasyPermissions;
|
import pub.devrel.easypermissions.EasyPermissions;
|
||||||
|
|
||||||
@@ -221,6 +230,10 @@ public class RoomActivity extends BaseMvpActivity<RoomPresenter, ActivityRoomBin
|
|||||||
private List<DialogInterface> activeDialogs = new ArrayList<>();
|
private List<DialogInterface> activeDialogs = new ArrayList<>();
|
||||||
private List<Fragment> activeDialogFragments = 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) {
|
public void addActiveDialog(DialogInterface dialog) {
|
||||||
activeDialogs.add(dialog);
|
activeDialogs.add(dialog);
|
||||||
@@ -249,44 +262,115 @@ public class RoomActivity extends BaseMvpActivity<RoomPresenter, ActivityRoomBin
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 处理从桌面重新启动的情况
|
||||||
|
// @Override
|
||||||
|
// protected void onNewIntent(Intent intent) {
|
||||||
|
// super.onNewIntent(intent);
|
||||||
|
// setIntent(intent);
|
||||||
|
//
|
||||||
|
// // 检查是否应该恢复最小化的房间
|
||||||
|
// handleRestoreFromMinimize(intent);
|
||||||
|
// }
|
||||||
|
|
||||||
|
private void handleRestoreFromMinimize(Intent intent) {
|
||||||
|
// 如果是从桌面启动且之前有最小化的房间
|
||||||
|
// if (Intent.ACTION_MAIN.equals(intent.getAction())
|
||||||
|
// && intent.hasCategory(Intent.CATEGORY_LAUNCHER)) {
|
||||||
|
//
|
||||||
|
// 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;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// 其他情况按正常流程处理
|
||||||
|
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
|
@Override
|
||||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||||
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
||||||
|
// 拦截返回键,显示退出对话框而不是直接退出
|
||||||
|
showExitRoomDialog();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
// else if (keyCode == KeyEvent.KEYCODE_HOME) {
|
||||||
|
// // Home 键按下时,保存状态但不特殊处理
|
||||||
|
// // 系统会自动将应用最小化
|
||||||
|
//// saveMinimizeState();
|
||||||
|
// return super.onKeyDown(keyCode, event);
|
||||||
|
// }
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// @Override
|
|
||||||
// public boolean dispatchTouchEvent(MotionEvent ev) {
|
private void showExitRoomDialog() {
|
||||||
// // 获取触摸位置的坐标
|
ExitRoomBottomSheet bottomSheet = ExitRoomBottomSheet.newInstance();
|
||||||
// float x = ev.getX();
|
bottomSheet.setOnOptionSelectedListener(new ExitRoomBottomSheet.OnOptionSelectedListener() {
|
||||||
// float y = ev.getY();
|
@Override
|
||||||
//
|
public void onMinimize() {
|
||||||
// // 找到 BFragment
|
// 处理最小化逻辑,比如不销毁 Activity,仅移至后台
|
||||||
// Fragment fragment = getSupportFragmentManager().findFragmentByTag("RoomKtvFragment");
|
// CommonAppContext.getInstance().isShow = false;
|
||||||
// if (fragment instanceof RoomKtvFragment) {
|
// ARouter.getInstance().build(ARouteConstants.ME).navigation();//栈顶复用
|
||||||
// // 获取负 margin 的视图
|
// moveTaskToBack(true);
|
||||||
// View negativeMarginView = ((RoomKtvFragment) fragment).getNegativeMarginView();
|
|
||||||
// if (negativeMarginView != null) {
|
CommonAppContext.getInstance().isShow = false;
|
||||||
// // 计算视图在屏幕上的位置
|
ARouter.getInstance().build(ARouteConstants.ME)
|
||||||
// int[] location = new int[2];
|
.withFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||||
// negativeMarginView.getLocationOnScreen(location);
|
.navigation();
|
||||||
// int viewX = location[0];
|
// moveTaskToBack(true);
|
||||||
// int viewY = location[1];
|
|
||||||
// int viewWidth = negativeMarginView.getWidth();
|
// 处理最小化逻辑
|
||||||
// int viewHeight = negativeMarginView.getHeight();
|
minimizeToBackground();
|
||||||
//
|
}
|
||||||
// // 检查触摸点是否在视图范围内
|
|
||||||
// if (x >= viewX && x <= viewX + viewWidth &&
|
@Override
|
||||||
// y >= viewY && y <= viewY + viewHeight) {
|
public void onExitRoom() {
|
||||||
// // 将事件传递给该视图
|
// 调用退出房间方法
|
||||||
// return negativeMarginView.dispatchTouchEvent(ev);
|
MvpPre.quitRoom(roomId, SpUtil.getUserId() + "");
|
||||||
// }
|
|
||||||
// }
|
// 真正退出房间
|
||||||
// }
|
performExitRoom();
|
||||||
//
|
}
|
||||||
// return super.dispatchTouchEvent(ev);
|
|
||||||
// }
|
@Override
|
||||||
|
public void onCancel() {
|
||||||
|
// 用户点击取消,不做任何事
|
||||||
|
}
|
||||||
|
});
|
||||||
|
bottomSheet.show(getSupportFragmentManager(), "ExitRoomBottomSheet");
|
||||||
|
addActiveDialogFragment(bottomSheet);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onConfigurationChanged(@NonNull Configuration newConfig) {
|
public void onConfigurationChanged(@NonNull Configuration newConfig) {
|
||||||
@@ -371,6 +455,9 @@ public class RoomActivity extends BaseMvpActivity<RoomPresenter, ActivityRoomBin
|
|||||||
// () -> EventBus.getDefault().post(new ShowOnWheatDialogEvent()),
|
// () -> EventBus.getDefault().post(new ShowOnWheatDialogEvent()),
|
||||||
// 10000);
|
// 10000);
|
||||||
|
|
||||||
|
isSave = false;
|
||||||
|
sDestroied = false;
|
||||||
|
isMinimized = false;
|
||||||
|
|
||||||
overridePendingTransition(0, 0); // 关闭转场动画
|
overridePendingTransition(0, 0); // 关闭转场动画
|
||||||
|
|
||||||
@@ -380,8 +467,11 @@ public class RoomActivity extends BaseMvpActivity<RoomPresenter, ActivityRoomBin
|
|||||||
|
|
||||||
SpUtil.saveMyRoomId(roomId);
|
SpUtil.saveMyRoomId(roomId);
|
||||||
MessageListenerSingleton.getInstance().joinGroup(roomId);
|
MessageListenerSingleton.getInstance().joinGroup(roomId);
|
||||||
// MvpPre.getRoomIn(roomId, password);
|
|
||||||
// MvpPre.getRoomOnline(roomId, "1", "10");
|
|
||||||
|
// 检查是否有保存的最小化状态
|
||||||
|
checkAndRestoreMinimizeState();
|
||||||
|
|
||||||
// 在子线程中执行网络请求
|
// 在子线程中执行网络请求
|
||||||
performNetworkRequestsAsync();
|
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);
|
roomFragment.updateSeatViewExchangedWithPitArray(mRoomInfoResp);
|
||||||
}
|
}
|
||||||
|
private List<GiftBean> playQueue = new ArrayList();
|
||||||
|
|
||||||
private void handleMsgType1005(RoomMessageEvent messageEvent, RoomMessageEvent.T text) {
|
private void handleMsgType1005(RoomMessageEvent messageEvent, RoomMessageEvent.T text) {
|
||||||
if (text == null || mRoomInfoResp == null || mRoomInfoResp.getRoom_info() == null) return;
|
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();
|
UserInfo toUserInfo = text.getToUserInfo();
|
||||||
if (giftInfo == null || toUserInfo == null) return;
|
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>() {
|
// ThreadUtils.executeBySingle(new ThreadUtils.SimpleTask<Void>() {
|
||||||
@Override
|
// @Override
|
||||||
public Void doInBackground() throws Throwable {
|
// public Void doInBackground() throws Throwable {
|
||||||
// 预处理礼物数据(如果需要)
|
// // 预处理礼物数据(如果需要)
|
||||||
return null;
|
// LogUtils.d("@@@@doInBackground",Thread.currentThread().getName());
|
||||||
}
|
// if ("mp4".equals(mBinding.svgaGift.getFileExtension(giftInfo.getPlay_image()))) {
|
||||||
|
// mBinding.svgaGift.downloadAndPlayMp4(giftInfo.getPlay_image());
|
||||||
@Override
|
// }
|
||||||
public void onSuccess(Void result) {
|
// return null;
|
||||||
// 在主线程中更新UI
|
// }
|
||||||
runOnUiThread(() -> {
|
//
|
||||||
try {
|
// @Override
|
||||||
// 使用post方法确保在下一个消息循环中执行
|
// public void onSuccess(Void result) {
|
||||||
mBinding.svgaGift.post(() -> {
|
// LogUtils.d("@@@@",Thread.currentThread().getName());
|
||||||
mBinding.svgaGift.setSource(giftInfo.getPlay_image(), 2);
|
//
|
||||||
});
|
// // 在主线程中更新UI
|
||||||
} catch (Exception e) {
|
//// runOnUiThread(() -> {
|
||||||
LogUtils.e("Error setting gift source: " + e.getMessage());
|
//// 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();
|
List<RoomPitBean> pitList = mRoomInfoResp.getRoom_info().getPit_list();
|
||||||
if (pitList == null) return;
|
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) {
|
private void handleMsgType1014(RoomMessageEvent messageEvent, RoomMessageEvent.T text) {
|
||||||
if (text == null) return;
|
if (text == null) return;
|
||||||
|
|
||||||
@@ -1792,36 +1922,44 @@ public class RoomActivity extends BaseMvpActivity<RoomPresenter, ActivityRoomBin
|
|||||||
fragment.show(getSupportFragmentManager(), "RoomChartsFragment");
|
fragment.show(getSupportFragmentManager(), "RoomChartsFragment");
|
||||||
addActiveDialogFragment(fragment);
|
addActiveDialogFragment(fragment);
|
||||||
} else if (id == R.id.btn_close_live) {
|
} else if (id == R.id.btn_close_live) {
|
||||||
|
showExitRoomDialog();
|
||||||
|
|
||||||
//最小化
|
//最小化
|
||||||
ExitRoomBottomSheet bottomSheet = ExitRoomBottomSheet.newInstance();
|
// ExitRoomBottomSheet bottomSheet = ExitRoomBottomSheet.newInstance();
|
||||||
bottomSheet.setOnOptionSelectedListener(new ExitRoomBottomSheet.OnOptionSelectedListener() {
|
// bottomSheet.setOnOptionSelectedListener(new ExitRoomBottomSheet.OnOptionSelectedListener() {
|
||||||
@Override
|
// @Override
|
||||||
public void onMinimize() {
|
// public void onMinimize() {
|
||||||
// 处理最小化逻辑,比如不销毁 Activity,仅移至后台
|
// // 处理最小化逻辑,比如不销毁 Activity,仅移至后台
|
||||||
|
//// CommonAppContext.getInstance().isShow = false;
|
||||||
|
//// ARouter.getInstance().build(ARouteConstants.ME).navigation();//栈顶复用
|
||||||
|
//// moveTaskToBack(true);
|
||||||
|
//
|
||||||
// CommonAppContext.getInstance().isShow = false;
|
// CommonAppContext.getInstance().isShow = false;
|
||||||
// ARouter.getInstance().build(ARouteConstants.ME).navigation();//栈顶复用
|
// ARouter.getInstance().build(ARouteConstants.ME)
|
||||||
// moveTaskToBack(true);
|
// .withFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||||
|
// .navigation();
|
||||||
CommonAppContext.getInstance().isShow = false;
|
//// moveTaskToBack(true);
|
||||||
ARouter.getInstance().build(ARouteConstants.ME)
|
//
|
||||||
.withFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
// // 处理最小化逻辑
|
||||||
.navigation();
|
// minimizeToBackground();
|
||||||
// moveTaskToBack(true);
|
// }
|
||||||
}
|
//
|
||||||
|
// @Override
|
||||||
@Override
|
// public void onExitRoom() {
|
||||||
public void onExitRoom() {
|
// // 调用退出房间方法
|
||||||
// 调用退出房间方法
|
// MvpPre.quitRoom(roomId, SpUtil.getUserId() + "");
|
||||||
MvpPre.quitRoom(roomId, SpUtil.getUserId() + "");
|
//
|
||||||
}
|
// // 真正退出房间
|
||||||
|
// performExitRoom();
|
||||||
@Override
|
// }
|
||||||
public void onCancel() {
|
//
|
||||||
// 用户点击取消,不做任何事
|
// @Override
|
||||||
}
|
// public void onCancel() {
|
||||||
});
|
// // 用户点击取消,不做任何事
|
||||||
bottomSheet.show(getSupportFragmentManager(), "ExitRoomBottomSheet");
|
// }
|
||||||
addActiveDialogFragment(bottomSheet);
|
// });
|
||||||
|
// bottomSheet.show(getSupportFragmentManager(), "ExitRoomBottomSheet");
|
||||||
|
// addActiveDialogFragment(bottomSheet);
|
||||||
} else if (id == R.id.tv_num) {
|
} else if (id == R.id.tv_num) {
|
||||||
// RoomOnlineDialogFragment.show(roomId, "", mRoomUserBean, mRoomInfoResp, getSupportFragmentManager());
|
// RoomOnlineDialogFragment.show(roomId, "", mRoomUserBean, mRoomInfoResp, getSupportFragmentManager());
|
||||||
RoomOnlineDialogFragment fragment = 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() {
|
private void queren() {
|
||||||
// 创建并显示确认对话框
|
// 创建并显示确认对话框
|
||||||
ConfirmDialog dialog = new ConfirmDialog(this,
|
ConfirmDialog dialog = new ConfirmDialog(this,
|
||||||
@@ -2635,10 +2864,17 @@ public class RoomActivity extends BaseMvpActivity<RoomPresenter, ActivityRoomBin
|
|||||||
super.onResume();
|
super.onResume();
|
||||||
CommonAppContext.getInstance().isShow = true;
|
CommonAppContext.getInstance().isShow = true;
|
||||||
CommonAppContext.getInstance().isPlaying = true;
|
CommonAppContext.getInstance().isPlaying = true;
|
||||||
// 延迟调整布局,确保视图已经完全加载
|
|
||||||
mBinding.mainContentContainer.post(this::adjustLayoutHeights);
|
// 检查是否是从最小化状态恢复
|
||||||
// MvpPre.postRoomInfo(roomId);
|
// if (wasMinimized()) {
|
||||||
// 检查是否从后台返回
|
// // 从最小化状态恢复,保持当前房间
|
||||||
|
// clearMinimizeState();
|
||||||
|
// isMinimized = false;
|
||||||
|
//
|
||||||
|
// // 恢复房间状态
|
||||||
|
// resumeRoomState();
|
||||||
|
// } else {
|
||||||
|
// 正常启动或从后台恢复
|
||||||
if (isInBackground) {
|
if (isInBackground) {
|
||||||
isInBackground = false;
|
isInBackground = false;
|
||||||
// 从后台回到前台时调用
|
// 从后台回到前台时调用
|
||||||
@@ -2646,15 +2882,48 @@ public class RoomActivity extends BaseMvpActivity<RoomPresenter, ActivityRoomBin
|
|||||||
MvpPre.postRoomInfo(roomId);
|
MvpPre.postRoomInfo(roomId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// }
|
||||||
|
|
||||||
|
// 延迟调整布局,确保视图已经完全加载
|
||||||
|
mBinding.mainContentContainer.post(this::adjustLayoutHeights);
|
||||||
|
|
||||||
|
// // 延迟调整布局,确保视图已经完全加载
|
||||||
|
// 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
|
@Override
|
||||||
protected void onStop() {
|
protected void onStop() {
|
||||||
super.onStop();
|
super.onStop();
|
||||||
// 判断应用是否进入后台
|
// 只有在真正进入后台时才标记
|
||||||
|
if (!isAppInForeground()) {
|
||||||
isInBackground = true;
|
isInBackground = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onWindowFocusChanged(boolean hasFocus) {
|
public void onWindowFocusChanged(boolean hasFocus) {
|
||||||
@@ -2888,17 +3157,17 @@ public class RoomActivity extends BaseMvpActivity<RoomPresenter, ActivityRoomBin
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void quitRoom() {
|
public void quitRoom() {
|
||||||
CommonAppContext.getInstance().isPlaying = false;
|
// CommonAppContext.getInstance().isPlaying = false;
|
||||||
CommonAppContext.getInstance().isShow = false;
|
// CommonAppContext.getInstance().isShow = false;
|
||||||
// AgoraManager.getInstance(this).destroy();
|
//// AgoraManager.getInstance(this).destroy();
|
||||||
AgoraManager.getInstance(this).stopScreenCapture();
|
// AgoraManager.getInstance(this).stopScreenCapture();
|
||||||
AgoraManager.getInstance(this).leaveRoom();
|
// AgoraManager.getInstance(this).leaveRoom();
|
||||||
AgoraManager.getInstance(this).cleanup();
|
// AgoraManager.getInstance(this).cleanup();
|
||||||
MyRoomSingleton.getInstance().onExitRoom();
|
// MyRoomSingleton.getInstance().onExitRoom();
|
||||||
MessageListenerSingleton.reset(roomId);
|
// MessageListenerSingleton.reset(roomId);
|
||||||
ARouter.getInstance().build(ARouteConstants.ME).navigation();//栈顶复用
|
// ARouter.getInstance().build(ARouteConstants.ME).navigation();//栈顶复用
|
||||||
cleanupResources();
|
// cleanupResources();
|
||||||
finish();
|
// finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void quit(){
|
public void quit(){
|
||||||
@@ -2997,6 +3266,11 @@ public class RoomActivity extends BaseMvpActivity<RoomPresenter, ActivityRoomBin
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onDestroy() {
|
protected void onDestroy() {
|
||||||
|
// 只有在真正退出房间时才清理最小化状态
|
||||||
|
if (!isMinimized) {
|
||||||
|
clearMinimizeState();
|
||||||
|
}
|
||||||
|
|
||||||
// 清理所有可能的内存泄漏点
|
// 清理所有可能的内存泄漏点
|
||||||
cleanupResources();
|
cleanupResources();
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,9 @@ import android.content.Context;
|
|||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.CountDownTimer;
|
import android.os.CountDownTimer;
|
||||||
|
import android.os.Handler;
|
||||||
|
import android.os.Looper;
|
||||||
|
import android.os.Message;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
@@ -44,6 +47,8 @@ import org.greenrobot.eventbus.Subscribe;
|
|||||||
import org.greenrobot.eventbus.ThreadMode;
|
import org.greenrobot.eventbus.ThreadMode;
|
||||||
|
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author qx
|
* @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) {
|
public void handleRoomMessage(RoomMessageEvent message) {
|
||||||
LogUtils.e("@@@", "handleRoomMessage: " + message);
|
if (message == null) return;
|
||||||
LogUtils.e("@@@", "handleRoomMessage: roomId" + roomId);
|
|
||||||
if (easeChatAdapter == null) {
|
if (easeChatAdapter == null) {
|
||||||
easeChatAdapter = new EaseChatAdapter();
|
easeChatAdapter = new EaseChatAdapter();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (message.getRoomId() == null) {
|
if (message.getRoomId() == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!message.getRoomId().contains(roomId)) {
|
|
||||||
|
if (roomId == null || !message.getRoomId().contains(roomId)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (message.getMsgType() == 1001) {
|
// 使用Handler将消息处理放到消息队列中,避免阻塞
|
||||||
RoomJoinMountModel roomJoinMountModel = new RoomJoinMountModel(message.getRoomId(), message.getText().getJia_jia(), 2);
|
if (messageHandler.hasMessages(MSG_HANDLE_ROOM_MESSAGE)) {
|
||||||
EventBus.getDefault().post(roomJoinMountModel);
|
// 如果队列中已有待处理消息,将当前消息加入队列
|
||||||
EventBus.getDefault().post(message);
|
Message msg = Message.obtain();
|
||||||
easeChatAdapter.addData(new EMMessageInfo(message));
|
msg.what = MSG_HANDLE_ROOM_MESSAGE;
|
||||||
scrollToBottomIfNeed();
|
msg.obj = message;
|
||||||
return;
|
messageHandler.sendMessage(msg);
|
||||||
} 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 {
|
} else {
|
||||||
easeChatAdapter.addData(new EMMessageInfo(message));
|
// 立即处理第一条消息
|
||||||
scrollToBottomIfNeed();
|
processRoomMessage(message);
|
||||||
return;
|
// 标记有待处理消息
|
||||||
|
messageHandler.sendEmptyMessageDelayed(MSG_HANDLE_ROOM_MESSAGE, 100);
|
||||||
}
|
}
|
||||||
} else if (message.getMsgType() == 1035) {
|
}
|
||||||
|
|
||||||
|
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);
|
EventBus.getDefault().post(message);
|
||||||
return;
|
}
|
||||||
} else if (message.getMsgType() == 1) {
|
|
||||||
EventBus.getDefault().post(message);
|
if (!messageInfos.isEmpty()) {
|
||||||
easeChatAdapter.addData(new EMMessageInfo(message));
|
easeChatAdapter.addData(messageInfos);
|
||||||
scrollToBottomIfNeed();
|
scrollToBottomIfNeed();
|
||||||
return;
|
}
|
||||||
} else if (message.getMsgType() == 1030 || message.getMsgType() == 1033 || message.getMsgType() == 1032) {
|
}
|
||||||
|
|
||||||
|
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);
|
EventBus.getDefault().post(message);
|
||||||
easeChatAdapter.addData(new EMMessageInfo(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();
|
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);
|
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));
|
easeChatAdapter.addData(new EMMessageInfo(message));
|
||||||
scrollToBottomIfNeed();
|
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void postAndAddMessage(RoomMessageEvent message) {
|
||||||
EventBus.getDefault().post(message);
|
EventBus.getDefault().post(message);
|
||||||
// easeChatAdapter.addData(new EMMessageInfo(message));
|
addSingleMessage(message);
|
||||||
// scrollToBottomIfNeed();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 在类的字段部分添加以下内容
|
||||||
|
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)
|
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||||
public void roomJoinMount(RoomSettingEvent roomSetting) {
|
public void roomJoinMount(RoomSettingEvent roomSetting) {
|
||||||
if (roomSetting == null) {
|
if (roomSetting == null) {
|
||||||
@@ -664,15 +924,15 @@ public class PublicScreenEaseChatFragment extends BaseMvpFragment<PublicScreenEa
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void scrollToBottomIfNeed() {
|
// private void scrollToBottomIfNeed() {
|
||||||
if (isBottom && mBinding.recycleView != null) {
|
// if (isBottom && mBinding.recycleView != null) {
|
||||||
mBinding.recycleView.scrollToPosition(easeChatAdapter.getItemCount() - 1);
|
// mBinding.recycleView.scrollToPosition(easeChatAdapter.getItemCount() - 1);
|
||||||
} else {
|
// } else {
|
||||||
count++;
|
// count++;
|
||||||
mBinding.tvCount.setText(count + "条新消息");
|
// mBinding.tvCount.setText(count + "条新消息");
|
||||||
mBinding.tvCount.setVisibility(View.VISIBLE);
|
// 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();
|
// ARouter.getInstance().build(ARouteConstants.ROOM_DETAILS).withString("from", "我的界面").withString("roomId", AgoraManager.getInstance(getActivity()).getLastRoomId()).navigation();
|
||||||
return;
|
return;
|
||||||
}else {
|
}else {
|
||||||
((RoomActivity) getActivity()).quitRoom();
|
((RoomActivity) getActivity()).performExitRoom();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import androidx.annotation.Nullable;
|
|||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
import androidx.fragment.app.FragmentManager;
|
import androidx.fragment.app.FragmentManager;
|
||||||
import androidx.fragment.app.FragmentStatePagerAdapter;
|
import androidx.fragment.app.FragmentStatePagerAdapter;
|
||||||
|
import androidx.viewpager.widget.ViewPager;
|
||||||
|
|
||||||
import com.example.modulevocal.R;
|
import com.example.modulevocal.R;
|
||||||
import com.example.modulevocal.conacts.RevenueConacts;
|
import com.example.modulevocal.conacts.RevenueConacts;
|
||||||
@@ -45,9 +46,42 @@ public class RevenueActivity extends BaseMvpActivity<RevenuePresenter, ActivityR
|
|||||||
}
|
}
|
||||||
|
|
||||||
mBinding.viewPager.setAdapter(new MyFragmentPagerAdapter(getSupportFragmentManager(), list,type));
|
mBinding.viewPager.setAdapter(new MyFragmentPagerAdapter(getSupportFragmentManager(), list,type));
|
||||||
|
mBinding.viewPager.setOffscreenPageLimit(0);
|
||||||
mBinding.slidingTabLayout.setViewPager(mBinding.viewPager);
|
mBinding.slidingTabLayout.setViewPager(mBinding.viewPager);
|
||||||
mBinding.slidingTabLayout.setCurrentTab(0);
|
mBinding.slidingTabLayout.setCurrentTab(0);
|
||||||
|
mBinding.viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
|
||||||
|
@Override
|
||||||
|
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPageSelected(int position) {
|
||||||
|
// 当页面切换时,控制 tv_bb_qs 按钮的显示
|
||||||
|
// 页面选中时,获取对应位置的 Fragment 并刷新数据
|
||||||
|
// 当页面切换时,控制 tv_bb_qs 按钮的显示
|
||||||
|
// 页面选中时,获取对应位置的 Fragment 并刷新数据
|
||||||
|
Fragment fragment = ((MyFragmentPagerAdapter) mBinding.viewPager.getAdapter()).getRegisteredFragment(position);
|
||||||
|
if (fragment instanceof RevenueFragment) {
|
||||||
|
// 根据 position 获取对应的 MyBagBean
|
||||||
|
MyBagBean model = list.get(position);
|
||||||
|
String direction = model.getMyBagType(); // 直接使用 MyBagBean 中的类型
|
||||||
|
int types=0;
|
||||||
|
if (model.getMyBagTitle().contains("钻石")){
|
||||||
|
types=2;
|
||||||
|
}else {
|
||||||
|
types=1;
|
||||||
|
}
|
||||||
|
// 调用 Fragment 的刷新方法并传递参数
|
||||||
|
((RevenueFragment) fragment).refreshData(types, direction);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPageScrollStateChanged(int state) {
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
// mBinding.slidingTabLayout.setOnTabSelectListener(new ViewPager.OnPageChangeListener() {
|
// mBinding.slidingTabLayout.setOnTabSelectListener(new ViewPager.OnPageChangeListener() {
|
||||||
// @Override
|
// @Override
|
||||||
// public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {}
|
// public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {}
|
||||||
|
|||||||
@@ -67,8 +67,10 @@ public class RevenueFragment extends BaseMvpFragment<RevenuePresenter, FragmentR
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void refreshData() {
|
public void refreshData(int type, String direction) {
|
||||||
isLoaded = false;
|
isLoaded = false;
|
||||||
|
this.type= String.valueOf(type);
|
||||||
|
this.revenueType=direction;
|
||||||
loadData();
|
loadData();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,7 +91,7 @@ public class RevenueFragment extends BaseMvpFragment<RevenuePresenter, FragmentR
|
|||||||
mBinding.tv2.setText(sdf.format(startDate));
|
mBinding.tv2.setText(sdf.format(startDate));
|
||||||
Log.d("SelectedTime", "结束时间:" + sdf.format(endDate));
|
Log.d("SelectedTime", "结束时间:" + sdf.format(endDate));
|
||||||
mBinding.tv22.setText(sdf.format(endDate));
|
mBinding.tv22.setText(sdf.format(endDate));
|
||||||
MvpPre.getRevenueData("1","50",type,mBinding.tv2.getText().toString(),mBinding.tv22.getText().toString(),revenueType);
|
MvpPre.getRevenueData("1","50",revenueType,mBinding.tv2.getText().toString(),mBinding.tv22.getText().toString(),type);
|
||||||
});
|
});
|
||||||
dialog.show(getParentFragmentManager(), "DoubleTimePicker");
|
dialog.show(getParentFragmentManager(), "DoubleTimePicker");
|
||||||
});
|
});
|
||||||
@@ -109,7 +111,7 @@ public class RevenueFragment extends BaseMvpFragment<RevenuePresenter, FragmentR
|
|||||||
String endDate = mBinding.tv22.getText().toString();
|
String endDate = mBinding.tv22.getText().toString();
|
||||||
if ( startDate!=null && !startDate.equals("") ){
|
if ( startDate!=null && !startDate.equals("") ){
|
||||||
if ( endDate!=null && !endDate.equals("") ){
|
if ( endDate!=null && !endDate.equals("") ){
|
||||||
MvpPre.getRevenueData(page+"","50",revenueType,startDate,endDate,revenueType);
|
MvpPre.getRevenueData(page+"","50",revenueType,startDate,endDate,type);
|
||||||
}else {
|
}else {
|
||||||
MvpPre.getRevenueData(page+"","50",revenueType,"",endDate,type);
|
MvpPre.getRevenueData(page+"","50",revenueType,"",endDate,type);
|
||||||
}
|
}
|
||||||
@@ -129,7 +131,7 @@ public class RevenueFragment extends BaseMvpFragment<RevenuePresenter, FragmentR
|
|||||||
String endDate = mBinding.tv22.getText().toString();
|
String endDate = mBinding.tv22.getText().toString();
|
||||||
if ( startDate!=null && !startDate.equals("") ){
|
if ( startDate!=null && !startDate.equals("") ){
|
||||||
if ( endDate!=null && !endDate.equals("") ){
|
if ( endDate!=null && !endDate.equals("") ){
|
||||||
MvpPre.getRevenueData(page+"","50",revenueType,startDate,endDate,revenueType);
|
MvpPre.getRevenueData(page+"","50",revenueType,startDate,endDate,type);
|
||||||
}else {
|
}else {
|
||||||
MvpPre.getRevenueData(page+"","50",revenueType,"",endDate,type);
|
MvpPre.getRevenueData(page+"","50",revenueType,"",endDate,type);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user