Skip to content

Commit

Permalink
Add expanded HomeScreen version
Browse files Browse the repository at this point in the history
  • Loading branch information
whitipet committed May 6, 2024
1 parent 6b02ef7 commit 9aa7fc8
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 16 deletions.
6 changes: 6 additions & 0 deletions dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ androidx-annotationExp = "1.4.1" # https://mvnrepository.com/artifa
androidx-appCompat = "1.7.0-beta01" # https://mvnrepository.com/artifact/androidx.appcompat/appcompat https://developer.android.com/jetpack/androidx/releases/appcompat
androidx-arch = "2.2.0" # https://mvnrepository.com/artifact/androidx.arch.core/core-common https://developer.android.com/jetpack/androidx/releases/arch
androidx-collection = "1.4.0" # https://mvnrepository.com/artifact/androidx.collection/collection https://developer.android.com/jetpack/androidx/releases/collection
androidx-compose-adaptive = "1.0.0-alpha12" # https://mvnrepository.com/artifact/androidx.compose.material3.adaptive/adaptive
androidx-compose-animation = "1.7.0-alpha08" # https://mvnrepository.com/artifact/androidx.compose.animation/animation https://developer.android.com/jetpack/androidx/releases/compose-animation
androidx-compose-foundation = "1.7.0-alpha08" # https://mvnrepository.com/artifact/androidx.compose.foundation/foundation https://developer.android.com/jetpack/androidx/releases/compose-foundation
androidx-compose-material3 = "1.3.0-alpha06" # https://mvnrepository.com/artifact/androidx.compose.material3/material3 https://developer.android.com/jetpack/androidx/releases/compose-material3
Expand All @@ -36,6 +37,7 @@ androidx-savedState = "1.2.1" # https://mvnrepository.com/artifa
androidx-sqlite = "2.5.0-alpha01" # https://mvnrepository.com/artifact/androidx.sqlite/sqlite https://developer.android.com/jetpack/androidx/releases/sqlite
androidx-vectorDrawable = "1.2.0" # https://mvnrepository.com/artifact/androidx.vectordrawable/vectordrawable https://developer.android.com/jetpack/androidx/releases/vectordrawable
androidx-versionedParcelable = "1.2.0" # https://mvnrepository.com/artifact/androidx.versionedparcelable/versionedparcelable https://developer.android.com/jetpack/androidx/releases/versionedparcelable
androidx-window = "1.3.0-beta02" # https://mvnrepository.com/artifact/androidx.window/window https://developer.android.com/jetpack/androidx/releases/window

google-material = "1.13.0-alpha01" # https://mvnrepository.com/artifact/com.google.android.material/material https://github.com/material-components/material-components-android/releases

Expand Down Expand Up @@ -77,13 +79,15 @@ androidx-arch-coreRuntime = { module = "androidx.arch.core:core-runtime", versio
androidx-arch-coreCommon = { module = "androidx.arch.core:core-common", version.ref = "androidx-arch" }
androidx-collection = { module = "androidx.collection:collection", version.ref = "androidx-collection" }
androidx-collection-ktx = { module = "androidx.collection:collection-ktx", version.ref = "androidx-collection" }
androidx-compose-adaptive = { module = "androidx.compose.material3.adaptive:adaptive-android", version.ref = "androidx-compose-adaptive" }
androidx-compose-animation = { module = "androidx.compose.animation:animation", version.ref = "androidx-compose-animation" }
androidx-compose-animation-core-android = { module = "androidx.compose.animation:animation-core-android", version.ref = "androidx-compose-animation" }
androidx-compose-foundation = { module = "androidx.compose.foundation:foundation", version.ref = "androidx-compose-foundation" }
androidx-compose-foundation-android = { module = "androidx.compose.foundation:foundation-android", version.ref = "androidx-compose-foundation" }
androidx-compose-foundation-layout-android = { module = "androidx.compose.foundation:foundation-layout-android", version.ref = "androidx-compose-foundation" }
androidx-compose-material3 = { module = "androidx.compose.material3:material3", version.ref = "androidx-compose-material3" }
androidx-compose-material3-android = { module = "androidx.compose.material3:material3-android", version.ref = "androidx-compose-material3" }
androidx-compose-material3-windowSizeClass = { module = "androidx.compose.material3:material3-window-size-class", version.ref = "androidx-compose-material3" }
androidx-compose-material = { module = "androidx.compose.material:material", version.ref = "androidx-compose-material" }
androidx-compose-material-android = { module = "androidx.compose.material:material-android", version.ref = "androidx-compose-material" }
androidx-compose-material-icons-core-android = { module = "androidx.compose.material:material-icons-core-android", version.ref = "androidx-compose-material" }
Expand Down Expand Up @@ -131,6 +135,8 @@ androidx-vectorDrawable = { module = "androidx.vectordrawable:vectordrawable", v
androidx-vectorDrawable-animated = { module = "androidx.vectordrawable:vectordrawable-animated", version.ref = "androidx-vectorDrawable" }
androidx-vectorDrawable-seekable = { module = "androidx.vectordrawable:vectordrawable-seekable", version.ref = "androidx-vectorDrawable" }
androidx-versionedParcelable = { module = "androidx.versionedparcelable:versionedparcelable", version.ref = "androidx-versionedParcelable" }
androidx-window = { module = "androidx.window:window", version.ref = "androidx-window" }
androidx-window-core-android = { module = "androidx.window:window-core-android", version.ref = "androidx-window" }

google-material = { module = "com.google.android.material:material", version.ref = "google-material" }

Expand Down
1 change: 1 addition & 0 deletions feature/home/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ dependencies {
implementation dep.androidx.compose.material3
debugImplementation dep.androidx.compose.ui.tooling
implementation dep.androidx.compose.ui.tooling.preview
implementation dep.androidx.compose.adaptive

implementation dep.androidx.navigation.compose
implementation dep.koin.compose.navigation
Expand Down
75 changes: 59 additions & 16 deletions feature/home/src/main/kotlin/feature/home/HomeScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.calculateEndPadding
import androidx.compose.foundation.layout.calculateStartPadding
Expand All @@ -17,6 +18,8 @@ import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.safeContent
import androidx.compose.foundation.layout.windowInsetsPadding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material.icons.Icons
Expand All @@ -28,6 +31,7 @@ import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.material3.adaptive.currentWindowAdaptiveInfo
import androidx.compose.runtime.Composable
import androidx.compose.runtime.State
import androidx.compose.runtime.mutableStateOf
Expand All @@ -47,6 +51,7 @@ import androidx.compose.ui.platform.LocalLayoutDirection
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.window.core.layout.WindowWidthSizeClass
import project.entity.Consumption
import project.ui.theme.Theme
import java.time.Instant
Expand Down Expand Up @@ -93,18 +98,57 @@ internal fun HomeScreen(
onAddAction: () -> Unit,
onGoalAction: () -> Unit,
onConsumptionAction: (consumptionId: Long) -> Unit,
) {
val current: Int = uiState.value.consumedKcal
val goal: Int = uiState.value.goal

Scaffold(
floatingActionButtonPosition = FabPosition.Center,
floatingActionButton = {
FloatingActionButton(onClick = onAddAction) {
Icon(Icons.Rounded.Add, "Add")
widthSizeClass: WindowWidthSizeClass = currentWindowAdaptiveInfo().windowSizeClass.windowWidthSizeClass,
) = Scaffold(
floatingActionButtonPosition =
if (widthSizeClass == WindowWidthSizeClass.EXPANDED) FabPosition.End
else FabPosition.Center,
floatingActionButton = {
FloatingActionButton(onClick = onAddAction) {
Icon(Icons.Rounded.Add, "Add")
}
}
) { padding ->
if (widthSizeClass == WindowWidthSizeClass.EXPANDED)
Row(
modifier = Modifier.fillMaxSize(),
verticalAlignment = Alignment.CenterVertically,
) {
ConsumptionProgress(
modifier = Modifier
.aspectRatio(1f, true)
.weight(1f)
.padding(padding)
.padding(16.dp)
.windowInsetsPadding(WindowInsets.safeContent),
current = uiState.value.consumedKcal,
goal = uiState.value.goal,
onGoalAction = onGoalAction
)
LazyColumn(
modifier = Modifier.weight(1f),
contentPadding = PaddingValues( // FIXME: PaddingValues causes frame skip during scroll
start = padding.calculateStartPadding(LocalLayoutDirection.current),
top = padding.calculateTopPadding() + 24.dp,
end = padding.calculateEndPadding(LocalLayoutDirection.current),
bottom = padding.calculateBottomPadding() + (56.dp + 32.dp) // TODO: Find way to calculate FAB size
),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.spacedBy(8.dp)
) {
items(
items = uiState.value.consumptions,
key = { it.id },
contentType = { it::class }
) { c ->
ItemConsumed(
consumption = c,
onClick = { onConsumptionAction(c.id) }
)
}
}
}
) { padding ->
else
LazyColumn(
modifier = Modifier.fillMaxSize(),
contentPadding = PaddingValues( // FIXME: PaddingValues causes frame skip during scroll
Expand All @@ -119,10 +163,12 @@ internal fun HomeScreen(
item {
ConsumptionProgress(
modifier = Modifier
.aspectRatio(1f)
.fillMaxWidth()
.padding(horizontal = 24.dp)
.padding(top = 66.dp, bottom = 24.dp),
current = current,
goal = goal,
current = uiState.value.consumedKcal,
goal = uiState.value.goal,
onGoalAction = onGoalAction
)
}
Expand All @@ -138,7 +184,6 @@ internal fun HomeScreen(
)
}
}
}
}

//region ConsumptionProgress
Expand All @@ -150,9 +195,7 @@ private fun ConsumptionProgress(
onGoalAction: () -> Unit,
) {
Box(
modifier = modifier
.aspectRatio(1f)
.fillMaxWidth(),
modifier = modifier.aspectRatio(1f),
contentAlignment = Alignment.Center
) {
ProgressBar(
Expand Down

0 comments on commit 9aa7fc8

Please sign in to comment.