From fa5525ad872b9f2e1e7e545904f64bc53f0ee605 Mon Sep 17 00:00:00 2001 From: terrylee Date: Thu, 16 Jul 2026 14:39:48 +0800 Subject: [PATCH] =?UTF-8?q?fix(app-ui):=20=E6=95=B4=E9=A0=81=E8=83=8C?= =?UTF-8?q?=E6=99=AF(BG0)=20applyBackground=20=E6=94=B9=E7=94=A8=20Glide?= =?UTF-8?q?=20=E8=BC=89=E5=85=A5(=E6=9C=AC=E5=9C=B0=E6=AA=94=E5=84=AA?= =?UTF-8?q?=E5=85=88/URL=20=E7=B6=B2=E8=B7=AF=20fallback=EF=BC=8C=E6=AD=A3?= =?UTF-8?q?=E7=A2=BA=E8=A7=A3=20webp)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 4.8 (1M context) --- .../unibuy/smartdevice/ui/tools/UiSkin.java | 37 +++++++++++++++---- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/unibuy/smartdevice/ui/tools/UiSkin.java b/app/src/main/java/com/unibuy/smartdevice/ui/tools/UiSkin.java index f04089b..9398a15 100644 --- a/app/src/main/java/com/unibuy/smartdevice/ui/tools/UiSkin.java +++ b/app/src/main/java/com/unibuy/smartdevice/ui/tools/UiSkin.java @@ -105,26 +105,49 @@ public class UiSkin { /** * 把某部位的後台設定圖套成指定 View 的「背景」(整頁背景等);未設定則不動、保留原背景。 - * 使用預先下載到本地的快取檔(UiSkin.save 時已 preload)。 + * 用 Glide 載入(有本地快取檔用檔案、否則直接以 URL 下載=網路 fallback),能正確解 webp。 */ public static void applyBackground(String partKey, View view) { if (view == null) { return; } - String url = getUrl(view.getContext(), partKey); + final android.content.Context ctx = view.getContext(); + if (ctx instanceof android.app.Activity) { + android.app.Activity a = (android.app.Activity) ctx; + if (a.isFinishing() || a.isDestroyed()) { + return; + } + } + + String url = getUrl(ctx, partKey); if (url == null) { return; } try { - java.io.File f = new com.unibuy.smartdevice.tools.HttpConnect().getFileFromUrl(url); - if (f != null && f.exists()) { - android.graphics.drawable.Drawable d = android.graphics.drawable.Drawable.createFromPath(f.getAbsolutePath()); - if (d != null) { - view.setBackground(d); + Object model = url; // 預設用 URL(無本地檔時走網路) + try { + java.io.File f = new com.unibuy.smartdevice.tools.HttpConnect().getFileFromUrl(url); + if (f != null && f.exists()) { + model = f; // 有本地快取檔優先用檔案 } + } catch (Exception ignore) { } + + com.bumptech.glide.Glide.with(ctx) + .load(model) + .into(new com.bumptech.glide.request.target.CustomTarget() { + @Override + public void onResourceReady(android.graphics.drawable.Drawable resource, + com.bumptech.glide.request.transition.Transition transition) { + view.setBackground(resource); + } + + @Override + public void onLoadCleared(android.graphics.drawable.Drawable placeholder) { + } + }); } catch (Exception ignore) { } }