feat: 添加设置页面 Activity
实现了设置页面的所有功能 - 播放模式选择(顺序/随机) - 更换间隔调整(1-60 分钟滑块) - 实时显示间隔时间 - 保存配置到 SharedPreferences - 如果服务已启用,自动重新调度定时器 - 保存后自动关闭页面并显示提示 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
aa65cce3b0
commit
62a89ead44
1 file changed
+93
@@ -0,0 +1,93 @@
|
||||
package cn.hugh.bz.gk2.ui;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.widget.Button;
|
||||
import android.widget.RadioButton;
|
||||
import android.widget.RadioGroup;
|
||||
import android.widget.SeekBar;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
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.WallpaperPreferences;
|
||||
|
||||
public class SettingsActivity extends AppCompatActivity {
|
||||
|
||||
private RadioButton rbSequential;
|
||||
private RadioButton rbRandom;
|
||||
private SeekBar seekBarInterval;
|
||||
private TextView tvIntervalValue;
|
||||
private Button btnSave;
|
||||
|
||||
private WallpaperPreferences prefs;
|
||||
private AppConfig config;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_settings);
|
||||
|
||||
prefs = new WallpaperPreferences(this);
|
||||
config = prefs.loadConfig();
|
||||
|
||||
initViews();
|
||||
loadConfig();
|
||||
}
|
||||
|
||||
private void initViews() {
|
||||
rbSequential = findViewById(R.id.rbSequential);
|
||||
rbRandom = findViewById(R.id.rbRandom);
|
||||
seekBarInterval = findViewById(R.id.seekBarInterval);
|
||||
tvIntervalValue = findViewById(R.id.tvIntervalValue);
|
||||
btnSave = findViewById(R.id.btnSave);
|
||||
|
||||
seekBarInterval.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
|
||||
@Override
|
||||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
||||
tvIntervalValue.setText(progress + " 分钟");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartTrackingTouch(SeekBar seekBar) {}
|
||||
|
||||
@Override
|
||||
public void onStopTrackingTouch(SeekBar seekBar) {}
|
||||
});
|
||||
|
||||
btnSave.setOnClickListener(v -> saveConfig());
|
||||
}
|
||||
|
||||
private void loadConfig() {
|
||||
rbSequential.setChecked(config.getPlayMode() == PlayMode.SEQUENTIAL);
|
||||
rbRandom.setChecked(config.getPlayMode() == PlayMode.RANDOM);
|
||||
seekBarInterval.setProgress(config.getIntervalMinutes());
|
||||
tvIntervalValue.setText(config.getIntervalMinutes() + " 分钟");
|
||||
}
|
||||
|
||||
private void saveConfig() {
|
||||
// Update play mode
|
||||
PlayMode playMode = rbSequential.isChecked() ? PlayMode.SEQUENTIAL : PlayMode.RANDOM;
|
||||
config.setPlayMode(playMode);
|
||||
|
||||
// Update interval
|
||||
int interval = seekBarInterval.getProgress();
|
||||
config.setIntervalMinutes(interval);
|
||||
|
||||
// Save
|
||||
prefs.saveConfig(config);
|
||||
|
||||
// Reschedule alarm if enabled
|
||||
if (config.isEnabled()) {
|
||||
AlarmScheduler scheduler = new AlarmScheduler(this);
|
||||
scheduler.scheduleWallpaperChange(interval);
|
||||
}
|
||||
|
||||
Toast.makeText(this, "设置已保存", Toast.LENGTH_SHORT).show();
|
||||
finish();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user