From 1a52bf53b966ec228352222d4d79991c940c0cf8 Mon Sep 17 00:00:00 2001 From: Nishant Mishra Date: Sat, 29 Nov 2025 20:47:36 +0530 Subject: [PATCH] feat(aod): make aod movement more subtle to avoid distraction Closes: #128 --- .../org/nsh07/pomodoro/ui/AlwaysOnDisplay.kt | 28 +++++++++---------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/org/nsh07/pomodoro/ui/AlwaysOnDisplay.kt b/app/src/main/java/org/nsh07/pomodoro/ui/AlwaysOnDisplay.kt index bc43cf1..e3cc1ea 100644 --- a/app/src/main/java/org/nsh07/pomodoro/ui/AlwaysOnDisplay.kt +++ b/app/src/main/java/org/nsh07/pomodoro/ui/AlwaysOnDisplay.kt @@ -23,7 +23,6 @@ import androidx.activity.compose.LocalActivity import androidx.compose.animation.SharedTransitionLayout import androidx.compose.animation.SharedTransitionScope import androidx.compose.animation.animateColorAsState -import androidx.compose.animation.core.animateIntAsState import androidx.compose.foundation.background import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.fillMaxSize @@ -159,7 +158,7 @@ fun SharedTransitionScope.AlwaysOnDisplay( animationSpec = motionScheme.slowEffectsSpec() ) - var randomX by remember { + var x by remember { mutableIntStateOf( Random.nextInt( 16.dp.toIntPx(density), @@ -167,7 +166,7 @@ fun SharedTransitionScope.AlwaysOnDisplay( ) ) } - var randomY by remember { + var y by remember { mutableIntStateOf( Random.nextInt( 16.dp.toIntPx(density), @@ -176,22 +175,21 @@ fun SharedTransitionScope.AlwaysOnDisplay( ) } - LaunchedEffect(timerState.timeStr[1]) { // Randomize position every minute + var xIncrement by remember { mutableIntStateOf(1) } + var yIncrement by remember { mutableIntStateOf(1) } + + LaunchedEffect(timerState.timeStr) { // Randomize position every minute if (sharedElementTransitionComplete) { - randomX = Random.nextInt( - 16.dp.toIntPx(density), - windowInfo.containerSize.width - 266.dp.toIntPx(density) - ) - randomY = Random.nextInt( - 16.dp.toIntPx(density), - windowInfo.containerSize.height - 266.dp.toIntPx(density) - ) + val elementSize = 266.dp.toIntPx(density) + if (windowInfo.containerSize.width - elementSize < x + xIncrement || x + xIncrement < 16) + xIncrement = -xIncrement + if (windowInfo.containerSize.height - elementSize < y + yIncrement || y + yIncrement < 16) + yIncrement = -yIncrement + x += xIncrement + y += yIncrement } } - val x by animateIntAsState(randomX, motionScheme.slowSpatialSpec()) - val y by animateIntAsState(randomY, motionScheme.slowSpatialSpec()) - Box( modifier = modifier .fillMaxSize()