From 612e9aef6a30b6b140f18e932c81638cc754b800 Mon Sep 17 00:00:00 2001 From: jhengazuki Date: Thu, 9 Oct 2025 17:47:20 +0800 Subject: [PATCH] Optimize gif wall --- app/build.gradle | 7 ++++--- .../android/tv/ui/custom/CustomWallView.java | 21 +++++++++++++++++-- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 806bda7c9..17c7aced1 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -93,9 +93,9 @@ dependencies { implementation 'androidx.appcompat:appcompat:1.7.1' implementation 'androidx.core:core-splashscreen:1.0.1' implementation 'androidx.media:media:1.7.1' - implementation 'androidx.room:room-runtime:2.8.1' + implementation 'androidx.room:room-runtime:2.8.2' implementation 'cat.ereza:customactivityoncrash:2.4.0' - implementation 'com.airbnb.android:lottie:6.6.9' + implementation 'com.airbnb.android:lottie:6.6.10' implementation 'com.github.bassaer:materialdesigncolors:1.0.0' implementation 'com.github.bumptech.glide:glide:' + glideVersion implementation 'com.github.bumptech.glide:annotations:' + glideVersion @@ -118,13 +118,14 @@ dependencies { implementation 'org.greenrobot:eventbus:3.3.1' implementation 'org.nanohttpd:nanohttpd:2.3.1' implementation('org.simpleframework:simple-xml:2.7.1') { exclude group: 'stax', module: 'stax-api' exclude group: 'xpp3', module: 'xpp3' } + implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.29' leanbackImplementation 'androidx.leanback:leanback:1.2.0' leanbackImplementation 'com.github.JessYanCoding:AndroidAutoSize:1.2.1' mobileImplementation 'androidx.biometric:biometric:1.1.0' mobileImplementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0' mobileImplementation 'com.google.android.flexbox:flexbox:3.0.0' mobileImplementation('com.journeyapps:zxing-android-embedded:4.3.0') { transitive = false } - annotationProcessor 'androidx.room:room-compiler:2.8.1' + annotationProcessor 'androidx.room:room-compiler:2.8.2' annotationProcessor 'com.github.bumptech.glide:compiler:' + glideVersion annotationProcessor 'org.greenrobot:eventbus-annotation-processor:3.3.1' coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs_nio:2.1.5' diff --git a/app/src/main/java/com/fongmi/android/tv/ui/custom/CustomWallView.java b/app/src/main/java/com/fongmi/android/tv/ui/custom/CustomWallView.java index 3359c6f63..971bcc3bf 100644 --- a/app/src/main/java/com/fongmi/android/tv/ui/custom/CustomWallView.java +++ b/app/src/main/java/com/fongmi/android/tv/ui/custom/CustomWallView.java @@ -17,7 +17,6 @@ import androidx.lifecycle.LifecycleOwner; import androidx.media3.common.MediaItem; import androidx.media3.exoplayer.ExoPlayer; -import com.bumptech.glide.Glide; import com.fongmi.android.tv.R; import com.fongmi.android.tv.Setting; import com.fongmi.android.tv.databinding.ViewWallBinding; @@ -30,10 +29,14 @@ import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.ThreadMode; import java.io.File; +import java.io.IOException; + +import pl.droidsonroids.gif.GifDrawable; public class CustomWallView extends FrameLayout implements DefaultLifecycleObserver { private ViewWallBinding binding; + private GifDrawable drawable; private ExoPlayer player; private Drawable cache; @@ -113,7 +116,9 @@ public class CustomWallView extends FrameLayout implements DefaultLifecycleObser player.clearMediaItems(); binding.video.setPlayer(null); binding.video.setVisibility(GONE); - Glide.with(binding.image).load(file).placeholder(cache).error(cache).override(ResUtil.getScreenWidth(), ResUtil.getScreenHeight()).into(binding.image); + binding.image.setImageDrawable(cache); + if (drawable != null) drawable.recycle(); + binding.image.setImageDrawable(drawable = gif(file)); } private void loadImage() { @@ -124,6 +129,14 @@ public class CustomWallView extends FrameLayout implements DefaultLifecycleObser else binding.image.setImageResource(R.drawable.wallpaper_1); } + private GifDrawable gif(File file) { + try { + return new GifDrawable(file); + } catch (IOException e) { + return null; + } + } + @Override public void onCreate(@NonNull LifecycleOwner owner) { EventBus.getDefault().register(this); @@ -131,6 +144,7 @@ public class CustomWallView extends FrameLayout implements DefaultLifecycleObser @Override public void onResume(@NonNull LifecycleOwner owner) { + if (drawable != null) drawable.start(); if (binding.video.getVisibility() != VISIBLE || player == null || player.getMediaItemCount() == 0) return; binding.video.setPlayer(player); player.play(); @@ -138,6 +152,7 @@ public class CustomWallView extends FrameLayout implements DefaultLifecycleObser @Override public void onPause(@NonNull LifecycleOwner owner) { + if (drawable != null) drawable.pause(); if (binding.video.getVisibility() != VISIBLE || player == null || player.getMediaItemCount() == 0) return; binding.video.setPlayer(null); player.pause(); @@ -146,8 +161,10 @@ public class CustomWallView extends FrameLayout implements DefaultLifecycleObser @Override public void onDestroy(@NonNull LifecycleOwner owner) { EventBus.getDefault().unregister(this); + if (drawable != null) drawable.recycle(); binding.video.setPlayer(null); player.release(); + drawable = null; binding = null; player = null; cache = null;