Skip to content

Commit 8392b77

Browse files
committed
Pull out ResultsScreen components to their own files
1 parent 575ab3a commit 8392b77

File tree

3 files changed

+184
-128
lines changed

3 files changed

+184
-128
lines changed
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/*
2+
* Copyright 2025 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.android.developers.androidify.results
17+
18+
import androidx.compose.foundation.basicMarquee
19+
import androidx.compose.foundation.layout.Box
20+
import androidx.compose.foundation.layout.fillMaxSize
21+
import androidx.compose.material3.MaterialTheme
22+
import androidx.compose.material3.Text
23+
import androidx.compose.runtime.Composable
24+
import androidx.compose.runtime.remember
25+
import androidx.compose.ui.Alignment
26+
import androidx.compose.ui.Modifier
27+
import androidx.compose.ui.platform.LocalInspectionMode
28+
import androidx.compose.ui.res.stringArrayResource
29+
import androidx.compose.ui.text.font.FontWeight.Companion.Bold
30+
import androidx.compose.ui.unit.dp
31+
import androidx.compose.ui.unit.sp
32+
33+
@Composable
34+
fun BackgroundQuotes(quote1: String, quote2: String?, verboseLayout: Boolean = true) {
35+
// Disable animation in tests
36+
val iterations = if (LocalInspectionMode.current) 0 else 100
37+
38+
Box(modifier = Modifier.fillMaxSize()) {
39+
Text(
40+
quote1,
41+
style = MaterialTheme.typography.titleLarge.copy(fontWeight = Bold),
42+
fontSize = 120.sp,
43+
modifier = Modifier
44+
.align(if (verboseLayout) Alignment.TopCenter else Alignment.Center)
45+
.basicMarquee(
46+
iterations = iterations,
47+
repeatDelayMillis = 0,
48+
velocity = 80.dp,
49+
initialDelayMillis = 500,
50+
),
51+
)
52+
if (quote2 != null) {
53+
Text(
54+
quote2,
55+
style = MaterialTheme.typography.titleLarge.copy(fontWeight = Bold),
56+
fontSize = 110.sp,
57+
modifier = Modifier
58+
.align(Alignment.BottomCenter)
59+
.basicMarquee(
60+
iterations = iterations,
61+
repeatDelayMillis = 0,
62+
velocity = 60.dp,
63+
initialDelayMillis = 500,
64+
),
65+
)
66+
}
67+
}
68+
}
69+
70+
@Composable
71+
fun BackgroundRandomQuotes(verboseLayout: Boolean = true) {
72+
val localInspectionMode = LocalInspectionMode.current
73+
val listResultCompliments = stringArrayResource(R.array.list_compliments)
74+
75+
val quote1 = remember {
76+
if (localInspectionMode) {
77+
listResultCompliments.first()
78+
} else {
79+
listResultCompliments.random()
80+
}
81+
}
82+
val quote2 = remember {
83+
if (verboseLayout) {
84+
val listMinusOther = listResultCompliments.asList().minus(quote1)
85+
if (localInspectionMode) {
86+
listMinusOther.first()
87+
} else {
88+
listMinusOther.random()
89+
}
90+
} else {
91+
null
92+
}
93+
}
94+
BackgroundQuotes(quote1, quote2, verboseLayout)
95+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright 2025 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.android.developers.androidify.results
17+
18+
import androidx.compose.foundation.layout.Row
19+
import androidx.compose.foundation.layout.Spacer
20+
import androidx.compose.foundation.layout.width
21+
import androidx.compose.material3.Icon
22+
import androidx.compose.runtime.Composable
23+
import androidx.compose.ui.Modifier
24+
import androidx.compose.ui.graphics.vector.ImageVector
25+
import androidx.compose.ui.res.stringResource
26+
import androidx.compose.ui.res.vectorResource
27+
import androidx.compose.ui.unit.dp
28+
import com.android.developers.androidify.theme.components.PrimaryButton
29+
30+
@Composable
31+
fun BotActionsButtonRow(
32+
onCustomizeShareClicked: () -> Unit,
33+
modifier: Modifier = Modifier,
34+
verboseLayout: Boolean = false,
35+
) {
36+
Row(modifier) {
37+
PrimaryButton(
38+
onClick = {
39+
onCustomizeShareClicked()
40+
},
41+
trailingIcon = {
42+
Row {
43+
Spacer(modifier = Modifier.width(8.dp))
44+
Icon(
45+
ImageVector
46+
.vectorResource(com.android.developers.androidify.theme.R.drawable.rounded_arrow_forward_24),
47+
contentDescription = null, // decorative element
48+
)
49+
}
50+
},
51+
buttonText = if (verboseLayout) stringResource(R.string.customize_and_share) else null,
52+
)
53+
}
54+
}

feature/results/src/main/java/com/android/developers/androidify/results/ResultsScreen.kt

Lines changed: 35 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,17 @@ import androidx.compose.animation.fadeIn
2525
import androidx.compose.animation.slideInHorizontally
2626
import androidx.compose.animation.slideInVertically
2727
import androidx.compose.foundation.background
28-
import androidx.compose.foundation.basicMarquee
2928
import androidx.compose.foundation.layout.Box
3029
import androidx.compose.foundation.layout.Column
3130
import androidx.compose.foundation.layout.PaddingValues
32-
import androidx.compose.foundation.layout.Row
33-
import androidx.compose.foundation.layout.Spacer
3431
import androidx.compose.foundation.layout.fillMaxSize
3532
import androidx.compose.foundation.layout.padding
36-
import androidx.compose.foundation.layout.width
3733
import androidx.compose.material3.ExperimentalMaterial3ExpressiveApi
38-
import androidx.compose.material3.Icon
3934
import androidx.compose.material3.MaterialTheme
4035
import androidx.compose.material3.Scaffold
4136
import androidx.compose.material3.Snackbar
4237
import androidx.compose.material3.SnackbarDefaults
4338
import androidx.compose.material3.SnackbarHost
44-
import androidx.compose.material3.Text
4539
import androidx.compose.runtime.Composable
4640
import androidx.compose.runtime.LaunchedEffect
4741
import androidx.compose.runtime.State
@@ -51,21 +45,13 @@ import androidx.compose.runtime.remember
5145
import androidx.compose.runtime.setValue
5246
import androidx.compose.ui.Alignment
5347
import androidx.compose.ui.Modifier
54-
import androidx.compose.ui.graphics.vector.ImageVector
55-
import androidx.compose.ui.platform.LocalInspectionMode
56-
import androidx.compose.ui.res.stringArrayResource
57-
import androidx.compose.ui.res.stringResource
58-
import androidx.compose.ui.res.vectorResource
59-
import androidx.compose.ui.text.font.FontWeight.Companion.Bold
6048
import androidx.compose.ui.tooling.preview.Preview
6149
import androidx.compose.ui.unit.dp
62-
import androidx.compose.ui.unit.sp
6350
import androidx.lifecycle.compose.collectAsStateWithLifecycle
6451
import com.android.developers.androidify.customize.getPlaceholderBotUri
6552
import com.android.developers.androidify.theme.AndroidifyTheme
6653
import com.android.developers.androidify.theme.components.AboutButton
6754
import com.android.developers.androidify.theme.components.AndroidifyTopAppBar
68-
import com.android.developers.androidify.theme.components.PrimaryButton
6955
import com.android.developers.androidify.theme.components.ResultsBackground
7056
import com.android.developers.androidify.util.AdaptivePreview
7157
import com.android.developers.androidify.util.SmallPhonePreview
@@ -126,53 +112,6 @@ fun ResultsScreen(
126112
}
127113
}
128114

129-
@AdaptivePreview
130-
@SmallPhonePreview
131-
@Preview
132-
@Composable
133-
private fun ResultsScreenPreview() {
134-
AndroidifyTheme {
135-
val imageUri = getPlaceholderBotUri()
136-
val state = remember {
137-
mutableStateOf(
138-
ResultState(
139-
resultImageUri = imageUri,
140-
promptText = "wearing a hat with straw hair",
141-
),
142-
)
143-
}
144-
145-
ResultsScreenContents(
146-
contentPadding = PaddingValues(0.dp),
147-
state = state,
148-
onCustomizeShareClicked = {},
149-
)
150-
}
151-
}
152-
153-
@SmallPhonePreview
154-
@Composable
155-
private fun ResultsScreenPreviewSmall() {
156-
AndroidifyTheme {
157-
val imageUri = getPlaceholderBotUri()
158-
val state = remember {
159-
mutableStateOf(
160-
ResultState(
161-
resultImageUri = imageUri,
162-
promptText = "wearing a hat with straw hair",
163-
),
164-
)
165-
}
166-
167-
ResultsScreenContents(
168-
contentPadding = PaddingValues(0.dp),
169-
state = state,
170-
verboseLayout = false,
171-
onCustomizeShareClicked = {},
172-
)
173-
}
174-
}
175-
176115
@Composable
177116
fun ResultsScreenContents(
178117
contentPadding: PaddingValues,
@@ -287,81 +226,49 @@ fun ResultsScreenContents(
287226
}
288227
}
289228

229+
@AdaptivePreview
230+
@SmallPhonePreview
231+
@Preview
290232
@Composable
291-
private fun BackgroundRandomQuotes(verboseLayout: Boolean = true) {
292-
val locaInspectionMode = LocalInspectionMode.current
293-
Box(modifier = Modifier.fillMaxSize()) {
294-
val listResultCompliments = stringArrayResource(R.array.list_compliments)
295-
val randomQuote = remember {
296-
if (locaInspectionMode) {
297-
listResultCompliments.first()
298-
} else {
299-
listResultCompliments.random()
300-
}
301-
}
302-
// Disable animation in tests
303-
val iterations = if (LocalInspectionMode.current) 0 else 100
304-
Text(
305-
randomQuote,
306-
style = MaterialTheme.typography.titleLarge.copy(fontWeight = Bold),
307-
fontSize = 120.sp,
308-
modifier = Modifier
309-
.align(if (verboseLayout) Alignment.TopCenter else Alignment.Center)
310-
.basicMarquee(
311-
iterations = iterations,
312-
repeatDelayMillis = 0,
313-
velocity = 80.dp,
314-
initialDelayMillis = 500,
233+
private fun ResultsScreenPreview() {
234+
AndroidifyTheme {
235+
val imageUri = getPlaceholderBotUri()
236+
val state = remember {
237+
mutableStateOf(
238+
ResultState(
239+
resultImageUri = imageUri,
240+
promptText = "wearing a hat with straw hair",
315241
),
316-
)
317-
if (verboseLayout) {
318-
val listMinusOther = listResultCompliments.asList().minus(randomQuote)
319-
val randomQuote2 = remember {
320-
if (locaInspectionMode) {
321-
listMinusOther.first()
322-
} else {
323-
listMinusOther.random()
324-
}
325-
}
326-
Text(
327-
randomQuote2,
328-
style = MaterialTheme.typography.titleLarge.copy(fontWeight = Bold),
329-
fontSize = 110.sp,
330-
modifier = Modifier
331-
.align(Alignment.BottomCenter)
332-
.basicMarquee(
333-
iterations = iterations,
334-
repeatDelayMillis = 0,
335-
velocity = 60.dp,
336-
initialDelayMillis = 500,
337-
),
338242
)
339243
}
244+
245+
ResultsScreenContents(
246+
contentPadding = PaddingValues(0.dp),
247+
state = state,
248+
onCustomizeShareClicked = {},
249+
)
340250
}
341251
}
342252

253+
@SmallPhonePreview
343254
@Composable
344-
private fun BotActionsButtonRow(
345-
onCustomizeShareClicked: () -> Unit,
346-
modifier: Modifier = Modifier,
347-
verboseLayout: Boolean = false,
348-
) {
349-
Row(modifier) {
350-
PrimaryButton(
351-
onClick = {
352-
onCustomizeShareClicked()
353-
},
354-
trailingIcon = {
355-
Row {
356-
Spacer(modifier = Modifier.width(8.dp))
357-
Icon(
358-
ImageVector
359-
.vectorResource(com.android.developers.androidify.theme.R.drawable.rounded_arrow_forward_24),
360-
contentDescription = null, // decorative element
361-
)
362-
}
363-
},
364-
buttonText = if (verboseLayout) stringResource(R.string.customize_and_share) else null,
255+
private fun ResultsScreenPreviewSmall() {
256+
AndroidifyTheme {
257+
val imageUri = getPlaceholderBotUri()
258+
val state = remember {
259+
mutableStateOf(
260+
ResultState(
261+
resultImageUri = imageUri,
262+
promptText = "wearing a hat with straw hair",
263+
),
264+
)
265+
}
266+
267+
ResultsScreenContents(
268+
contentPadding = PaddingValues(0.dp),
269+
state = state,
270+
verboseLayout = false,
271+
onCustomizeShareClicked = {},
365272
)
366273
}
367274
}

0 commit comments

Comments
 (0)