diff --git a/app/src/main/java/cn/hugh/bz/gk2/ui/SettingsActivity.java b/app/src/main/java/cn/hugh/bz/gk2/ui/SettingsActivity.java new file mode 100644 index 0000000..12ee656 --- /dev/null +++ b/app/src/main/java/cn/hugh/bz/gk2/ui/SettingsActivity.java @@ -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(); + } +}