-
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Move alarm settings page into its own nav destination
- Loading branch information
1 parent
87a5a52
commit 19bc6fd
Showing
14 changed files
with
507 additions
and
368 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
app/src/main/java/com/bnyro/clock/domain/usecase/CreateUpdateDeleteAlarmUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.bnyro.clock.domain.usecase | ||
|
||
import android.content.Context | ||
import com.bnyro.clock.data.database.DatabaseHolder | ||
import com.bnyro.clock.domain.model.Alarm | ||
import com.bnyro.clock.util.AlarmHelper | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.withContext | ||
|
||
class CreateUpdateDeleteAlarmUseCase(private val context: Context) { | ||
suspend fun createAlarm(alarm: Alarm) { | ||
alarm.enabled = true | ||
AlarmHelper.enqueue(context, alarm) | ||
withContext(Dispatchers.IO) { | ||
DatabaseHolder.instance.alarmsDao().insert(alarm) | ||
} | ||
} | ||
|
||
suspend fun updateAlarm(alarm: Alarm) { | ||
AlarmHelper.enqueue(context, alarm) | ||
withContext(Dispatchers.IO) { | ||
DatabaseHolder.instance.alarmsDao().update(alarm) | ||
} | ||
} | ||
|
||
suspend fun deleteAlarm(alarm: Alarm) { | ||
AlarmHelper.cancel(context, alarm) | ||
withContext(Dispatchers.IO) { | ||
DatabaseHolder.instance.alarmsDao().delete(alarm) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,16 @@ | ||
package com.bnyro.clock.navigation | ||
|
||
import androidx.navigation.NavType | ||
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 }) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.