From 6a0379e4189a2f846b9f5a08f13d7d8e613ccddd Mon Sep 17 00:00:00 2001 From: liangxiaojiang <461355754@qq.com> Date: Fri, 29 Aug 2025 01:14:35 +0800 Subject: [PATCH] =?UTF-8?q?1:=E4=BC=98=E5=8C=96=E7=A4=BC=E7=89=A9=E6=92=AD?= =?UTF-8?q?=E6=94=BE=E5=92=8C=E4=B8=8B=E8=BD=BD=E6=96=B9=E5=BC=8F=202:?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=BD=AC=E7=9B=98=E5=B1=95=E7=A4=BA=E6=95=88?= =?UTF-8?q?=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dialog/giftLottery/GiftLotteryDialog.java | 25 ++ .../GiftLotteryDialogFragment.java | 24 +- .../dialog/giftLottery/PrizePoolDialog.java | 45 ++- .../moduleutil/widget/AvatarFrameView.java | 261 ++++++++++-------- .../xscm/moduleutil/widget/GiftCardView.java | 17 +- .../layout/dialog_gift_lottery_fragment.xml | 2 - .../src/main/res/layout/dialog_mirroe_sky.xml | 2 +- .../src/main/res/layout/item_prize_pool.xml | 8 +- 8 files changed, 236 insertions(+), 148 deletions(-) diff --git a/moduleUtil/src/main/java/com/xscm/moduleutil/dialog/giftLottery/GiftLotteryDialog.java b/moduleUtil/src/main/java/com/xscm/moduleutil/dialog/giftLottery/GiftLotteryDialog.java index dec963d..d231527 100644 --- a/moduleUtil/src/main/java/com/xscm/moduleutil/dialog/giftLottery/GiftLotteryDialog.java +++ b/moduleUtil/src/main/java/com/xscm/moduleutil/dialog/giftLottery/GiftLotteryDialog.java @@ -9,7 +9,9 @@ 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; @@ -133,7 +135,29 @@ public class GiftLotteryDialog extends BaseMvpDialogFragment { private Context mContext; private List gift_list; - private int type ; + private int type; public PrizePoolDialog(@NonNull Context context) { super(context); this.mContext = context; + // 设置对话框从底部弹出并紧贴底部 + if (getWindow() != null) { + getWindow().setGravity(android.view.Gravity.BOTTOM); + } + } + + @Override + public void onStart() { + super.onStart(); + if (getWindow() != null) { + // 获取屏幕尺寸 + android.util.DisplayMetrics displayMetrics = getContext().getResources().getDisplayMetrics(); + // 设置高度为屏幕高度的80% + android.view.WindowManager.LayoutParams params = getWindow().getAttributes(); + params.height = (int) (displayMetrics.heightPixels * 0.8); + params.width = android.view.ViewGroup.LayoutParams.MATCH_PARENT; + getWindow().setAttributes(params); + } } @@ -43,8 +62,6 @@ public class PrizePoolDialog extends BaseDialog { @Override public void initView() { - - } @@ -60,14 +77,14 @@ public class PrizePoolDialog extends BaseDialog { } // 提供更新数据的方法 - public void updateData(List newData ,int type) { - if (type==10){ + public void updateData(List newData, int type) { + if (type == 10) { mBinding.clPrize.setBackgroundResource(R.mipmap.tkzj); mBinding.imJc.setImageResource(R.mipmap.jiangc); - }else if (type==11){ + } else if (type == 11) { mBinding.clPrize.setBackgroundResource(R.mipmap.syzc); mBinding.imJc.setImageResource(R.mipmap.syzc_jc); - }else if (type==12){ + } else if (type == 12) { mBinding.clPrize.setBackgroundResource(R.mipmap.skzj); mBinding.imJc.setImageResource(R.mipmap.skzl_jc); } @@ -77,13 +94,13 @@ public class PrizePoolDialog extends BaseDialog { float density = mContext.getResources().getDisplayMetrics().density; if (density <= 2.0) { // 低密度屏幕(如mdpi, hdpi) - rows = 3; - columns = 2; + rows = 5; + columns = 3; } else if (density <= 3.0) { // 中密度屏幕(如xhdpi) - rows = 3; + rows = 5; columns = 3; } else { // 高密度屏幕(如xxhdpi, xxxhdpi) - rows = 4; + rows = 5; columns = 3; } diff --git a/moduleUtil/src/main/java/com/xscm/moduleutil/widget/AvatarFrameView.java b/moduleUtil/src/main/java/com/xscm/moduleutil/widget/AvatarFrameView.java index f61fcd2..dfebb87 100644 --- a/moduleUtil/src/main/java/com/xscm/moduleutil/widget/AvatarFrameView.java +++ b/moduleUtil/src/main/java/com/xscm/moduleutil/widget/AvatarFrameView.java @@ -48,6 +48,7 @@ import com.xscm.moduleutil.utils.SpUtil; import com.xscm.moduleutil.utils.logger.Logger; import java.io.File; +import java.io.FileOutputStream; import java.io.IOException; import java.lang.ref.WeakReference; import java.net.URL; @@ -56,6 +57,13 @@ import java.util.LinkedList; import java.util.Map; import java.util.Queue; +import okhttp3.Call; +import okhttp3.Callback; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.Response; +import okhttp3.ResponseBody; + public class AvatarFrameView extends FrameLayout implements IAnimListener { @Override @@ -322,142 +330,151 @@ public class AvatarFrameView extends FrameLayout implements IAnimListener { return memoryUsage > 0.8 || usedMemory > MAX_MEMORY_THRESHOLD; } -// public void setSource(String url, int type2) { -// if (SpUtil.getOpenEffect()==1) { -// playQueue.offer(new PlayItem(url, type2)); -// if (!isPlaying) { -// playNextFromQueue(); -// } -// }else { -// playQueue.clear(); -// isPlaying = false; -// } -// -//// RenderType type = null; -//// if ("svga".equalsIgnoreCase(getFileExtension(url))){ -//// type = RenderType.SVGA; -//// }else if ("mp4".equalsIgnoreCase(getFileExtension(url))){ -//// type = RenderType.MP4; -//// } -//// -//// clearPrevious(); -//// renderType = type; -//// mType = type2; -//// switch (type) { -//// case SVGA: -//// mBinding.playView.stopPlay(); -//// mBinding.playView.setVisibility(View.GONE); -//// loadSVGA(url); -//// break; -//// case MP4: -////// loadMP4(url); -//// mBinding.playView.setVisibility(View.VISIBLE); -//// downloadAndPlayMp4(url); -//// break; -//// } -// } + boolean isTxk = false; private void downloadAndPlayMp4(String url) { - String filePath = PathUtils.getInternalAppCachePath() + Md5Utils.getStringMD5(url) + ".mp4"; + + // 提取文件名 + String fileName = url.substring(url.lastIndexOf("/")); + String filePath = getContext().getCacheDir().getAbsolutePath() + fileName; File file = new File(filePath); - if (file.exists() && file.length() > 0) { - playMp4(file); - mFile = file; - } else { - // 删除可能存在的损坏文件 -// if (file.exists()) { -// file.delete(); -// } - DownloadTask task = new DownloadTask.Builder(url, PathUtils.getInternalAppCachePath() - , Md5Utils.getStringMD5(url) + ".mp4") - .setMinIntervalMillisCallbackProcess(300) - .setPassIfAlreadyCompleted(true) - .setAutoCallbackToUIThread(true) - .setConnectionCount(3) // 增加连接数提高稳定性 - .setReadBufferSize(1024 * 8) // 增大缓冲区 + if (!file.exists()) { + LogUtils.e("无缓存"); + // 使用OkHttp进行下载 + OkHttpClient client = new OkHttpClient(); + Request request = new Request.Builder() + .url(url) .build(); - if (StatusUtil.isCompleted(task)) { - playMp4(task.getFile()); - mFile = task.getFile(); - } else if (StatusUtil.isSameTaskPendingOrRunning(task)) { - // 如果任务正在进行中,等待完成 - // 可以通过监听器处理 - attachToExistingTask(task); - } else { - task.enqueue(new DownloadListener1() { - @Override - public void taskStart(@NonNull DownloadTask task, @NonNull Listener1Assist.Listener1Model model) { - Logger.e("AvatarFrameView1", model); - } - @Override - public void retry(@NonNull DownloadTask task, @NonNull ResumeFailedCause cause) { - Logger.e("AvatarFrameView2", cause); + client.newCall(request).enqueue(new Callback() { + @Override + public void onFailure(Call call, IOException e) { + Log.d("sssssssssss", e.toString()); + } - } - - @Override - public void connected(@NonNull DownloadTask task, int blockCount, long currentOffset, long totalLength) { - Logger.e("AvatarFrameView3", blockCount); - } - - @Override - public void progress(@NonNull DownloadTask task, long currentOffset, long totalLength) { - Logger.e("AvatarFrameView4", currentOffset); - } - - @Override - public void taskEnd(@NonNull DownloadTask task, @NonNull EndCause cause, @Nullable Exception realCause, @NonNull Listener1Assist.Listener1Model model) { - Logger.e("AvatarFrameView5", model); -// playMp4(task.getFile()); -// mFile = task.getFile(); -// if (cause != null && cause != EndCause.COMPLETED) { -//// CrashReport.postCatchedException(new RuntimeException("下载任务结束:" + cause == null ? "" : cause.name() + "_realCause:" + realCause == null ? "" : realCause.getMessage())); -// } - - if (cause == EndCause.COMPLETED) { - File downloadedFile = task.getFile(); - if (downloadedFile != null && downloadedFile.exists() && downloadedFile.length() > 0) { - playMp4(downloadedFile); - mFile = downloadedFile; - } else { - Logger.e(TAG, "Downloaded file is invalid"); - handleDownloadFailure(url, cause, new IOException("Downloaded file is invalid")); + @Override + public void onResponse(Call call, Response response) throws IOException { + if (response.isSuccessful()) { + // 保存文件到缓存目录 + try (ResponseBody responseBody = response.body()) { + if (responseBody != null) { + File downloadedFile = new File(filePath); + FileOutputStream fos = new FileOutputStream(downloadedFile); + fos.write(responseBody.bytes()); + fos.close(); + isTxk=true; + // 在主线程中播放动画 + mainHandler.post(() -> { + if (isTxk) { + mBinding.playView.setLoop(20); + } + mBinding.playView.startPlay(downloadedFile); + }); } - } else { - handleDownloadFailure(url, cause, realCause); } } - }); + } + }); + } else { + isTxk=true; + LogUtils.e("有缓存"); + // 直接播放缓存文件 + if (isTxk) { + mBinding.playView.setLoop(20); } + mBinding.playView.startPlay(file); } } - private void handleDownloadFailure(String url, EndCause cause, Exception realCause) { - Logger.e(TAG, "Download failed: " + cause + ", real cause: " + realCause); - // 尝试重试一次 - mainHandler.postDelayed(() -> { - // 检查队列是否仍然包含这个项目 - boolean shouldRetry = false; - for (PlayItem item : playQueue) { - if (item.url.equals(url)) { - shouldRetry = true; - break; - } - } - - if (shouldRetry) { - // 重新添加到队列开头 - playQueue.add(new PlayItem(url, mType)); - playNextFromQueue(); - } else { - isPlaying = false; - playNextFromQueue(); - } - }, 1000); // 1秒后重试 - } + // private void downloadAndPlayMp4(String url) { +// String filePath = PathUtils.getInternalAppCachePath() + Md5Utils.getStringMD5(url) + ".mp4"; +// File file = new File(filePath); +// +// if (file.exists() && file.length() > 0) { +// playMp4(file); +// mFile = file; +// } else { +// // 删除可能存在的损坏文件 +//// if (file.exists()) { +//// file.delete(); +//// } +// +// DownloadTask task = new DownloadTask.Builder(url, PathUtils.getInternalAppCachePath() +// , Md5Utils.getStringMD5(url) + ".mp4") +// .setMinIntervalMillisCallbackProcess(300) +// .setPassIfAlreadyCompleted(true) +// .setAutoCallbackToUIThread(true) +// .setConnectionCount(3) // 增加连接数提高稳定性 +// .setReadBufferSize(1024 * 8) // 增大缓冲区 +// .build(); +// if (StatusUtil.isCompleted(task)) { +// playMp4(task.getFile()); +// mFile = task.getFile(); +// } else if (StatusUtil.isSameTaskPendingOrRunning(task)) { +// Logger.d(TAG, "Task is pending or running, checking if it's stuck"); +// // 检查任务是否可能卡住了 +// // 添加超时机制,如果任务长时间没有进展,则重新开始 +// checkAndHandleStuckTask(task, url); +// } else { +// Logger.d(TAG, "Starting new download task"); +// startNewDownload(task, url); +// } +// +//// else if (StatusUtil.isSameTaskPendingOrRunning(task)) { +//// // 如果任务正在进行中,等待完成 +//// // 可以通过监听器处理 +//// attachToExistingTask(task); +//// } else { +//// task.enqueue(new DownloadListener1() { +//// @Override +//// public void taskStart(@NonNull DownloadTask task, @NonNull Listener1Assist.Listener1Model model) { +//// Logger.e("AvatarFrameView1", model); +//// } +//// +//// @Override +//// public void retry(@NonNull DownloadTask task, @NonNull ResumeFailedCause cause) { +//// Logger.e("AvatarFrameView2", cause); +//// +//// } +//// +//// @Override +//// public void connected(@NonNull DownloadTask task, int blockCount, long currentOffset, long totalLength) { +//// Logger.e("AvatarFrameView3", blockCount); +//// } +//// +//// @Override +//// public void progress(@NonNull DownloadTask task, long currentOffset, long totalLength) { +//// Logger.e("AvatarFrameView4", currentOffset); +//// } +//// +//// @Override +//// public void taskEnd(@NonNull DownloadTask task, @NonNull EndCause cause, @Nullable Exception realCause, @NonNull Listener1Assist.Listener1Model model) { +//// Logger.e("AvatarFrameView5", model); +////// playMp4(task.getFile()); +////// mFile = task.getFile(); +////// if (cause != null && cause != EndCause.COMPLETED) { +//////// CrashReport.postCatchedException(new RuntimeException("下载任务结束:" + cause == null ? "" : cause.name() + "_realCause:" + realCause == null ? "" : realCause.getMessage())); +////// } +//// +//// if (cause == EndCause.COMPLETED) { +//// File downloadedFile = task.getFile(); +//// if (downloadedFile != null && downloadedFile.exists() && downloadedFile.length() > 0) { +//// playMp4(downloadedFile); +//// mFile = downloadedFile; +//// } else { +//// Logger.e(TAG, "Downloaded file is invalid"); +//// handleDownloadFailure(url, cause, new IOException("Downloaded file is invalid")); +//// } +//// } else { +//// handleDownloadFailure(url, cause, realCause); +//// } +//// } +//// }); +//// } +// } +// } // 添加检查进行中任务的方法 private void attachToExistingTask(DownloadTask task) { // 为已经在队列中的任务附加监听器 @@ -802,7 +819,7 @@ public class AvatarFrameView extends FrameLayout implements IAnimListener { } @Override - protected boolean removeEldestEntry(Map.Entry eldest) { + protected boolean removeEldestEntry(Entry eldest) { return size() > maxSize; } } diff --git a/moduleUtil/src/main/java/com/xscm/moduleutil/widget/GiftCardView.java b/moduleUtil/src/main/java/com/xscm/moduleutil/widget/GiftCardView.java index 0986b1a..62e7324 100644 --- a/moduleUtil/src/main/java/com/xscm/moduleutil/widget/GiftCardView.java +++ b/moduleUtil/src/main/java/com/xscm/moduleutil/widget/GiftCardView.java @@ -154,6 +154,7 @@ public class GiftCardView extends FrameLayout { } } } + private android.animation.AnimatorSet animatorSet; public void startPulseAnimationWithLayer() { if (pulseAnimator != null && pulseAnimator.isRunning()) { @@ -169,7 +170,7 @@ public class GiftCardView extends FrameLayout { scaleYAnimator.setRepeatMode(ObjectAnimator.REVERSE); // 组合动画 - android.animation.AnimatorSet animatorSet = new android.animation.AnimatorSet(); + animatorSet = new android.animation.AnimatorSet(); animatorSet.playTogether(pulseAnimator, scaleYAnimator); animatorSet.start(); } @@ -178,8 +179,22 @@ public class GiftCardView extends FrameLayout { if (pulseAnimator != null) { pulseAnimator.cancel(); } + + // 停止组合动画 + if (animatorSet != null && animatorSet.isRunning()) { + animatorSet.cancel(); + } + + // 清除引用 + animatorSet = null; + pulseAnimator = null; + + // 重置缩放 this.setScaleX(1f); this.setScaleY(1f); + + // 强制重新绘制 + this.invalidate(); } /** * 设置礼物名称 diff --git a/moduleUtil/src/main/res/layout/dialog_gift_lottery_fragment.xml b/moduleUtil/src/main/res/layout/dialog_gift_lottery_fragment.xml index d4c3bc9..552697f 100644 --- a/moduleUtil/src/main/res/layout/dialog_gift_lottery_fragment.xml +++ b/moduleUtil/src/main/res/layout/dialog_gift_lottery_fragment.xml @@ -27,7 +27,6 @@ android:layout_marginStart="@dimen/dp_16" android:layout_marginTop="@dimen/dp_10" android:layout_marginEnd="@dimen/dp_16" - android:layout_marginBottom="@dimen/dp_30" android:background="#80000000" android:orientation="vertical" app:layout_constraintBottom_toBottomOf="parent" @@ -77,7 +76,6 @@ android:layout_height="0dp" android:layout_weight="1" android:layout_marginTop="@dimen/dp_16" - android:layout_marginBottom="@dimen/dp_30" app:srlEnableLoadMore="true" app:srlEnableRefresh="true"> diff --git a/moduleUtil/src/main/res/layout/dialog_mirroe_sky.xml b/moduleUtil/src/main/res/layout/dialog_mirroe_sky.xml index 1955088..b8b28d6 100644 --- a/moduleUtil/src/main/res/layout/dialog_mirroe_sky.xml +++ b/moduleUtil/src/main/res/layout/dialog_mirroe_sky.xml @@ -12,7 +12,7 @@ android:id="@+id/lottery_buttons_layout" android:layout_width="0dp" android:layout_height="wrap_content" - android:layout_margin="@dimen/dp_16" + android:layout_margin="@dimen/dp_10" android:gravity="center" android:orientation="horizontal" app:layout_constraintBottom_toBottomOf="parent" diff --git a/moduleUtil/src/main/res/layout/item_prize_pool.xml b/moduleUtil/src/main/res/layout/item_prize_pool.xml index 44d4339..345892b 100644 --- a/moduleUtil/src/main/res/layout/item_prize_pool.xml +++ b/moduleUtil/src/main/res/layout/item_prize_pool.xml @@ -6,8 +6,8 @@ xmlns:tools="http://schemas.android.com/tools">