1:修改BUG

This commit is contained in:
2025-09-23 14:39:49 +08:00
parent f12ed5ef84
commit 1c54f0c072
120 changed files with 3821 additions and 869 deletions

View File

@@ -22,6 +22,7 @@ import com.blankj.utilcode.util.LogUtils;
import com.blankj.utilcode.util.ScreenUtils;
import com.xscm.moduleutil.R;
import com.xscm.moduleutil.base.CommonAppContext;
import com.xscm.moduleutil.base.RoomManager;
import com.xscm.moduleutil.databinding.WebViewDialogBinding;
import com.xscm.moduleutil.utils.ARouteConstants;
import com.xscm.moduleutil.widget.dialog.BaseDialog;
@@ -162,7 +163,9 @@ public class WebViewDialog extends BaseDialog<WebViewDialogBinding> {
@JavascriptInterface
public void jumpRoomPage(String room_id) {
ARouter.getInstance().build(ARouteConstants.ROOM_DETAILS).withString("form", "首页").withString("roomId", room_id).navigation();
RoomManager.getInstance().fetchRoomDataAndEnter(getContext(), room_id,"");
// ARouter.getInstance().build(ARouteConstants.ROOM_DETAILS).withString("form", "首页").withString("roomId", room_id).navigation();
}
@JavascriptInterface
public void jumpWebPage(String objects) {

View File

@@ -22,16 +22,20 @@ import androidx.core.content.ContextCompat;
import androidx.fragment.app.FragmentManager;
import com.alibaba.android.arouter.launcher.ARouter;
import com.blankj.utilcode.util.GsonUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.xscm.moduleutil.R;
import com.xscm.moduleutil.base.BaseMvpDialogFragment;
import com.xscm.moduleutil.bean.GiftBean;
import com.xscm.moduleutil.bean.MqttXlhEnd;
import com.xscm.moduleutil.bean.RoomMessageEvent;
import com.xscm.moduleutil.bean.WalletBean;
import com.xscm.moduleutil.bean.XLHBean;
import com.xscm.moduleutil.bean.blindboxwheel.BlindBoxBean;
import com.xscm.moduleutil.bean.blindboxwheel.BlindReslutBean;
import com.xscm.moduleutil.bean.blindboxwheel.XlhDrawBean;
import com.xscm.moduleutil.databinding.DialogGiftLotteryBinding;
import com.xscm.moduleutil.dialog.RechargeDialogFragment;
import com.xscm.moduleutil.dialog.WebViewDialog;
import com.xscm.moduleutil.event.LotteryEvent;
import com.xscm.moduleutil.utils.ARouteConstants;
@@ -81,8 +85,8 @@ public class GiftLotteryDialog extends BaseMvpDialogFragment<GiftLotteryPresente
private GiftCardView currentGiftCardView;
private boolean isDrawing;//是否正在抽奖
private boolean isOpenSound;//是否开启音效
private boolean isOpenSpecial;//是否开启特效
private boolean isOpenSpecial;//是否开启特效
private Handler handler;
private Runnable timerRunnable;//定时器
private int startType;//类型点击的事抽奖1次还是10次还是100次
@@ -145,7 +149,7 @@ public class GiftLotteryDialog extends BaseMvpDialogFragment<GiftLotteryPresente
mBinding.mirroeSky.swLockYx.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean check) {
isOpenSound= check;
isOpenSound= check;//音效
if(!check){
stopPlay();
}
@@ -154,7 +158,7 @@ public class GiftLotteryDialog extends BaseMvpDialogFragment<GiftLotteryPresente
mBinding.cityTime.swLockYx.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean check) {
isOpenSound= check;
isOpenSound= check;//音效
if(!check){
stopPlay();
}
@@ -163,7 +167,7 @@ public class GiftLotteryDialog extends BaseMvpDialogFragment<GiftLotteryPresente
mBinding.pinnacleTime.swLockYx.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean check) {
isOpenSound= check;
isOpenSound= check;//音效
if(!check){
stopPlay();
}
@@ -437,7 +441,8 @@ public class GiftLotteryDialog extends BaseMvpDialogFragment<GiftLotteryPresente
}
}
} else if (id == R.id.exchange_layout) {
ARouter.getInstance().build(ARouteConstants.CURRENCY).navigation();
// ARouter.getInstance().build(ARouteConstants.CURRENCY).navigation();
RechargeDialogFragment.show(roomId, null, getActivity().getSupportFragmentManager());
}
}
@@ -571,13 +576,19 @@ public class GiftLotteryDialog extends BaseMvpDialogFragment<GiftLotteryPresente
mBinding.pinnacleTime.llHundred.setBackground(getResources().getDrawable(R.mipmap.chou_w));
}
}
@Subscribe(threadMode = ThreadMode.MAIN)
public void onMessageReceived(MqttXlhEnd event) {
BlindBoxBean.XlhData xlhData =new BlindBoxBean.XlhData();
xlhData.setCurrent_num(0);
xlhData.setCurrent_num(0);
xlhData.setStatus(0);
UpView(xlhData);
XLHBean xlhBean= GsonUtils.fromJson(event.getMessage(), XLHBean.class);
// if (xlhBean.getFrom_type()==3) {
// dismiss();
// }
// BlindBoxBean.XlhData xlhData =new BlindBoxBean.XlhData();
if (xlhBean.getFrom_type()==3) {
xlhData.setCurrent_num(0);
xlhData.setStatus(0);
UpView(xlhData);
}
}
/// 定时器
public void startFastAnimate() {
@@ -661,6 +672,7 @@ public class GiftLotteryDialog extends BaseMvpDialogFragment<GiftLotteryPresente
MvpPre.giftSend(blind_box_turntable_id);
MvpPre.wallet();
isDrawing = false;
playSound("xuanz.mp3");
stopFastAnimate();
return;
}
@@ -803,6 +815,11 @@ public class GiftLotteryDialog extends BaseMvpDialogFragment<GiftLotteryPresente
}
}
@Subscribe(threadMode = ThreadMode.MAIN)
public void onMessageReceived(BlindBoxBean.XlhData xlhData) {
UpView(xlhData);
}
public void UpView(BlindBoxBean.XlhData xlhData) {
if (xlhData != null) {
this.xlhData = xlhData;
@@ -897,17 +914,22 @@ public class GiftLotteryDialog extends BaseMvpDialogFragment<GiftLotteryPresente
MvpPre = new GiftLotteryPresenter(this, getActivity());
}
MvpPre.wallet();
isDrawing = false;
MvpPre.giftSend(blind_box_turntable_id);
Log.e("isOpenSound===","isOpenSound1222"+isOpenSound);
if (isOpenSpecial) {
if (isOpenSpecial) {//特效
Log.e("isOpenSound===","isOpenSound333"+isOpenSound);
startFastAnimate();
}else{
if(isOpenSound){
if(isOpenSound){//音效
isDrawing = false;
playSound("xuanz.mp3");
}else {
isDrawing = false;
}
}
}else {
isDrawing = false;
}
}

View File

@@ -30,6 +30,7 @@ import com.xscm.moduleutil.bean.blindboxwheel.BlindBoxBean;
import com.xscm.moduleutil.bean.blindboxwheel.BlindReslutBean;
import com.xscm.moduleutil.bean.blindboxwheel.XlhDrawBean;
import com.xscm.moduleutil.databinding.FragmentTourClubDialogBinding;
import com.xscm.moduleutil.dialog.RechargeDialogFragment;
import com.xscm.moduleutil.dialog.WebViewDialog;
import com.xscm.moduleutil.event.MqttBean;
import com.xscm.moduleutil.utils.ARouteConstants;
@@ -75,6 +76,14 @@ public class TourClubDialogFragment extends BaseMvpDialogFragment<GiftLotteryPre
private boolean isDrawing;//是否正在抽奖
// 添加自动滚动相关的成员变量
private Handler autoScrollHandler = new Handler();
private Runnable autoScrollRunnable;
private boolean isAutoScrolling = false;
private static final int AUTO_SCROLL_DELAY = 1000; // 1秒滚动一个item
private boolean vCheckbox=false;
@Override
protected GiftLotteryPresenter bindPresenter() {
return new GiftLotteryPresenter(this, getActivity());
@@ -146,8 +155,7 @@ public class TourClubDialogFragment extends BaseMvpDialogFragment<GiftLotteryPre
mBinding.tvBd.setOnClickListener(this::onClick);
mBinding.tvJl.setOnClickListener(this::onClick);
mBinding.exchangeLayout.setOnClickListener(this::onClick);
mBinding.vCheckbox.setOnClickListener(this::onClick);
giftXlhChouAdapter = new GiftXlhChouAdapter();
// 使用 LinearLayoutManager 横向滚动
LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity(), LinearLayoutManager.HORIZONTAL, false);
@@ -173,10 +181,75 @@ public class TourClubDialogFragment extends BaseMvpDialogFragment<GiftLotteryPre
mBinding.recycleView.scrollToPosition(middlePosition);
}
});
}
// 添加自动滚动相关的方法
private void startAutoScroll() {
// 如果已经在自动滚动或数据为空,则不启动
if (isAutoScrolling || giftLists == null || giftLists.isEmpty()) {
return;
}
isAutoScrolling = true;
autoScrollRunnable = new Runnable() {
@Override
public void run() {
if (isAutoScrolling && mBinding != null && mBinding.recycleView != null) {
// 获取当前显示的第一个可见item位置
LinearLayoutManager layoutManager = (LinearLayoutManager) mBinding.recycleView.getLayoutManager();
if (layoutManager != null) {
int currentPosition = layoutManager.findFirstVisibleItemPosition();
// 如果没有完全可见的item使用第一个可见item
if (currentPosition == RecyclerView.NO_POSITION) {
currentPosition = layoutManager.findFirstVisibleItemPosition();
}
// 如果还是没有有效的position从0开始
if (currentPosition == RecyclerView.NO_POSITION) {
currentPosition = 0;
}
// 计算下一个位置
int nextPosition = currentPosition + 1;
// 如果到达末尾,回到开始位置
if (nextPosition >= giftXlhChouAdapter.getItemCount()) {
nextPosition = 0;
}
// 平滑滚动到下一个位置
mBinding.recycleView.smoothScrollToPosition(nextPosition);
}
// 1秒后继续滚动
autoScrollHandler.postDelayed(this, AUTO_SCROLL_DELAY);
}
}
};
// 开始自动滚动
autoScrollHandler.postDelayed(autoScrollRunnable, AUTO_SCROLL_DELAY);
}
private void stopAutoScroll() {
isAutoScrolling = false;
if (autoScrollRunnable != null) {
autoScrollHandler.removeCallbacks(autoScrollRunnable);
autoScrollRunnable = null;
}
}
// 在抽奖结束后重新启动自动滚动
private void resumeAutoScrollAfterLottery() {
// 延迟一段时间后再启动自动滚动,让用户看到抽奖结果
mBinding.recycleView.postDelayed(() -> {
if (isVisible() && !isDrawing) {
startAutoScroll();
}
}, 3000); // 3秒后重新开始自动滚动
}
private void onClick(View view) {
int id = view.getId();
if (id == R.id.tv_jc) {
@@ -240,7 +313,11 @@ public class TourClubDialogFragment extends BaseMvpDialogFragment<GiftLotteryPre
xlhRecordDialog = XlhRecordDialog.newInstance(roomId);
xlhRecordDialog.show(getChildFragmentManager(), "XlhRecordDialog");
} else if (id == R.id.exchange_layout) {//钻石兑换
ARouter.getInstance().build(ARouteConstants.CURRENCY).navigation();
// ARouter.getInstance().build(ARouteConstants.CURRENCY).navigation();
RechargeDialogFragment.show(roomId, null, getActivity().getSupportFragmentManager());
}else if (id==R.id.v_checkbox){
mBinding.vCheckbox.setSelected(!mBinding.vCheckbox.isSelected());
vCheckbox=mBinding.vCheckbox.isSelected();
}
}
@@ -288,12 +365,24 @@ public class TourClubDialogFragment extends BaseMvpDialogFragment<GiftLotteryPre
}
giftXlhChouAdapter.setNewData(giftLists);
// // 数据加载完成后启动自动滚动
// if (giftLists != null && !giftLists.isEmpty()) {
// mBinding.recycleView.post(() -> {
// // 确保在UI线程中启动自动滚动
// startAutoScroll();
// });
// }
}else {
isDrawing = false;
}
}
int mboxPrice;
// TODO: 2025/9/4 设置底部按钮文字
private void upTitle(int boxPrice) {
this.mboxPrice = boxPrice;
mBinding.tvOne.setText(boxPrice + "币一次");
mBinding.tvTen.setText((boxPrice * 10) + "币十次");
mBinding.tvHundred.setText((boxPrice * 100) + "币百次");
@@ -309,9 +398,15 @@ public class TourClubDialogFragment extends BaseMvpDialogFragment<GiftLotteryPre
mBinding.tvGiftCount.setText(message.getText().getGift_num() != null ? message.getText().getGift_num() : "0");
mBinding.userName.setText(message.getText().getFromUserInfo().getNickname() != null ? message.getText().getFromUserInfo().getNickname() : "");
ImageUtils.loadHeadCC(message.getText().getFromUserInfo().getAvatar(), mBinding.userPic);
isDrawing=false;
}
}
@Subscribe(threadMode = ThreadMode.MAIN)
public void onMessageReceived(RoomMessageEvent event) {
onMusicPlay( event);
}
@Subscribe(threadMode = ThreadMode.MAIN)
public void onMessageReceived(MqttXlhEnd event) {
dismiss();
@@ -429,6 +524,9 @@ public class TourClubDialogFragment extends BaseMvpDialogFragment<GiftLotteryPre
if (xlhObtainDialog != null && xlhObtainDialog.isShowing()) {
xlhObtainDialog.dismiss();
}
stopAutoScroll();
autoScrollHandler.removeCallbacksAndMessages(null);
}
@@ -452,10 +550,37 @@ public class TourClubDialogFragment extends BaseMvpDialogFragment<GiftLotteryPre
}
private int icon;
@Override
public void wallet(WalletBean walletBean) {
if (walletBean != null) {
mBinding.tvIcon.setText(walletBean.getCoin());
icon = (int) Double.parseDouble(
(walletBean.getCoin() != null && !walletBean.getCoin().isEmpty())
? walletBean.getCoin()
: "0"
);
mBinding.tvIcon.setText(walletBean.getCoin()!=null && !walletBean.getCoin().isEmpty() ?walletBean.getCoin():"0");
showView();
}
}
private void showView() {
if (icon>=mboxPrice){
mBinding.llOne.setClickable( true);
}else {
mBinding.llOne.setClickable( false);
}
if (icon>=mboxPrice*10){
mBinding.llTen.setClickable( true);
}else {
mBinding.llTen.setClickable( false);
}
if (icon>=mboxPrice*100){
mBinding.llHundred.setClickable( true);
}else {
mBinding.llHundred.setClickable( false);
}
}
@@ -465,74 +590,85 @@ public class TourClubDialogFragment extends BaseMvpDialogFragment<GiftLotteryPre
@Override
public void xlhChouSuccess(List<XlhDrawBean> data) {
if (data != null) {
if (vCheckbox){
showResultDialog(data);
}else {
// showResultDialog(data);
showResultDialog(data);
// 取消之前可能存在的任务
clearPendingTasks();
// 抽奖完成后执行动画滚动
pendingLotteryRunnable = new Runnable() {
@Override
public void run() {
// 清理之前的状态
if (giftXlhChouAdapter != null) {
giftXlhChouAdapter.clearSelection();
}
int winningPosition = findHighestValueWinningPosition(data);//这是获取到的中奖位置下标
if (winningPosition != -1) {
if (scrollHelper == null) {
scrollHelper = new CenterScrollHelper(mBinding.recycleView);
}
// 取消之前可能存在的任务
// clearPendingTasks();
// // 抽奖完成后执行动画滚动
// pendingLotteryRunnable = new Runnable() {
// @Override
// public void run() {
// // 清理之前的状态
// if (giftXlhChouAdapter != null) {
// giftXlhChouAdapter.clearSelection();
// }
// int winningPosition = findHighestValueWinningPosition(data);//这是获取到的中奖位置下标
// if (winningPosition != -1) {
// if (scrollHelper == null) {
// scrollHelper = new CenterScrollHelper(mBinding.recycleView);
// }
//
// // 计算在循环列表中的目标位置(滚动几圈后停在目标位置)
// int loopCount = 4; // 滚动4圈
// int originalSize = giftLists.size();///这是列表的总大小
// // 计算目标在循环列表中的位置(确保在中间区域)
// ///这是计算总圈数的大小
// int middleBaseIndex = (loopCount * originalSize);
// ///这里是展示在中奖的位置,加上总圈数的大小,
// int targetLoopIndex = middleBaseIndex + (winningPosition % originalSize);
//
// // 使用scrollWithCircles方法执行带动画的滚动带完成回调
// scrollHelper.scrollWithCircles(
// targetLoopIndex, // 在循环列表中的位置
// loopCount, // 滚动圈数
// 200, // 每个item滚动时间200ms控制速度
// originalSize, // 原始数据大小
// () -> { // 滚动完成回调
// // 滚动完成后更新选中状态(使用原始位置)
// if (giftXlhChouAdapter != null) {
// giftXlhChouAdapter.setSelectedPosition(winningPosition);
// }
// // 滚动完成后延迟一小段时间再居中确保UI更新完成
// pendingCenteringRunnable = new Runnable() {
// @Override
// public void run() {
// // 手动将选中项居中
// centerSelectedItem(winningPosition, originalSize);
//
// // 显示结果对话框
// getActivity().runOnUiThread(() -> {
// scrollHelper = null;
// showResultDialog(data);
// });
// }
// };
// mBinding.recycleView.postDelayed(pendingCenteringRunnable, 100);
// }
// );
//
// } else {
// // 如果没有找到中奖位置,直接显示对话框
// showResultDialog(data);
// }
// }
// };
// mBinding.recycleView.postDelayed(pendingLotteryRunnable, 300);
// 计算在循环列表中的目标位置(滚动几圈后停在目标位置)
int loopCount = 4; // 滚动4圈
int originalSize = giftLists.size();///这是列表的总大小
// 计算目标在循环列表中的位置(确保在中间区域)
///这是计算总圈数的大小
int middleBaseIndex = (loopCount * originalSize);
///这里是展示在中奖的位置,加上总圈数的大小,
int targetLoopIndex = middleBaseIndex + (winningPosition % originalSize);
// 使用scrollWithCircles方法执行带动画的滚动带完成回调
scrollHelper.scrollWithCircles(
targetLoopIndex, // 在循环列表中的位置
loopCount, // 滚动圈数
1000, // 每个item滚动时间200ms控制速度
originalSize, // 原始数据大小
() -> { // 滚动完成回调
// 滚动完成后更新选中状态(使用原始位置)
if (giftXlhChouAdapter != null) {
giftXlhChouAdapter.setSelectedPosition(winningPosition);
}
// 滚动完成后延迟一小段时间再居中确保UI更新完成
pendingCenteringRunnable = new Runnable() {
@Override
public void run() {
// 手动将选中项居中
centerSelectedItem(winningPosition, originalSize);
// 显示结果对话框
getActivity().runOnUiThread(() -> {
scrollHelper = null;
showResultDialog(data);
// 抽奖结束后重新启动自动滚动
// resumeAutoScrollAfterLottery();
});
}
};
mBinding.recycleView.postDelayed(pendingCenteringRunnable, 1000);
}
);
} else {
// 如果没有找到中奖位置,直接显示对话框
showResultDialog(data);
// 抽奖结束后重新启动自动滚动
// resumeAutoScrollAfterLottery();
}
}
};
mBinding.recycleView.postDelayed(pendingLotteryRunnable, 1000);
}
}else {
isDrawing=false;
// 抽奖失败也重新启动自动滚动
// resumeAutoScrollAfterLottery();
}
MvpPre.wallet();
}
@@ -540,6 +676,10 @@ public class TourClubDialogFragment extends BaseMvpDialogFragment<GiftLotteryPre
* 为新的抽奖做准备,清理之前的状态
*/
private void prepareForNewLottery() {
// 停止自动滚动
stopAutoScroll();
// 取消之前可能存在的任务
clearPendingTasks();
@@ -843,6 +983,7 @@ public class TourClubDialogFragment extends BaseMvpDialogFragment<GiftLotteryPre
public void onCloseClick() {
// 处理关闭点击事件
if (xlhObtainDialog != null && xlhObtainDialog.isShowing()) {
isDrawing = false;
xlhObtainDialog.dismiss();
}
xlhObtainDialog = null;