From 4dc1aada3f7f3eb6355a4e31784ce5a5f325e739 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Mon, 28 Oct 2024 17:22:23 +0100 Subject: [PATCH] chore: some code cleanups --- .../java/com/bnyro/clock/navigation/NavRoutes.kt | 14 +++++++------- .../screens/alarm/components/TimePickerDialog.kt | 2 +- .../screens/alarmpicker/model/AlarmPickerModel.kt | 8 ++++---- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/com/bnyro/clock/navigation/NavRoutes.kt b/app/src/main/java/com/bnyro/clock/navigation/NavRoutes.kt index fff55a8d..3a1841a4 100644 --- a/app/src/main/java/com/bnyro/clock/navigation/NavRoutes.kt +++ b/app/src/main/java/com/bnyro/clock/navigation/NavRoutes.kt @@ -6,13 +6,13 @@ import androidx.navigation.navArgument sealed class NavRoutes( val route: String ) { - object Home : NavRoutes("home") - object Settings : NavRoutes("settings") - object AlarmPicker : NavRoutes("alarmPicker") { - const val alarmId = "alarmId" - val routeWithArgs = "$route/{$alarmId}" - val args = listOf(navArgument(alarmId) { NavType.LongType }) + data object Home : NavRoutes("home") + data object Settings : NavRoutes("settings") + data object AlarmPicker : NavRoutes("alarmPicker") { + const val ALARM_ID = "alarmId" + val routeWithArgs = "$route/{$ALARM_ID}" + val args = listOf(navArgument(ALARM_ID) { NavType.LongType }) } - object Permissions : NavRoutes("permissions") + data object Permissions : NavRoutes("permissions") } \ No newline at end of file diff --git a/app/src/main/java/com/bnyro/clock/presentation/screens/alarm/components/TimePickerDialog.kt b/app/src/main/java/com/bnyro/clock/presentation/screens/alarm/components/TimePickerDialog.kt index c8b6cdf2..f6678f0c 100644 --- a/app/src/main/java/com/bnyro/clock/presentation/screens/alarm/components/TimePickerDialog.kt +++ b/app/src/main/java/com/bnyro/clock/presentation/screens/alarm/components/TimePickerDialog.kt @@ -44,7 +44,7 @@ fun TimePickerDialog( initialHour = initialTime?.hours ?: 0, initialMinute = initialTime?.minutes ?: 0 ) - var keyboardPickerState by remember { + val keyboardPickerState by remember { mutableStateOf(KeyboardPickerState()) } diff --git a/app/src/main/java/com/bnyro/clock/presentation/screens/alarmpicker/model/AlarmPickerModel.kt b/app/src/main/java/com/bnyro/clock/presentation/screens/alarmpicker/model/AlarmPickerModel.kt index d1669c20..595519a1 100644 --- a/app/src/main/java/com/bnyro/clock/presentation/screens/alarmpicker/model/AlarmPickerModel.kt +++ b/app/src/main/java/com/bnyro/clock/presentation/screens/alarmpicker/model/AlarmPickerModel.kt @@ -20,7 +20,7 @@ import kotlin.time.Duration.Companion.milliseconds class AlarmPickerModel(application: Application, savedStateHandle: SavedStateHandle) : AndroidViewModel(application) { - private val id: String? = savedStateHandle[NavRoutes.AlarmPicker.alarmId] + private val id: String? = savedStateHandle[NavRoutes.AlarmPicker.ALARM_ID] private val alarmRepository = (application as App).container.alarmRepository private val createUpdateDeleteAlarmUseCase = @@ -30,10 +30,10 @@ class AlarmPickerModel(application: Application, savedStateHandle: SavedStateHan init { val alarmId = id?.toLong() ?: 0L - if (alarmId == 0L) { - alarm = Alarm(time = 0) + alarm = if (alarmId == 0L) { + Alarm(time = 0) } else { - alarm = runBlocking(Dispatchers.IO) { + runBlocking(Dispatchers.IO) { alarmRepository.getAlarmById(alarmId) } }