Unofficial YouTube Music / Spotify Premium client for Android, built in Liquid Glass. Audio effects, Spotify Connect, listening history, 8 languages. Rust core on librespot.
Kotlin alternativeandroidandroid-applicationclientglassmorphisminnertubelibrespotliquid-glassspotifyspotify-connectspotifyapiyoutube-musicyoutube-playerytdlnis
Answer a tap with the element instead of a ripple
Leloniof4b9ee0845c2
diff --git a/app/src/main/java/dev/lelonio/square/ui/glass/Pressable.kt b/app/src/main/java/dev/lelonio/square/ui/glass/Pressable.ktnew file mode 100644index 0000000..b5cf110--- /dev/null+++ b/app/src/main/java/dev/lelonio/square/ui/glass/Pressable.kt@@ -0,0 +1,119 @@+package dev.lelonio.square.ui.glass++import androidx.compose.animation.core.Animatable+import androidx.compose.animation.core.FastOutSlowInEasing+import androidx.compose.animation.core.Spring+import androidx.compose.animation.core.spring+import androidx.compose.animation.core.tween+import androidx.compose.foundation.combinedClickable+import androidx.compose.foundation.interaction.MutableInteractionSource+import androidx.compose.foundation.interaction.PressInteraction+import androidx.compose.runtime.Composable+import androidx.compose.runtime.LaunchedEffect+import androidx.compose.runtime.remember+import androidx.compose.ui.Modifier+import androidx.compose.ui.draw.drawWithContent+import androidx.compose.ui.graphics.Color+import androidx.compose.ui.graphics.Shape+import androidx.compose.ui.graphics.drawOutline+import androidx.compose.ui.graphics.graphicsLayer++/**+ * A tap that the element answers itself, instead of a ripple over it.+ *+ * Material's ripple expands a circle from the finger and fills the whole hit+ * area with the theme's colour. On this interface that is wrong twice over: the+ * covers are pictures rather than surfaces, so the wash sits on top of the+ * artwork, and the shape the ripple fills is the layout box rather than the+ * rounded tile the user can see.+ *+ * What replaces it is the press itself. The element gives a little under the+ * finger and springs back when it is let go, which is the whole of the+ * feedback: no colour over the artwork, and nothing drawn outside the shape.+ * Rows, which are mostly empty space and where a shrink alone reads as a+ * wobble, can pass a [shape] and get a soft tint inside it as well.+ */+@Composable+fun Modifier.pressable(+ onClick: () -> Unit,+ /** When set, the row is tinted inside this shape while held. */+ shape: Shape? = null,+ /** How far it gives. Small tiles want less than a full-width card. */+ pressedScale: Float = 0.96f,+ onLongClick: (() -> Unit)? = null,+ enabled: Boolean = true,+): Modifier {+ val interaction = remember { MutableInteractionSource() }++ // Read as a stream of presses and releases rather than as a "held" flag.+ //+ // A flag gives no way to tell a tap from an element that has simply never+ // been touched, and no time to play anything: a tap is over in a few dozen+ // milliseconds, so an animation that turns round the moment the flag drops+ // never gets far enough down to be seen. Only a deliberate hold showed+ // anything, and answering the flag's initial value animated everything on+ // screen at once as it scrolled in.+ //+ // Handled one event at a time, so the dip is always finished before it is+ // undone: the release waits its turn while the element goes down, and+ // whatever the finger did, what is seen is a full press and a release.+ val scale = remember { Animatable(1f) }+ LaunchedEffect(interaction, enabled, pressedScale) {+ interaction.interactions.collect { event ->+ when (event) {+ is PressInteraction.Press -> if (enabled) {+ scale.animateTo(pressedScale, tween(90, easing = FastOutSlowInEasing))+ }++ is PressInteraction.Release, is PressInteraction.Cancel -> {+ // Softly damped rather than bouncy on the way back: this+ // fires dozens of times a session, and an overshoot that+ // reads as lively on the first tap reads as loose by the+ // tenth.+ scale.animateTo(+ 1f,+ spring(+ dampingRatio = Spring.DampingRatioNoBouncy,+ stiffness = Spring.StiffnessMediumLow,+ ),+ )+ }+ }+ }+ }++ // Tied to the dip instead of animated on its own, so the two cannot come+ // apart on a fast tap.+ val travel = (1f - pressedScale).coerceAtLeast(0.0001f)+ val tint = ((1f - scale.value) / travel).coerceIn(0f, 1f) * 0.10f++ return this+ .graphicsLayer {+ scaleX = scale.value+ scaleY = scale.value+ }+ .then(+ if (shape == null) {+ Modifier+ } else {+ Modifier.drawWithContent {+ drawContent()+ if (tint > 0f) {+ drawOutline(+ outline = shape.createOutline(size, layoutDirection, this),+ color = Color.White.copy(alpha = tint),+ )+ }+ }+ },+ )+ .combinedClickable(+ interactionSource = interaction,+ // The press animation is the indication. Leaving the default here+ // would draw the ripple on top of it.+ indication = null,+ enabled = enabled,+ onLongClick = onLongClick,+ onClick = onClick,+ )+}diff --git a/app/src/main/java/dev/lelonio/square/ui/home/HomeScreen.kt b/app/src/main/java/dev/lelonio/square/ui/home/HomeScreen.ktindex e243084..d87c82e 100644--- a/app/src/main/java/dev/lelonio/square/ui/home/HomeScreen.kt+++ b/app/src/main/java/dev/lelonio/square/ui/home/HomeScreen.kt@@ -2,7 +2,6 @@ package dev.lelonio.square.ui.homeimport androidx.annotation.StringResimport androidx.compose.foundation.background-import androidx.compose.foundation.clickableimport androidx.compose.foundation.layout.Arrangementimport androidx.compose.foundation.layout.Boximport androidx.compose.foundation.layout.Column@@ -76,6 +75,7 @@ import dev.lelonio.square.ui.components.SquareWordmarkimport androidx.compose.ui.layout.layoutimport androidx.compose.ui.unit.Constraintsimport dev.lelonio.square.ui.glass.LiquidButton+import dev.lelonio.square.ui.glass.pressableimport dev.lelonio.square.ui.player.GlassFilmimport dev.lelonio.square.ui.theme.Inkimport dev.lelonio.square.ui.theme.InkDim@@ -591,7 +591,7 @@ private fun Header(layout(side, side) { placeable.place(0, 0) }}.clip(CircleShape)- .clickable(onClick = onOpenSettings)+ .pressable(onOpenSettings, pressedScale = 0.90f).softShadow(CircleShape, elevation = 10.dp),corner = 23.dp,decodeSize = 46.dp,@@ -651,7 +651,7 @@ private fun FeedCard(item: SearchItem, onClick: () -> Unit) {.fillMaxWidth().softShadow(shape, elevation = 26.dp, spot = 0.55f).clip(shape)- .clickable(onClick = onClick),+ .pressable(onClick, pressedScale = 0.98f),) {// The same cover twice, and that is the point.//@@ -719,7 +719,7 @@ private fun ArtistTile(artist: SearchItem, onClick: () -> Unit) {Column(Modifier.width(110.dp)- .clickable(onClick = onClick),+ .pressable(onClick),horizontalAlignment = Alignment.CenterHorizontally,) {Artwork(@@ -747,7 +747,7 @@ private fun PlaylistTile(playlist: CatalogPlaylist, onClick: () -> Unit) {Column(Modifier.width(152.dp)- .clickable(onClick = onClick),+ .pressable(onClick),) {Artwork(url = playlist.artworkUrl,@@ -774,7 +774,7 @@ private fun TrackTile(track: CatalogTrack, onClick: () -> Unit) {// which spreads wider than the tile itself.Modifier.width(128.dp)- .clickable(onClick = onClick),+ .pressable(onClick),) {Artwork(url = track.artworkUrl,@@ -882,7 +882,7 @@ private fun FeedTile(item: SearchItem, onClick: () -> Unit) {Column(Modifier.width(152.dp)- .clickable(onClick = onClick),+ .pressable(onClick),) {Artwork(url = item.artworkUrl,diff --git a/app/src/main/java/dev/lelonio/square/ui/library/LibraryScreen.kt b/app/src/main/java/dev/lelonio/square/ui/library/LibraryScreen.ktindex a82252f..68186be 100644--- a/app/src/main/java/dev/lelonio/square/ui/library/LibraryScreen.kt+++ b/app/src/main/java/dev/lelonio/square/ui/library/LibraryScreen.kt@@ -1,8 +1,6 @@package dev.lelonio.square.ui.libraryimport androidx.annotation.StringRes-import androidx.compose.foundation.clickable-import androidx.compose.foundation.combinedClickableimport androidx.compose.foundation.layout.Arrangementimport androidx.compose.foundation.layout.Boximport androidx.compose.foundation.layout.Column@@ -44,6 +42,7 @@ import dev.lelonio.square.data.sortedByRecentlyOpenedimport dev.lelonio.square.ui.MainViewModelimport dev.lelonio.square.ui.components.Artworkimport dev.lelonio.square.ui.glass.LiquidButton+import dev.lelonio.square.ui.glass.pressableimport dev.lelonio.square.ui.player.GlassFilmimport dev.lelonio.square.ui.theme.Inkimport dev.lelonio.square.ui.theme.InkDim@@ -316,7 +315,7 @@ private fun GridTile(onLongClick: (() -> Unit)?,) {Column(- Modifier.combinedClickable(onClick = onClick, onLongClick = onLongClick),+ Modifier.pressable(onClick, onLongClick = onLongClick),) {Artwork(url = playlist.artworkUrl,@@ -348,7 +347,12 @@ private fun ListRow(Modifier.fillMaxWidth().clip(RoundedCornerShape(16.dp))- .combinedClickable(onClick = onClick, onLongClick = onLongClick)+ .pressable(+ onClick,+ shape = RoundedCornerShape(16.dp),+ pressedScale = 0.98f,+ onLongClick = onLongClick,+ ).padding(vertical = 8.dp),verticalAlignment = Alignment.CenterVertically,) {diff --git a/app/src/main/java/dev/lelonio/square/ui/library/PlaylistScreen.kt b/app/src/main/java/dev/lelonio/square/ui/library/PlaylistScreen.ktindex 57addba..c966087 100644--- a/app/src/main/java/dev/lelonio/square/ui/library/PlaylistScreen.kt+++ b/app/src/main/java/dev/lelonio/square/ui/library/PlaylistScreen.kt@@ -5,7 +5,6 @@ import androidx.compose.animation.AnimatedVisibilityimport androidx.compose.animation.core.animateFloatAsStateimport androidx.compose.animation.core.tweenimport androidx.compose.foundation.background-import androidx.compose.foundation.clickableimport androidx.compose.foundation.layout.Arrangementimport androidx.compose.foundation.layout.Boximport androidx.compose.foundation.layout.Column@@ -79,6 +78,7 @@ import dev.lelonio.square.ui.components.GlassChoiceMenuimport dev.lelonio.square.ui.components.LazyScrollBarimport dev.lelonio.square.ui.components.SwipeToQueueimport dev.lelonio.square.ui.glass.LiquidButton+import dev.lelonio.square.ui.glass.pressableimport dev.lelonio.square.ui.theme.rememberArtworkColorimport dev.lelonio.square.ui.theme.softShadowimport java.util.Locale@@ -579,7 +579,7 @@ private fun DetailHeader(.softShadow(CircleShape, elevation = 18.dp, spot = 0.3f).clip(CircleShape).background(Color.White)- .clickable(onClick = onPlay),+ .pressable(onPlay, pressedScale = 0.92f),contentAlignment = Alignment.Center,) {Icon(@@ -772,7 +772,7 @@ private fun AlbumStrip(Column(Modifier.width(132.dp)- .clickable { onOpen(album) },+ .pressable({ onOpen(album) }),) {Artwork(url = album.artworkUrl,@@ -895,7 +895,7 @@ private fun TrackRow(alpha = MaterialTheme.colorScheme.surface.alpha * highlight,),)- .clickable(onClick = onClick)+ .pressable(onClick, shape = shape, pressedScale = 0.985f).padding(horizontal = 12.dp, vertical = 11.dp),verticalAlignment = Alignment.CenterVertically,) {diff --git a/app/src/main/java/dev/lelonio/square/ui/player/PlayerScreen.kt b/app/src/main/java/dev/lelonio/square/ui/player/PlayerScreen.ktindex b3942f9..626ce72 100644--- a/app/src/main/java/dev/lelonio/square/ui/player/PlayerScreen.kt+++ b/app/src/main/java/dev/lelonio/square/ui/player/PlayerScreen.kt@@ -19,6 +19,7 @@ import androidx.compose.foundation.backgroundimport androidx.compose.foundation.verticalScrollimport androidx.compose.foundation.rememberScrollStateimport androidx.compose.foundation.clickable+import androidx.compose.foundation.interaction.MutableInteractionSourceimport androidx.compose.foundation.layout.Arrangementimport androidx.compose.foundation.layout.Boximport androidx.compose.foundation.layout.Column@@ -177,6 +178,11 @@ fun PlayerScreen(* of one thing.*/onAddToPlaylist: () -> Unit,+ /**+ * Opens an artist, a playlist or an album by uri, with a name to show while+ * it loads. The player closes itself first; see the two callers.+ */+ onOpenUri: (String, String) -> Unit = { _, _ -> },/*** Whether this track is already in one of the account's playlists.*@@ -396,6 +402,12 @@ fun PlayerScreen(backdrop = glassBackdrop,panel = panel,source = state.source,+ onOpenSource = state.contextUri?.let { uri ->+ {+ onCollapse()+ onOpenUri(uri, state.source.substringAfterLast("· ").trim())+ }+ },onCollapse = onCollapse,onOpenDevices = {panel = if (panel == PlayerPanel.DEVICES) {@@ -599,7 +611,16 @@ fun PlayerScreen(Modifier.padding(start = 22.dp, end = 10.dp, top = 12.dp, bottom = 12.dp),verticalAlignment = Alignment.CenterVertically,) {- TitleBlock(state, Modifier.weight(1f))+ TitleBlock(+ state,+ Modifier.weight(1f),+ onOpenArtist = {+ state.artistUri?.let { uri ->+ onCollapse()+ onOpenUri(uri, state.artist)+ }+ },+ )// The queue's one control. It is a sheet that// opens over the player rather than a view of// it, which is why it sits here and not in the@@ -881,6 +902,8 @@ private fun TopBar(panel: PlayerPanel,/** Where the queue came from: "Playlist · Estate 2025", "Ricerca". */source: String,+ /** Opens that place, when it is one; null leaves the line as a caption. */+ onOpenSource: (() -> Unit)?,onCollapse: () -> Unit,onOpenDevices: () -> Unit,connectAvailable: Boolean,@@ -918,11 +941,19 @@ private fun TopBar(label = "topBarTitle",modifier = Modifier.weight(1f),) { title ->+ // Only the source line is a way back, and only while it is the one+ // being shown: the panel names above it are labels for what is on+ // screen already.+ val open = onOpenSource.takeIf { panel == PlayerPanel.NONE && source.isNotBlank() }Text(title,style = MaterialTheme.typography.titleMedium,textAlign = TextAlign.Center,- modifier = Modifier.fillMaxWidth(),+ modifier = Modifier+ .fillMaxWidth()+ .then(+ if (open != null) Modifier.plainClickable(open) else Modifier,+ ),)}// Connect gets the permanent slot rather than hiding behind "more":@@ -1036,7 +1067,11 @@ private fun Cover(}@Composable-private fun TitleBlock(state: PlaybackState, modifier: Modifier = Modifier) {+private fun TitleBlock(+ state: PlaybackState,+ modifier: Modifier = Modifier,+ onOpenArtist: () -> Unit = {},+) {// Slid rather than swapped on a track change: this capsule is the only place// the track is named now that the big cover is gone, so the change has to be// visible without watching for it.@@ -1056,17 +1091,39 @@ private fun TitleBlock(state: PlaybackState, modifier: Modifier = Modifier) {maxLines = 1,overflow = TextOverflow.Ellipsis,)+ // Tappable only when there is somewhere to go: a queue built from+ // search results, or a track another device is playing, names an+ // artist this app has no page for, and a line that looks like a+ // link and does nothing is worse than plain text.Text(text = artist,style = MaterialTheme.typography.bodyMedium,color = GlassInkDim,maxLines = 1,overflow = TextOverflow.Ellipsis,+ modifier = if (state.artistUri != null) {+ Modifier.plainClickable(onOpenArtist)+ } else {+ Modifier+ },)}}}+/**+ * A tap with no ripple behind it.+ *+ * These two are lines of text rather than controls, and the ripple draws a+ * rectangle around a word: the highlight ends up wider and squarer than the+ * thing it is meant to be acknowledging.+ */+@Composable+private fun Modifier.plainClickable(onClick: () -> Unit): Modifier {+ val interaction = remember { MutableInteractionSource() }+ return clickable(interactionSource = interaction, indication = null, onClick = onClick)+}+/** Isolated so the ticking position recomposes only these two labels. */@Composableprivate fun TimeRow(positionMs: State<Long>, durationMs: Long) {diff --git a/app/src/main/java/dev/lelonio/square/ui/search/SearchScreen.kt b/app/src/main/java/dev/lelonio/square/ui/search/SearchScreen.ktindex e10ae86..b49fd2d 100644--- a/app/src/main/java/dev/lelonio/square/ui/search/SearchScreen.kt+++ b/app/src/main/java/dev/lelonio/square/ui/search/SearchScreen.kt@@ -2,7 +2,6 @@ package dev.lelonio.square.ui.searchimport androidx.annotation.StringResimport androidx.compose.foundation.background-import androidx.compose.foundation.clickableimport androidx.compose.foundation.layout.Arrangementimport androidx.compose.foundation.layout.Boximport androidx.compose.foundation.layout.Column@@ -46,6 +45,7 @@ import dev.lelonio.square.ui.MainViewModelimport dev.lelonio.square.ui.components.Artworkimport dev.lelonio.square.ui.components.SwipeToQueueimport dev.lelonio.square.ui.glass.LiquidButton+import dev.lelonio.square.ui.glass.pressableimport dev.lelonio.square.ui.player.GlassFilmimport dev.lelonio.square.ui.settings.WebApiSetupimport dev.lelonio.square.ui.theme.Ink@@ -246,7 +246,7 @@ private fun SearchField(tint = InkDim,modifier = Modifier.clip(RoundedCornerShape(50))- .clickable { onQueryChange("") }+ .pressable({ onQueryChange("") }, pressedScale = 0.88f).size(20.dp),)}@@ -333,7 +333,7 @@ private fun ResultRow(Row(Modifier.fillMaxWidth()- .clickable(onClick = onClick)+ .pressable(onClick, shape = RoundedCornerShape(16.dp), pressedScale = 0.98f).padding(start = 24.dp, end = 12.dp, top = 8.dp, bottom = 8.dp),verticalAlignment = Alignment.CenterVertically,) {@@ -373,7 +373,7 @@ private fun ResultRow(tint = InkDim,modifier = Modifier.clip(RoundedCornerShape(50))- .clickable(onClick = onMenu)+ .pressable(onMenu, pressedScale = 0.88f).padding(10.dp).size(20.dp),)