From 4a1d54ce3f9301783d6d7021a6e06bffc4547c47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20de=20Souza?= Date: Fri, 29 Mar 2024 18:16:08 +0100 Subject: [PATCH] Replace `if` with `when` in `LeaningSideHandler` --- .../blitz/ui/components/LeaningSideHandler.kt | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/app/src/main/kotlin/net/leodesouza/blitz/ui/components/LeaningSideHandler.kt b/app/src/main/kotlin/net/leodesouza/blitz/ui/components/LeaningSideHandler.kt index 79322cf..a352615 100644 --- a/app/src/main/kotlin/net/leodesouza/blitz/ui/components/LeaningSideHandler.kt +++ b/app/src/main/kotlin/net/leodesouza/blitz/ui/components/LeaningSideHandler.kt @@ -23,8 +23,8 @@ enum class LeaningSide { LEFT, RIGHT } /** * Call [onLeaningSideChanged] when the side that the device is currently leaning towards, which is - * calculated from the orientation in degrees returned by [orientationProvider], changes from the - * current [LeaningSide] that is returned by [leaningSideProvider]. + * calculated from the orientation in degrees returned by [orientationProvider], becomes different + * to the [LeaningSide] that is returned by [leaningSideProvider]. */ @Composable fun LeaningSideHandler( @@ -35,9 +35,8 @@ fun LeaningSideHandler( val orientation = orientationProvider() val leaningSide = leaningSideProvider() - val isChangingFromLeftToRight = leaningSide == LeaningSide.LEFT && orientation in 10 until 170 - val isChangingFromRightToLeft = leaningSide == LeaningSide.RIGHT && orientation in 190 until 350 - if (isChangingFromLeftToRight || isChangingFromRightToLeft) { - onLeaningSideChanged() + when (leaningSide) { + LeaningSide.LEFT -> if (orientation in 10 until 170) onLeaningSideChanged() + LeaningSide.RIGHT -> if (orientation in 190 until 350) onLeaningSideChanged() } }