refactor: 简化设置页面,只保留背景图片设置功能
删除的功能: - 播放模式设置(顺序/随机)- 已在相册编辑器中实现 - 更换间隔设置 - 已在相册编辑器中实现 - 返回桌面更换壁纸开关 - 已在相册编辑器中实现 保留的功能: - 应用背景图片设置(启用/禁用、选择、透明度、清除) 简化原因: - 避免功能重复 - 设置页面专注于个性化设置 - 壁纸配置集中在相册管理中 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
5026020423
commit
8d1b592292
2 files changed
+9
-193
No files matched your search
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -14,124 +14,16 @@
|
||||
android:padding="@dimen/spacing_md"
|
||||
tools:context=".ui.SettingsFragment">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvPlayModeLabel"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="播放模式"
|
||||
android:textSize="18sp"
|
||||
android:textStyle="bold"
|
||||
android:layout_marginTop="16dp"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent" />
|
||||
|
||||
<RadioGroup
|
||||
android:id="@+id/rgPlayMode"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:orientation="horizontal"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvPlayModeLabel"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent">
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/rbSequential"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="顺序播放" />
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/rbRandom"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="16dp"
|
||||
android:text="随机播放" />
|
||||
</RadioGroup>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvIntervalLabel"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="更换间隔(分钟)"
|
||||
android:textSize="18sp"
|
||||
android:textStyle="bold"
|
||||
android:layout_marginTop="24dp"
|
||||
app:layout_constraintTop_toBottomOf="@id/rgPlayMode"
|
||||
app:layout_constraintStart_toStartOf="parent" />
|
||||
|
||||
<SeekBar
|
||||
android:id="@+id/seekBarInterval"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:max="60"
|
||||
android:min="1"
|
||||
android:progress="30"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvIntervalLabel"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvIntervalValue"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="30 分钟"
|
||||
android:textSize="16sp"
|
||||
android:layout_marginTop="8dp"
|
||||
app:layout_constraintTop_toBottomOf="@id/seekBarInterval"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvChangeOnReturnLabel"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/setting_change_on_return_title"
|
||||
android:textSize="18sp"
|
||||
android:textStyle="bold"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:layout_marginTop="24dp"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvIntervalValue"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvChangeOnReturnDesc"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/setting_change_on_return_desc"
|
||||
android:textSize="14sp"
|
||||
android:textColor="@android:color/darker_gray"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:layout_marginTop="4dp"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvChangeOnReturnLabel"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent" />
|
||||
|
||||
<Switch
|
||||
android:id="@+id/switchChangeOnReturn"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/spacing_sm"
|
||||
android:layout_marginEnd="@dimen/spacing_md"
|
||||
android:checked="true"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvChangeOnReturnDesc"
|
||||
app:layout_constraintEnd_toEndOf="parent" />
|
||||
|
||||
<!-- 背景图片设置卡片 -->
|
||||
<TextView
|
||||
android:id="@+id/tvBackgroundLabel"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="应用背景"
|
||||
android:textSize="@dimen/text_size_lg"
|
||||
android:textSize="@dimen/text_size_xxl"
|
||||
android:textStyle="bold"
|
||||
android:textColor="@color/text_primary"
|
||||
android:layout_marginTop="@dimen/spacing_lg"
|
||||
app:layout_constraintTop_toBottomOf="@id/switchChangeOnReturn"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent" />
|
||||
|
||||
<com.google.android.material.card.MaterialCardView
|
||||
|
||||
Reference in new issue
Block a user