Skip to content

Unofficial YouTube Music / Spotify Premium client for Android, built in Liquid Glass. Audio effects, Spotify Connect, listening history, 8 languages. Rust core on librespot.

Close the player by gesture, not by dragging it around

Lelonio3ee598a46d1a
diff --git a/.claude/settings.local.json b/.claude/settings.local.json
index 6b048b9..2f46be5 100644
--- a/.claude/settings.local.json
+++ b/.claude/settings.local.json
@@ -101,7 +101,8 @@
"Bash(javap -classpath . com.adamglin.phosphoricons.__FillKt)",
"Bash(xargs -0 sed -i '' -e s/Magnifyingglass/MagnifyingGlass/g -e s/Musicnotes/MusicNotes/g -e s/Skipback/SkipBack/g -e s/Skipforward/SkipForward/g -e s/Arrowclockwise/ArrowClockwise/g -e s/Arrowleft/ArrowLeft/g -e s/Arrowsdownup/ArrowsDownUp/g -e s/Caretdown/CaretDown/g -e s/Devicemobile/DeviceMobile/g -e s/Dotsthree/DotsThree/g -e s/Listbullets/ListBullets/g -e s/Slidershorizontal/SlidersHorizontal/g -e s/Speakerhifi/SpeakerHifi/g -e s/Squaresfour/SquaresFour/g -e s/Textalignleft/TextAlignLeft/g -e s/Vinylrecord/VinylRecord/g -e s/RepeatOne/RepeatOnce/g)",
"Bash(./gradlew :app:assembleDev -q)",
- "Bash(git commit -q -m 'Swap every icon to Phosphor *)"
+ "Bash(git commit -q -m 'Swap every icon to Phosphor *)",
+ "Bash(git commit -q -m 'Close the player by gesture, not by dragging it around *)"
]
}
}
diff --git a/app/.cxx/RelWithDebInfo/151m4dr6/arm64-v8a/configure_fingerprint.bin b/app/.cxx/RelWithDebInfo/151m4dr6/arm64-v8a/configure_fingerprint.bin
index fd4053a..a11ba5f 100644
--- a/app/.cxx/RelWithDebInfo/151m4dr6/arm64-v8a/configure_fingerprint.bin
+++ b/app/.cxx/RelWithDebInfo/151m4dr6/arm64-v8a/configure_fingerprint.bin
@@ -2,27 +2,27 @@ C/C++ Structured Logl
j
h/Users/emanuele/Progetto Spotify/app/.cxx/RelWithDebInfo/151m4dr6/arm64-v8a/additional_project_files.txtC
A
-?com.android.build.gradle.internal.cxx.io.EncodedFileFingerPrint  �����3  ����3i
+?com.android.build.gradle.internal.cxx.io.EncodedFileFingerPrint  �����3  ����3i
g
-e/Users/emanuele/Progetto Spotify/app/.cxx/RelWithDebInfo/151m4dr6/arm64-v8a/android_gradle_build.json  �����3� ����3n
+e/Users/emanuele/Progetto Spotify/app/.cxx/RelWithDebInfo/151m4dr6/arm64-v8a/android_gradle_build.json  �����3� ����3n
l
-j/Users/emanuele/Progetto Spotify/app/.cxx/RelWithDebInfo/151m4dr6/arm64-v8a/android_gradle_build_mini.json  �����3� �����3[
+j/Users/emanuele/Progetto Spotify/app/.cxx/RelWithDebInfo/151m4dr6/arm64-v8a/android_gradle_build_mini.json  �����3� �����3[
Y
-W/Users/emanuele/Progetto Spotify/app/.cxx/RelWithDebInfo/151m4dr6/arm64-v8a/build.ninja  �����3�� ����3_
+W/Users/emanuele/Progetto Spotify/app/.cxx/RelWithDebInfo/151m4dr6/arm64-v8a/build.ninja  �����3�� ����3_
]
-[/Users/emanuele/Progetto Spotify/app/.cxx/RelWithDebInfo/151m4dr6/arm64-v8a/build.ninja.txt  �����3d
+[/Users/emanuele/Progetto Spotify/app/.cxx/RelWithDebInfo/151m4dr6/arm64-v8a/build.ninja.txt  �����3d
b
-`/Users/emanuele/Progetto Spotify/app/.cxx/RelWithDebInfo/151m4dr6/arm64-v8a/build_file_index.txt  �����3 @ ����3e
+`/Users/emanuele/Progetto Spotify/app/.cxx/RelWithDebInfo/151m4dr6/arm64-v8a/build_file_index.txt  �����3 @ ����3e
c
-a/Users/emanuele/Progetto Spotify/app/.cxx/RelWithDebInfo/151m4dr6/arm64-v8a/compile_commands.json  �����3�� ����3i
+a/Users/emanuele/Progetto Spotify/app/.cxx/RelWithDebInfo/151m4dr6/arm64-v8a/compile_commands.json  �����3�� ����3i
g
-e/Users/emanuele/Progetto Spotify/app/.cxx/RelWithDebInfo/151m4dr6/arm64-v8a/compile_commands.json.bin  �����3 �" ����3o
+e/Users/emanuele/Progetto Spotify/app/.cxx/RelWithDebInfo/151m4dr6/arm64-v8a/compile_commands.json.bin  �����3 �" ����3o
m
-k/Users/emanuele/Progetto Spotify/app/.cxx/RelWithDebInfo/151m4dr6/arm64-v8a/metadata_generation_command.txt  �����3
+k/Users/emanuele/Progetto Spotify/app/.cxx/RelWithDebInfo/151m4dr6/arm64-v8a/metadata_generation_command.txt  �����3
� ����3b
`
-^/Users/emanuele/Progetto Spotify/app/.cxx/RelWithDebInfo/151m4dr6/arm64-v8a/prefab_config.json  �����3  ( ����3g
+^/Users/emanuele/Progetto Spotify/app/.cxx/RelWithDebInfo/151m4dr6/arm64-v8a/prefab_config.json  �����3  ( ����3g
e
-c/Users/emanuele/Progetto Spotify/app/.cxx/RelWithDebInfo/151m4dr6/arm64-v8a/symbol_folder_index.txt  �����3  b ����3D
+c/Users/emanuele/Progetto Spotify/app/.cxx/RelWithDebInfo/151m4dr6/arm64-v8a/symbol_folder_index.txt  �����3  b ����3D
B
-@/Users/emanuele/Progetto Spotify/app/src/main/cpp/CMakeLists.txt  �����3 � �Ȅ��3
\ No newline at end of file
+@/Users/emanuele/Progetto Spotify/app/src/main/cpp/CMakeLists.txt  �����3 � �Ȅ��3
\ No newline at end of file
diff --git a/app/src/main/java/dev/emanuele/spot/ui/glass/LiquidBottomTabs.kt b/app/src/main/java/dev/emanuele/spot/ui/glass/LiquidBottomTabs.kt
index c8bbd6d..ab5c269 100644
--- a/app/src/main/java/dev/emanuele/spot/ui/glass/LiquidBottomTabs.kt
+++ b/app/src/main/java/dev/emanuele/spot/ui/glass/LiquidBottomTabs.kt
@@ -83,6 +83,12 @@ fun LiquidBottomTabs(
// version of the same control, and copying the file to change one number
// would leave two of them to keep in step.
height: Dp = 64f.dp,
+ // LOCAL CHANGE: how deep the capsule refracts what is behind it. Upstream's
+ // 24dp is tuned for the 64dp bar; on a shorter one the bend coming down from
+ // the top edge and the bend coming up from the bottom meet in the middle and
+ // leave a hard horizontal seam across the glass. Keep it below half the
+ // height.
+ lensDepth: Dp = 24f.dp,
content: @Composable RowScope.() -> Unit
) {
val isLightTheme = !isSystemInDarkTheme()
@@ -183,7 +189,7 @@ fun LiquidBottomTabs(
effects = {
vibrancy()
blur(8f.dp.toPx())
- lens(24f.dp.toPx(), 24f.dp.toPx())
+ lens(lensDepth.toPx(), lensDepth.toPx())
},
layerBlock = {
val progress = dampedDragAnimation.pressProgress
@@ -222,8 +228,8 @@ fun LiquidBottomTabs(
vibrancy()
blur(8f.dp.toPx())
lens(
- 24f.dp.toPx() * progress,
- 24f.dp.toPx() * progress
+ lensDepth.toPx() * progress,
+ lensDepth.toPx() * progress
)
},
highlight = {
diff --git a/app/src/main/java/dev/emanuele/spot/ui/player/CoverGestures.kt b/app/src/main/java/dev/emanuele/spot/ui/player/CoverGestures.kt
index bf91fa5..5dd66b6 100644
--- a/app/src/main/java/dev/emanuele/spot/ui/player/CoverGestures.kt
+++ b/app/src/main/java/dev/emanuele/spot/ui/player/CoverGestures.kt
@@ -38,6 +38,11 @@ fun CoverGestures(
canGoNext: Boolean,
canGoPrevious: Boolean,
modifier: Modifier = Modifier,
+ /**
+ * Whether the content tracks the finger. Off over a Canvas, where the thing
+ * the swipe refers to is the clip behind this box rather than the box.
+ */
+ followFinger: Boolean = true,
content: @Composable () -> Unit,
) {
val offsetX = remember { Animatable(0f) }
@@ -51,6 +56,7 @@ fun CoverGestures(
Box(
modifier
.graphicsLayer {
+ if (!followFinger) return@graphicsLayer
translationX = offsetX.value
// Dimmest exactly where releasing would act.
val travel = abs(offsetX.value) / threshold
diff --git a/app/src/main/java/dev/emanuele/spot/ui/player/DismissibleScreen.kt b/app/src/main/java/dev/emanuele/spot/ui/player/DismissibleScreen.kt
index 3923d34..f661291 100644
--- a/app/src/main/java/dev/emanuele/spot/ui/player/DismissibleScreen.kt
+++ b/app/src/main/java/dev/emanuele/spot/ui/player/DismissibleScreen.kt
@@ -1,15 +1,11 @@
package dev.emanuele.spot.ui.player
-import androidx.compose.animation.core.Animatable
-import androidx.compose.animation.core.spring
import androidx.compose.foundation.gestures.detectVerticalDragGestures
import androidx.compose.foundation.layout.Box
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
-import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset
-import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
import androidx.compose.ui.input.nestedscroll.NestedScrollConnection
import androidx.compose.ui.input.nestedscroll.NestedScrollSource
@@ -19,24 +15,25 @@ import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.platform.LocalHapticFeedback
import androidx.compose.ui.unit.Velocity
import androidx.compose.ui.unit.dp
-import kotlinx.coroutines.launch
/**
- * Drag anywhere on the screen to push it down and close it.
+ * Drag down anywhere on the screen to close it.
*
- * The whole screen moves, not just the cover. The first version put this on the
- * cover alongside the track-change swipe, which had two problems: the gesture
- * only worked if you happened to start on the artwork, and it slid the cover
- * out from under a header and a set of controls that stayed put — the screen
- * came apart instead of leaving.
+ * A gesture, not a transform: the screen does not follow the finger. It used to
+ * — it slid, shrank and faded with the drag — but the player is already a sheet
+ * that animates itself into the now-playing bar, so a second, different
+ * displacement of the same content on the same axis meant a downward drag pulled
+ * the whole screen around before anything committed. Once the drag passes the
+ * threshold this hands over to that one animation, which is the only thing that
+ * should be moving the player.
*
* Wired through [NestedScrollConnection] rather than a plain drag detector
* because the content scrolls. A drag detector on the parent and a scrolling
* child fight over the same vertical axis; nested scroll gives a defined order —
* the list gets the drag first, and only what it cannot use reaches this. So a
* downward drag scrolls the content until it hits the top, and from there the
- * same continuous movement starts closing the screen. The pointer input below
- * covers the parts that do not scroll at all.
+ * same continuous movement closes the screen. The pointer input below covers the
+ * parts that do not scroll at all.
*/
@Composable
fun DismissibleScreen(
@@ -44,43 +41,37 @@ fun DismissibleScreen(
modifier: Modifier = Modifier,
content: @Composable () -> Unit,
) {
- val offset = remember { Animatable(0f) }
- val scope = rememberCoroutineScope()
val haptics = LocalHapticFeedback.current
val density = LocalDensity.current
val threshold = with(density) { DISMISS_THRESHOLD.toPx() }
- fun settle() {
- if (offset.value >= threshold) {
- haptics.performHapticFeedback(HapticFeedbackType.LongPress)
- onDismiss()
- // Not animated away: the navigation transition takes over from here,
- // and running both would play two exits on top of each other.
- scope.launch { offset.snapTo(0f) }
- } else {
- scope.launch { offset.animateTo(0f, spring()) }
- }
+ // Plain vars in a remembered holder rather than state: nothing recomposes on
+ // them, they only have to survive between drag events.
+ val travel = remember { Travel() }
+
+ fun reset() {
+ travel.distance = 0f
+ travel.fired = false
}
fun drag(amount: Float) {
- // Upward movement is resisted rather than ignored, so overscrolling at
- // the top has some give instead of stopping dead.
- val next = if (offset.value + amount < 0f) offset.value + amount * 0.2f else offset.value + amount
- scope.launch { offset.snapTo(next.coerceAtLeast(0f)) }
+ if (travel.fired) return
+ // Upward movement gives the accumulated distance back instead of going
+ // negative, so a drag that wanders up and down does not close the player
+ // on its total rather than its extent.
+ travel.distance = (travel.distance + amount).coerceAtLeast(0f)
+ if (travel.distance >= threshold) {
+ travel.fired = true
+ haptics.performHapticFeedback(HapticFeedbackType.LongPress)
+ onDismiss()
+ }
}
val connection = remember {
object : NestedScrollConnection {
override fun onPreScroll(available: Offset, source: NestedScrollSource): Offset {
- // While the screen is already pulled down, an upward drag puts
- // it back before the content is allowed to scroll again —
- // otherwise the list starts moving with the screen still
- // displaced.
- if (available.y < 0 && offset.value > 0f) {
- drag(available.y)
- return Offset(0f, available.y)
- }
+ if (available.y < 0) travel.distance = 0f
return Offset.Zero
}
@@ -99,10 +90,7 @@ fun DismissibleScreen(
}
override suspend fun onPreFling(available: Velocity): Velocity {
- if (offset.value > 0f) {
- settle()
- return available
- }
+ reset()
return Velocity.Zero
}
}
@@ -110,21 +98,12 @@ fun DismissibleScreen(
Box(
modifier
- .graphicsLayer {
- translationY = offset.value
- // Scales and fades with the travel so the screen reads as
- // receding, not merely sliding off the bottom.
- val travel = (offset.value / threshold).coerceIn(0f, 1f)
- val shrink = 1f - travel * 0.08f
- scaleX = shrink
- scaleY = shrink
- alpha = 1f - travel * 0.35f
- }
.nestedScroll(connection)
.pointerInput(Unit) {
detectVerticalDragGestures(
- onDragEnd = { settle() },
- onDragCancel = { scope.launch { offset.animateTo(0f, spring()) } },
+ onDragStart = { reset() },
+ onDragEnd = { reset() },
+ onDragCancel = { reset() },
) { change, amount ->
change.consume()
drag(amount)
@@ -135,4 +114,9 @@ fun DismissibleScreen(
}
}
-private val DISMISS_THRESHOLD = 140.dp
+private class Travel {
+ var distance = 0f
+ var fired = false
+}
+
+private val DISMISS_THRESHOLD = 110.dp
diff --git a/app/src/main/java/dev/emanuele/spot/ui/player/PlayerPanel.kt b/app/src/main/java/dev/emanuele/spot/ui/player/PlayerPanel.kt
index 6469ca6..ce8ea52 100644
--- a/app/src/main/java/dev/emanuele/spot/ui/player/PlayerPanel.kt
+++ b/app/src/main/java/dev/emanuele/spot/ui/player/PlayerPanel.kt
@@ -109,6 +109,9 @@ fun PlayerPanelSection(
// transport rather than at the edge of the window, so it has to
// read as a smaller thing than the app's own navigation.
height = 42.dp,
+ // Under half the height, or the refraction from the two long edges
+ // meets in the middle and draws a seam across the capsule.
+ lensDepth = 12.dp,
modifier = Modifier
.fillMaxWidth(0.72f)
.padding(top = 14.dp),
diff --git a/app/src/main/java/dev/emanuele/spot/ui/player/PlayerScreen.kt b/app/src/main/java/dev/emanuele/spot/ui/player/PlayerScreen.kt
index d47f2bf..4b66168 100644
--- a/app/src/main/java/dev/emanuele/spot/ui/player/PlayerScreen.kt
+++ b/app/src/main/java/dev/emanuele/spot/ui/player/PlayerScreen.kt
@@ -331,7 +331,22 @@ fun PlayerScreen(
// The clip is the picture, and it is drawn
// behind everything: this slot only has to keep
// the space.
- Stage.CANVAS -> Box(Modifier.fillMaxSize())
+ // With a clip playing there is no cover to
+ // swipe, and the track-change gesture went with
+ // it. The slot keeps the same drag handler over
+ // the clip — nothing moves, because the clip is
+ // drawn behind this and is not ours to shift,
+ // but the swipe still changes track.
+ Stage.CANVAS -> CoverGestures(
+ onNext = onNext,
+ onPrevious = onPrevious,
+ canGoNext = state.hasNext,
+ canGoPrevious = state.hasPrevious,
+ followFinger = false,
+ modifier = Modifier.fillMaxSize(),
+ ) {
+ Box(Modifier.fillMaxSize())
+ }
}
}