From 8d1b5922929765ce9e928d36e9f1b2e3f1cf2b3a Mon Sep 17 00:00:00 2001 From: hugh <1012760428@qq.com> Date: Sun, 25 Jan 2026 15:08:23 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E7=AE=80=E5=8C=96=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E9=A1=B5=E9=9D=A2=EF=BC=8C=E5=8F=AA=E4=BF=9D=E7=95=99?= =?UTF-8?q?=E8=83=8C=E6=99=AF=E5=9B=BE=E7=89=87=E8=AE=BE=E7=BD=AE=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 删除的功能: - 播放模式设置(顺序/随机)- 已在相册编辑器中实现 - 更换间隔设置 - 已在相册编辑器中实现 - 返回桌面更换壁纸开关 - 已在相册编辑器中实现 保留的功能: - 应用背景图片设置(启用/禁用、选择、透明度、清除) 简化原因: - 避免功能重复 - 设置页面专注于个性化设置 - 壁纸配置集中在相册管理中 Co-Authored-By: Claude Sonnet 4.5 --- .../cn/hugh/bz/gk2/ui/SettingsFragment.java | 90 +----- app/src/main/res/layout/fragment_settings.xml | 288 ++++++------------ 2 files changed, 97 insertions(+), 281 deletions(-) diff --git a/app/src/main/java/cn/hugh/bz/gk2/ui/SettingsFragment.java b/app/src/main/java/cn/hugh/bz/gk2/ui/SettingsFragment.java index 42cb5c8..543a369 100644 --- a/app/src/main/java/cn/hugh/bz/gk2/ui/SettingsFragment.java +++ b/app/src/main/java/cn/hugh/bz/gk2/ui/SettingsFragment.java @@ -5,8 +5,6 @@ import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.widget.Button; -import android.widget.RadioButton; -import android.widget.RadioGroup; import android.widget.SeekBar; import android.widget.Switch; import android.widget.TextView; @@ -23,26 +21,14 @@ import android.view.View; import android.view.ViewGroup; import cn.hugh.bz.gk2.R; -import cn.hugh.bz.gk2.model.AppConfig; -import cn.hugh.bz.gk2.model.PlayMode; -import cn.hugh.bz.gk2.utils.AlarmScheduler; import cn.hugh.bz.gk2.wallpaper.BackgroundPreferences; -import cn.hugh.bz.gk2.wallpaper.WallpaperPreferences; /** * 设置 Fragment - * 负责播放模式、更换间隔、返回桌面更换等设置 - * 所有设置实时保存,无需保存按钮 + * 负责应用背景图片设置 */ public class SettingsFragment extends Fragment { - private RadioButton rbSequential; - private RadioButton rbRandom; - private RadioGroup rgPlayMode; - private SeekBar seekBarInterval; - private TextView tvIntervalValue; - private Switch switchChangeOnReturn; - // 背景图片相关控件 private Switch switchBackground; private Button btnSelectBackground; @@ -50,8 +36,6 @@ public class SettingsFragment extends Fragment { private SeekBar seekBarBackgroundAlpha; private TextView tvBackgroundAlpha; - private WallpaperPreferences prefs; - private AppConfig config; private BackgroundPreferences backgroundPrefs; // 图片选择器 @@ -66,26 +50,16 @@ public class SettingsFragment extends Fragment { public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); - prefs = new WallpaperPreferences(requireContext()); - config = prefs.loadConfig(); backgroundPrefs = new BackgroundPreferences(requireContext()); // 初始化图片选择器 initPickImageLauncher(); initViews(view); - loadConfig(); loadBackgroundConfig(); } private void initViews(View view) { - rbSequential = view.findViewById(R.id.rbSequential); - rbRandom = view.findViewById(R.id.rbRandom); - rgPlayMode = view.findViewById(R.id.rgPlayMode); - seekBarInterval = view.findViewById(R.id.seekBarInterval); - tvIntervalValue = view.findViewById(R.id.tvIntervalValue); - switchChangeOnReturn = view.findViewById(R.id.switchChangeOnReturn); - // 背景图片控件 switchBackground = view.findViewById(R.id.switchBackground); btnSelectBackground = view.findViewById(R.id.btnSelectBackground); @@ -93,47 +67,6 @@ public class SettingsFragment extends Fragment { seekBarBackgroundAlpha = view.findViewById(R.id.seekBarBackgroundAlpha); tvBackgroundAlpha = view.findViewById(R.id.tvBackgroundAlpha); - // 播放模式切换监听器(实时保存) - rgPlayMode.setOnCheckedChangeListener((group, checkedId) -> { - PlayMode playMode = rbSequential.isChecked() ? PlayMode.SEQUENTIAL : PlayMode.RANDOM; - config.setPlayMode(playMode); - prefs.saveConfig(config); - }); - - // 间隔调节监听器(实时保存) - seekBarInterval.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { - @Override - public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { - tvIntervalValue.setText(progress + " 分钟"); - - // 实时保存配置 - config.setIntervalMinutes(progress); - prefs.saveConfig(config); - - // 如果服务已启用,重新调度定时器 - if (config.isEnabled() && fromUser) { - AlarmScheduler scheduler = new AlarmScheduler(requireContext()); - scheduler.scheduleWallpaperChange(progress); - } - } - - @Override - public void onStartTrackingTouch(SeekBar seekBar) { - // Do nothing - } - - @Override - public void onStopTrackingTouch(SeekBar seekBar) { - // Do nothing - } - }); - - // 返回桌面更换开关监听器(实时保存) - switchChangeOnReturn.setOnCheckedChangeListener((buttonView, isChecked) -> { - config.setChangeOnReturnToHome(isChecked); - prefs.saveConfig(config); - }); - // 背景图片开关监听器 switchBackground.setOnCheckedChangeListener((buttonView, isChecked) -> { backgroundPrefs.setBackgroundEnabled(isChecked); @@ -168,21 +101,6 @@ public class SettingsFragment extends Fragment { btnClearBackground.setOnClickListener(v -> clearBackgroundImage()); } - private void loadConfig() { - rbSequential.setChecked(config.getPlayMode() == PlayMode.SEQUENTIAL); - rbRandom.setChecked(config.getPlayMode() == PlayMode.RANDOM); - seekBarInterval.setProgress(config.getIntervalMinutes()); - tvIntervalValue.setText(config.getIntervalMinutes() + " 分钟"); - switchChangeOnReturn.setChecked(config.isChangeOnReturnToHome()); - } - - @Override - public void onResume() { - super.onResume(); - config = prefs.loadConfig(); - loadConfig(); - } - // ==================== 背景图片相关方法 ==================== /** @@ -264,4 +182,10 @@ public class SettingsFragment extends Fragment { .setNegativeButton("取消", null) .show(); } + + @Override + public void onResume() { + super.onResume(); + loadBackgroundConfig(); + } } diff --git a/app/src/main/res/layout/fragment_settings.xml b/app/src/main/res/layout/fragment_settings.xml index 2bdd417..af7db53 100644 --- a/app/src/main/res/layout/fragment_settings.xml +++ b/app/src/main/res/layout/fragment_settings.xml @@ -14,223 +14,115 @@ android:padding="@dimen/spacing_md" tools:context=".ui.SettingsFragment"> - - - - - + + android:text="应用背景" + android:textSize="@dimen/text_size_xxl" + android:textStyle="bold" + android:textColor="@color/text_primary" + app:layout_constraintTop_toTopOf="parent" + app:layout_constraintStart_toStartOf="parent" /> - - + android:layout_marginTop="@dimen/spacing_sm" + app:cardElevation="@dimen/card_elevation" + app:cardCornerRadius="@dimen/corner_radius_md" + app:cardBackgroundColor="@color/bg_card" + app:strokeColor="@color/glass_border" + app:strokeWidth="@dimen/glass_border_width" + app:layout_constraintTop_toBottomOf="@id/tvBackgroundLabel" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintEnd_toEndOf="parent"> - - - - - - - - - - - - - - - - - - - - + android:orientation="vertical" + android:padding="@dimen/card_padding"> - + + android:orientation="horizontal" + android:gravity="center_vertical"> - + + + + + + + + + + + + + + + style="@style/Widget.Material3.Button.OutlinedButton" + android:textColor="@color/color_error" + app:iconTint="@color/color_error" + app:strokeColor="@color/color_error" /> - - - - - - - - - - - - - +