diff --git a/JetLagged/app/build.gradle.kts b/JetLagged/app/build.gradle.kts index 2c04303b04..5b69f279ed 100644 --- a/JetLagged/app/build.gradle.kts +++ b/JetLagged/app/build.gradle.kts @@ -117,7 +117,8 @@ dependencies { implementation(libs.androidx.compose.material3) implementation(libs.androidx.compose.animation) implementation(libs.androidx.compose.material.iconsExtended) - implementation(libs.androidx.compose.materialWindow) + + implementation(libs.androidx.compose.material3.adaptive) implementation(libs.androidx.compose.ui.googlefonts) implementation(libs.androidx.compose.ui.tooling.preview) debugImplementation(libs.androidx.compose.ui.tooling) diff --git a/JetLagged/app/src/main/java/com/example/jetlagged/HomeScreenCards.kt b/JetLagged/app/src/main/java/com/example/jetlagged/HomeScreenCards.kt index fd9718b401..d7d8d9c771 100644 --- a/JetLagged/app/src/main/java/com/example/jetlagged/HomeScreenCards.kt +++ b/JetLagged/app/src/main/java/com/example/jetlagged/HomeScreenCards.kt @@ -22,7 +22,6 @@ import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.BoxWithConstraints import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.ExperimentalLayoutApi -import androidx.compose.foundation.layout.FlowRow import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.aspectRatio @@ -210,7 +209,7 @@ fun WellnessCard( borderColor = JetLaggedTheme.extraColors.wellness, modifier = modifier .widthIn(max = 400.dp) - .heightIn(min = 200.dp) + .heightIn(min = 100.dp, max = 200.dp) ) { FadingCircleBackground(36.dp, JetLaggedTheme.extraColors.wellness.copy(0.25f)) Column( @@ -219,9 +218,8 @@ fun WellnessCard( .fillMaxWidth() ) { HomeScreenCardHeading(text = stringResource(R.string.wellness_heading)) - FlowRow( + Row( horizontalArrangement = Arrangement.Center, - verticalArrangement = Arrangement.Center, modifier = Modifier.fillMaxHeight() ) { WellnessBubble( diff --git a/JetLagged/app/src/main/java/com/example/jetlagged/JetLaggedDrawer.kt b/JetLagged/app/src/main/java/com/example/jetlagged/JetLaggedDrawer.kt index 9277d1af5f..6df6025cdf 100644 --- a/JetLagged/app/src/main/java/com/example/jetlagged/JetLaggedDrawer.kt +++ b/JetLagged/app/src/main/java/com/example/jetlagged/JetLaggedDrawer.kt @@ -39,8 +39,6 @@ import androidx.compose.material3.Icon import androidx.compose.material3.NavigationDrawerItem import androidx.compose.material3.Surface import androidx.compose.material3.Text -import androidx.compose.material3.windowsizeclass.WindowSizeClass -import androidx.compose.material3.windowsizeclass.WindowWidthSizeClass import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf @@ -55,6 +53,8 @@ import androidx.compose.ui.input.pointer.util.VelocityTracker import androidx.compose.ui.platform.LocalDensity import androidx.compose.ui.unit.dp import androidx.compose.ui.util.lerp +import androidx.window.core.layout.WindowSizeClass +import androidx.window.core.layout.WindowWidthSizeClass import kotlin.coroutines.cancellation.CancellationException import kotlinx.coroutines.launch @@ -133,7 +133,7 @@ fun HomeScreenDrawer(windowSizeClass: WindowSizeClass) { }) val decay = rememberSplineBasedDecay() ScreenContents( - windowWidthSizeClass = windowSizeClass.widthSizeClass, + windowWidthSizeClass = windowSizeClass.windowWidthSizeClass, selectedScreen = screenState, onDrawerClicked = ::toggleDrawerState, modifier = Modifier diff --git a/JetLagged/app/src/main/java/com/example/jetlagged/JetLaggedScreen.kt b/JetLagged/app/src/main/java/com/example/jetlagged/JetLaggedScreen.kt index 05ce288c26..41e7fa830b 100644 --- a/JetLagged/app/src/main/java/com/example/jetlagged/JetLaggedScreen.kt +++ b/JetLagged/app/src/main/java/com/example/jetlagged/JetLaggedScreen.kt @@ -16,6 +16,11 @@ package com.example.jetlagged +import androidx.compose.animation.ExperimentalSharedTransitionApi +import androidx.compose.animation.animateBounds +import androidx.compose.animation.core.Spring +import androidx.compose.animation.core.VisibilityThreshold +import androidx.compose.animation.core.spring import androidx.compose.foundation.background import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column @@ -34,12 +39,16 @@ import androidx.compose.foundation.layout.windowInsetsPadding import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.verticalScroll import androidx.compose.material3.MaterialTheme -import androidx.compose.material3.windowsizeclass.WindowWidthSizeClass import androidx.compose.runtime.Composable +import androidx.compose.runtime.movableContentOf +import androidx.compose.runtime.remember import androidx.compose.ui.Modifier +import androidx.compose.ui.geometry.Rect +import androidx.compose.ui.layout.LookaheadScope import androidx.compose.ui.unit.dp import androidx.lifecycle.compose.collectAsStateWithLifecycle import androidx.lifecycle.viewmodel.compose.viewModel +import androidx.window.core.layout.WindowWidthSizeClass import com.example.jetlagged.backgrounds.movingStripesBackground import com.example.jetlagged.data.JetLaggedHomeScreenViewModel import com.example.jetlagged.heartrate.HeartRateCard @@ -48,12 +57,12 @@ import com.example.jetlagged.sleep.JetLaggedSleepGraphCard import com.example.jetlagged.ui.theme.JetLaggedTheme import com.example.jetlagged.ui.util.MultiDevicePreview -@OptIn(ExperimentalLayoutApi::class) +@OptIn(ExperimentalLayoutApi::class, ExperimentalSharedTransitionApi::class) @MultiDevicePreview @Composable fun JetLaggedScreen( modifier: Modifier = Modifier, - windowSizeClass: WindowWidthSizeClass = WindowWidthSizeClass.Compact, + windowSizeClass: WindowWidthSizeClass = WindowWidthSizeClass.COMPACT, viewModel: JetLaggedHomeScreenViewModel = viewModel(), onDrawerClicked: () -> Unit = {} ) { @@ -80,47 +89,67 @@ fun JetLaggedScreen( val insets = WindowInsets.safeDrawing.only( WindowInsetsSides.Bottom + WindowInsetsSides.Horizontal ) - FlowRow( - modifier = Modifier - .fillMaxSize() - .windowInsetsPadding(insets), - horizontalArrangement = Arrangement.Center, - verticalArrangement = Arrangement.Center, - maxItemsInEachRow = 3 - ) { - JetLaggedSleepGraphCard(uiState.value.sleepGraphData, Modifier.widthIn(max = 600.dp)) - if (windowSizeClass == WindowWidthSizeClass.Compact) { - AverageTimeInBedCard() - AverageTimeAsleepCard() - } else { - FlowColumn { - AverageTimeInBedCard() - AverageTimeAsleepCard() + val boundsTransform = { _: Rect, _: Rect -> + spring( + dampingRatio = Spring.DampingRatioNoBouncy, + stiffness = Spring.StiffnessMedium, + visibilityThreshold = Rect.VisibilityThreshold + ) + } + LookaheadScope { + val animateBoundsModifier = Modifier.animateBounds( + lookaheadScope = this@LookaheadScope, + boundsTransform = boundsTransform + ) + val timeSleepSummaryCards = remember { + movableContentOf { + AverageTimeInBedCard(animateBoundsModifier) + AverageTimeAsleepCard(animateBoundsModifier) } } - if (windowSizeClass == WindowWidthSizeClass.Compact) { - WellnessCard( - wellnessData = uiState.value.wellnessData, - modifier = Modifier - .widthIn(max = 400.dp) - .heightIn(min = 200.dp) - ) - HeartRateCard( - modifier = Modifier.widthIn(max = 400.dp, min = 200.dp), - uiState.value.heartRateData + FlowRow( + modifier = Modifier + .fillMaxSize() + .windowInsetsPadding(insets), + horizontalArrangement = Arrangement.Center, + verticalArrangement = Arrangement.Center, + maxItemsInEachRow = 3 + ) { + JetLaggedSleepGraphCard( + uiState.value.sleepGraphData, + Modifier.widthIn(max = 600.dp) ) - } else { - FlowColumn { + if (windowSizeClass == WindowWidthSizeClass.COMPACT) { + timeSleepSummaryCards() + } else { + FlowColumn { + timeSleepSummaryCards() + } + } + if (windowSizeClass == WindowWidthSizeClass.COMPACT) { WellnessCard( wellnessData = uiState.value.wellnessData, - modifier = Modifier + modifier = animateBoundsModifier .widthIn(max = 400.dp) .heightIn(min = 200.dp) ) HeartRateCard( - modifier = Modifier.widthIn(max = 400.dp, min = 200.dp), + modifier = animateBoundsModifier.widthIn(max = 400.dp, min = 200.dp), uiState.value.heartRateData ) + } else { + FlowColumn { + WellnessCard( + wellnessData = uiState.value.wellnessData, + modifier = animateBoundsModifier + .widthIn(max = 400.dp) + .heightIn(min = 200.dp) + ) + HeartRateCard( + modifier = animateBoundsModifier.widthIn(max = 400.dp, min = 200.dp), + uiState.value.heartRateData + ) + } } } } diff --git a/JetLagged/app/src/main/java/com/example/jetlagged/MainActivity.kt b/JetLagged/app/src/main/java/com/example/jetlagged/MainActivity.kt index aa07582086..9c405a1f45 100644 --- a/JetLagged/app/src/main/java/com/example/jetlagged/MainActivity.kt +++ b/JetLagged/app/src/main/java/com/example/jetlagged/MainActivity.kt @@ -21,18 +21,16 @@ import android.os.Bundle import androidx.activity.ComponentActivity import androidx.activity.compose.setContent import androidx.activity.enableEdgeToEdge -import androidx.compose.material3.windowsizeclass.ExperimentalMaterial3WindowSizeClassApi -import androidx.compose.material3.windowsizeclass.calculateWindowSizeClass +import androidx.compose.material3.adaptive.currentWindowAdaptiveInfo import com.example.jetlagged.ui.theme.JetLaggedTheme class MainActivity : ComponentActivity() { - @OptIn(ExperimentalMaterial3WindowSizeClassApi::class) override fun onCreate(savedInstanceState: Bundle?) { enableEdgeToEdge() super.onCreate(savedInstanceState) setContent { - val windowSizeClass = calculateWindowSizeClass(this) + val windowSizeClass = currentWindowAdaptiveInfo().windowSizeClass JetLaggedTheme { HomeScreenDrawer(windowSizeClass) } diff --git a/JetLagged/gradle/libs.versions.toml b/JetLagged/gradle/libs.versions.toml index c9043348c6..6c7b2006fe 100644 --- a/JetLagged/gradle/libs.versions.toml +++ b/JetLagged/gradle/libs.versions.toml @@ -31,7 +31,7 @@ androidxHiltNavigationCompose = "1.2.0" androix-test-uiautomator = "2.3.0" coil = "2.6.0" # @keep -compileSdk = "34" +compileSdk = "35" coroutines = "1.9.0" google-maps = "18.2.0" gradle-versions = "0.51.0" @@ -56,7 +56,7 @@ rome = "1.18.0" room = "2.6.0" secrets = "2.0.1" # @keep -targetSdk = "33" +targetSdk = "35" version-catalog-update = "0.8.4" [libraries] @@ -72,7 +72,7 @@ androidx-appcompat = { module = "androidx.appcompat:appcompat", version.ref = "a androidx-benchmark-macrobenchmark = { module = "androidx.benchmark:benchmark-macro", version.ref = "androidx-benchmark" } androidx-benchmark-macrobenchmark-junit4 = { module = "androidx.benchmark:benchmark-macro-junit4", version.ref = "androidx-benchmark-junit4" } androidx-compose-animation = { module = "androidx.compose.animation:animation" } -androidx-compose-bom = { module = "androidx.compose:compose-bom", version.ref = "androidx-compose-bom" } +androidx-compose-bom = { module = "androidx.compose:compose-bom-alpha", version.ref = "androidx-compose-bom" } androidx-compose-foundation = { module = "androidx.compose.foundation:foundation" } androidx-compose-foundation-layout = { module = "androidx.compose.foundation:foundation-layout" } androidx-compose-material-iconsExtended = { module = "androidx.compose.material:material-icons-extended" }