fix(app-ui): 整頁背景(BG0) applyBackground 改用 Glide 載入(本地檔優先/URL 網路 fallback,正確解 webp)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
terrylee 2026-07-16 14:39:48 +08:00
parent d224354c23
commit fa5525ad87

View File

@ -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<android.graphics.drawable.Drawable>() {
@Override
public void onResourceReady(android.graphics.drawable.Drawable resource,
com.bumptech.glide.request.transition.Transition<? super android.graphics.drawable.Drawable> transition) {
view.setBackground(resource);
}
@Override
public void onLoadCleared(android.graphics.drawable.Drawable placeholder) {
}
});
} catch (Exception ignore) {
}
}