From 03ae37dc916c132618fd804f2a25406ebea175fe Mon Sep 17 00:00:00 2001 From: ZhanGSKen Date: Sat, 2 May 2026 10:32:58 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20BackgroundUtils=E5=88=9D=E5=A7=8B?= =?UTF-8?q?=E5=8C=96=E6=97=B6=E8=87=AA=E5=8A=A8=E4=BF=9D=E5=AD=98=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E8=87=B3SP?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - initFromResource 和 initFromColor 增加自动调用 saveToPreferences() - 优化 initFromPreferences 默认逻辑,避免重复调用保存方法 --- .../cc/winboll/studio/gallery/utils/BackgroundUtils.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/gallery/src/main/java/cc/winboll/studio/gallery/utils/BackgroundUtils.java b/gallery/src/main/java/cc/winboll/studio/gallery/utils/BackgroundUtils.java index 1b526db..f55cef8 100644 --- a/gallery/src/main/java/cc/winboll/studio/gallery/utils/BackgroundUtils.java +++ b/gallery/src/main/java/cc/winboll/studio/gallery/utils/BackgroundUtils.java @@ -50,6 +50,7 @@ public class BackgroundUtils { utils.drawableType = DrawableType.RESOURCE_ID; utils.resId = resId; utils.drawable = ContextCompat.getDrawable(utils.context, resId); + utils.saveToPreferences(); return utils; } } @@ -61,6 +62,7 @@ public class BackgroundUtils { utils.drawableType = DrawableType.COLOR; utils.color = color; utils.drawable = new ColorDrawable(color); + utils.saveToPreferences(); return utils; } } @@ -79,9 +81,8 @@ public class BackgroundUtils { int color = prefs.getInt(KEY_COLOR, Color.BLACK); return initFromColor(appContext, color); } - BackgroundUtils utils = initFromColor(appContext, 0xFF00FF00); - utils.saveToPreferences(); - return utils; + // 默认情况,initFromColor 内部已经调用了 saveToPreferences() + return initFromColor(appContext, 0xFF00FF00); } }