Skip to content

Commit 7382101

Browse files
committed
Refine backgrounds and navigation colors
Change-Id: I9fd863cc608f21078ab78c39c2c3d227aedbac7c
1 parent 8c11769 commit 7382101

File tree

5 files changed

+124
-119
lines changed
  • app/src/main/java/com/google/samples/apps/nowinandroid/ui
  • core/designsystem/src/main/java/com/google/samples/apps/nowinandroid/core/designsystem/component
  • feature
    • bookmarks/src/main/java/com/google/samples/apps/nowinandroid/feature/bookmarks
    • foryou/src/main/java/com/google/samples/apps/nowinandroid/feature/foryou

5 files changed

+124
-119
lines changed

app/src/main/java/com/google/samples/apps/nowinandroid/ui/NiaApp.kt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,16 @@ import androidx.compose.ui.semantics.testTagsAsResourceId
4444
import androidx.navigation.NavDestination
4545
import androidx.navigation.NavDestination.Companion.hierarchy
4646
import com.google.samples.apps.nowinandroid.core.designsystem.component.NiaBackground
47+
import com.google.samples.apps.nowinandroid.core.designsystem.component.NiaGradientBackground
4748
import com.google.samples.apps.nowinandroid.core.designsystem.component.NiaNavigationBar
4849
import com.google.samples.apps.nowinandroid.core.designsystem.component.NiaNavigationBarItem
4950
import com.google.samples.apps.nowinandroid.core.designsystem.component.NiaNavigationRail
5051
import com.google.samples.apps.nowinandroid.core.designsystem.component.NiaNavigationRailItem
5152
import com.google.samples.apps.nowinandroid.core.designsystem.icon.Icon.DrawableResourceIcon
5253
import com.google.samples.apps.nowinandroid.core.designsystem.icon.Icon.ImageVectorIcon
5354
import com.google.samples.apps.nowinandroid.core.designsystem.theme.NiaTheme
55+
import com.google.samples.apps.nowinandroid.core.navigation.NiaNavigationDestination
56+
import com.google.samples.apps.nowinandroid.feature.foryou.navigation.ForYouDestination
5457
import com.google.samples.apps.nowinandroid.navigation.NiaNavHost
5558
import com.google.samples.apps.nowinandroid.navigation.TopLevelDestination
5659

@@ -65,7 +68,13 @@ fun NiaApp(
6568
appState: NiaAppState = rememberNiaAppState(windowSizeClass)
6669
) {
6770
NiaTheme {
68-
NiaBackground {
71+
val background: @Composable (@Composable () -> Unit) -> Unit =
72+
when (appState.currentDestination?.route) {
73+
ForYouDestination.route -> { content -> NiaGradientBackground(content = content) }
74+
else -> { content -> NiaBackground(content = content) }
75+
}
76+
77+
background {
6978
Scaffold(
7079
modifier = Modifier.semantics {
7180
testTagsAsResourceId = true

core/designsystem/src/main/java/com/google/samples/apps/nowinandroid/core/designsystem/component/Chip.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package com.google.samples.apps.nowinandroid.core.designsystem.component
1818

19+
import androidx.compose.foundation.shape.CircleShape
1920
import androidx.compose.material3.ExperimentalMaterial3Api
2021
import androidx.compose.material3.FilterChip
2122
import androidx.compose.material3.FilterChipDefaults
@@ -63,6 +64,7 @@ fun NiaFilterChip(
6364
contentDescription = null
6465
)
6566
},
67+
shape = CircleShape,
6668
border = FilterChipDefaults.filterChipBorder(
6769
borderColor = MaterialTheme.colorScheme.onBackground,
6870
selectedBorderColor = MaterialTheme.colorScheme.onBackground,

core/designsystem/src/main/java/com/google/samples/apps/nowinandroid/core/designsystem/component/Navigation.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ fun NiaNavigationBar(
8888
) {
8989
NavigationBar(
9090
modifier = modifier,
91-
containerColor = NiaNavigationDefaults.NavigationContainerColor,
9291
contentColor = NiaNavigationDefaults.navigationContentColor(),
9392
tonalElevation = 0.dp,
9493
content = content
@@ -155,7 +154,7 @@ fun NiaNavigationRail(
155154
) {
156155
NavigationRail(
157156
modifier = modifier,
158-
containerColor = NiaNavigationDefaults.NavigationContainerColor,
157+
containerColor = Color.Transparent,
159158
contentColor = NiaNavigationDefaults.navigationContentColor(),
160159
header = header,
161160
content = content
@@ -166,7 +165,6 @@ fun NiaNavigationRail(
166165
* Now in Android navigation default values.
167166
*/
168167
object NiaNavigationDefaults {
169-
val NavigationContainerColor = Color.Transparent
170168
@Composable
171169
fun navigationContentColor() = MaterialTheme.colorScheme.onSurfaceVariant
172170
@Composable

feature/bookmarks/src/main/java/com/google/samples/apps/nowinandroid/feature/bookmarks/BookmarksScreen.kt

Lines changed: 34 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -69,44 +69,42 @@ fun BookmarksScreen(
6969
removeFromBookmarks: (String) -> Unit,
7070
modifier: Modifier = Modifier
7171
) {
72-
NiaGradientBackground {
73-
Scaffold(
74-
topBar = {
75-
NiaTopAppBar(
76-
titleRes = R.string.top_app_bar_title_saved,
77-
actionIcon = NiaIcons.AccountCircle,
78-
actionIconContentDescription = stringResource(
79-
id = R.string.top_app_bar_action_menu
80-
),
81-
colors = TopAppBarDefaults.centerAlignedTopAppBarColors(
82-
containerColor = Color.Transparent
83-
)
84-
)
85-
},
86-
containerColor = Color.Transparent,
87-
contentWindowInsets = WindowInsets(0, 0, 0, 0)
88-
) { innerPadding ->
89-
LazyVerticalGrid(
90-
columns = Adaptive(300.dp),
91-
contentPadding = PaddingValues(16.dp),
92-
horizontalArrangement = Arrangement.spacedBy(32.dp),
93-
verticalArrangement = Arrangement.spacedBy(24.dp),
94-
modifier = modifier
95-
.fillMaxSize()
96-
.testTag("bookmarks:feed")
97-
.padding(innerPadding)
98-
.consumedWindowInsets(innerPadding)
99-
) {
100-
newsFeed(
101-
feedState = feedState,
102-
onNewsResourcesCheckedChanged = { id, _ -> removeFromBookmarks(id) },
103-
showLoadingUIIfLoading = true,
104-
loadingContentDescription = R.string.saved_loading
72+
Scaffold(
73+
topBar = {
74+
NiaTopAppBar(
75+
titleRes = R.string.top_app_bar_title_saved,
76+
actionIcon = NiaIcons.AccountCircle,
77+
actionIconContentDescription = stringResource(
78+
id = R.string.top_app_bar_action_menu
79+
),
80+
colors = TopAppBarDefaults.centerAlignedTopAppBarColors(
81+
containerColor = Color.Transparent
10582
)
83+
)
84+
},
85+
containerColor = Color.Transparent,
86+
contentWindowInsets = WindowInsets(0, 0, 0, 0)
87+
) { innerPadding ->
88+
LazyVerticalGrid(
89+
columns = Adaptive(300.dp),
90+
contentPadding = PaddingValues(16.dp),
91+
horizontalArrangement = Arrangement.spacedBy(32.dp),
92+
verticalArrangement = Arrangement.spacedBy(24.dp),
93+
modifier = modifier
94+
.fillMaxSize()
95+
.testTag("bookmarks:feed")
96+
.padding(innerPadding)
97+
.consumedWindowInsets(innerPadding)
98+
) {
99+
newsFeed(
100+
feedState = feedState,
101+
onNewsResourcesCheckedChanged = { id, _ -> removeFromBookmarks(id) },
102+
showLoadingUIIfLoading = true,
103+
loadingContentDescription = R.string.saved_loading
104+
)
106105

107-
item(span = { GridItemSpan(maxLineSpan) }) {
108-
Spacer(Modifier.windowInsetsBottomHeight(WindowInsets.safeDrawing))
109-
}
106+
item(span = { GridItemSpan(maxLineSpan) }) {
107+
Spacer(Modifier.windowInsetsBottomHeight(WindowInsets.safeDrawing))
110108
}
111109
}
112110
}

feature/foryou/src/main/java/com/google/samples/apps/nowinandroid/feature/foryou/ForYouScreen.kt

Lines changed: 77 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -124,95 +124,93 @@ fun ForYouScreen(
124124
onNewsResourcesCheckedChanged: (String, Boolean) -> Unit,
125125
modifier: Modifier = Modifier,
126126
) {
127-
NiaGradientBackground {
128-
Scaffold(
129-
topBar = {
130-
NiaTopAppBar(
131-
titleRes = R.string.top_app_bar_title,
132-
actionIcon = NiaIcons.AccountCircle,
133-
actionIconContentDescription = stringResource(
134-
id = R.string.for_you_top_app_bar_action_my_account
135-
),
136-
colors = TopAppBarDefaults.centerAlignedTopAppBarColors(
137-
containerColor = Color.Transparent
138-
)
127+
Scaffold(
128+
topBar = {
129+
NiaTopAppBar(
130+
titleRes = R.string.top_app_bar_title,
131+
actionIcon = NiaIcons.AccountCircle,
132+
actionIconContentDescription = stringResource(
133+
id = R.string.for_you_top_app_bar_action_my_account
134+
),
135+
colors = TopAppBarDefaults.centerAlignedTopAppBarColors(
136+
containerColor = Color.Transparent
139137
)
140-
},
141-
containerColor = Color.Transparent,
142-
contentWindowInsets = WindowInsets(0, 0, 0, 0)
143-
) { innerPadding ->
144-
// Workaround to call Activity.reportFullyDrawn from Jetpack Compose.
145-
// This code should be called when the UI is ready for use
146-
// and relates to Time To Full Display.
147-
val interestsLoaded =
148-
interestsSelectionState !is ForYouInterestsSelectionUiState.Loading
149-
val feedLoaded = feedState !is NewsFeedUiState.Loading
138+
)
139+
},
140+
containerColor = Color.Transparent,
141+
contentWindowInsets = WindowInsets(0, 0, 0, 0)
142+
) { innerPadding ->
143+
// Workaround to call Activity.reportFullyDrawn from Jetpack Compose.
144+
// This code should be called when the UI is ready for use
145+
// and relates to Time To Full Display.
146+
val interestsLoaded =
147+
interestsSelectionState !is ForYouInterestsSelectionUiState.Loading
148+
val feedLoaded = feedState !is NewsFeedUiState.Loading
150149

151-
if (interestsLoaded && feedLoaded) {
152-
val localView = LocalView.current
153-
// We use Unit to call reportFullyDrawn only on the first recomposition,
154-
// however it will be called again if this composable goes out of scope.
155-
// Activity.reportFullyDrawn() has its own check for this
156-
// and is safe to call multiple times though.
157-
LaunchedEffect(Unit) {
158-
// We're leveraging the fact, that the current view is directly set as content of Activity.
159-
val activity = localView.context as? Activity ?: return@LaunchedEffect
160-
// To be sure not to call in the middle of a frame draw.
161-
localView.doOnPreDraw { activity.reportFullyDrawn() }
162-
}
150+
if (interestsLoaded && feedLoaded) {
151+
val localView = LocalView.current
152+
// We use Unit to call reportFullyDrawn only on the first recomposition,
153+
// however it will be called again if this composable goes out of scope.
154+
// Activity.reportFullyDrawn() has its own check for this
155+
// and is safe to call multiple times though.
156+
LaunchedEffect(Unit) {
157+
// We're leveraging the fact, that the current view is directly set as content of Activity.
158+
val activity = localView.context as? Activity ?: return@LaunchedEffect
159+
// To be sure not to call in the middle of a frame draw.
160+
localView.doOnPreDraw { activity.reportFullyDrawn() }
163161
}
162+
}
164163

165-
val tag = "forYou:feed"
164+
val tag = "forYou:feed"
166165

167-
val lazyGridState = rememberLazyGridState()
168-
TrackScrollJank(scrollableState = lazyGridState, stateName = tag)
166+
val lazyGridState = rememberLazyGridState()
167+
TrackScrollJank(scrollableState = lazyGridState, stateName = tag)
169168

170-
LazyVerticalGrid(
171-
columns = Adaptive(300.dp),
172-
contentPadding = PaddingValues(16.dp),
173-
horizontalArrangement = Arrangement.spacedBy(16.dp),
174-
verticalArrangement = Arrangement.spacedBy(24.dp),
175-
modifier = modifier
176-
.padding(innerPadding)
177-
.consumedWindowInsets(innerPadding)
178-
.fillMaxSize()
179-
.testTag("forYou:feed"),
180-
state = lazyGridState
181-
) {
182-
interestsSelection(
183-
interestsSelectionState = interestsSelectionState,
184-
onAuthorCheckedChanged = onAuthorCheckedChanged,
185-
onTopicCheckedChanged = onTopicCheckedChanged,
186-
saveFollowedTopics = saveFollowedTopics,
187-
// Custom LayoutModifier to remove the enforced parent 16.dp contentPadding
188-
// from the LazyVerticalGrid and enable edge-to-edge scrolling for this section
189-
interestsItemModifier = Modifier.layout { measurable, constraints ->
190-
val placeable = measurable.measure(
191-
constraints.copy(
192-
maxWidth = constraints.maxWidth + 32.dp.roundToPx()
193-
)
169+
LazyVerticalGrid(
170+
columns = Adaptive(300.dp),
171+
contentPadding = PaddingValues(16.dp),
172+
horizontalArrangement = Arrangement.spacedBy(16.dp),
173+
verticalArrangement = Arrangement.spacedBy(24.dp),
174+
modifier = modifier
175+
.padding(innerPadding)
176+
.consumedWindowInsets(innerPadding)
177+
.fillMaxSize()
178+
.testTag("forYou:feed"),
179+
state = lazyGridState
180+
) {
181+
interestsSelection(
182+
interestsSelectionState = interestsSelectionState,
183+
onAuthorCheckedChanged = onAuthorCheckedChanged,
184+
onTopicCheckedChanged = onTopicCheckedChanged,
185+
saveFollowedTopics = saveFollowedTopics,
186+
// Custom LayoutModifier to remove the enforced parent 16.dp contentPadding
187+
// from the LazyVerticalGrid and enable edge-to-edge scrolling for this section
188+
interestsItemModifier = Modifier.layout { measurable, constraints ->
189+
val placeable = measurable.measure(
190+
constraints.copy(
191+
maxWidth = constraints.maxWidth + 32.dp.roundToPx()
194192
)
195-
layout(placeable.width, placeable.height) {
196-
placeable.place(0, 0)
197-
}
193+
)
194+
layout(placeable.width, placeable.height) {
195+
placeable.place(0, 0)
198196
}
199-
)
197+
}
198+
)
200199

201-
newsFeed(
202-
feedState = feedState,
203-
// Avoid showing a second loading wheel if we already are for the interests
204-
// selection
205-
showLoadingUIIfLoading =
206-
interestsSelectionState !is ForYouInterestsSelectionUiState.Loading,
207-
onNewsResourcesCheckedChanged = onNewsResourcesCheckedChanged,
208-
loadingContentDescription = R.string.for_you_loading
209-
)
200+
newsFeed(
201+
feedState = feedState,
202+
// Avoid showing a second loading wheel if we already are for the interests
203+
// selection
204+
showLoadingUIIfLoading =
205+
interestsSelectionState !is ForYouInterestsSelectionUiState.Loading,
206+
onNewsResourcesCheckedChanged = onNewsResourcesCheckedChanged,
207+
loadingContentDescription = R.string.for_you_loading
208+
)
210209

211-
item(span = { GridItemSpan(maxLineSpan) }) {
212-
Column {
213-
Spacer(modifier = Modifier.height(8.dp))
214-
Spacer(Modifier.windowInsetsBottomHeight(WindowInsets.safeDrawing))
215-
}
210+
item(span = { GridItemSpan(maxLineSpan) }) {
211+
Column {
212+
Spacer(modifier = Modifier.height(8.dp))
213+
Spacer(Modifier.windowInsetsBottomHeight(WindowInsets.safeDrawing))
216214
}
217215
}
218216
}

0 commit comments

Comments
 (0)