mirror of
https://github.com/SimpleMobileTools/Simple-Clock.git
synced 2024-12-15 09:53:57 +01:00
Fixed - remember last used alarm config
This commit is contained in:
parent
09ff527a1e
commit
3473bfafee
@ -21,6 +21,7 @@ class EditAlarmDialog(val activity: SimpleActivity, val alarm: Alarm, val callba
|
||||
private val textColor = activity.config.textColor
|
||||
|
||||
init {
|
||||
restoreLastAlarm()
|
||||
updateAlarmTime()
|
||||
|
||||
view.apply {
|
||||
@ -109,6 +110,8 @@ class EditAlarmDialog(val activity: SimpleActivity, val alarm: Alarm, val callba
|
||||
activity.toast(R.string.unknown_error_occurred)
|
||||
}
|
||||
}
|
||||
|
||||
activity.config.alarmLastConfig = alarm
|
||||
callback(alarmId)
|
||||
dismiss()
|
||||
}
|
||||
@ -116,6 +119,19 @@ class EditAlarmDialog(val activity: SimpleActivity, val alarm: Alarm, val callba
|
||||
}
|
||||
}
|
||||
|
||||
private fun restoreLastAlarm() {
|
||||
if (alarm.id == 0) {
|
||||
activity.config.alarmLastConfig?.let { lastConfig ->
|
||||
alarm.label = lastConfig.label
|
||||
alarm.days = lastConfig.days
|
||||
alarm.soundTitle = lastConfig.soundTitle
|
||||
alarm.soundUri = lastConfig.soundUri
|
||||
alarm.timeInMinutes = lastConfig.timeInMinutes
|
||||
alarm.vibrate = lastConfig.vibrate
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private val timeSetListener = TimePickerDialog.OnTimeSetListener { view, hourOfDay, minute ->
|
||||
alarm.timeInMinutes = hourOfDay * 60 + minute
|
||||
updateAlarmTime()
|
||||
|
@ -2,6 +2,7 @@ package com.simplemobiletools.clock.helpers
|
||||
|
||||
import android.content.Context
|
||||
import com.simplemobiletools.clock.extensions.gson.gson
|
||||
import com.simplemobiletools.clock.models.Alarm
|
||||
import com.simplemobiletools.clock.models.StateWrapper
|
||||
import com.simplemobiletools.clock.models.TimerState
|
||||
import com.simplemobiletools.commons.extensions.getDefaultAlarmTitle
|
||||
@ -63,4 +64,10 @@ class Config(context: Context) : BaseConfig(context) {
|
||||
var increaseVolumeGradually: Boolean
|
||||
get() = prefs.getBoolean(INCREASE_VOLUME_GRADUALLY, true)
|
||||
set(increaseVolumeGradually) = prefs.edit().putBoolean(INCREASE_VOLUME_GRADUALLY, increaseVolumeGradually).apply()
|
||||
|
||||
var alarmLastConfig: Alarm?
|
||||
get() = prefs.getString(ALARM_LAST_CONFIG, null)?.let { lastAlarm ->
|
||||
gson.fromJson(lastAlarm, Alarm::class.java)
|
||||
}
|
||||
set(alarm) = prefs.edit().putString(ALARM_LAST_CONFIG, gson.toJson(alarm)).apply()
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ const val TIMER_SOUND_URI = "timer_sound_uri"
|
||||
const val TIMER_SOUND_TITLE = "timer_sound_title"
|
||||
const val TIMER_MAX_REMINDER_SECS = "timer_max_reminder_secs"
|
||||
const val ALARM_MAX_REMINDER_SECS = "alarm_max_reminder_secs"
|
||||
const val ALARM_LAST_CONFIG = "alarm_last_config"
|
||||
const val USE_TEXT_SHADOW = "use_text_shadow"
|
||||
const val INCREASE_VOLUME_GRADUALLY = "increase_volume_gradually"
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user