From 3473bfafee1d16e85aa8be6978b95fdad87b303a Mon Sep 17 00:00:00 2001 From: Pavol Franek <> Date: Wed, 11 Mar 2020 08:41:24 +0100 Subject: [PATCH] Fixed - remember last used alarm config --- .../clock/dialogs/EditAlarmDialog.kt | 16 ++++++++++++++++ .../simplemobiletools/clock/helpers/Config.kt | 7 +++++++ .../simplemobiletools/clock/helpers/Constants.kt | 1 + 3 files changed, 24 insertions(+) diff --git a/app/src/main/kotlin/com/simplemobiletools/clock/dialogs/EditAlarmDialog.kt b/app/src/main/kotlin/com/simplemobiletools/clock/dialogs/EditAlarmDialog.kt index 7f61d3b8..57be48fc 100644 --- a/app/src/main/kotlin/com/simplemobiletools/clock/dialogs/EditAlarmDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/clock/dialogs/EditAlarmDialog.kt @@ -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() diff --git a/app/src/main/kotlin/com/simplemobiletools/clock/helpers/Config.kt b/app/src/main/kotlin/com/simplemobiletools/clock/helpers/Config.kt index 0bcd5cb9..e243589e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/clock/helpers/Config.kt +++ b/app/src/main/kotlin/com/simplemobiletools/clock/helpers/Config.kt @@ -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() } diff --git a/app/src/main/kotlin/com/simplemobiletools/clock/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/clock/helpers/Constants.kt index c58f2a5d..fe6f409e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/clock/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/clock/helpers/Constants.kt @@ -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"