修改BUG
This commit is contained in:
@@ -22,6 +22,7 @@ import androidx.databinding.DataBindingUtil;
|
||||
|
||||
import com.blankj.utilcode.util.LogUtils;
|
||||
import com.blankj.utilcode.util.PathUtils;
|
||||
import com.blankj.utilcode.util.ThreadUtils;
|
||||
import com.google.android.exoplayer2.ExoPlayer;
|
||||
import com.google.android.exoplayer2.MediaItem;
|
||||
import com.google.android.exoplayer2.ui.PlayerView;
|
||||
@@ -299,10 +300,42 @@ public class AvatarFrameView extends FrameLayout implements IAnimListener {
|
||||
clearQueue();
|
||||
return;
|
||||
}
|
||||
// 异步处理URL解析等耗时操作
|
||||
ThreadUtils.executeByIo(new ThreadUtils.SimpleTask<String>() {
|
||||
@Override
|
||||
public String doInBackground() throws Throwable {
|
||||
// 在后台线程进行URL有效性检查或其他预处理
|
||||
if (url == null || url.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return url; // 返回处理后的URL
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(String processedUrl) {
|
||||
if (processedUrl != null) {
|
||||
// 使用post方法确保在下一个UI循环中执行
|
||||
mainHandler.post(() -> {
|
||||
// 再次检查状态
|
||||
if (!isDestroyed && !isPlaying) {
|
||||
playQueue.add(new PlayItem(processedUrl, type2));
|
||||
checkAndStartPlayback();
|
||||
} else {
|
||||
// 如果正在播放,添加到队列中
|
||||
playQueue.add(new PlayItem(processedUrl, type2));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFail(Throwable e) {
|
||||
LogUtils.e("Error processing gift URL: " + e.getMessage());
|
||||
}
|
||||
});
|
||||
// 添加到播放队列
|
||||
// playQueue.offer(new PlayItem(url, type2));
|
||||
playQueue.add(new PlayItem(url, type2));
|
||||
// playQueue.add(new PlayItem(url, type2));
|
||||
Logger.d("AvatarFrameView", "Added to queue, queue size: " + playQueue.size() + ", url: " + url);
|
||||
|
||||
// 如果当前没有在播放,则开始播放
|
||||
@@ -310,7 +343,7 @@ public class AvatarFrameView extends FrameLayout implements IAnimListener {
|
||||
// playNextFromQueue();
|
||||
// }
|
||||
// 改进播放检查逻辑
|
||||
checkAndStartPlayback();
|
||||
// checkAndStartPlayback();
|
||||
}
|
||||
|
||||
|
||||
@@ -829,43 +862,113 @@ public class AvatarFrameView extends FrameLayout implements IAnimListener {
|
||||
private void releaseResources() {
|
||||
LogUtils.d(TAG, "Releasing all resources");
|
||||
|
||||
// if (isDestroyed) return;
|
||||
if (isDestroyed) return;
|
||||
// 使用异步线程处理耗时操作
|
||||
new Thread(() -> {
|
||||
try {
|
||||
// 在后台线程处理文件操作和大对象清理
|
||||
performHeavyCleanup();
|
||||
|
||||
try {
|
||||
// 清理 SVGA 资源
|
||||
if (svgaSurface != null && svgaSurface.getDrawable() instanceof SVGADrawable) {
|
||||
SVGADrawable drawable = (SVGADrawable) svgaSurface.getDrawable();
|
||||
if (drawable != null) {
|
||||
try {
|
||||
drawable.stop();
|
||||
svgaSurface.clearAnimation();
|
||||
svgaSurface.setImageDrawable(null);
|
||||
} catch (Exception e) {
|
||||
LogUtils.e(TAG, "Error releasing SVGA resources: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
// 回到主线程处理 UI 相关的清理
|
||||
mainHandler.post(() -> {
|
||||
performUICleanup();
|
||||
});
|
||||
} catch (Exception e) {
|
||||
Logger.e(TAG, "Error in async releaseResources: " + e.getMessage());
|
||||
// 出错时仍在主线程清理 UI 资源
|
||||
mainHandler.post(() -> {
|
||||
performUICleanup();
|
||||
});
|
||||
}
|
||||
}).start();
|
||||
|
||||
|
||||
// try {
|
||||
// // 清理 SVGA 资源
|
||||
// if (svgaSurface != null && svgaSurface.getDrawable() instanceof SVGADrawable) {
|
||||
// SVGADrawable drawable = (SVGADrawable) svgaSurface.getDrawable();
|
||||
// if (drawable != null) {
|
||||
// try {
|
||||
// drawable.stop();
|
||||
// svgaSurface.clearAnimation();
|
||||
// svgaSurface.setImageDrawable(null);
|
||||
// } catch (Exception e) {
|
||||
// LogUtils.e(TAG, "Error releasing SVGA resources: " + e.getMessage());
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// // 停止并清理播放器
|
||||
// if (mBinding != null && mBinding.playView != null) {
|
||||
// mBinding.playView.stopPlay();
|
||||
// }
|
||||
//
|
||||
// // 清理 ExoPlayer 资源
|
||||
// if (exoPlayer != null) {
|
||||
// try {
|
||||
// exoPlayer.stop();
|
||||
// exoPlayer.clearVideoSurface();
|
||||
// } catch (Exception e) {
|
||||
// LogUtils.e(TAG, "Error releasing ExoPlayer resources: " + e.getMessage());
|
||||
// }
|
||||
// }
|
||||
// } catch (Exception e) {
|
||||
// LogUtils.e(TAG, "Error in releaseResources: " + e.getMessage());
|
||||
// }
|
||||
}
|
||||
/**
|
||||
* 在后台线程执行耗时的清理操作
|
||||
*/
|
||||
private void performHeavyCleanup() {
|
||||
try {
|
||||
// 清理缓存文件(如果需要)
|
||||
// 清理大对象引用等
|
||||
// clearCacheFiles();
|
||||
} catch (Exception e) {
|
||||
Logger.e(TAG, "Error in performHeavyCleanup: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 在主线程执行 UI 相关的清理操作
|
||||
*/
|
||||
private void performUICleanup() {
|
||||
try {
|
||||
// 停止并清理播放器
|
||||
if (mBinding != null && mBinding.playView != null) {
|
||||
mBinding.playView.stopPlay();
|
||||
try {
|
||||
mBinding.playView.stopPlay();
|
||||
} catch (Exception e) {
|
||||
Logger.e(TAG, "Error stopping playView: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// 清理 ExoPlayer 资源
|
||||
if (exoPlayer != null) {
|
||||
try {
|
||||
// 使用异步停止避免阻塞
|
||||
exoPlayer.stop();
|
||||
exoPlayer.clearVideoSurface();
|
||||
} catch (Exception e) {
|
||||
LogUtils.e(TAG, "Error releasing ExoPlayer resources: " + e.getMessage());
|
||||
Logger.e(TAG, "Error releasing ExoPlayer resources: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// 清理 SVGA 资源
|
||||
if (svgaSurface != null) {
|
||||
try {
|
||||
svgaSurface.pauseAnimation();
|
||||
svgaSurface.clearAnimation();
|
||||
svgaSurface.setImageDrawable(null);
|
||||
} catch (Exception e) {
|
||||
Logger.e(TAG, "Error releasing SVGA resources: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LogUtils.e(TAG, "Error in releaseResources: " + e.getMessage());
|
||||
Logger.e(TAG, "Error in performUICleanup: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 公共释放方法,用于外部主动释放资源
|
||||
*/
|
||||
@@ -877,7 +980,7 @@ public class AvatarFrameView extends FrameLayout implements IAnimListener {
|
||||
mainHandler.post(this::release);
|
||||
return;
|
||||
}
|
||||
// isDestroyed = true;
|
||||
isDestroyed = true;
|
||||
|
||||
try {
|
||||
// 清空播放队列
|
||||
@@ -886,26 +989,36 @@ public class AvatarFrameView extends FrameLayout implements IAnimListener {
|
||||
// 释放所有资源
|
||||
releaseResources();
|
||||
|
||||
// 释放 ExoPlayer
|
||||
if (exoPlayer != null) {
|
||||
try {
|
||||
exoPlayer.stop();
|
||||
exoPlayer.release();
|
||||
} catch (Exception e) {
|
||||
LogUtils.e(TAG, "Error releasing ExoPlayer: " + e.getMessage());
|
||||
// 延迟清理 ExoPlayer(避免主线程阻塞)
|
||||
mainHandler.postDelayed(() -> {
|
||||
if (exoPlayer != null) {
|
||||
try {
|
||||
exoPlayer.release();
|
||||
} catch (Exception e) {
|
||||
Logger.e(TAG, "Error releasing ExoPlayer: " + e.getMessage());
|
||||
}
|
||||
exoPlayer = null;
|
||||
}
|
||||
exoPlayer = null;
|
||||
}
|
||||
}, 50);
|
||||
|
||||
// 清理 PlayerView
|
||||
if (playerView != null) {
|
||||
try {
|
||||
playerView.setPlayer(null);
|
||||
} catch (Exception e) {
|
||||
LogUtils.e(TAG, "Error releasing PlayerView: " + e.getMessage());
|
||||
// 延迟清理其他资源
|
||||
mainHandler.postDelayed(() -> {
|
||||
// 清理 PlayerView
|
||||
if (playerView != null) {
|
||||
try {
|
||||
playerView.setPlayer(null);
|
||||
} catch (Exception e) {
|
||||
Logger.e(TAG, "Error releasing PlayerView: " + e.getMessage());
|
||||
}
|
||||
playerView = null;
|
||||
}
|
||||
playerView = null;
|
||||
}
|
||||
|
||||
// 清理 binding
|
||||
if (mBinding != null) {
|
||||
mBinding = null;
|
||||
}
|
||||
}, 100);
|
||||
|
||||
|
||||
// 清理 SVGAImageView
|
||||
if (svgaSurface != null) {
|
||||
@@ -931,7 +1044,7 @@ public class AvatarFrameView extends FrameLayout implements IAnimListener {
|
||||
LogUtils.e(TAG, "Error in AvatarFrameView release: " + e.getMessage());
|
||||
} finally {
|
||||
// 建议进行垃圾回收
|
||||
MemoryOptimizationUtils.forceGC();
|
||||
// MemoryOptimizationUtils.forceGC();
|
||||
}
|
||||
}
|
||||
public void clearQueue() {
|
||||
|
||||
@@ -351,17 +351,15 @@ public abstract class BaseWheatView extends ConstraintLayout implements IBaseWhe
|
||||
// @Subscribe(threadMode = ThreadMode.MAIN)
|
||||
|
||||
public void setOnlineStatus(UserOnlineStatusBean isOnline) {
|
||||
// iv_on_line.setVisibility(isOnline ? GONE : VISIBLE);
|
||||
|
||||
if (pitBean.getUser_id() != null && !pitBean.getUser_id().equals("0") && !pitBean.getUser_id().isEmpty()) {
|
||||
//// for (UserOnlineStatusBean userOnlineStatus : userOnlineStatusBean) {
|
||||
if (pitBean.getUser_id().equals(isOnline.getUser_id())) {
|
||||
if (isOnline.getIs_online() == 1) {
|
||||
iv_on_line.setVisibility(GONE);
|
||||
} else {
|
||||
iv_on_line.setVisibility(VISIBLE);
|
||||
if (pitBean!=null) {
|
||||
if (pitBean.getUser_id() != null && !pitBean.getUser_id().equals("0") && !pitBean.getUser_id().isEmpty()) {
|
||||
if (pitBean.getUser_id().equals(isOnline.getUser_id())) {
|
||||
if (isOnline.getIs_online() == 1) {
|
||||
iv_on_line.setVisibility(GONE);
|
||||
} else {
|
||||
iv_on_line.setVisibility(VISIBLE);
|
||||
}
|
||||
}
|
||||
//// }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,20 +5,25 @@ import static com.liulishuo.okdownload.OkDownloadProvider.context;
|
||||
import android.animation.Animator;
|
||||
import android.animation.AnimatorListenerAdapter;
|
||||
import android.animation.ObjectAnimator;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.view.animation.DecelerateInterpolator;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.alibaba.android.arouter.launcher.ARouter;
|
||||
import com.blankj.utilcode.util.LogUtils;
|
||||
import com.petterp.floatingx.FloatingX;
|
||||
import com.petterp.floatingx.assist.FxGravity;
|
||||
import com.petterp.floatingx.assist.helper.FxAppHelper;
|
||||
import com.xscm.moduleutil.R;
|
||||
import com.xscm.moduleutil.bean.XLHBean;
|
||||
import com.xscm.moduleutil.event.MqttBean;
|
||||
import com.xscm.moduleutil.utils.ARouteConstants;
|
||||
import com.xscm.moduleutil.utils.ImageUtils;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
@@ -39,7 +44,9 @@ public class PiaoPingManager {
|
||||
private View piaoPingView;
|
||||
private boolean isPiaoPingShown = false;
|
||||
private Queue<MqttBean> messageQueue = new ConcurrentLinkedQueue<>(); // 消息队列
|
||||
private Queue<XLHBean> XLHmessageQueue = new ConcurrentLinkedQueue<>(); // 消息队列
|
||||
private boolean isAnimating = false; // 动画状态标记
|
||||
private boolean XLHisAnimating = false; // 动画状态标记
|
||||
private PiaoPingManager(Context context) {
|
||||
windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
|
||||
if (windowManager == null) return;
|
||||
@@ -155,6 +162,8 @@ public class PiaoPingManager {
|
||||
}
|
||||
messageQueue.clear();
|
||||
isAnimating = false; // 重置动画状态
|
||||
XLHmessageQueue.clear();
|
||||
XLHisAnimating = false;
|
||||
}
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
@@ -164,5 +173,103 @@ public class PiaoPingManager {
|
||||
// FxAppHelper fxAppHelper = FxAppHelper.builder().setContext( context).setLayout(R.layout.item_piaoping).build();
|
||||
// FloatingX.install(fxAppHelper).show();
|
||||
}
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onEvent(XLHBean event) {
|
||||
showPiaoPingMessageXlh(event);
|
||||
}
|
||||
|
||||
private void showPiaoPingMessageXlh(XLHBean event) {
|
||||
// 创建 FloatingX 配置
|
||||
// 添加到队列
|
||||
XLHmessageQueue.offer(event);
|
||||
// 如果当前没有动画正在进行,则开始处理
|
||||
if (!XLHisAnimating) {
|
||||
processNextMessageXlh();
|
||||
}
|
||||
}
|
||||
|
||||
private void processNextMessageXlh() {
|
||||
if (XLHmessageQueue.isEmpty()) {
|
||||
XLHisAnimating = false;
|
||||
return;
|
||||
}
|
||||
|
||||
XLHisAnimating = true;
|
||||
XLHBean xlhBean = XLHmessageQueue.poll();
|
||||
displayMessageXlh(xlhBean);
|
||||
}
|
||||
@SuppressLint({"MissingInflatedId", "LocalSuppress"})
|
||||
private void displayMessageXlh(XLHBean xlhBean) {
|
||||
// 获取悬浮窗视图并设置内容
|
||||
View floatingView = LayoutInflater.from(context).inflate(R.layout.item_piaoping_xlh, new FrameLayout(context), false);
|
||||
TextView textView = floatingView.findViewById(R.id.tv_name);
|
||||
ImageView xlh_image = floatingView.findViewById(R.id.im_xlh);
|
||||
// if (xlhBean.getFrom_type() == 1){
|
||||
// xlh_image.setImageResource(R.mipmap.xlh_jjks);
|
||||
// }else {
|
||||
// xlh_image.setImageResource(R.mipmap.xlh_zsks);
|
||||
// }
|
||||
|
||||
xlh_image.setImageDrawable(xlhBean.getFrom_type() == 1 ? context.getResources().getDrawable(R.mipmap.xlh_jjks) : context.getResources().getDrawable(R.mipmap.xlh_zsks));
|
||||
|
||||
textView.setText(xlhBean.getText());
|
||||
|
||||
// 先将视图放置在屏幕右侧外部,避免闪现问题
|
||||
floatingView.setTranslationX(10000); // 先放到屏幕外
|
||||
|
||||
FxAppHelper fxAppHelper = FxAppHelper.builder()
|
||||
.setContext(context)
|
||||
.setLayoutView(floatingView)
|
||||
.setGravity(FxGravity.RIGHT_OR_TOP)
|
||||
.setX(0)
|
||||
.setY(100)
|
||||
.build();
|
||||
|
||||
FloatingX.install(fxAppHelper).show();
|
||||
// 添加点击事件监听器
|
||||
floatingView.setOnClickListener(v -> {
|
||||
// 点击时执行跳转操作
|
||||
handleItemClick(xlhBean);
|
||||
});
|
||||
// 首先从右侧滑入到屏幕中央
|
||||
floatingView.post(() -> {
|
||||
// 确保初始位置在屏幕右侧外部
|
||||
floatingView.setTranslationX(floatingView.getWidth());
|
||||
|
||||
// 第一阶段:从右到屏幕右侧边缘(缓慢进入)
|
||||
ObjectAnimator animator1 = ObjectAnimator.ofFloat(floatingView, "translationX",
|
||||
floatingView.getWidth(), 0f);
|
||||
animator1.setDuration(1500); // 延长动画时间到1.5秒
|
||||
animator1.setInterpolator(new DecelerateInterpolator(2.0f)); // 更平缓的减速效果
|
||||
animator1.start();
|
||||
|
||||
// 第二阶段:延迟1秒后从当前位置向左滑出
|
||||
floatingView.postDelayed(() -> {
|
||||
ObjectAnimator animator2 = ObjectAnimator.ofFloat(floatingView, "translationX",
|
||||
0f, -floatingView.getWidth());
|
||||
animator2.setDuration(1500); // 延长动画时间到1.5秒
|
||||
animator2.setInterpolator(new DecelerateInterpolator(2.0f)); // 更平缓的减速效果
|
||||
animator2.addListener(new AnimatorListenerAdapter() {
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
// 动画结束后移除悬浮窗
|
||||
FloatingX.uninstallAll();
|
||||
// 处理下一个消息
|
||||
processNextMessageXlh();
|
||||
}
|
||||
});
|
||||
animator2.start();
|
||||
}, 4000); // 停留1秒
|
||||
});
|
||||
}
|
||||
|
||||
private void handleItemClick(XLHBean xlhBean) {
|
||||
// 这里可以根据实际需求实现跳转逻辑
|
||||
// 例如:跳转到礼物详情页面、用户主页等
|
||||
|
||||
ARouter.getInstance().build(ARouteConstants.ROOM_DETAILS).withString("from", "我的界面").withString("roomId", xlhBean.getRoom_id()).navigation();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -71,7 +71,7 @@ public class RoomMakeWheatView extends BaseWheatView {
|
||||
mIvRipple.stopAnimation();
|
||||
mIvRipple.setVisibility(VISIBLE);
|
||||
mTvName.setText(bean.getNickname());
|
||||
ImageUtils.loadCenterCrop(bean.getAvatar(), mRiv);
|
||||
ImageUtils.loadHeadCC(bean.getAvatar(), mRiv);
|
||||
if (TextUtils.isEmpty(pitBean.getDress_picture())) {
|
||||
mIvFrame.setVisibility(INVISIBLE);
|
||||
} else {
|
||||
|
||||
@@ -23,7 +23,7 @@ public class RoomSingSongWheatView extends BaseWheatView {
|
||||
public ImageView mIvTagBoss;
|
||||
public TextView mTvTime;
|
||||
public TextView tv_time_pk;
|
||||
|
||||
public boolean isClickListenerSet = false;
|
||||
private boolean showBoss;//显示老板标识
|
||||
|
||||
public RoomSingSongWheatView(Context context) {
|
||||
|
||||
@@ -227,6 +227,7 @@ public class WheatLayoutManager {
|
||||
return metrics.widthPixels;
|
||||
}
|
||||
|
||||
|
||||
public void updateSingleWheat(RoomPitBean pitBean, int pitNumber) {
|
||||
if (pitList == null || pitList.isEmpty() || pitNumber < 1 || pitNumber > 10) return;
|
||||
if (isSingleMode && this.currentSinglePit != pitNumber) return;
|
||||
|
||||
Reference in New Issue
Block a user