From dd42cedc09f5c66a3ed5abaa0506777c22b76607 Mon Sep 17 00:00:00 2001 From: Naveen Singh Date: Sun, 30 Mar 2025 05:12:07 +0530 Subject: [PATCH 1/4] Replace checkboxes with switches See https://github.com/orgs/FossifyOrg/discussions/78 --- app/src/main/res/layout/activity_settings.xml | 31 ++++++++++--------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/app/src/main/res/layout/activity_settings.xml b/app/src/main/res/layout/activity_settings.xml index e55fd580..9295c63b 100644 --- a/app/src/main/res/layout/activity_settings.xml +++ b/app/src/main/res/layout/activity_settings.xml @@ -97,13 +97,13 @@ - @@ -135,13 +135,13 @@ - @@ -183,6 +183,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/start_week_on" /> + - @@ -244,13 +245,13 @@ - @@ -259,13 +260,13 @@ - From 3fc619521e3109b4d189600712d7aeb4516a9d13 Mon Sep 17 00:00:00 2001 From: Naveen Singh Date: Sun, 30 Mar 2025 05:16:01 +0530 Subject: [PATCH 2/4] Fix migrating label color --- .../kotlin/org/fossify/clock/activities/SettingsActivity.kt | 5 +++-- app/src/main/res/layout/activity_settings.xml | 5 ++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/src/main/kotlin/org/fossify/clock/activities/SettingsActivity.kt b/app/src/main/kotlin/org/fossify/clock/activities/SettingsActivity.kt index 1b34b658..b828e736 100644 --- a/app/src/main/kotlin/org/fossify/clock/activities/SettingsActivity.kt +++ b/app/src/main/kotlin/org/fossify/clock/activities/SettingsActivity.kt @@ -111,6 +111,7 @@ class SettingsActivity : SimpleActivity() { binding.settingsGeneralSettingsLabel, binding.settingsAlarmTabLabel, binding.settingsTimerTabLabel, + binding.settingsMigratingLabel ).forEach { it.setTextColor(getProperPrimaryColor()) } @@ -338,7 +339,7 @@ class SettingsActivity : SimpleActivity() { ExportDataDialog(this, config.lastDataExportPath) { file -> try { exportActivityResultLauncher.launch(file.name) - } catch (@Suppress("SwallowedException") e: ActivityNotFoundException) { + } catch (@Suppress("SwallowedException") _: ActivityNotFoundException) { toast( id = org.fossify.commons.R.string.system_service_disabled, length = Toast.LENGTH_LONG @@ -352,7 +353,7 @@ class SettingsActivity : SimpleActivity() { private fun tryImportData() { try { importActivityResultLauncher.launch(IMPORT_BACKUP_MIME_TYPES.toTypedArray()) - } catch (@Suppress("SwallowedException") e: ActivityNotFoundException) { + } catch (@Suppress("SwallowedException") _: ActivityNotFoundException) { toast(org.fossify.commons.R.string.system_service_disabled, Toast.LENGTH_LONG) } catch (e: Exception) { showErrorToast(e) diff --git a/app/src/main/res/layout/activity_settings.xml b/app/src/main/res/layout/activity_settings.xml index 9295c63b..4165158d 100644 --- a/app/src/main/res/layout/activity_settings.xml +++ b/app/src/main/res/layout/activity_settings.xml @@ -331,17 +331,16 @@ - Date: Sun, 30 Mar 2025 07:38:25 +0530 Subject: [PATCH 3/4] Switch to `config.firstDayOfWeek` from commons --- .../fossify/clock/activities/MainActivity.kt | 10 ++-- .../clock/activities/SettingsActivity.kt | 34 +++++++----- .../fossify/clock/dialogs/EditAlarmDialog.kt | 4 +- .../org/fossify/clock/extensions/Context.kt | 16 ++---- .../org/fossify/clock/helpers/Config.kt | 55 ++++++++++++------- .../org/fossify/clock/helpers/Constants.kt | 4 +- gradle/libs.versions.toml | 2 +- 7 files changed, 71 insertions(+), 54 deletions(-) diff --git a/app/src/main/kotlin/org/fossify/clock/activities/MainActivity.kt b/app/src/main/kotlin/org/fossify/clock/activities/MainActivity.kt index 69b317f0..46a2853b 100644 --- a/app/src/main/kotlin/org/fossify/clock/activities/MainActivity.kt +++ b/app/src/main/kotlin/org/fossify/clock/activities/MainActivity.kt @@ -56,6 +56,8 @@ import org.fossify.commons.helpers.LICENSE_RTL import org.fossify.commons.helpers.LICENSE_STETHO import org.fossify.commons.helpers.ensureBackgroundThread import org.fossify.commons.models.FAQItem +import java.time.temporal.WeekFields +import java.util.Locale class MainActivity : SimpleActivity() { private var storedTextColor = 0 @@ -407,11 +409,9 @@ class MainActivity : SimpleActivity() { @Deprecated("Remove this method in future releases") private fun migrateFirstDayOfWeek() { - // check existing config.isSundayFirst to migrate setting value - if (config.isSundayFirst) { - config.firstDayOfWeek = 6 - // revert old setting to not run this code anymore - config.isSundayFirst = false + if (config.migrateFirstDayOfWeek) { + config.migrateFirstDayOfWeek = false + config.firstDayOfWeek = WeekFields.of(Locale.getDefault()).firstDayOfWeek.value } } diff --git a/app/src/main/kotlin/org/fossify/clock/activities/SettingsActivity.kt b/app/src/main/kotlin/org/fossify/clock/activities/SettingsActivity.kt index b828e736..ecf61dd1 100644 --- a/app/src/main/kotlin/org/fossify/clock/activities/SettingsActivity.kt +++ b/app/src/main/kotlin/org/fossify/clock/activities/SettingsActivity.kt @@ -49,6 +49,7 @@ import org.fossify.commons.helpers.TAB_LAST_USED import org.fossify.commons.helpers.ensureBackgroundThread import org.fossify.commons.helpers.isTiramisuPlus import org.fossify.commons.models.RadioItem +import java.time.DayOfWeek import java.util.Locale import kotlin.system.exitProcess @@ -199,24 +200,31 @@ class SettingsActivity : SimpleActivity() { } private fun setupStartWeekOn() { - val items = arrayListOf( - RadioItem(6, getString(org.fossify.commons.R.string.sunday)), - RadioItem(0, getString(org.fossify.commons.R.string.monday)), - RadioItem(1, getString(org.fossify.commons.R.string.tuesday)), - RadioItem(2, getString(org.fossify.commons.R.string.wednesday)), - RadioItem(3, getString(org.fossify.commons.R.string.thursday)), - RadioItem(4, getString(org.fossify.commons.R.string.friday)), - RadioItem(5, getString(org.fossify.commons.R.string.saturday)), + binding.settingsStartWeekOn.text = resources.getStringArray( + org.fossify.commons.R.array.week_days + )[config.firstDayOfWeek - 1] + + val weekDays = arrayListOf( + RadioItem(DayOfWeek.SUNDAY.value, getString(org.fossify.commons.R.string.sunday)), + RadioItem(DayOfWeek.MONDAY.value, getString(org.fossify.commons.R.string.monday)), + RadioItem(DayOfWeek.TUESDAY.value, getString(org.fossify.commons.R.string.tuesday)), + RadioItem(DayOfWeek.WEDNESDAY.value, getString(org.fossify.commons.R.string.wednesday)), + RadioItem(DayOfWeek.THURSDAY.value, getString(org.fossify.commons.R.string.thursday)), + RadioItem(DayOfWeek.FRIDAY.value, getString(org.fossify.commons.R.string.friday)), + RadioItem(DayOfWeek.SATURDAY.value, getString(org.fossify.commons.R.string.saturday)), ) - binding.settingsStartWeekOn.text = - resources.getStringArray(org.fossify.commons.R.array.week_days)[config.firstDayOfWeek] binding.settingsStartWeekOnHolder.setOnClickListener { - RadioGroupDialog(this@SettingsActivity, items, config.firstDayOfWeek) { day -> + RadioGroupDialog( + activity = this, + items = weekDays, + checkedItemId = config.firstDayOfWeek + ) { day -> val firstDayOfWeek = day as Int config.firstDayOfWeek = firstDayOfWeek - binding.settingsStartWeekOn.text = - resources.getStringArray(org.fossify.commons.R.array.week_days)[config.firstDayOfWeek] + binding.settingsStartWeekOn.text = resources.getStringArray( + org.fossify.commons.R.array.week_days + )[config.firstDayOfWeek - 1] } } } diff --git a/app/src/main/kotlin/org/fossify/clock/dialogs/EditAlarmDialog.kt b/app/src/main/kotlin/org/fossify/clock/dialogs/EditAlarmDialog.kt index e9202140..f73bfaa7 100644 --- a/app/src/main/kotlin/org/fossify/clock/dialogs/EditAlarmDialog.kt +++ b/app/src/main/kotlin/org/fossify/clock/dialogs/EditAlarmDialog.kt @@ -17,7 +17,7 @@ import org.fossify.clock.extensions.config import org.fossify.clock.extensions.dbHelper import org.fossify.clock.extensions.getFormattedTime import org.fossify.clock.extensions.handleFullScreenNotificationsPermission -import org.fossify.clock.extensions.orderDaysList +import org.fossify.clock.extensions.rotateWeekdays import org.fossify.clock.helpers.PICK_AUDIO_FILE_INTENT_ID import org.fossify.clock.helpers.TODAY_BIT import org.fossify.clock.helpers.TOMORROW_BIT @@ -124,7 +124,7 @@ class EditAlarmDialog( val dayLetters = activity.resources.getStringArray(org.fossify.commons.R.array.week_day_letters) .toList() as ArrayList - val dayIndexes = activity.orderDaysList(arrayListOf(0, 1, 2, 3, 4, 5, 6)) + val dayIndexes = activity.rotateWeekdays(arrayListOf(0, 1, 2, 3, 4, 5, 6)) dayIndexes.forEach { val bitmask = 1 shl it diff --git a/app/src/main/kotlin/org/fossify/clock/extensions/Context.kt b/app/src/main/kotlin/org/fossify/clock/extensions/Context.kt index ceb7432f..00819e1a 100644 --- a/app/src/main/kotlin/org/fossify/clock/extensions/Context.kt +++ b/app/src/main/kotlin/org/fossify/clock/extensions/Context.kt @@ -28,7 +28,6 @@ import org.fossify.clock.helpers.ALARM_ID import org.fossify.clock.helpers.AlarmController import org.fossify.clock.helpers.Config import org.fossify.clock.helpers.DBHelper -import org.fossify.clock.helpers.UPCOMING_ALARM_INTENT_ID import org.fossify.clock.helpers.EDITED_TIME_ZONE_SEPARATOR import org.fossify.clock.helpers.FORMAT_12H import org.fossify.clock.helpers.FORMAT_24H @@ -45,6 +44,7 @@ import org.fossify.clock.helpers.TIMER_ID import org.fossify.clock.helpers.TODAY_BIT import org.fossify.clock.helpers.TOMORROW_BIT import org.fossify.clock.helpers.TimerHelper +import org.fossify.clock.helpers.UPCOMING_ALARM_INTENT_ID import org.fossify.clock.helpers.formatTime import org.fossify.clock.helpers.getAllTimeZones import org.fossify.clock.helpers.getDefaultTimeZoneTitle @@ -69,6 +69,7 @@ import org.fossify.commons.extensions.getProperPrimaryColor import org.fossify.commons.extensions.getSelectedDaysString import org.fossify.commons.extensions.grantReadUriPermission import org.fossify.commons.extensions.notificationManager +import org.fossify.commons.extensions.rotateLeft import org.fossify.commons.extensions.showErrorToast import org.fossify.commons.extensions.toInt import org.fossify.commons.extensions.toast @@ -566,24 +567,17 @@ fun Context.getAlarmSelectedDaysString(bitMask: Int): String { TODAY_BIT -> getString(org.fossify.commons.R.string.today) TOMORROW_BIT -> getString(org.fossify.commons.R.string.tomorrow) EVERY_DAY_BIT -> getString(org.fossify.commons.R.string.every_day) - else -> getSelectedDaysString(bitMask) + else -> getSelectedDaysString(bitMask) // TODO: This does not respect config.firstDayOfWeek } } -fun Context.orderDaysList(days: List): List { - if (config.firstDayOfWeek > 0) { - val range = (config.firstDayOfWeek..6).toList() + (0..) = days.rotateLeft(config.firstDayOfWeek - 1) fun Context.firstDayOrder(bitMask: Int): Int { if (bitMask == TODAY_BIT) return -2 if (bitMask == TOMORROW_BIT) return -1 - val dayBits = orderDaysList( + val dayBits = rotateWeekdays( arrayListOf( MONDAY_BIT, TUESDAY_BIT, diff --git a/app/src/main/kotlin/org/fossify/clock/helpers/Config.kt b/app/src/main/kotlin/org/fossify/clock/helpers/Config.kt index 9a545bea..e9d8939d 100644 --- a/app/src/main/kotlin/org/fossify/clock/helpers/Config.kt +++ b/app/src/main/kotlin/org/fossify/clock/helpers/Config.kt @@ -2,6 +2,7 @@ package org.fossify.clock.helpers import android.content.Context import android.media.RingtoneManager +import androidx.core.content.edit import org.fossify.clock.extensions.gson.gson import org.fossify.clock.models.Alarm import org.fossify.clock.models.ObfuscatedAlarm @@ -11,8 +12,6 @@ import org.fossify.commons.extensions.getDefaultAlarmSound import org.fossify.commons.extensions.getDefaultAlarmTitle import org.fossify.commons.helpers.BaseConfig import org.fossify.commons.helpers.SORT_DESCENDING -import java.util.Calendar -import java.util.Locale class Config(context: Context) : BaseConfig(context) { companion object { @@ -21,11 +20,13 @@ class Config(context: Context) : BaseConfig(context) { var selectedTimeZones: Set get() = prefs.getStringSet(SELECTED_TIME_ZONES, HashSet())!! - set(selectedTimeZones) = prefs.edit().putStringSet(SELECTED_TIME_ZONES, selectedTimeZones).apply() + set(selectedTimeZones) = prefs.edit().putStringSet(SELECTED_TIME_ZONES, selectedTimeZones) + .apply() var editedTimeZoneTitles: Set get() = prefs.getStringSet(EDITED_TIME_ZONE_TITLES, HashSet())!! - set(editedTimeZoneTitles) = prefs.edit().putStringSet(EDITED_TIME_ZONE_TITLES, editedTimeZoneTitles).apply() + set(editedTimeZoneTitles) = prefs.edit() + .putStringSet(EDITED_TIME_ZONE_TITLES, editedTimeZoneTitles).apply() var timerSeconds: Int get() = prefs.getInt(TIMER_SECONDS, 300) @@ -36,16 +37,23 @@ class Config(context: Context) : BaseConfig(context) { set(timerVibrate) = prefs.edit().putBoolean(TIMER_VIBRATE, timerVibrate).apply() var timerSoundUri: String - get() = prefs.getString(TIMER_SOUND_URI, context.getDefaultAlarmSound(RingtoneManager.TYPE_ALARM).uri)!! + get() = prefs.getString( + TIMER_SOUND_URI, + context.getDefaultAlarmSound(RingtoneManager.TYPE_ALARM).uri + )!! set(timerSoundUri) = prefs.edit().putString(TIMER_SOUND_URI, timerSoundUri).apply() var timerSoundTitle: String - get() = prefs.getString(TIMER_SOUND_TITLE, context.getDefaultAlarmTitle(RingtoneManager.TYPE_ALARM))!! + get() = prefs.getString( + TIMER_SOUND_TITLE, + context.getDefaultAlarmTitle(RingtoneManager.TYPE_ALARM) + )!! set(timerSoundTitle) = prefs.edit().putString(TIMER_SOUND_TITLE, timerSoundTitle).apply() var timerMaxReminderSecs: Int get() = prefs.getInt(TIMER_MAX_REMINDER_SECS, DEFAULT_MAX_TIMER_REMINDER_SECS) - set(timerMaxReminderSecs) = prefs.edit().putInt(TIMER_MAX_REMINDER_SECS, timerMaxReminderSecs).apply() + set(timerMaxReminderSecs) = prefs.edit() + .putInt(TIMER_MAX_REMINDER_SECS, timerMaxReminderSecs).apply() var timerLabel: String? get() = prefs.getString(TIMER_LABEL, null) @@ -61,7 +69,8 @@ class Config(context: Context) : BaseConfig(context) { var alarmsCustomSorting: String get() = prefs.getString(ALARMS_CUSTOM_SORTING, "")!! - set(alarmsCustomSorting) = prefs.edit().putString(ALARMS_CUSTOM_SORTING, alarmsCustomSorting).apply() + set(alarmsCustomSorting) = prefs.edit() + .putString(ALARMS_CUSTOM_SORTING, alarmsCustomSorting).apply() var timerSort: Int get() = prefs.getInt(TIMERS_SORT_BY, SORT_BY_CREATION_ORDER) @@ -69,15 +78,18 @@ class Config(context: Context) : BaseConfig(context) { var timersCustomSorting: String get() = prefs.getString(TIMERS_CUSTOM_SORTING, "")!! - set(timersCustomSorting) = prefs.edit().putString(TIMERS_CUSTOM_SORTING, timersCustomSorting).apply() + set(timersCustomSorting) = prefs.edit() + .putString(TIMERS_CUSTOM_SORTING, timersCustomSorting).apply() var alarmMaxReminderSecs: Int get() = prefs.getInt(ALARM_MAX_REMINDER_SECS, DEFAULT_MAX_ALARM_REMINDER_SECS) - set(alarmMaxReminderSecs) = prefs.edit().putInt(ALARM_MAX_REMINDER_SECS, alarmMaxReminderSecs).apply() + set(alarmMaxReminderSecs) = prefs.edit() + .putInt(ALARM_MAX_REMINDER_SECS, alarmMaxReminderSecs).apply() var increaseVolumeGradually: Boolean get() = prefs.getBoolean(INCREASE_VOLUME_GRADUALLY, true) - set(increaseVolumeGradually) = prefs.edit().putBoolean(INCREASE_VOLUME_GRADUALLY, increaseVolumeGradually).apply() + set(increaseVolumeGradually) = prefs.edit() + .putBoolean(INCREASE_VOLUME_GRADUALLY, increaseVolumeGradually).apply() var alarmLastConfig: Alarm? get() = prefs.getString(ALARM_LAST_CONFIG, null)?.let { lastAlarm -> @@ -113,20 +125,23 @@ class Config(context: Context) : BaseConfig(context) { var stopwatchLapsSort: Int get() = prefs.getInt(STOPWATCH_LAPS_SORT_BY, SORT_BY_LAP or SORT_DESCENDING) - set(stopwatchLapsSort) = prefs.edit().putInt(STOPWATCH_LAPS_SORT_BY, stopwatchLapsSort).apply() + set(stopwatchLapsSort) = prefs.edit().putInt(STOPWATCH_LAPS_SORT_BY, stopwatchLapsSort) + .apply() var wasInitialWidgetSetUp: Boolean get() = prefs.getBoolean(WAS_INITIAL_WIDGET_SET_UP, false) - set(wasInitialWidgetSetUp) = prefs.edit().putBoolean(WAS_INITIAL_WIDGET_SET_UP, wasInitialWidgetSetUp).apply() + set(wasInitialWidgetSetUp) = prefs.edit() + .putBoolean(WAS_INITIAL_WIDGET_SET_UP, wasInitialWidgetSetUp).apply() var lastDataExportPath: String get() = prefs.getString(LAST_DATA_EXPORT_PATH, "")!! - set(lastDataExportPath) = prefs.edit().putString(LAST_DATA_EXPORT_PATH, lastDataExportPath).apply() - - var firstDayOfWeek: Int - get() { - val defaultFirstDayOfWeek = Calendar.getInstance(Locale.getDefault()).firstDayOfWeek - return prefs.getInt(FIRST_DAY_OF_WEEK, getDayNumber(defaultFirstDayOfWeek)) + set(lastDataExportPath) = prefs.edit().putString(LAST_DATA_EXPORT_PATH, lastDataExportPath) + .apply() + + @Deprecated("Remove this method in future releases") + var migrateFirstDayOfWeek: Boolean + get() = prefs.getBoolean(MIGRATE_FIRST_DAY_OF_WEEK, true) + set(migrateFirstDayOfWeek) = prefs.edit { + putBoolean(MIGRATE_FIRST_DAY_OF_WEEK, migrateFirstDayOfWeek) } - set(firstDayOfWeek) = prefs.edit().putInt(FIRST_DAY_OF_WEEK, firstDayOfWeek).apply() } diff --git a/app/src/main/kotlin/org/fossify/clock/helpers/Constants.kt b/app/src/main/kotlin/org/fossify/clock/helpers/Constants.kt index 74287bf5..9477e94e 100644 --- a/app/src/main/kotlin/org/fossify/clock/helpers/Constants.kt +++ b/app/src/main/kotlin/org/fossify/clock/helpers/Constants.kt @@ -40,7 +40,7 @@ const val STOPWATCH_LAPS_SORT_BY = "stopwatch_laps_sort_by" const val WAS_INITIAL_WIDGET_SET_UP = "was_initial_widget_set_up" const val DATA_EXPORT_EXTENSION = ".json" const val LAST_DATA_EXPORT_PATH = "last_alarms_export_path" -const val FIRST_DAY_OF_WEEK = "first_day_of_week" +const val MIGRATE_FIRST_DAY_OF_WEEK = "migrate_first_day_of_week" const val TABS_COUNT = 4 const val EDITED_TIME_ZONE_SEPARATOR = ":" @@ -100,7 +100,7 @@ const val FORMAT_24H = "HH:mm" const val FORMAT_12H_WITH_SECONDS = "h:mm:ss a" const val FORMAT_24H_WITH_SECONDS = "HH:mm:ss" -val DAY_BIT_MAP = mapOf( +private val DAY_BIT_MAP = mapOf( Calendar.SUNDAY to SUNDAY_BIT, Calendar.MONDAY to MONDAY_BIT, Calendar.TUESDAY to TUESDAY_BIT, diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 357c7bcd..32d49efd 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -22,7 +22,7 @@ numberpicker = "2.4.13" #Room room = "2.6.1" #Fossify -commons = "5c9248f16e" +commons = "b3897c7e30" #Stetho stetho = "1.6.0" #Gradle From 2ed7964375e4567a2f6e949d88b8564d82dd3d4c Mon Sep 17 00:00:00 2001 From: Naveen Singh Date: Sun, 30 Mar 2025 07:49:05 +0530 Subject: [PATCH 4/4] Switch to KTX extension for preferences --- .../org/fossify/clock/helpers/Config.kt | 72 ++++++++++--------- 1 file changed, 39 insertions(+), 33 deletions(-) diff --git a/app/src/main/kotlin/org/fossify/clock/helpers/Config.kt b/app/src/main/kotlin/org/fossify/clock/helpers/Config.kt index e9d8939d..1839bfcc 100644 --- a/app/src/main/kotlin/org/fossify/clock/helpers/Config.kt +++ b/app/src/main/kotlin/org/fossify/clock/helpers/Config.kt @@ -20,76 +20,81 @@ class Config(context: Context) : BaseConfig(context) { var selectedTimeZones: Set get() = prefs.getStringSet(SELECTED_TIME_ZONES, HashSet())!! - set(selectedTimeZones) = prefs.edit().putStringSet(SELECTED_TIME_ZONES, selectedTimeZones) - .apply() + set(selectedTimeZones) = prefs.edit { putStringSet(SELECTED_TIME_ZONES, selectedTimeZones) } var editedTimeZoneTitles: Set get() = prefs.getStringSet(EDITED_TIME_ZONE_TITLES, HashSet())!! - set(editedTimeZoneTitles) = prefs.edit() - .putStringSet(EDITED_TIME_ZONE_TITLES, editedTimeZoneTitles).apply() + set(editedTimeZoneTitles) = prefs.edit { + putStringSet(EDITED_TIME_ZONE_TITLES, editedTimeZoneTitles) + } var timerSeconds: Int get() = prefs.getInt(TIMER_SECONDS, 300) - set(lastTimerSeconds) = prefs.edit().putInt(TIMER_SECONDS, lastTimerSeconds).apply() + set(lastTimerSeconds) = prefs.edit { putInt(TIMER_SECONDS, lastTimerSeconds) } var timerVibrate: Boolean get() = prefs.getBoolean(TIMER_VIBRATE, false) - set(timerVibrate) = prefs.edit().putBoolean(TIMER_VIBRATE, timerVibrate).apply() + set(timerVibrate) = prefs.edit { putBoolean(TIMER_VIBRATE, timerVibrate) } var timerSoundUri: String get() = prefs.getString( TIMER_SOUND_URI, context.getDefaultAlarmSound(RingtoneManager.TYPE_ALARM).uri )!! - set(timerSoundUri) = prefs.edit().putString(TIMER_SOUND_URI, timerSoundUri).apply() + set(timerSoundUri) = prefs.edit { putString(TIMER_SOUND_URI, timerSoundUri) } var timerSoundTitle: String get() = prefs.getString( TIMER_SOUND_TITLE, context.getDefaultAlarmTitle(RingtoneManager.TYPE_ALARM) )!! - set(timerSoundTitle) = prefs.edit().putString(TIMER_SOUND_TITLE, timerSoundTitle).apply() + set(timerSoundTitle) = prefs.edit { putString(TIMER_SOUND_TITLE, timerSoundTitle) } var timerMaxReminderSecs: Int get() = prefs.getInt(TIMER_MAX_REMINDER_SECS, DEFAULT_MAX_TIMER_REMINDER_SECS) - set(timerMaxReminderSecs) = prefs.edit() - .putInt(TIMER_MAX_REMINDER_SECS, timerMaxReminderSecs).apply() + set(timerMaxReminderSecs) = prefs.edit { + putInt(TIMER_MAX_REMINDER_SECS, timerMaxReminderSecs) + } var timerLabel: String? get() = prefs.getString(TIMER_LABEL, null) - set(label) = prefs.edit().putString(TIMER_LABEL, label).apply() + set(label) = prefs.edit { putString(TIMER_LABEL, label) } var toggleStopwatch: Boolean get() = prefs.getBoolean(TOGGLE_STOPWATCH, false) - set(toggleStopwatch) = prefs.edit().putBoolean(TOGGLE_STOPWATCH, toggleStopwatch).apply() + set(toggleStopwatch) = prefs.edit { putBoolean(TOGGLE_STOPWATCH, toggleStopwatch) } var alarmSort: Int get() = prefs.getInt(ALARMS_SORT_BY, SORT_BY_CREATION_ORDER) - set(alarmSort) = prefs.edit().putInt(ALARMS_SORT_BY, alarmSort).apply() + set(alarmSort) = prefs.edit { putInt(ALARMS_SORT_BY, alarmSort) } var alarmsCustomSorting: String get() = prefs.getString(ALARMS_CUSTOM_SORTING, "")!! - set(alarmsCustomSorting) = prefs.edit() - .putString(ALARMS_CUSTOM_SORTING, alarmsCustomSorting).apply() + set(alarmsCustomSorting) = prefs.edit { + putString(ALARMS_CUSTOM_SORTING, alarmsCustomSorting) + } var timerSort: Int get() = prefs.getInt(TIMERS_SORT_BY, SORT_BY_CREATION_ORDER) - set(timerSort) = prefs.edit().putInt(TIMERS_SORT_BY, timerSort).apply() + set(timerSort) = prefs.edit { putInt(TIMERS_SORT_BY, timerSort) } var timersCustomSorting: String get() = prefs.getString(TIMERS_CUSTOM_SORTING, "")!! - set(timersCustomSorting) = prefs.edit() - .putString(TIMERS_CUSTOM_SORTING, timersCustomSorting).apply() + set(timersCustomSorting) = prefs.edit { + putString(TIMERS_CUSTOM_SORTING, timersCustomSorting) + } var alarmMaxReminderSecs: Int get() = prefs.getInt(ALARM_MAX_REMINDER_SECS, DEFAULT_MAX_ALARM_REMINDER_SECS) - set(alarmMaxReminderSecs) = prefs.edit() - .putInt(ALARM_MAX_REMINDER_SECS, alarmMaxReminderSecs).apply() + set(alarmMaxReminderSecs) = prefs.edit { + putInt(ALARM_MAX_REMINDER_SECS, alarmMaxReminderSecs) + } var increaseVolumeGradually: Boolean get() = prefs.getBoolean(INCREASE_VOLUME_GRADUALLY, true) - set(increaseVolumeGradually) = prefs.edit() - .putBoolean(INCREASE_VOLUME_GRADUALLY, increaseVolumeGradually).apply() + set(increaseVolumeGradually) = prefs.edit { + putBoolean(INCREASE_VOLUME_GRADUALLY, increaseVolumeGradually) + } var alarmLastConfig: Alarm? get() = prefs.getString(ALARM_LAST_CONFIG, null)?.let { lastAlarm -> @@ -99,11 +104,11 @@ class Config(context: Context) : BaseConfig(context) { } else { gson.fromJson(lastAlarm, Alarm::class.java) } - } catch (e: Exception) { + } catch (_: Exception) { null } } - set(alarm) = prefs.edit().putString(ALARM_LAST_CONFIG, gson.toJson(alarm)).apply() + set(alarm) = prefs.edit { putString(ALARM_LAST_CONFIG, gson.toJson(alarm)) } var timerLastConfig: Timer? get() = prefs.getString(TIMER_LAST_CONFIG, null)?.let { lastTimer -> @@ -113,30 +118,31 @@ class Config(context: Context) : BaseConfig(context) { } else { gson.fromJson(lastTimer, Timer::class.java) } - } catch (e: Exception) { + } catch (_: Exception) { null } } - set(timer) = prefs.edit().putString(TIMER_LAST_CONFIG, gson.toJson(timer)).apply() + set(timer) = prefs.edit { putString(TIMER_LAST_CONFIG, gson.toJson(timer)) } var timerChannelId: String? get() = prefs.getString(TIMER_CHANNEL_ID, null) - set(id) = prefs.edit().putString(TIMER_CHANNEL_ID, id).apply() + set(id) = prefs.edit { putString(TIMER_CHANNEL_ID, id) } var stopwatchLapsSort: Int get() = prefs.getInt(STOPWATCH_LAPS_SORT_BY, SORT_BY_LAP or SORT_DESCENDING) - set(stopwatchLapsSort) = prefs.edit().putInt(STOPWATCH_LAPS_SORT_BY, stopwatchLapsSort) - .apply() + set(stopwatchLapsSort) = prefs.edit { putInt(STOPWATCH_LAPS_SORT_BY, stopwatchLapsSort) } var wasInitialWidgetSetUp: Boolean get() = prefs.getBoolean(WAS_INITIAL_WIDGET_SET_UP, false) - set(wasInitialWidgetSetUp) = prefs.edit() - .putBoolean(WAS_INITIAL_WIDGET_SET_UP, wasInitialWidgetSetUp).apply() + set(wasInitialWidgetSetUp) = prefs.edit { + putBoolean(WAS_INITIAL_WIDGET_SET_UP, wasInitialWidgetSetUp) + } var lastDataExportPath: String get() = prefs.getString(LAST_DATA_EXPORT_PATH, "")!! - set(lastDataExportPath) = prefs.edit().putString(LAST_DATA_EXPORT_PATH, lastDataExportPath) - .apply() + set(lastDataExportPath) = prefs.edit { + putString(LAST_DATA_EXPORT_PATH, lastDataExportPath) + } @Deprecated("Remove this method in future releases") var migrateFirstDayOfWeek: Boolean