Switch to KTX extension for preferences

This commit is contained in:
Naveen Singh
2025-03-30 07:49:05 +05:30
parent 0075e5beae
commit 2ed7964375

View File

@@ -20,76 +20,81 @@ class Config(context: Context) : BaseConfig(context) {
var selectedTimeZones: Set<String>
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<String>
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