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" />
-
-
-
-
-
-
-
-
-
-
-
-
-
+