1:完成天空之境的页面,可以打开规则页面,
This commit is contained in:
@@ -3,6 +3,8 @@ package com.xscm.moduleutil.dialog.giftLottery;
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.res.AssetFileDescriptor;
|
||||
import android.media.MediaPlayer;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
@@ -14,6 +16,7 @@ import androidx.annotation.Nullable;
|
||||
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;
|
||||
@@ -22,10 +25,14 @@ import com.xscm.moduleutil.bean.GiftBean;
|
||||
import com.xscm.moduleutil.bean.blindboxwheel.BlindBoxBean;
|
||||
import com.xscm.moduleutil.bean.blindboxwheel.BlindReslutBean;
|
||||
import com.xscm.moduleutil.databinding.DialogGiftLotteryBinding;
|
||||
import com.xscm.moduleutil.dialog.WebViewDialog;
|
||||
import com.xscm.moduleutil.http.RetrofitClient;
|
||||
import com.xscm.moduleutil.utils.ARouteConstants;
|
||||
import com.xscm.moduleutil.widget.GiftCardView;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -135,10 +142,12 @@ public class GiftLotteryDialog extends BaseMvpDialogFragment<GiftLotteryPresente
|
||||
mBinding.llHundred.setOnClickListener(this::onClisk);
|
||||
mBinding.swLockYx.setOnClickListener(this::onClisk);
|
||||
mBinding.swTex.setOnClickListener(this::onClisk);
|
||||
mBinding.tvGz.setOnClickListener(this::onClisk);
|
||||
init(0);
|
||||
mBinding.swLockYx.setChecked(true);
|
||||
mBinding.swTex.setChecked(true);
|
||||
isOpenSpecial=true;
|
||||
isOpenSound=true;
|
||||
}
|
||||
|
||||
private void onClisk(View view) {
|
||||
@@ -169,9 +178,13 @@ public class GiftLotteryDialog extends BaseMvpDialogFragment<GiftLotteryPresente
|
||||
com.hjq.toast.ToastUtils.show("正在抽奖中...");
|
||||
}
|
||||
}else if (id == R.id.sw_lock_yx){
|
||||
isOpenSpecial=mBinding.swLockYx.isChecked();
|
||||
isOpenSound=mBinding.swLockYx.isChecked();
|
||||
}else if (id == R.id.sw_tex){
|
||||
isOpenSpecial=mBinding.swTex.isChecked();
|
||||
}else if (id==R.id.tv_gz){
|
||||
WebViewDialog webViewDialog = new WebViewDialog(getActivity(), getRule_url);
|
||||
webViewDialog.show();
|
||||
// ARouter.getInstance().build(ARouteConstants.H5).withString("url", getRule_url).withString("title", "盲盒规则").navigation();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -207,8 +220,8 @@ public class GiftLotteryDialog extends BaseMvpDialogFragment<GiftLotteryPresente
|
||||
|
||||
if (isOpenSound) {
|
||||
// 假设此处有播放音乐的逻辑
|
||||
// player.seekTo(0);
|
||||
// player.start();
|
||||
playSound("draw_music.mp3");
|
||||
isOpenSound=false;
|
||||
}
|
||||
|
||||
roundCount = 0;
|
||||
@@ -244,15 +257,29 @@ public class GiftLotteryDialog extends BaseMvpDialogFragment<GiftLotteryPresente
|
||||
currentGiftCardView = giftView;
|
||||
|
||||
if (roundCount / giftMaxCount == minRoundCount) {
|
||||
for (int i = 0; i < targetArrayIndex.size(); i++) {
|
||||
int index = targetArrayIndex.get(i);
|
||||
// 使用迭代器安全地遍历和修改列表
|
||||
boolean foundTarget = false;
|
||||
Iterator<Integer> iterator = targetArrayIndex.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
int index = iterator.next();
|
||||
if (currentIndex == index) {
|
||||
GiftCardView targetGiftView = allViewsArray.get(index);
|
||||
targetGiftView.setSelected(true);
|
||||
targetGiftView.setVisibilitymResultTextView(true);
|
||||
targetGiftView.startPulseAnimationWithLayer();
|
||||
targetArrayIndex.remove(i);
|
||||
iterator.remove(); // 安全地移除元素
|
||||
finishTargetArrayIndex.add(index);
|
||||
foundTarget = true;
|
||||
if (!isOpenSound){
|
||||
if (player != null) {
|
||||
player.stop();
|
||||
player.release();
|
||||
player = null;
|
||||
}
|
||||
}
|
||||
if (!isOpenSpecial){
|
||||
playSound("draw.mp3");
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -260,6 +287,7 @@ public class GiftLotteryDialog extends BaseMvpDialogFragment<GiftLotteryPresente
|
||||
if (targetArrayIndex.size()==0) {
|
||||
isDrawing = false;
|
||||
stopFastAnimate();
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
delayTime = delayTime - 0.02;
|
||||
@@ -267,33 +295,71 @@ public class GiftLotteryDialog extends BaseMvpDialogFragment<GiftLotteryPresente
|
||||
delayTime = 0.03;
|
||||
}
|
||||
}
|
||||
|
||||
// 重新调度任务
|
||||
handler.postDelayed(this, (long) (delayTime * 1000));
|
||||
}
|
||||
};
|
||||
|
||||
// 启动定时器
|
||||
handler.postDelayed(timerRunnable, (long) (0.2 * 1000));
|
||||
if (handler != null && timerRunnable != null) {
|
||||
// 启动定时器
|
||||
handler.postDelayed(timerRunnable, (long) (0.2 * 1000));
|
||||
}
|
||||
}
|
||||
|
||||
public void stopFastAnimate() {
|
||||
isDrawing = false; // 设置标志位
|
||||
if (handler != null && timerRunnable != null) {
|
||||
handler.removeCallbacksAndMessages(null); // 移除所有回调和消息
|
||||
handler = null; // 清空引用
|
||||
}
|
||||
// timerRunnable = null;
|
||||
}
|
||||
|
||||
handler.removeCallbacks(timerRunnable);
|
||||
timerRunnable=null;
|
||||
private MediaPlayer player;
|
||||
// 播放音频的方法
|
||||
private void playSound(String fileName) {
|
||||
try {
|
||||
MediaPlayer mediaPlayer = getPlayer(fileName);
|
||||
if (mediaPlayer != null) {
|
||||
if (mediaPlayer.isPlaying()) {
|
||||
mediaPlayer.seekTo(0);
|
||||
}
|
||||
mediaPlayer.start();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
private MediaPlayer getPlayer(String fileName) {
|
||||
if (player == null) {
|
||||
try {
|
||||
// 从assets目录加载音频文件
|
||||
AssetFileDescriptor afd = getContext().getAssets().openFd(fileName);
|
||||
player = new MediaPlayer();
|
||||
player.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength());
|
||||
player.prepare();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
// 如果assets中没有找到文件,尝试从raw资源目录加载
|
||||
// try {
|
||||
// player = MediaPlayer.create(getContext(), R.raw.draw_music);
|
||||
// } catch (Exception ex) {
|
||||
// ex.printStackTrace();
|
||||
// }
|
||||
}
|
||||
}
|
||||
return player;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getLayoutId() {
|
||||
return R.layout.dialog_gift_lottery;
|
||||
}
|
||||
|
||||
private String getRule_url;
|
||||
@Override
|
||||
public void getGiftListSuccess(BlindBoxBean blindBoxBean) {
|
||||
if (blindBoxBean != null && blindBoxBean.getGift_list() != null) {
|
||||
giftLists = blindBoxBean.getGift_list();
|
||||
|
||||
getRule_url=blindBoxBean.getRule_url();
|
||||
// 确保数据数量不超过视图数量
|
||||
int size = Math.min(giftLists.size(), allViewsArray.size());
|
||||
|
||||
@@ -313,27 +379,34 @@ public class GiftLotteryDialog extends BaseMvpDialogFragment<GiftLotteryPresente
|
||||
|
||||
@Override
|
||||
public void drawGiftListSuccess(BlindReslutBean blindReslutBean) {
|
||||
if (blindReslutBean!=null || !blindReslutBean.getReslut_list().isEmpty()){
|
||||
for (int i=0;i<blindReslutBean.getReslut_list().size();i++){
|
||||
if (blindReslutBean != null && blindReslutBean.getReslut_list() != null &&
|
||||
!blindReslutBean.getReslut_list().isEmpty()) {
|
||||
|
||||
// 清空之前的数据
|
||||
targetArrayIndex.clear();
|
||||
finishTargetArrayIndex.clear();
|
||||
|
||||
for (int i = 0; i < blindReslutBean.getReslut_list().size(); i++) {
|
||||
BlindReslutBean.ReslutList reslutList = blindReslutBean.getReslut_list().get(i);
|
||||
for (int j=0;j<giftLists.size();j++){
|
||||
if (giftLists.get(j).getGift_id().equals(reslutList.getGift_id()+"")){
|
||||
for (int j = 0; j < giftLists.size(); j++) {
|
||||
if (giftLists.get(j).getGift_id().equals(reslutList.getGift_id() + "")) {
|
||||
targetArrayIndex.add(j);
|
||||
if (j<12){
|
||||
GiftCardView giftCardView=allViewsArray.get(j);
|
||||
GiftBean giftBean=giftLists.get(j);
|
||||
if (j < 12) {
|
||||
GiftCardView giftCardView = allViewsArray.get(j);
|
||||
GiftBean giftBean = giftLists.get(j);
|
||||
giftBean.setNumber(reslutList.getCount());
|
||||
|
||||
if (!isOpenSpecial){
|
||||
giftCardView.setVisibilitymResultTextView(false);
|
||||
giftCardView.setSelected( true);
|
||||
isDrawing=true;
|
||||
if (!isOpenSpecial) {
|
||||
giftCardView.setVisibilitymResultTextView(true);
|
||||
giftCardView.setSelected(true);
|
||||
playSound("draw.mp3");
|
||||
// 不要设置isDrawing=true,这会影响动画控制
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isOpenSpecial){
|
||||
if (isOpenSpecial) {
|
||||
startFastAnimate();
|
||||
}
|
||||
}
|
||||
@@ -351,6 +424,12 @@ public class GiftLotteryDialog extends BaseMvpDialogFragment<GiftLotteryPresente
|
||||
releaseResources();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCancel(@NonNull DialogInterface dialog) {
|
||||
super.onCancel(dialog);
|
||||
releaseResources();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
@@ -362,11 +441,12 @@ public class GiftLotteryDialog extends BaseMvpDialogFragment<GiftLotteryPresente
|
||||
*/
|
||||
private void releaseResources() {
|
||||
// 清理定时器
|
||||
if (handler != null && timerRunnable != null) {
|
||||
// 清理定时器
|
||||
if (handler != null) {
|
||||
handler.removeCallbacksAndMessages(null);
|
||||
timerRunnable = null;
|
||||
handler = null;
|
||||
}
|
||||
|
||||
timerRunnable = null;
|
||||
// 停止并清理所有动画
|
||||
stopAllAnimations();
|
||||
|
||||
@@ -378,15 +458,16 @@ public class GiftLotteryDialog extends BaseMvpDialogFragment<GiftLotteryPresente
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 清理Presenter
|
||||
if (MvpPre != null) {
|
||||
// 如果Presenter中有需要清理的资源,在这里处理
|
||||
}
|
||||
|
||||
// 清理视图引用
|
||||
clearViewReferences();
|
||||
|
||||
if (player != null){
|
||||
player.release();
|
||||
player = null;
|
||||
}
|
||||
// 建议进行垃圾回收
|
||||
System.gc();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user