fix bugs 55 3

This commit is contained in:
2025-11-27 11:47:10 +08:00
parent 366478f547
commit 5ed3717acc
22 changed files with 271 additions and 193 deletions

View File

@@ -80,9 +80,6 @@ public class GiftDisplayManager {
}
public void receiveGift(GiftBean gift) {
if (isInBackground){
return;
}
if (gift == null) return;
LogUtils.e("GiftDisplayManager", "Received gift: " + gift.getSenderName() +
@@ -112,7 +109,7 @@ public class GiftDisplayManager {
// 有可用视图,立即显示
String key = gift.getGiftKey();
accumulatedGifts.put(key, gift.clone());
availableView.showGift(gift);
availableView.showGift(availableView,gift);
LogUtils.e("GiftDisplayManager", "Immediately display gift on view: " + gift);
} else {
// 没有可用视图,加入队列
@@ -206,20 +203,6 @@ public class GiftDisplayManager {
// 立即处理队列,而不是延迟
mainHandler.post(this::processGiftQueue);
}
private boolean isInBackground=false;
public void isBackGround(){
for (GiftDisplayView view : displayViews) {
view.finishAnimationImmediately();
}
giftQueue.clear();
accumulatedGifts.clear();
isProcessingQueue = false;
isInBackground=true;
}
public void becomeFront(){
isInBackground=false;
}
public void clearAll() {
LogUtils.e("GiftDisplayManager", "Clear all gifts and queue");
@@ -234,19 +217,6 @@ public class GiftDisplayManager {
isProcessingQueue = false;
}
// 调试方法
public void printDebugInfo() {
LogUtils.e("GiftDisplayManager", "=== Gift Display Manager Status ===");
LogUtils.e("GiftDisplayManager", "Queue size: " + giftQueue.size());
LogUtils.e("GiftDisplayManager", "Accumulated records: " + accumulatedGifts.size());
for (int i = 0; i < displayViews.size(); i++) {
GiftDisplayView view = displayViews.get(i);
LogUtils.e("GiftDisplayManager", "View " + i + ": Animating=" + view.isAnimating() +
", Gift=" + (view.getCurrentGift() != null ? view.getCurrentGift().getGift_name() : "None"));
}
LogUtils.e("GiftDisplayManager", "===================================");
}
private int dpToPx(int dp) {
if (containerRef == null || containerRef.get() == null) return dp;

View File

@@ -62,12 +62,59 @@ public class GiftDisplayView extends FrameLayout {
// setBackgroundResource(R.drawable.gift_background);
setAlpha(0f);
}
public void showGift(GiftBean gift) {
if (isAnimating) {
LogUtils.e("GiftDisplayView", "View is animating, cannot show new gift");
return;
}
// 更新UI
if (gift == null)
return;
this.currentGift = gift;
this.isAnimating = true;
LogUtils.e("GiftDisplayView", "Start showing gift: " + gift.getGift_name());
senderTextView.setText(gift.getNickname() != null ? gift.getNickname() : "未知用户");
// 更新礼物信息
giftTextView.setText("送给 " + (gift.getSenderName() != null ? gift.getSenderName() : "未知用户") + (gift.getGift_name() != null ? gift.getGift_name() : "礼物"));
// 更新礼物数量
countTextView.setText("x" + gift.getNumber());
// 加载头像图片这里可以使用Glide、Picasso等图片加载库
loadAvatarImage(avatarImageView, gift.getUserAvatar());
// 加载礼物图片
loadGiftImage(giftImageView, gift.getBase_image());
LogUtils.e("GiftDisplayView", "Update UI: " + gift.getSenderName() + " - " +
gift.getGift_name() + " x" + gift.getNumber());
// 重置位置
setTranslationX(-getWidth());
setAlpha(1f);
// 从左往右进入动画
animate()
.translationX(0)
.setDuration(500)
.setInterpolator(new AccelerateDecelerateInterpolator())
.setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
LogUtils.e("GiftDisplayView", "Enter animation completed: " + gift.getGift_name());
startHideTimer();
}
})
.start();
}
public void showGift(GiftDisplayView reuseView, GiftBean gift) {
if (isAnimating) {
LogUtils.e("GiftDisplayView", "View is animating, cannot show new gift");
return;
}
this.currentGift = gift;
this.isAnimating = true;
@@ -75,7 +122,7 @@ public class GiftDisplayView extends FrameLayout {
LogUtils.e("GiftDisplayView", "Start showing gift: " + gift.getGift_name());
// 更新UI
updateUIWithGift(gift);
updateUIWithGift(reuseView, gift);
// 重置位置
setTranslationX(-getWidth());
@@ -96,54 +143,47 @@ public class GiftDisplayView extends FrameLayout {
.start();
}
private void updateUIWithGift(GiftBean gift) {
if (gift == null) return;
senderTextView.setText(gift.getNickname()!=null ? gift.getNickname() : "未知用户");
// 更新发送者名称
// senderTextView.setText(gift.getSenderName() != null ? gift.getSenderName() : "未知用户");
private void updateUIWithGift(GiftDisplayView reuseView, GiftBean gift) {
if (gift == null || reuseView == null)
return;
ImageView avatarImageView = reuseView.findViewById(R.id.iv_avatar);
TextView senderTextView = reuseView.findViewById(R.id.tv_sender);
TextView giftTextView = reuseView.findViewById(R.id.tv_gift);
TextView countTextView = reuseView.findViewById(R.id.tv_count);
ImageView giftImageView = reuseView.findViewById(R.id.iv_gift);
senderTextView.setText(gift.getNickname() != null ? gift.getNickname() : "未知用户");
// 更新礼物信息
giftTextView.setText("送给 "+(gift.getSenderName() != null ? gift.getSenderName() : "未知用户") + (gift.getGift_name() != null ? gift.getGift_name() : "礼物"));
giftTextView.setText("送给 " + (gift.getSenderName() != null ? gift.getSenderName() : "未知用户") + (gift.getGift_name() != null ? gift.getGift_name() : "礼物"));
// 更新礼物数量
countTextView.setText("x" + gift.getNumber());
// 加载头像图片这里可以使用Glide、Picasso等图片加载库
loadAvatarImage(gift.getUserAvatar());
loadAvatarImage(avatarImageView, gift.getUserAvatar());
// 加载礼物图片
loadGiftImage(gift.getBase_image());
loadGiftImage(giftImageView, gift.getBase_image());
LogUtils.e("GiftDisplayView", "Update UI: " + gift.getSenderName() + " - " +
gift.getGift_name() + " x" + gift.getNumber());
}
private void loadAvatarImage(String avatarUrl) {
private void loadAvatarImage(ImageView imageView, String avatarUrl) {
if (avatarUrl != null && !avatarUrl.isEmpty()) {
// 使用图片加载库,例如:
// Glide.with(getContext()).load(avatarUrl).into(avatarImageView);
// 临时用颜色代替
// avatarImageView.setBackgroundColor(getRandomColor());
if (avatarImageView!=null&&avatarImageView.getContext()!=null) {
ImageUtils.loadHeadCC(avatarUrl, avatarImageView);
if (imageView != null && imageView.getContext() != null) {
ImageUtils.loadHeadCC(avatarUrl, imageView);
}
} else {
avatarImageView.setBackgroundColor(Color.LTGRAY);
imageView.setBackgroundColor(Color.LTGRAY);
}
}
private void loadGiftImage(String giftImageUrl) {
private void loadGiftImage(ImageView imageView, String giftImageUrl) {
if (giftImageUrl != null && !giftImageUrl.isEmpty()) {
// 使用图片加载库
// Glide.with(getContext()).load(giftImageUrl).into(giftImageView);
// 临时用颜色代替
// giftImageView.setBackgroundColor(getRandomColor());
ImageUtils.loadHeadCC(giftImageUrl, giftImageView);
ImageUtils.loadHeadCC(giftImageUrl, imageView);
} else {
giftImageView.setBackgroundColor(Color.parseColor("#FFA500"));
imageView.setBackgroundColor(Color.parseColor("#FFA500"));
}
}
@@ -163,12 +203,12 @@ public class GiftDisplayView extends FrameLayout {
// 更新数量显示
countTextView.setText("x" + gift.getNumber());
if (senderTextView.getText().toString().isEmpty()){
senderTextView.setText(gift.getNickname()!=null ? gift.getNickname() : "未知用户");
if (senderTextView.getText().toString().isEmpty()) {
senderTextView.setText(gift.getNickname() != null ? gift.getNickname() : "未知用户");
}
if (giftTextView.getText().toString().isEmpty()){
giftTextView.setText("送给 "+(gift.getSenderName() != null ? gift.getSenderName() : "未知用户") + (gift.getGift_name() != null ? gift.getGift_name() : "礼物"));
if (giftTextView.getText().toString().isEmpty()) {
giftTextView.setText("送给 " + (gift.getSenderName() != null ? gift.getSenderName() : "未知用户") + (gift.getGift_name() != null ? gift.getGift_name() : "礼物"));
}