Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
25huizengek1 committed Apr 23, 2024
1 parent 767457e commit ade84cb
Show file tree
Hide file tree
Showing 17 changed files with 101 additions and 93 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,18 +131,16 @@ class BottomSheetState(
animatable.animateTo(newValue, spec)
}

fun collapse(spec: AnimationSpec<Dp>) {
private fun collapse(spec: AnimationSpec<Dp> = spring()) {
onAnchorChanged(Anchor.Collapsed)
deferAnimateTo(collapsedBound, spec)
}

fun expand(spec: AnimationSpec<Dp>) {
private fun expand(spec: AnimationSpec<Dp> = spring()) {
onAnchorChanged(Anchor.Expanded)
deferAnimateTo(animatable.upperBound!!, spec)
}

private fun collapse() = collapse(spring())
private fun expand() = expand(spring())
fun collapseSoft() = collapse(tween(300))
fun expandSoft() = expand(tween(300))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.BasicText
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ fun <T> ValueSelectorDialogBody(
}
}

@Suppress("ModifierMissing") // intentional, I guess
@Composable
fun ColumnScope.SliderDialogBody(
provideState: @Composable () -> MutableState<Float>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,12 @@ import app.vitune.android.utils.isCached
import app.vitune.android.utils.launchYouTubeMusic
import app.vitune.android.utils.medium
import app.vitune.android.utils.semiBold
import app.vitune.android.utils.thumbnail
import app.vitune.android.utils.toast
import app.vitune.core.data.enums.PlaylistSortBy
import app.vitune.core.data.enums.SortOrder
import app.vitune.core.ui.Dimensions
import app.vitune.core.ui.LocalAppearance
import app.vitune.core.ui.favoritesIcon
import app.vitune.core.ui.utils.px
import app.vitune.core.ui.utils.roundedShape
import app.vitune.providers.innertube.models.NavigationEndpoint
import kotlinx.coroutines.Dispatchers
Expand Down
5 changes: 2 additions & 3 deletions app/src/main/kotlin/app/vitune/android/ui/items/SongItem.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.text.BasicText
import androidx.compose.material3.Icon
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
Expand Down Expand Up @@ -112,7 +111,7 @@ fun SongItem(
trailingContent: @Composable (() -> Unit)? = null,
showDuration: Boolean = true
) {
val (colorPalette, typography) = LocalAppearance.current
val (colorPalette, typography, _, thumbnailShape) = LocalAppearance.current

SongItem(
title = title,
Expand All @@ -123,7 +122,7 @@ fun SongItem(
thumbnailContent = {
Box(
modifier = Modifier
.clip(LocalAppearance.current.thumbnailShape)
.clip(thumbnailShape)
.background(colorPalette.background1)
.fillMaxSize()
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,16 @@ import androidx.compose.foundation.layout.WindowInsetsSides
import androidx.compose.foundation.layout.asPaddingValues
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.only
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.foundation.text.BasicText
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextOverflow
import app.vitune.android.Database
import app.vitune.android.LocalPlayerAwareWindowInsets
import app.vitune.android.LocalPlayerServiceBinder
Expand All @@ -37,12 +34,9 @@ import app.vitune.android.ui.items.SongItem
import app.vitune.android.ui.items.SongItemPlaceholder
import app.vitune.android.utils.PlaylistDownloadIcon
import app.vitune.android.utils.asMediaItem
import app.vitune.android.utils.center
import app.vitune.android.utils.disabled
import app.vitune.android.utils.enqueue
import app.vitune.android.utils.forcePlayAtIndex
import app.vitune.android.utils.forcePlayFromBeginning
import app.vitune.android.utils.semiBold
import app.vitune.compose.persist.persistList
import app.vitune.core.ui.Dimensions
import app.vitune.core.ui.LocalAppearance
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package app.vitune.android.ui.screens.builtinplaylist

import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.background
import androidx.compose.foundation.combinedClickable
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
Expand Down
20 changes: 11 additions & 9 deletions app/src/main/kotlin/app/vitune/android/ui/screens/player/Lyrics.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateListOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberUpdatedState
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
Expand Down Expand Up @@ -107,17 +108,18 @@ fun Lyrics(
modifier: Modifier = Modifier,
onMenuLaunched: () -> Unit = { }
) = with(PlayerPreferences) {
val currentMediaMetadataProvider by rememberUpdatedState(mediaMetadataProvider)
val (colorPalette, typography) = LocalAppearance.current
val context = LocalContext.current
val menuState = LocalMenuState.current
val currentView = LocalView.current
val binder = LocalPlayerServiceBinder.current

AnimatedVisibility(
visible = isDisplayed,
enter = fadeIn(),
exit = fadeOut()
) {
val (colorPalette, typography) = LocalAppearance.current
val context = LocalContext.current
val menuState = LocalMenuState.current
val currentView = LocalView.current
val binder = LocalPlayerServiceBinder.current

var isEditing by remember(mediaId, isShowingSynchronizedLyrics) { mutableStateOf(false) }
var isPicking by remember(mediaId, isShowingSynchronizedLyrics) { mutableStateOf(false) }
var lyrics by remember { mutableStateOf<Lyrics?>(null) }
Expand All @@ -132,7 +134,7 @@ fun Lyrics(
when {
isShowingSynchronizedLyrics && currentLyrics?.synced == null -> {
lyrics = null
val mediaMetadata = mediaMetadataProvider()
val mediaMetadata = currentMediaMetadataProvider()
var duration = withContext(Dispatchers.Main) { durationProvider() }

while (duration == C.TIME_UNSET) {
Expand Down Expand Up @@ -230,7 +232,7 @@ fun Lyrics(
var error by remember { mutableStateOf(false) }

LaunchedEffect(Unit) {
val mediaMetadata = mediaMetadataProvider()
val mediaMetadata = currentMediaMetadataProvider()

LrcLib.lyrics(
artist = mediaMetadata.artist?.toString().orEmpty(),
Expand Down Expand Up @@ -486,7 +488,7 @@ fun Lyrics(
text = stringResource(R.string.search_lyrics_online),
onClick = {
menuState.hide()
val mediaMetadata = mediaMetadataProvider()
val mediaMetadata = currentMediaMetadataProvider()

try {
context.startActivity(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ import app.vitune.compose.persist.PersistMapCleanup
import app.vitune.compose.routing.OnGlobalRoute
import app.vitune.core.ui.Dimensions
import app.vitune.core.ui.LocalAppearance
import app.vitune.core.ui.collapsedPlayerProgressBar
import app.vitune.core.ui.ThumbnailRoundness
import app.vitune.core.ui.collapsedPlayerProgressBar
import app.vitune.core.ui.utils.isLandscape
import app.vitune.core.ui.utils.px
import app.vitune.core.ui.utils.roundedShape
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import kotlinx.coroutines.isActive
import kotlinx.coroutines.launch
import kotlinx.coroutines.suspendCancellableCoroutine

@Suppress("LambdaParameterInRestartableEffect") // Invalid: crossinline param
@Composable
inline fun Player.DisposableListener(
key: Any = this,
Expand Down
14 changes: 10 additions & 4 deletions app/src/main/res/drawable/explicit.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:tint="#000000" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp">

<path android:fillColor="@android:color/white" android:pathData="M19,3L5,3c-1.1,0 -2,0.9 -2,2v14c0,1.1 0.9,2 2,2h14c1.1,0 2,-0.9 2,-2L21,5c0,-1.1 -0.9,-2 -2,-2zM15,9h-4v2h4v2h-4v2h4v2L9,17L9,7h6v2z"/>

<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="#000000"
android:viewportWidth="24"
android:viewportHeight="24">

<path
android:fillColor="@android:color/white"
android:pathData="M19,3L5,3c-1.1,0 -2,0.9 -2,2v14c0,1.1 0.9,2 2,2h14c1.1,0 2,-0.9 2,-2L21,5c0,-1.1 -0.9,-2 -2,-2zM15,9h-4v2h4v2h-4v2h4v2L9,17L9,7h6v2z" />
</vector>
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,30 @@ package app.vitune.compose.routing

import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.rememberUpdatedState
import kotlinx.coroutines.flow.MutableSharedFlow

internal val globalRouteFlow = MutableSharedFlow<Pair<Route, Array<Any?>>>(extraBufferCapacity = 1)
typealias RouteRequestDefinition = Pair<Route, Array<Any?>>

// Same runtime type as before, but just syntactically nicer
@JvmInline
value class RouteRequest private constructor(private val def: RouteRequestDefinition) {
constructor(route: Route, args: Array<Any?>) : this(route to args)

val route get() = def.first
val args get() = def.second
}

internal val globalRouteFlow = MutableSharedFlow<RouteRequest>(extraBufferCapacity = 1)

@Composable
fun OnGlobalRoute(block: suspend (Pair<Route, Array<Any?>>) -> Unit) {
fun OnGlobalRoute(block: suspend (RouteRequest) -> Unit) {
val currentBlock by rememberUpdatedState(block)

LaunchedEffect(Unit) {
globalRouteFlow.collect(block)
globalRouteFlow.collect {
currentBlock(it)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ class Route0(tag: String) : Route(tag) {
}

fun global() {
globalRouteFlow.tryEmit(this to emptyArray())
globalRouteFlow.tryEmit(RouteRequest(route = this, args = emptyArray()))
}

suspend fun ensureGlobal() {
globalRouteFlow.subscriptionCount.filter { it > 0 }.first()
globalRouteFlow.emit(this to arrayOf())
globalRouteFlow.emit(RouteRequest(route = this, args = emptyArray()))
}
}

Expand All @@ -51,12 +51,12 @@ class Route1<P0>(tag: String) : Route(tag) {
}

fun global(p0: P0) {
globalRouteFlow.tryEmit(this to arrayOf(p0))
globalRouteFlow.tryEmit(RouteRequest(route = this, args = arrayOf(p0)))
}

suspend fun ensureGlobal(p0: P0) {
globalRouteFlow.subscriptionCount.filter { it > 0 }.first()
globalRouteFlow.emit(this to arrayOf(p0))
globalRouteFlow.emit(RouteRequest(route = this, args = arrayOf(p0)))
}
}

Expand All @@ -69,12 +69,12 @@ class Route2<P0, P1>(tag: String) : Route(tag) {
}

fun global(p0: P0, p1: P1) {
globalRouteFlow.tryEmit(this to arrayOf(p0, p1))
globalRouteFlow.tryEmit(RouteRequest(route = this, args = arrayOf(p0, p1)))
}

suspend fun ensureGlobal(p0: P0, p1: P1) {
globalRouteFlow.subscriptionCount.filter { it > 0 }.first()
globalRouteFlow.emit(this to arrayOf(p0, p1))
globalRouteFlow.emit(RouteRequest(route = this, args = arrayOf(p0, p1)))
}
}

Expand All @@ -87,11 +87,11 @@ class Route3<P0, P1, P2>(tag: String) : Route(tag) {
}

fun global(p0: P0, p1: P1, p2: P2) {
globalRouteFlow.tryEmit(this to arrayOf(p0, p1, p2))
globalRouteFlow.tryEmit(RouteRequest(route = this, args = arrayOf(p0, p1, p2)))
}

suspend fun ensureGlobal(p0: P0, p1: P1, p2: P2) {
globalRouteFlow.subscriptionCount.filter { it > 0 }.first()
globalRouteFlow.emit(this to arrayOf(p0, p1, p2))
globalRouteFlow.emit(RouteRequest(route = this, args = arrayOf(p0, p1, p2)))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,7 @@ fun RouteHandler(
) {
val backDispatcher = LocalOnBackPressedDispatcherOwner.current?.onBackPressedDispatcher

val parameters = rememberSaveable {
arrayOfNulls<Any?>(3)
}

val parameters = rememberSaveable { arrayOfNulls<Any?>(3) }
val scope = remember(route) {
RouteHandlerScope(
route = route,
Expand All @@ -77,11 +74,9 @@ fun RouteHandler(
)
}

if (listenToGlobalEmitter && route == null) {
OnGlobalRoute { (newRoute, newParameters) ->
newParameters.forEachIndexed(parameters::set)
onRouteChanged(newRoute)
}
if (listenToGlobalEmitter && route == null) OnGlobalRoute { request ->
request.args.forEachIndexed(parameters::set)
onRouteChanged(request.route)
}

BackHandler(enabled = handleBackPress && route != null) {
Expand Down
2 changes: 1 addition & 1 deletion core/ui/src/main/kotlin/app/vitune/core/ui/ColorPalette.kt
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ fun ColorPalette.amoled() = if (isDark) {
hue = hue,
saturation = saturation.coerceAtMost(0.4f),
lightness = 0.2f
),
)
)
} else this

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import kotlinx.serialization.Serializable

@Serializable
data class Badge(
val musicInlineBadgeRenderer: MusicInlineBadgeRenderer?,
val musicInlineBadgeRenderer: MusicInlineBadgeRenderer?
) {
@Serializable
data class MusicInlineBadgeRenderer(
val icon: MusicNavigationButtonRenderer.Icon,
val icon: MusicNavigationButtonRenderer.Icon
)
}

Expand Down
Loading

0 comments on commit ade84cb

Please sign in to comment.