Skip to content

Commit fb06c01

Browse files
committed
Rearrange buttons to avoid scrolling vertically on phone landscape
1 parent d18a87a commit fb06c01

File tree

2 files changed

+67
-0
lines changed
  • core/util/src/main/java/com/android/developers/androidify/util
  • feature/creation/src/main/java/com/android/developers/androidify/creation

2 files changed

+67
-0
lines changed

core/util/src/main/java/com/android/developers/androidify/util/LayoutUtils.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ fun isHeightAtLeastMedium(): Boolean {
4949
return sizeClass.isHeightAtLeastBreakpoint(WindowSizeClass.HEIGHT_DP_MEDIUM_LOWER_BOUND)
5050
}
5151

52+
@Composable
53+
fun isHorizontalWindow(): Boolean {
54+
val sizeClass = calculateWindowSizeClass()
55+
return sizeClass.minWidthDp >= sizeClass.minHeightDp
56+
}
57+
5258
/***
5359
* This function is useful to limit the number of buttons when the window is too small to show
5460
* everything that should otherwise appear on the screen.

feature/creation/src/main/java/com/android/developers/androidify/creation/PhotoPrompt.kt

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ import com.android.developers.androidify.theme.components.SecondaryOutlinedButto
9898
import com.android.developers.androidify.theme.sharedBoundsRevealWithShapeMorph
9999
import com.android.developers.androidify.theme.sharedBoundsWithDefaults
100100
import com.android.developers.androidify.util.dashedRoundedRectBorder
101+
import com.android.developers.androidify.util.isHorizontalWindow
101102
import com.android.developers.androidify.creation.R as CreationR
102103

103104
@Composable
@@ -169,6 +170,27 @@ private fun UploadEmptyState(
169170
onCameraPressed: () -> Unit,
170171
onChooseImagePress: () -> Unit,
171172
modifier: Modifier = Modifier,
173+
) {
174+
if (isHorizontalWindow()) {
175+
HorizontallyAlignedUploadEmptyState(
176+
onCameraPressed = onCameraPressed,
177+
onChooseImagePress = onChooseImagePress,
178+
modifier = modifier,
179+
)
180+
} else {
181+
VerticallyAlignedUploadEmptyState(
182+
onCameraPressed = onCameraPressed,
183+
onChooseImagePress = onChooseImagePress,
184+
modifier = modifier,
185+
)
186+
}
187+
}
188+
189+
@Composable
190+
private fun VerticallyAlignedUploadEmptyState(
191+
onCameraPressed: () -> Unit,
192+
onChooseImagePress: () -> Unit,
193+
modifier: Modifier = Modifier,
172194
) {
173195
Column(
174196
modifier = modifier
@@ -206,6 +228,45 @@ private fun UploadEmptyState(
206228
}
207229
}
208230

231+
@Composable
232+
private fun HorizontallyAlignedUploadEmptyState(
233+
onCameraPressed: () -> Unit,
234+
onChooseImagePress: () -> Unit,
235+
modifier: Modifier = Modifier,
236+
) {
237+
Row(
238+
modifier = modifier
239+
.padding(16.dp),
240+
horizontalArrangement = Arrangement.SpaceEvenly,
241+
verticalAlignment = Alignment.CenterVertically,
242+
) {
243+
TakePhotoButton(onCameraPressed)
244+
Text(
245+
stringResource(CreationR.string.photo_picker_title),
246+
fontSize = 28.sp,
247+
textAlign = TextAlign.Center,
248+
lineHeight = 40.sp,
249+
minLines = 2,
250+
maxLines = 2,
251+
)
252+
SecondaryOutlinedButton(
253+
onClick = {
254+
onChooseImagePress()
255+
},
256+
leadingIcon = {
257+
Image(
258+
painterResource(CreationR.drawable.choose_picture_image),
259+
contentDescription = null,
260+
modifier = Modifier
261+
.padding(end = 8.dp)
262+
.size(24.dp),
263+
)
264+
},
265+
buttonText = stringResource(CreationR.string.photo_picker_choose_photo_label),
266+
)
267+
}
268+
}
269+
209270
@Composable
210271
private fun TakePhotoButton(onCameraPressed: () -> Unit) {
211272
val interactionSource = remember { MutableInteractionSource() }

0 commit comments

Comments
 (0)