Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ class PhoneCopiesTest {
compose.onNodeWithTag("collection-live_photos").assertIsDisplayed()
compose.onNodeWithTag("collection-live_photos").performSemanticsAction(androidx.compose.ui.semantics.SemanticsActions.OnClick) { it() }
compose.openGalleryMedia("fixture:icloud:0020")
compose.onNodeWithTag("viewer-live").assertContentDescriptionEquals("Play Live Photo").performClick()
compose.onNodeWithTag("viewer-live").assertContentDescriptionEquals("Live Photo").assertIsOff().performClick()
compose.waitUntil(LONG_WAIT) {
compose.onAllNodes(SemanticsMatcher.expectValue(SemanticsProperties.StateDescription, "Playing")).fetchSemanticsNodes().isNotEmpty()
}
// The same button now offers the still photo again.
compose.onNodeWithTag("viewer-live").assertContentDescriptionEquals("Show still photo").performClick()
// The same switch, now on, turns the motion off again.
compose.onNodeWithTag("viewer-live").assertContentDescriptionEquals("Live Photo").assertIsOn().performClick()
val repository = (compose.activity.application as AlbaApplication).graph.galleryRepository
repository.keepOriginalOffline("fixture:icloud:0020")
val media = repository.observeGallery().first().first { it.id == "fixture:icloud:0020" }
Expand Down
25 changes: 17 additions & 8 deletions app/src/main/java/me/lvca/alba/app/ui/collections/AlbumDialogs.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package me.lvca.alba.app.ui.collections

import androidx.activity.compose.BackHandler
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
Expand All @@ -12,7 +13,6 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import me.lvca.alba.app.R
import me.lvca.alba.app.ui.designsystem.AlbaBottomSheet
import me.lvca.alba.app.ui.designsystem.AlbaChevron
import me.lvca.alba.app.ui.designsystem.AlbaIcons
import me.lvca.alba.app.ui.designsystem.AlbaListRow
import me.lvca.alba.app.ui.designsystem.AlbaSheetHeading
Expand Down Expand Up @@ -60,23 +60,32 @@ internal fun AlbumChooser(collections: List<GalleryCollection>, dismiss: () -> U
creating = false; create(name)
}
AlbaBottomSheet(onDismissRequest = dismiss) {
val up = { folder = collections.firstOrNull { it.id == folder }?.parentId }
// Back goes up one folder, as the heading's arrow does; at the top level it closes the sheet.
BackHandler(enabled = folder != null, onBack = up)
Column(Modifier.fillMaxWidth().padding(horizontal = 20.dp)) {
AlbaSheetHeading(title, subtitle = collections.firstOrNull { it.id == folder }?.name, dismiss = dismiss)
AlbaSheetHeading(title, subtitle = collections.firstOrNull { it.id == folder }?.name, dismiss = dismiss,
navigationIcon = if (folder == null) null else {
{
IconButton(onClick = up, modifier = Modifier.testTag("album-chooser-up")) {
Icon(AlbaIcons.ArrowBack, stringResource(R.string.back_action))
}
}
})
// Shared albums have no folders: offer every one the person can add to.
val entries = remember(collections, folder, shared) {
if (shared) collections.filter { it.shared?.canContribute == true }.sortedWith(compareBy(String.CASE_INSENSITIVE_ORDER) { it.name })
else albumChooserEntries(collections, folder)
}
if (folder != null) AlbaListRow(stringResource(R.string.back_action), { folder = collections.firstOrNull { it.id == folder }?.parentId },
leading = { Icon(AlbaIcons.ArrowBack, null) }, shape = MaterialTheme.shapes.small,
contentPadding = PaddingValues(horizontal = AlbaSpacing.md, vertical = AlbaSpacing.sm), modifier = Modifier.testTag("album-chooser-up"))
else if (canCreate && !shared) TextButton(onClick = { creating = true }, modifier = Modifier.fillMaxWidth().testTag("album-chooser-new")) {
Text(stringResource(R.string.new_album))
if (folder == null && canCreate && !shared) {
TextButton(onClick = { creating = true }, modifier = Modifier.fillMaxWidth().testTag("album-chooser-new")) {
Text(stringResource(R.string.new_album))
}
}
LazyColumn(Modifier.fillMaxWidth().heightIn(max = 440.dp), contentPadding = PaddingValues(bottom = 24.dp + WindowInsets.navigationBars.asPaddingValues().calculateBottomPadding())) {
items(entries, key = { it.id }) { album ->
if (album.isFolder) AlbaListRow(album.name, { folder = album.id }, leading = { Icon(AlbaIcons.PhotoLibrary, null) },
trailing = { AlbaChevron() }, shape = MaterialTheme.shapes.small,
shape = MaterialTheme.shapes.small,
contentPadding = rowPadding, modifier = Modifier.testTag("album-chooser-folder-${album.id}"))
else AlbaListRow(album.name, { choose(album.id) },
leading = { ICloudIcon(if (shared) R.drawable.icloud_shared_albums else R.drawable.icloud_albums) }, shape = MaterialTheme.shapes.small,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ import me.lvca.alba.app.ui.designsystem.theme.AlbaSpacing

/**
* Grouped cards keep utility screens quiet while the gallery remains image-led: one container step above the page, so
* they lift off it in both themes (lighter than the page in dark mode, a quiet grey in light mode).
* they lift off it in both themes (lighter than the page in dark mode, a quiet grey in light mode). A sheet is itself
* a step above the page, so groups on one go a step higher.
*/
@Composable
internal fun albaGroupColor() = MaterialTheme.colorScheme.surfaceContainer
internal fun albaGroupColor() =
if (LocalInAlbaSheet.current) MaterialTheme.colorScheme.surfaceContainerHigh else MaterialTheme.colorScheme.surfaceContainer

/**
* Alba's grouped card: a full-width rounded surface holding a column of rows or a block of content.
Expand Down
30 changes: 30 additions & 0 deletions app/src/main/java/me/lvca/alba/app/ui/designsystem/AlbaIcons.kt
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,17 @@ internal object AlbaIcons {
)
}

/** Material Symbols Rounded redo, outlined. */
val Redo: ImageVector by lazy {
symbol(
"Redo",
"M648-560H396q-63 0-109.5 40T240-420q0 60 46.5 100T396-280h244q17 0 28.5 11.5T680-240q0 17-11.5 28.5T640-200H396q-97 " +
"0-166.5-63T160-420q0-94 69.5-157T396-640h252l-76-76q-11-11-11-28t11-28q11-11 28-11t28 11l144 144q6 6 8.5 13t2.5 15q0" +
" 8-2.5 15t-8.5 13L628-428q-11 11-28 11t-28-11q-11-11-11-28t11-28l76-76Z",
autoMirror = true,
)
}

/** Material Symbols Rounded refresh, outlined. */
val Refresh: ImageVector by lazy {
symbol(
Expand All @@ -537,6 +548,14 @@ internal object AlbaIcons {
)
}

/** Material Symbols Rounded remove, outlined. */
val Remove: ImageVector by lazy {
symbol(
"Remove",
"M240-440q-17 0-28.5-11.5T200-480q0-17 11.5-28.5T240-520h480q17 0 28.5 11.5T760-480q0 17-11.5 28.5T720-440H240Z",
)
}

/** Material Symbols Rounded download, outlined. */
val SaveAlt: ImageVector by lazy {
symbol(
Expand Down Expand Up @@ -603,6 +622,17 @@ internal object AlbaIcons {
)
}

/** Material Symbols Rounded undo, outlined. */
val Undo: ImageVector by lazy {
symbol(
"Undo",
"M320-200q-17 0-28.5-11.5T280-240q0-17 11.5-28.5T320-280h244q63 0 109.5-40T720-420q0-60-46.5-100T564-560H312l76 76q11" +
" 11 11 28t-11 28q-11 11-28 11t-28-11L188-572q-6-6-8.5-13t-2.5-15q0-8 2.5-15t8.5-13l144-144q11-11 28-11t28 11q11 11 1" +
"1 28t-11 28l-76 76h252q97 0 166.5 63T800-420q0 94-69.5 157T564-200H320Z",
autoMirror = true,
)
}

/** Material Symbols Rounded verified_user, outlined. */
val VerifiedUser: ImageVector by lazy {
symbol(
Expand Down
37 changes: 33 additions & 4 deletions app/src/main/java/me/lvca/alba/app/ui/designsystem/AlbaSurfaces.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.*
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.key
import androidx.compose.runtime.staticCompositionLocalOf
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.luminance
Expand Down Expand Up @@ -63,6 +65,13 @@ internal fun AlbaPageScaffold(title: String, onBack: () -> Unit, content: @Compo
}
}

/** Whether content sits on an [AlbaBottomSheet], whose container is already a step above the page. */
internal val LocalInAlbaSheet = staticCompositionLocalOf { false }

/**
* Alba's modal bottom sheet: Material's, on its own container colour and drag handle, with the body limited so the
* sheet never reaches the status bar.
*/
@OptIn(ExperimentalMaterial3Api::class)
@Composable
internal fun AlbaBottomSheet(
Expand All @@ -76,26 +85,46 @@ internal fun AlbaBottomSheet(
val windowHeight = with(density) { LocalWindowInfo.current.containerSize.height.toDp() }
val safeTop = with(density) { WindowInsets.safeDrawing.getTop(this).toDp() }
val maximumHeight = minOf(windowHeight * maxHeightFraction, windowHeight - safeTop - 16.dp).coerceAtLeast(0.dp)
// Material's sheet container, one step above the page, so a sheet rises off it in dark mode too.
val container = BottomSheetDefaults.ContainerColor
ModalBottomSheet(
onDismissRequest = onDismissRequest, modifier = modifier, sheetState = sheetState,
containerColor = MaterialTheme.colorScheme.background, tonalElevation = 0.dp,
containerColor = container,
properties = ModalBottomSheetProperties(
isAppearanceLightStatusBars = MaterialTheme.colorScheme.background.luminance() > .5f,
isAppearanceLightNavigationBars = MaterialTheme.colorScheme.background.luminance() > .5f,
isAppearanceLightNavigationBars = container.luminance() > .5f,
),
shape = MaterialTheme.shapes.sheet,
// Scrolling bodies supply their own trailing navigation inset. Avoid clipping the
// whole sheet above the gesture area, which creates an opaque rectangular shelf.
contentWindowInsets = { WindowInsets.safeDrawing.only(WindowInsetsSides.Horizontal) },
// Limit the body, not the modal itself: its drag anchors need the full window
// constraints to keep the sheet attached to the bottom edge. Reserve the handle.
content = { Column(Modifier.heightIn(max = (maximumHeight - 48.dp).coerceAtLeast(0.dp)), content = content) },
content = {
CompositionLocalProvider(LocalInAlbaSheet provides true) {
Column(Modifier.heightIn(max = (maximumHeight - 48.dp).coerceAtLeast(0.dp)), content = content)
}
},
)
}

/**
* A sheet's title, with Close at the end. [navigationIcon], when given, goes before the title, as a top app bar's does:
* a way up out of a level inside the sheet.
*/
@Composable
internal fun AlbaSheetHeading(title: String, subtitle: String? = null, dismiss: () -> Unit, enabled: Boolean = true) {
internal fun AlbaSheetHeading(
title: String,
subtitle: String? = null,
dismiss: () -> Unit,
enabled: Boolean = true,
navigationIcon: (@Composable () -> Unit)? = null,
) {
Row(Modifier.fillMaxWidth().padding(bottom = AlbaSpacing.sm), verticalAlignment = Alignment.Top) {
navigationIcon?.let {
it()
Spacer(Modifier.width(AlbaSpacing.xs))
}
Column(Modifier.weight(1f).padding(top = AlbaSpacing.sm), verticalArrangement = Arrangement.spacedBy(AlbaSpacing.xs)) {
Text(title, style = MaterialTheme.typography.titleLarge)
subtitle?.let { Text(it, style = MaterialTheme.typography.bodyMedium, color = MaterialTheme.colorScheme.onSurfaceVariant) }
Expand Down
11 changes: 7 additions & 4 deletions app/src/main/java/me/lvca/alba/app/ui/editor/EditorPanels.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import me.lvca.alba.app.editing.AutoEnhance
import me.lvca.alba.app.editing.ColorMatrices
import me.lvca.alba.app.editing.LookFilter
import me.lvca.alba.app.platform.PhotoCrop
import me.lvca.alba.app.ui.designsystem.AlbaIcons

internal val Adjustment.label: Int get() = when (this) {
Adjustment.BRIGHTNESS -> R.string.adjust_brightness
Expand Down Expand Up @@ -114,10 +115,12 @@ internal fun CropPanel(edit: PhotoEditState, preview: Bitmap?, enabled: Boolean,
val direction = if (edge < 2) 1f else -1f
Row(Modifier.fillMaxWidth(), verticalAlignment = Alignment.CenterVertically) {
Text(label, Modifier.weight(1f))
TextButton(enabled = enabled, onClick = { edit.adjustEdge(edge, -CROP_NUDGE * direction) },
modifier = Modifier.semantics { contentDescription = adjustmentLabels[edge].first }) { Text("−") }
TextButton(enabled = enabled, onClick = { edit.adjustEdge(edge, CROP_NUDGE * direction) },
modifier = Modifier.semantics { contentDescription = adjustmentLabels[edge].second }) { Text("+") }
IconButton(enabled = enabled, onClick = { edit.adjustEdge(edge, -CROP_NUDGE * direction) }) {
Icon(AlbaIcons.Remove, adjustmentLabels[edge].first)
}
IconButton(enabled = enabled, onClick = { edit.adjustEdge(edge, CROP_NUDGE * direction) }) {
Icon(AlbaIcons.Add, adjustmentLabels[edge].second)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,14 +242,11 @@ private fun EditorTopBar(
var menu by remember { mutableStateOf(false) }
Row(Modifier.fillMaxWidth().padding(horizontal = 8.dp), verticalAlignment = Alignment.CenterVertically) {
IconButton(onClick = requestClose, enabled = !saving) { Icon(AlbaIcons.Close, stringResource(R.string.cancel)) }
// Plain glyphs: the core icon set has no undo or redo arrows.
val undo = stringResource(R.string.undo_edit)
val redo = stringResource(R.string.redo_edit)
IconButton(onClick = edit::undo, enabled = !busy && edit.canUndo, modifier = Modifier.testTag("undo-edit").semantics { contentDescription = undo }) {
Text("↶", Modifier.clearAndSetSemantics { }, style = MaterialTheme.typography.titleLarge)
IconButton(onClick = edit::undo, enabled = !busy && edit.canUndo, modifier = Modifier.testTag("undo-edit")) {
Icon(AlbaIcons.Undo, stringResource(R.string.undo_edit))
}
IconButton(onClick = edit::redo, enabled = !busy && edit.canRedo, modifier = Modifier.testTag("redo-edit").semantics { contentDescription = redo }) {
Text("↷", Modifier.clearAndSetSemantics { }, style = MaterialTheme.typography.titleLarge)
IconButton(onClick = edit::redo, enabled = !busy && edit.canRedo, modifier = Modifier.testTag("redo-edit")) {
Icon(AlbaIcons.Redo, stringResource(R.string.redo_edit))
}
Spacer(Modifier.weight(1f))
Button(enabled = canSave, onClick = save, modifier = Modifier.testTag("save-edited-copy")) { Text(stringResource(R.string.save_copy)) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ internal fun GalleryFastScroll(grid: LazyGridState, labels: List<GalleryScrollLa
if (next != month) {
month = next
months.trySend(next)
haptic.performHapticFeedback(HapticFeedbackType.VirtualKey)
haptic.performHapticFeedback(HapticFeedbackType.SegmentFrequentTick)
}
change.consume()
}
Expand Down
19 changes: 13 additions & 6 deletions app/src/main/java/me/lvca/alba/app/ui/viewer/MediaDetailScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import androidx.compose.foundation.layout.*
import androidx.compose.foundation.pager.HorizontalPager
import androidx.compose.foundation.pager.PagerState
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.selection.toggleable
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.*
Expand Down Expand Up @@ -669,9 +670,10 @@ private fun ViewerActionBar(
} else ViewerAction(stringResource(R.string.details), true, onDetails, Modifier.weight(1f)) {
Icon(AlbaIcons.Info, null)
}
if (media.kind == MediaKind.LIVE_PHOTO) ViewerAction(stringResource(if (playingLive) R.string.show_still_photo else R.string.play_live_photo), true, onLive,
Modifier.weight(1f).testTag("viewer-live")) {
Icon(AlbaIcons.PlayArrow, null)
// A switch with a stable name: TalkBack reads "Live Photo, on" while the motion plays.
if (media.kind == MediaKind.LIVE_PHOTO) ViewerAction(stringResource(R.string.live_photo), true, onLive,
Modifier.weight(1f).testTag("viewer-live"), checked = playingLive) {
ICloudIcon(R.drawable.icloud_live_photos, tint = if (playingLive) MaterialTheme.colorScheme.primary else LocalContentColor.current)
}
}
}
Expand All @@ -681,12 +683,17 @@ private fun ViewerActionBar(
private val GalleryMedia.canJoinAlbum: Boolean
get() = origin == MediaOrigin.ICLOUD && !isShared && !(isHidden || isTrashed)

/** One viewer action, as Photos': a 24dp icon over a 14sp label, sharing the row's width evenly. */
/**
* One viewer action, as Photos': a 24dp icon over a 14sp label, sharing the row's width evenly. With [checked] it is a
* switch that keeps its label and reports on or off, rather than a button whose label changes.
*/
@Composable
private fun ViewerAction(label: String, enabled: Boolean, click: () -> Unit, modifier: Modifier = Modifier, description: String = label,
icon: @Composable () -> Unit) {
checked: Boolean? = null, icon: @Composable () -> Unit) {
val ink = LocalContentColor.current
Column(modifier.clickable(enabled = enabled, role = Role.Button, onClick = click)
val action = if (checked == null) Modifier.clickable(enabled = enabled, role = Role.Button, onClick = click)
else Modifier.toggleable(checked, enabled = enabled, role = Role.Switch) { click() }
Column(modifier.then(action)
.height(76.dp).semantics { contentDescription = description }, horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center) {
CompositionLocalProvider(LocalContentColor provides if (enabled) ink else ink.copy(alpha = .38f)) {
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/me/lvca/alba/app/ui/viewer/PhotoZoom.kt
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ internal fun Modifier.photoZoomGestures(state: PhotoZoomState, reduceMotion: Boo
awaitFirstDown(requireUnconsumed = false)
state.stop()
val gesture = ZoomGesture(state, density) {
haptics.performHapticFeedback(HapticFeedbackType.VirtualKey)
haptics.performHapticFeedback(HapticFeedbackType.GestureThresholdActivate)
}
// Whoever was told about this pinch to close hears how it ends, even if the viewer changed meanwhile.
var closing: PinchToClose? = null
Expand Down Expand Up @@ -444,7 +444,7 @@ internal fun Modifier.photoTapGestures(state: PhotoZoomState, reduceMotion: Bool
}
second.consume()
val quick = QuickScaleTracker(viewConfiguration.touchSlop, distancePx)
val zoom = ZoomGesture(state, density) { haptics.performHapticFeedback(HapticFeedbackType.VirtualKey) }
val zoom = ZoomGesture(state, density) { haptics.performHapticFeedback(HapticFeedbackType.GestureThresholdActivate) }
while (true) {
val event = awaitPointerEvent()
// A second finger turns this into a pinch, which photoZoomGestures handles.
Expand Down
Loading