1.修改BUG

2.礼物添加一键全送功能
3.转盘修改底部按钮展示、音效和特效功能
This commit is contained in:
2025-09-09 19:18:06 +08:00
parent 6d3f67e53c
commit c54cc692e0
36 changed files with 917 additions and 528 deletions

View File

@@ -16,6 +16,7 @@ import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.provider.Settings;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
@@ -38,6 +39,7 @@ import androidx.databinding.ViewDataBinding;
import com.alibaba.android.arouter.launcher.ARouter;
import com.blankj.utilcode.util.ActivityUtils;
import com.blankj.utilcode.util.BarUtils;
import com.blankj.utilcode.util.LogUtils;
import com.hjq.toast.ToastUtils;
import com.tencent.qcloud.tuikit.tuichat.bean.ChatInfo;
import com.xscm.moduleutil.R;
@@ -47,6 +49,7 @@ import com.xscm.moduleutil.event.MqttBean;
import com.xscm.moduleutil.utils.ARouteConstants;
import com.xscm.moduleutil.utils.BackgroundManager;
import com.xscm.moduleutil.utils.ColorManager;
import com.xscm.moduleutil.utils.DialogUtils;
import com.xscm.moduleutil.utils.DisplayUtil;
import com.xscm.moduleutil.utils.ImageUtils;
import com.xscm.moduleutil.utils.LanguageUtil;
@@ -279,6 +282,36 @@ public abstract class BaseAppCompatActivity<VDB extends ViewDataBinding> extends
@Override
protected void onDestroy() {
// 清理MQTT相关资源
synchronized (mqttQueueLock) {
mqttMessageQueue.clear();
isMqttPlaying = false;
}
// 清理XLH相关资源
synchronized (xlhQueueLock) {
xlhMessageQueue.clear();
isXlhPlaying = false;
}
// 移除当前显示的视图
try {
if (currentMqttView != null && currentMqttView.getParent() != null) {
ViewGroup parent = (ViewGroup) currentMqttView.getParent();
parent.removeView(currentMqttView);
}
currentMqttView = null;
if (currentXlhView != null && currentXlhView.getParent() != null) {
ViewGroup parent = (ViewGroup) currentXlhView.getParent();
parent.removeView(currentXlhView);
}
currentXlhView = null;
} catch (Exception e) {
LogUtils.e("清理飘屏视图失败", e);
}
// 移除背景更新监听器
BackgroundManager.getInstance().removeListener(this);
// 移除颜色变化监听器
@@ -289,6 +322,12 @@ public abstract class BaseAppCompatActivity<VDB extends ViewDataBinding> extends
if (EventBus.getDefault().isRegistered(this)) {
EventBus.getDefault().unregister(this);
}
try {
unregisterReceiver(mLogoutReceiver);
} catch (Exception e) {
// 忽略异常
}
try {
unregisterReceiver(mLogoutReceiver);
} catch (Exception e) {
@@ -363,164 +402,255 @@ public abstract class BaseAppCompatActivity<VDB extends ViewDataBinding> extends
// 在类中添加以下成员变量
private final List<MqttBean> messageQueue = new ArrayList<>(); // 消息队列
private boolean isPlaying = false; // 播放状态标志
private boolean isPlaying2 = false; // 播放状态标志
private final Object queueLock = new Object(); // 队列同步锁
/// 礼物特效
// 在类中添加以下成员变量
private final List<MqttBean> mqttMessageQueue = new ArrayList<>(); // MQTT消息队列
private final List<XLHBean> xlhMessageQueue = new ArrayList<>(); // XLH消息队列
private boolean isMqttPlaying = false; // MQTT播放状态标志
private boolean isXlhPlaying = false; // XLH播放状态标志
private final Object mqttQueueLock = new Object(); // MQTT队列同步锁
private final Object xlhQueueLock = new Object(); // XLH队列同步锁
private View currentMqttView = null; // 当前正在播放的MQTT视图
private View currentXlhView = null; // 当前正在播放的XLH视图
/// 礼物特效 - MQTT消息处理
@Subscribe(threadMode = ThreadMode.MAIN)
public void onMessageReceived(MqttBean mqttBean) {
if (mqttBean == null) {
return;
}
LogUtils.e("收到MQTT", mqttBean);
if (mqttBean == null) return;
// 将消息添加到队列
synchronized (queueLock) {
messageQueue.add(mqttBean);
synchronized (mqttQueueLock) {
mqttMessageQueue.add(mqttBean);
if (!isMqttPlaying) {
isMqttPlaying = true;
processNextMqttMessage();
}
}
// 尝试播放下一个消息
processNextMessage();
}
/// XLH消息处理
@Subscribe(threadMode = ThreadMode.MAIN)
public void onEvent(XLHBean event) {
LogUtils.e("收到XLH", event);
if (event == null) return;
private void processNextMessage() {
synchronized (queueLock) {
// 如果正在播放或队列为空,则不处理
if (isPlaying || messageQueue.isEmpty()) {
synchronized (xlhQueueLock) {
xlhMessageQueue.add(event);
if (!isXlhPlaying) {
isXlhPlaying = true;
processNextXlhMessage();
}
}
}
// 处理下一个MQTT消息
private void processNextMqttMessage() {
MqttBean mqttBean;
synchronized (mqttQueueLock) {
if (mqttMessageQueue.isEmpty()) {
isMqttPlaying = false;
return;
}
// 标记为正在播放
isPlaying = true;
mqttBean = mqttMessageQueue.remove(0);
}
MqttBean mqttBean;
synchronized (queueLock) {
mqttBean = messageQueue.remove(0); // 取出队列中的第一个消息
}
// 显示飘屏消息
showFloatingMessage(mqttBean);
}
private void showFloatingMessage(MqttBean mqttBean) {
ViewGroup decorView = (ViewGroup) this.getWindow().getDecorView();
// 如果浮动视图未创建,则创建一次
View floatingView = LayoutInflater.from(this).inflate(R.layout.item_piaoping, null);
// 设置布局参数
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(
FrameLayout.LayoutParams.MATCH_PARENT,
FrameLayout.LayoutParams.WRAP_CONTENT
);
layoutParams.topMargin = com.sunfusheng.marqueeview.DisplayUtil.dip2px(this, 70);
layoutParams.gravity = android.view.Gravity.TOP | android.view.Gravity.CENTER_HORIZONTAL;
floatingView.setLayoutParams(layoutParams);
// 初始化动画监听器
setupAnimationListener(floatingView, decorView);
// 更新视图数据
updateFloatingViewData(floatingView, mqttBean);
// 如果浮动视图未添加到 decorView则添加
decorView.addView(floatingView);
// 重置视图位置并开始动画
resetAndStartAnimation(floatingView);
// 处理下一个XLH消息
private void processNextXlhMessage() {
XLHBean xlhBean;
synchronized (xlhQueueLock) {
if (xlhMessageQueue.isEmpty()) {
isXlhPlaying = false;
return;
}
xlhBean = xlhMessageQueue.remove(0);
}
showPiaoPingMessageXlh(xlhBean);
}
private void setupAnimationListener(View floatingView, ViewGroup decorView) {
// 为视图添加一个全局布局监听器,确保在视图完全加载后再设置动画
floatingView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
// 移除监听器,避免重复调用
floatingView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
ViewGroup decorView;
ViewGroup decorView1;
// 确保初始位置在屏幕右侧外部
floatingView.setTranslationX(floatingView.getWidth());
private void showFloatingMessage(MqttBean mqttBean) {
try {
// 清理之前的视图(如果存在)
if (currentMqttView != null && currentMqttView.getParent() != null) {
ViewGroup parent = (ViewGroup) currentMqttView.getParent();
parent.removeView(currentMqttView);
}
// 第一阶段:从右到屏幕右侧边缘(缓慢进入)
ObjectAnimator animator1 = ObjectAnimator.ofFloat(floatingView, "translationX",
floatingView.getWidth(), 0f);
animator1.setDuration(1500); // 延长动画时间到1.5秒
animator1.setInterpolator(new DecelerateInterpolator(2.0f)); // 更平缓的减速效果
animator1.start();
if (decorView == null) {
decorView = (ViewGroup) getWindow().getDecorView();
}
// 第二阶段延迟1秒后从当前位置向左滑出
floatingView.postDelayed(() -> {
ObjectAnimator animator2 = ObjectAnimator.ofFloat(floatingView, "translationX",
0f, -floatingView.getWidth());
animator2.setDuration(1500); // 延长动画时间到1.5秒
animator2.setInterpolator(new DecelerateInterpolator(2.0f)); // 更平缓的减速效果
currentMqttView = LayoutInflater.from(this).inflate(R.layout.item_piaoping, null);
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(
FrameLayout.LayoutParams.MATCH_PARENT,
FrameLayout.LayoutParams.WRAP_CONTENT);
layoutParams.topMargin = com.sunfusheng.marqueeview.DisplayUtil.dip2px(this, 70);
layoutParams.gravity = Gravity.TOP | Gravity.CENTER_HORIZONTAL;
currentMqttView.setLayoutParams(layoutParams);
decorView.addView(currentMqttView);
updateFloatingViewData(currentMqttView, mqttBean);
resetAndStartMqttAnimation(currentMqttView, () -> {
// 清理当前视图
if (currentMqttView != null && currentMqttView.getParent() != null) {
ViewGroup parent = (ViewGroup) currentMqttView.getParent();
parent.removeView(currentMqttView);
}
currentMqttView = null;
// 处理队列中的下一条消息
synchronized (mqttQueueLock) {
isMqttPlaying = false;
processNextMqttMessage();
}
});
} catch (Exception e) {
LogUtils.e("显示MQTT飘屏失败", e);
// 出现异常时继续处理队列
synchronized (mqttQueueLock) {
isMqttPlaying = false;
processNextMqttMessage();
}
}
}
private void showPiaoPingMessageXlh(XLHBean event) {
try {
// 清理之前的视图(如果存在)
if (currentXlhView != null && currentXlhView.getParent() != null) {
ViewGroup parent = (ViewGroup) currentXlhView.getParent();
parent.removeView(currentXlhView);
}
if (decorView1 == null) {
decorView1 = (ViewGroup) getWindow().getDecorView();
}
currentXlhView = LayoutInflater.from(this).inflate(R.layout.item_piaoping_xlh, null);
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(
FrameLayout.LayoutParams.MATCH_PARENT,
FrameLayout.LayoutParams.WRAP_CONTENT);
layoutParams.topMargin = com.sunfusheng.marqueeview.DisplayUtil.dip2px(this, 100);
layoutParams.gravity = Gravity.TOP | Gravity.CENTER_HORIZONTAL;
currentXlhView.setLayoutParams(layoutParams);
decorView1.addView(currentXlhView);
updateXlhFloatingViewData(currentXlhView, event);
resetAndStartXlhAnimation(currentXlhView, () -> {
// 清理当前视图
if (currentXlhView != null && currentXlhView.getParent() != null) {
ViewGroup parent = (ViewGroup) currentXlhView.getParent();
parent.removeView(currentXlhView);
}
currentXlhView = null;
// 处理队列中的下一条消息
synchronized (xlhQueueLock) {
isXlhPlaying = false;
processNextXlhMessage();
}
});
} catch (Exception e) {
LogUtils.e("显示XLH飘屏失败", e);
// 出现异常时继续处理队列
synchronized (xlhQueueLock) {
isXlhPlaying = false;
processNextXlhMessage();
}
}
}
private void resetAndStartMqttAnimation(View view, Runnable onAnimationEnd) {
try {
view.setTranslationX(view.getWidth());
ObjectAnimator animator1 = ObjectAnimator.ofFloat(view, "translationX", view.getWidth(), 0f);
animator1.setDuration(1500);
animator1.setInterpolator(new DecelerateInterpolator(2.0f));
animator1.start();
view.postDelayed(() -> {
try {
ObjectAnimator animator2 = ObjectAnimator.ofFloat(view, "translationX", 0f, -view.getWidth());
animator2.setDuration(1500);
animator2.setInterpolator(new DecelerateInterpolator(2.0f));
animator2.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
// 动画结束后移除悬浮窗
decorView.removeView(floatingView);
onAnimationEnd.run();
}
// 标记播放结束并处理下一个消息
synchronized (queueLock) {
isPlaying = false;
}
processNextMessage();
@Override
public void onAnimationCancel(Animator animation) {
onAnimationEnd.run();
}
});
animator2.start();
}, 3000); // 停留1秒
}
});
} catch (Exception e) {
LogUtils.e("MQTT动画执行失败", e);
onAnimationEnd.run();
}
}, 3000);
} catch (Exception e) {
LogUtils.e("MQTT动画启动失败", e);
onAnimationEnd.run();
}
}
private void resetAndStartAnimation(View floatingView) {
// 重置视图位置并开始动画
floatingView.setTranslationX(floatingView.getWidth());
private void resetAndStartXlhAnimation(View view, Runnable onAnimationEnd) {
try {
view.setTranslationX(view.getWidth());
ObjectAnimator animator1 = ObjectAnimator.ofFloat(view, "translationX", view.getWidth(), 0f);
animator1.setDuration(1500);
animator1.setInterpolator(new DecelerateInterpolator(2.0f));
animator1.start();
// 第一阶段:从右到屏幕右侧边缘(缓慢进入)
ObjectAnimator animator1 = ObjectAnimator.ofFloat(floatingView, "translationX",
floatingView.getWidth(), 0f);
animator1.setDuration(1500);
animator1.setInterpolator(new DecelerateInterpolator(2.0f));
animator1.start();
view.postDelayed(() -> {
try {
ObjectAnimator animator2 = ObjectAnimator.ofFloat(view, "translationX", 0f, -view.getWidth());
animator2.setDuration(1500);
animator2.setInterpolator(new DecelerateInterpolator(2.0f));
animator2.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
onAnimationEnd.run();
}
// 第二阶段延迟1秒后从当前位置向左滑出
floatingView.postDelayed(() -> {
ObjectAnimator animator2 = ObjectAnimator.ofFloat(floatingView, "translationX",
0f, -floatingView.getWidth());
animator2.setDuration(1500);
animator2.setInterpolator(new DecelerateInterpolator(2.0f));
animator2.start();
}, 3000);
@Override
public void onAnimationCancel(Animator animation) {
onAnimationEnd.run();
}
});
animator2.start();
} catch (Exception e) {
LogUtils.e("XLH动画执行失败", e);
onAnimationEnd.run();
}
}, 3000);
} catch (Exception e) {
LogUtils.e("XLH动画启动失败", e);
onAnimationEnd.run();
}
}
private void updateFloatingViewData(View floatingView, MqttBean mqttBean) {
TextView textView = floatingView.findViewById(R.id.tv_name);
TextView textView2 = floatingView.findViewById(R.id.tv_to_name);
TextView tv_time = floatingView.findViewById(R.id.tv_num);
private void updateFloatingViewData(View view, MqttBean mqttBean) {
TextView textView = view.findViewById(R.id.tv_name);
TextView textView2 = view.findViewById(R.id.tv_to_name);
TextView tv_time = view.findViewById(R.id.tv_num);
if (mqttBean.getList() != null) {
if (mqttBean.getList().getToUserName() != null) {
textView2.setText("送给" + mqttBean.getList().getToUserName());
} else {
textView2.setText("送给");
}
if (mqttBean.getList().getFromUserName() != null) {
textView.setText(mqttBean.getList().getFromUserName());
} else {
textView.setText("");
}
textView2.setText("送给" + (mqttBean.getList().getToUserName() != null ? mqttBean.getList().getToUserName() : ""));
textView.setText(mqttBean.getList().getFromUserName() != null ? mqttBean.getList().getFromUserName() : "");
if (mqttBean.getList().getGift_picture() != null) {
ImageUtils.loadHeadCC(mqttBean.getList().getGift_picture(), floatingView.findViewById(R.id.iv_piaoping));
}
if (mqttBean.getList().getNumber() != null) {
tv_time.setText("x" + mqttBean.getList().getNumber());
} else {
tv_time.setText("x1");
ImageUtils.loadHeadCC(mqttBean.getList().getGift_picture(), view.findViewById(R.id.iv_piaoping));
}
tv_time.setText("x" + (mqttBean.getList().getNumber() != null ? mqttBean.getList().getNumber() : "1"));
} else {
textView2.setText("送给");
textView.setText("");
@@ -528,207 +658,34 @@ public abstract class BaseAppCompatActivity<VDB extends ViewDataBinding> extends
}
}
// private void showFloatingMessage(MqttBean mqttBean) {
// ViewGroup decorView = (ViewGroup) this.getWindow().getDecorView();
// View floatingView = LayoutInflater.from(this).inflate(R.layout.item_piaoping, null);
//
// // 设置布局参数使整个布局显示在屏幕顶部并距离顶部100dp
// FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(
// FrameLayout.LayoutParams.MATCH_PARENT,
// FrameLayout.LayoutParams.WRAP_CONTENT
// );
// layoutParams.topMargin = com.sunfusheng.marqueeview.DisplayUtil.dip2px(this, 100); // 距离顶部100dp
// layoutParams.gravity = android.view.Gravity.TOP | android.view.Gravity.CENTER_HORIZONTAL; // 顶部居中
// floatingView.setLayoutParams(layoutParams);
//
// TextView textView = floatingView.findViewById(R.id.tv_name);
// TextView textView2 = floatingView.findViewById(R.id.tv_to_name);
// TextView tv_time = floatingView.findViewById(R.id.tv_num);
//
// // 添加对 getList() 返回值的空值检查
// if (mqttBean.getList() != null) {
// // 检查各个字段是否为 null
// if (mqttBean.getList().getToUserName() != null) {
// textView2.setText("送给" + mqttBean.getList().getToUserName());
// } else {
// textView2.setText("送给");
// }
//
// if (mqttBean.getList().getFromUserName() != null) {
// textView.setText(mqttBean.getList().getFromUserName());
// } else {
// textView.setText("");
// }
//
// // 检查礼物图片
// if (mqttBean.getList().getGift_picture() != null) {
// ImageUtils.loadHeadCC(mqttBean.getList().getGift_picture(), floatingView.findViewById(R.id.iv_piaoping));
// }
//
// // 检查数量
// if (mqttBean.getList().getNumber() != null) {
// tv_time.setText("x" + mqttBean.getList().getNumber());
// } else {
// tv_time.setText("x1");
// }
// } else {
// // 如果 getList() 返回 null设置默认值
// textView2.setText("送给");
// textView.setText("");
// tv_time.setText("x1");
// }
//
// floatingView.setTranslationX(10000); // 先放到屏幕外
//
// 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) {
// // 动画结束后移除悬浮窗
// decorView.removeView(floatingView);
//
// // 标记播放结束并处理下一个消息
// synchronized (queueLock) {
// isPlaying = false;
// }
// processNextMessage();
// }
// });
// animator2.start();
// }, 3000); // 停留1秒
// });
// decorView.addView(floatingView);
// }
// 在类中添加新的成员变量
@Subscribe(threadMode = ThreadMode.MAIN)
public void onEvent(XLHBean event) {
showPiaoPingMessageXlh(event);
}
private void showPiaoPingMessageXlh(XLHBean event) {
// 创建 FloatingX 配置
ViewGroup decorView = (ViewGroup) this.getWindow().getDecorView();
// 如果XLH浮动视图未创建则创建一次
View xlhFloatingView = LayoutInflater.from(this).inflate(R.layout.item_piaoping_xlh, null);
// 设置布局参数
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(
FrameLayout.LayoutParams.MATCH_PARENT,
FrameLayout.LayoutParams.WRAP_CONTENT
);
layoutParams.topMargin = com.sunfusheng.marqueeview.DisplayUtil.dip2px(this, 100);
layoutParams.gravity = android.view.Gravity.TOP | android.view.Gravity.CENTER_HORIZONTAL;
xlhFloatingView.setLayoutParams(layoutParams);
// 初始化动画监听器
setupXlhAnimationListener(xlhFloatingView, decorView);
updateXlhFloatingViewData(xlhFloatingView, event);
// 如果浮动视图未添加到 decorView则添加
decorView.addView(xlhFloatingView);
// 重置视图位置并开始动画
resetAndStartXlhAnimation(xlhFloatingView);
}
private void setupXlhAnimationListener(View floatingView, ViewGroup decorView) {
// 为视图添加一个全局布局监听器,确保在视图完全加载后再设置动画
floatingView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
// 移除监听器,避免重复调用
floatingView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
// 确保初始位置在屏幕右侧外部
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) {
// 动画结束后移除悬浮窗
decorView.removeView(floatingView);
// 标记播放结束并处理下一个消息
synchronized (queueLock) {
isPlaying = false;
}
processNextMessage();
}
});
animator2.start();
}, 3000); // 停留1秒
}
});
}
private void resetAndStartXlhAnimation(View floatingView) {
// 重置视图位置并开始动画
floatingView.setTranslationX(floatingView.getWidth());
// 第一阶段:从右到屏幕右侧边缘(缓慢进入)
ObjectAnimator animator1 = ObjectAnimator.ofFloat(floatingView, "translationX",
floatingView.getWidth(), 0f);
animator1.setDuration(1500);
animator1.setInterpolator(new DecelerateInterpolator(2.0f));
animator1.start();
// 第二阶段延迟1秒后从当前位置向左滑出
floatingView.postDelayed(() -> {
ObjectAnimator animator2 = ObjectAnimator.ofFloat(floatingView, "translationX",
0f, -floatingView.getWidth());
animator2.setDuration(1500);
animator2.setInterpolator(new DecelerateInterpolator(2.0f));
animator2.start();
}, 3000);
}
private void updateXlhFloatingViewData(View xlhFloatingView, XLHBean xlhBean) {
TextView textView = xlhFloatingView.findViewById(R.id.tv_name);
ImageView xlh_image = xlhFloatingView.findViewById(R.id.im_xlh);
private void updateXlhFloatingViewData(View view, XLHBean xlhBean) {
TextView textView = view.findViewById(R.id.tv_name);
ImageView xlh_image = view.findViewById(R.id.im_xlh);
if (xlhBean != null) {
xlh_image.setImageDrawable(xlhBean.getFrom_type() == 1 ? getResources().getDrawable(R.mipmap.xlh_jjks) : getResources().getDrawable(R.mipmap.xlh_zsks));
xlh_image.setImageDrawable(xlhBean.getFrom_type() == 1 ?
getResources().getDrawable(R.mipmap.xlh_jjks) :
getResources().getDrawable(R.mipmap.xlh_zsks));
textView.setText(xlhBean.getText());
} else {
textView.setText("");
}
view.setOnClickListener(v -> {
// 点击时执行跳转操作
handleItemClick(xlhBean);
});
}
private void handleItemClick(XLHBean xlhBean) {
// 这里可以根据实际需求实现跳转逻辑
// 例如:跳转到礼物详情页面、用户主页等
ARouter.getInstance().build(ARouteConstants.ROOM_DETAILS).withString("from", "我的界面").withString("roomId", xlhBean.getRoom_id()).navigation();
}
@Subscribe(threadMode = ThreadMode.MAIN)
public void onEvent(ChatInfo event) {
String id = event.getId().replace("g", "");

View File

@@ -44,6 +44,7 @@ public class GiftTwoDetailsFragment extends BaseMvpFragment<RewardGiftPresenter,
private List<RoonGiftModel> giftList = new ArrayList<>();
private List<GiftPackBean> giftPackList = new ArrayList<>();
private String roomId;
private String bdgiftId;
public static GiftTwoDetailsFragment newInstance(String id, int type, String roomId) {
@@ -92,6 +93,12 @@ public class GiftTwoDetailsFragment extends BaseMvpFragment<RewardGiftPresenter,
}
}
@Subscribe(threadMode = ThreadMode.MAIN)
public void onString(String giftId){
bdgiftId=giftId;
MvpPre.giftPack();
}
@Override
protected void initData() {
if (id.equals("0")) {
@@ -176,6 +183,15 @@ public class GiftTwoDetailsFragment extends BaseMvpFragment<RewardGiftPresenter,
@Override
public void giftPack(List<GiftPackBean> giftPackBean) {
giftPackList = new ArrayList<>();
if (bdgiftId!=null){
for (GiftPackBean item : giftPackBean){
if (item.getGift_id().equals(bdgiftId)){
item.setChecked(true);
}
}
}
giftPackList.addAll(giftPackBean);
pageCount = (int) Math.ceil(giftPackBean.size() * 1.0 / pageSize);
for (int j = 0; j < pageCount; j++) {
@@ -186,6 +202,11 @@ public class GiftTwoDetailsFragment extends BaseMvpFragment<RewardGiftPresenter,
}
}
@Override
public void getGiftPack(String s) {
}
@Override
public void getRewardList(List<RewardUserBean> rewardUserBeanList) {

View File

@@ -4,27 +4,23 @@ import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.res.AssetFileDescriptor;
import android.graphics.drawable.Drawable;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.GridView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.FragmentManager;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.alibaba.android.arouter.launcher.ARouter;
import com.blankj.utilcode.util.ToastUtils;
import com.xscm.moduleutil.R;
import com.xscm.moduleutil.activity.IPresenter;
import com.xscm.moduleutil.base.BaseMvpDialogFragment;
import com.xscm.moduleutil.bean.GiftBean;
import com.xscm.moduleutil.bean.RoomMessageEvent;
@@ -35,7 +31,6 @@ import com.xscm.moduleutil.bean.blindboxwheel.XlhDrawBean;
import com.xscm.moduleutil.databinding.DialogGiftLotteryBinding;
import com.xscm.moduleutil.dialog.WebViewDialog;
import com.xscm.moduleutil.event.LotteryEvent;
import com.xscm.moduleutil.http.RetrofitClient;
import com.xscm.moduleutil.utils.ARouteConstants;
import com.xscm.moduleutil.widget.CircularProgressView;
import com.xscm.moduleutil.widget.GiftCardView;
@@ -94,6 +89,7 @@ public class GiftLotteryDialog extends BaseMvpDialogFragment<GiftLotteryPresente
private GiftLotteryDialogFragment giftLotteryDialogFragment;
private String blind_box_turntable_id = "";//本次抽奖标识id
private BlindBoxBean.XlhData xlhData;
private int icon;//金币金额
@Override
protected GiftLotteryPresenter bindPresenter() {
@@ -310,8 +306,8 @@ public class GiftLotteryDialog extends BaseMvpDialogFragment<GiftLotteryPresente
int id = view.getId();
if (id == R.id.ll_one) {
if (!isDrawing) {
isDrawing=true;
init(1);
isDrawing = true;
// init(1);
startType = 1;
MvpPre.drawGiftList(giftBagId, userIds, roomId, "1");
} else {
@@ -320,8 +316,8 @@ public class GiftLotteryDialog extends BaseMvpDialogFragment<GiftLotteryPresente
}
} else if (id == R.id.ll_ten) {
if (!isDrawing) {
isDrawing=true;
init(2);
isDrawing = true;
// init(2);
startType = 2;
MvpPre.drawGiftList(giftBagId, userIds, roomId, "10");
@@ -330,8 +326,8 @@ public class GiftLotteryDialog extends BaseMvpDialogFragment<GiftLotteryPresente
}
} else if (id == R.id.ll_hundred) {//抽奖100次
if (!isDrawing) {
isDrawing=true;
init(3);
isDrawing = true;
// init(3);
startType = 3;
MvpPre.drawGiftList(giftBagId, userIds, roomId, "100");
} else {
@@ -366,23 +362,94 @@ public class GiftLotteryDialog extends BaseMvpDialogFragment<GiftLotteryPresente
giftLotteryDialogFragment = GiftLotteryDialogFragment.newInstance(giftBagId);
giftLotteryDialogFragment.show(getChildFragmentManager(), "GiftLotteryDialogFragment");
}else if (id == R.id.tv_start){
if (xlhData!=null){
if (xlhData.getStatus()==1){
} else if (id == R.id.tv_start) {
if (xlhData != null) {
if (xlhData.getStatus() == 1) {
FragmentManager fm = getParentFragmentManager();
if (fm != null && !fm.isDestroyed()) {
TourClubDialogFragment newDialog = TourClubDialogFragment.newInstance(
roomId);
roomId);
newDialog.show(fm, "TourClubDialogFragment");
}
this.dismissAllowingStateLoss();
}
}
}else if (id == R.id.exchange_layout){
} else if (id == R.id.exchange_layout) {
ARouter.getInstance().build(ARouteConstants.CURRENCY).navigation();
}
}
private void setBackground() {
// 预加载资源
Drawable drawableX = ContextCompat.getDrawable(getContext(), R.mipmap.chou_x);
Drawable drawableW = ContextCompat.getDrawable(getContext(), R.mipmap.chou_w);
if (icon > 0 && box_price > 0) {
if (type == 10) {
updateBackground(mBinding.mirroeSky.llOne, icon > box_price, drawableX, drawableW);
updateBackground(mBinding.mirroeSky.llTen, icon > box_price * 10, drawableX, drawableW);
updateBackground(mBinding.mirroeSky.llHundred, icon > box_price * 100, drawableX, drawableW);
} else if (type == 11) {
updateBackground(mBinding.cityTime.llOne, icon > box_price, drawableX, drawableW);
updateBackground(mBinding.cityTime.llTen, icon > box_price * 10, drawableX, drawableW);
updateBackground(mBinding.cityTime.llHundred, icon > box_price * 100, drawableX, drawableW);
} else if (type == 12) {
updateBackground(mBinding.pinnacleTime.llOne, icon > box_price, drawableX, drawableW);
updateBackground(mBinding.pinnacleTime.llTen, icon > box_price * 10, drawableX, drawableW);
updateBackground(mBinding.pinnacleTime.llHundred, icon > box_price * 100, drawableX, drawableW);
} else {
// 兜底处理:未知 type 时全部设为不可点击 + 默认背景
setAllBackgroundToDefault(drawableW);
}
} else {
// icon 或 box_price <= 0 时全部置灰不可点击
setAllBackgroundToDefault(drawableW);
}
}
private void updateBackground(View view, boolean clickable, Drawable drawableX, Drawable drawableW) {
if (clickable) {
view.setBackground(drawableX);
view.setClickable(true);
} else {
view.setBackground(drawableW);
view.setClickable(false);
}
}
private void setAllBackgroundToDefault(Drawable defaultDrawable) {
switch (type) {
case 10:
mBinding.mirroeSky.llOne.setBackground(defaultDrawable);
mBinding.mirroeSky.llTen.setBackground(defaultDrawable);
mBinding.mirroeSky.llHundred.setBackground(defaultDrawable);
mBinding.mirroeSky.llOne.setClickable(false);
mBinding.mirroeSky.llTen.setClickable(false);
mBinding.mirroeSky.llHundred.setClickable(false);
break;
case 11:
mBinding.cityTime.llOne.setBackground(defaultDrawable);
mBinding.cityTime.llTen.setBackground(defaultDrawable);
mBinding.cityTime.llHundred.setBackground(defaultDrawable);
mBinding.cityTime.llOne.setClickable(false);
mBinding.cityTime.llTen.setClickable(false);
mBinding.cityTime.llHundred.setClickable(false);
break;
case 12:
mBinding.pinnacleTime.llOne.setBackground(defaultDrawable);
mBinding.pinnacleTime.llTen.setBackground(defaultDrawable);
mBinding.pinnacleTime.llHundred.setBackground(defaultDrawable);
mBinding.pinnacleTime.llOne.setClickable(false);
mBinding.pinnacleTime.llTen.setClickable(false);
mBinding.pinnacleTime.llHundred.setClickable(false);
break;
default:
// 忽略未知类型
break;
}
}
private void init(int type) {
if (type == 1) {
mBinding.mirroeSky.llOne.setBackground(getResources().getDrawable(R.mipmap.chou_x));
@@ -515,7 +582,7 @@ public class GiftLotteryDialog extends BaseMvpDialogFragment<GiftLotteryPresente
finishTargetArrayIndex.add(index);
foundTarget = true;
if (!isOpenSpecial || !isOpenSound) {
playSound("draw.mp3");
playSound("xuanz.mp3");
}
break;
@@ -605,11 +672,12 @@ public class GiftLotteryDialog extends BaseMvpDialogFragment<GiftLotteryPresente
}
private String getRule_url;
private int box_price;//服务器返回的单次抽奖价格
@Override
public void getGiftListSuccess(BlindBoxBean blindBoxBean) {
if (blindBoxBean != null && blindBoxBean.getGift_list() != null) {
box_price = blindBoxBean.getBox_price();
upTitle(blindBoxBean.getBox_price());
giftLists = blindBoxBean.getGift_list();
getRule_url = blindBoxBean.getRule_url();
@@ -647,23 +715,24 @@ public class GiftLotteryDialog extends BaseMvpDialogFragment<GiftLotteryPresente
}
}
}
setBackground();
}
private void upTitle(int boxPrice){
if (type==10){
mBinding.mirroeSky.oneTitle.setText(boxPrice+"币一次");
mBinding.mirroeSky.tenTitle.setText((boxPrice*10)+"币十次");
mBinding.mirroeSky.hundredTitle.setText((boxPrice*100)+"");
}else if (type==11){
mBinding.cityTime.oneTitle.setText(boxPrice+"币一次");
mBinding.cityTime.tenTitle.setText((boxPrice*10)+"币十次");
mBinding.cityTime.hundredTitle.setText((boxPrice*100)+"");
private void upTitle(int boxPrice) {
if (type == 10) {
mBinding.mirroeSky.oneTitle.setText(boxPrice + "币一次");
mBinding.mirroeSky.tenTitle.setText((boxPrice * 10) + "币十次");
mBinding.mirroeSky.hundredTitle.setText((boxPrice * 100) + "");
} else if (type == 11) {
mBinding.cityTime.oneTitle.setText(boxPrice + "币一次");
mBinding.cityTime.tenTitle.setText((boxPrice * 10) + "币十次");
mBinding.cityTime.hundredTitle.setText((boxPrice * 100) + "");
}else if (type==12){
mBinding.pinnacleTime.oneTitle.setText(boxPrice+"币一次");
mBinding.pinnacleTime.tenTitle.setText((boxPrice*10)+"币十次");
mBinding.pinnacleTime.hundredTitle.setText((boxPrice*100)+"");
} else if (type == 12) {
mBinding.pinnacleTime.oneTitle.setText(boxPrice + "币一次");
mBinding.pinnacleTime.tenTitle.setText((boxPrice * 10) + "币十次");
mBinding.pinnacleTime.hundredTitle.setText((boxPrice * 100) + "");
}
}
@@ -713,11 +782,17 @@ public class GiftLotteryDialog extends BaseMvpDialogFragment<GiftLotteryPresente
}
}
@Override
public void drawGiftListSuccess(BlindReslutBean blindReslutBean) {
if (blindReslutBean != null && blindReslutBean.getReslut_list() != null &&
!blindReslutBean.getReslut_list().isEmpty()) {
for (GiftCardView gridView : allViewsArray) {
gridView.setSelected(false);
gridView.stopPulseAnimationWithLayer();
gridView.setVisibilitymResultTextView(false);
}
// 清空之前的数据
targetArrayIndex.clear();
finishTargetArrayIndex.clear();
@@ -739,10 +814,10 @@ public class GiftLotteryDialog extends BaseMvpDialogFragment<GiftLotteryPresente
if (!isOpenSpecial) {
giftCardView.setVisibilitymResultTextView(true);
giftCardView.setSelected(true);
playSound("draw.mp3");
playSound("xuanz.mp3");
// 不要设置isDrawing=true这会影响动画控制
MvpPre.wallet();
isDrawing=false;
isDrawing = false;
MvpPre.giftSend(blind_box_turntable_id);
}
giftCardView.bindGiftData(giftBean);
@@ -775,6 +850,11 @@ public class GiftLotteryDialog extends BaseMvpDialogFragment<GiftLotteryPresente
@Override
public void wallet(WalletBean walletBean) {
if (walletBean != null) {
icon = (int) Double.parseDouble(
(walletBean.getCoin() != null && !walletBean.getCoin().isEmpty())
? walletBean.getCoin()
: "0"
);
if (type == 10) {
mBinding.mirroeSky.tvIcon.setText(walletBean.getCoin());
} else if (type == 11) {
@@ -783,6 +863,7 @@ public class GiftLotteryDialog extends BaseMvpDialogFragment<GiftLotteryPresente
mBinding.pinnacleTime.tvIcon.setText(walletBean.getCoin());
}
}
setBackground();
}
@@ -793,11 +874,11 @@ public class GiftLotteryDialog extends BaseMvpDialogFragment<GiftLotteryPresente
// TODO: 2025/8/29 接收im推送过来的消息
@Subscribe(threadMode = ThreadMode.MAIN)
public void onMusicPlay(RoomMessageEvent message) {
if (message.getMsgType() == 1056){
public void onMusicPlay(RoomMessageEvent message) {
if (message.getMsgType() == 1056) {
UpView(message.getText().getXlh_data());
}
}
}
@Override
public void onDestroyView() {
@@ -855,7 +936,7 @@ public class GiftLotteryDialog extends BaseMvpDialogFragment<GiftLotteryPresente
player.release();
player = null;
}
if (!EventBus.getDefault().isRegistered( this)){
if (!EventBus.getDefault().isRegistered(this)) {
EventBus.getDefault().unregister(this);
}
// 建议进行垃圾回收

View File

@@ -763,4 +763,9 @@ public interface ApiServer {
@GET(Constants.GET_XLH_MY_RECORD)
Call<BaseModel<List<GiftBean>>> xlhMyRecord(@Query("room_id") String room_id, @Query("page") String page, @Query("page_size") String page_size);
@FormUrlEncoded
@POST(Constants.POST_GIFT_ALL_CLEAR)
Call<BaseModel<String>> getGiftPack(@Field("room_id") String roomId,@Field("to_uid") String user_id);
}

View File

@@ -457,6 +457,27 @@ public class RetrofitClient {
sApiServer.giftPack().compose(new DefaultTransformer<>()).subscribe(observer);
}
public void getGiftPack(String roomId, String userId,BaseObserver<String> observer){
sApiServer.getGiftPack(roomId,userId).enqueue(new Callback<BaseModel<String>>() {
@Override
public void onResponse(Call<BaseModel<String>> call, Response<BaseModel<String>> response) {
if (response.code() == 200){
BaseModel<String> baseModel = response.body();
if (baseModel.getCode() == 1){
observer.onNext(baseModel.getMsg());
}else {
observer.onNext(null);
}
}
}
@Override
public void onFailure(Call<BaseModel<String>> call, Throwable t) {
t.printStackTrace();
}
});
}
public void tasksLihen(BaseObserver<GiftBoxBean> observer) {
sApiServer.tasksLihen().enqueue(new Callback<ResponseBody>() {
@Override

View File

@@ -27,6 +27,8 @@ public class RewardGiftContacts {
void reward_zone();
void roomAuctionJoin(RoomAuction.AuctionListBean auctionListBean);
void giftPack(List<GiftPackBean> giftPackBean);
void getGiftPack(String s);
}
public interface IIndexPre extends IPresenter {
@@ -48,5 +50,7 @@ public class RewardGiftContacts {
void roomAuctionJoin(String auction_id,String user_id, String gift_id, String num,String type);
void giftPack();
void getGiftPack(String roomId,String userId);
}
}

View File

@@ -208,4 +208,26 @@ public class RewardGiftPresenter extends BasePresenter<RewardGiftContacts.View>
}
});
}
@Override
public void getGiftPack(String roomId,String userId) {
api.getGiftPack(roomId,userId, new BaseObserver<String>() {
@Override
public void onSubscribe(Disposable d) {
addDisposable(d);
}
@Override
public void onNext(String s) {
if (MvpRef==null){
MvpRef = new WeakReference<>(mView);
}
if (s==null){
MvpRef.get().getGiftPack(null);
}else {
MvpRef.get().getGiftPack(s);
}
}
});
}
}

View File

@@ -34,7 +34,7 @@ public class MqttInitCallback implements MqttCallback {
@Override
public void connectionLost(Throwable cause) {
Log.d(Tag,"mqtt连接断开,执行重连");
ToastUtils.show("mqtt连接断开,执行重连");
// ToastUtils.show("mqtt连接断开,执行重连");
mqttConnect = MqttConnect.getInstance(context, HOST, clientId);
mqttConnect.mqttClient();
}

View File

@@ -1284,14 +1284,14 @@ public class AvatarFrameView extends FrameLayout implements IAnimListener {
// 清空队列
clearQueue();
// 释放资源
releaseResources();
//清空队列
// releaseResources();
// 清空队列
// playQueue.clear();
//关闭动画
// if (mBinding.image != null && isPlaying && mBinding.image.isAnimating()) {
// mBinding.image.setAnimation(null);
// mBinding.image.clearAnimation();
// mBinding.image.stopAnimation();
// 关闭动画
// if (mBinding.playView != null && isPlaying && mBinding.playView.isRunning()) {
// mBinding.playView.setAnimation(null);
// mBinding.playView.clearAnimation();
// mBinding.playView.stopPlay();
// }
}

View File

@@ -384,6 +384,7 @@ public class Constants {
public static final String POST_DRAW_GIFT_LIST_XLH = "/api/BlindBoxTurntable/xlh_draw_gift";///巡乐会抽奖
public static final String POST_XLH_ALL_RECORD = "/api/BlindBoxTurntable/get_xlh_all_record";///巡乐会榜单
public static final String GET_XLH_MY_RECORD = "/api/BlindBoxTurntable/get_xlh_my_record";///巡乐会记录
public static final String POST_GIFT_ALL_CLEAR = "/api/Room/room_gift_all_clear";///背包礼物全清

View File

@@ -191,4 +191,9 @@ public class RewardDialogFragment extends BaseMvpDialogFragment<RewardGiftPresen
public void giftPack(List<GiftPackBean> giftPackBean) {
}
@Override
public void getGiftPack(String s) {
}
}

View File

@@ -287,6 +287,11 @@ public class RewardGiftDialogFragment extends BaseMvpDialogFragment<RewardGiftPr
}
@Override
public void getGiftPack(String s) {
}
private static class MyFragmentPagerAdapter extends FragmentStatePagerAdapter {
private List<GiftLabelBean> list;