Improve playerBottomSheetState handling
This commit is contained in:
@@ -59,9 +59,6 @@ import it.vfsfitvnm.vimusic.enums.ThumbnailRoundness
|
|||||||
import it.vfsfitvnm.vimusic.service.PlayerService
|
import it.vfsfitvnm.vimusic.service.PlayerService
|
||||||
import it.vfsfitvnm.vimusic.ui.components.BottomSheetMenu
|
import it.vfsfitvnm.vimusic.ui.components.BottomSheetMenu
|
||||||
import it.vfsfitvnm.vimusic.ui.components.LocalMenuState
|
import it.vfsfitvnm.vimusic.ui.components.LocalMenuState
|
||||||
import it.vfsfitvnm.vimusic.ui.components.collapsedAnchor
|
|
||||||
import it.vfsfitvnm.vimusic.ui.components.dismissedAnchor
|
|
||||||
import it.vfsfitvnm.vimusic.ui.components.expandedAnchor
|
|
||||||
import it.vfsfitvnm.vimusic.ui.components.rememberBottomSheetState
|
import it.vfsfitvnm.vimusic.ui.components.rememberBottomSheetState
|
||||||
import it.vfsfitvnm.vimusic.ui.screens.albumRoute
|
import it.vfsfitvnm.vimusic.ui.screens.albumRoute
|
||||||
import it.vfsfitvnm.vimusic.ui.screens.home.HomeScreen
|
import it.vfsfitvnm.vimusic.ui.screens.home.HomeScreen
|
||||||
@@ -94,10 +91,6 @@ import kotlinx.coroutines.launch
|
|||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
|
|
||||||
class MainActivity : ComponentActivity() {
|
class MainActivity : ComponentActivity() {
|
||||||
companion object {
|
|
||||||
private var alreadyRunning = false
|
|
||||||
}
|
|
||||||
|
|
||||||
private val serviceConnection = object : ServiceConnection {
|
private val serviceConnection = object : ServiceConnection {
|
||||||
override fun onServiceConnected(name: ComponentName?, service: IBinder?) {
|
override fun onServiceConnected(name: ComponentName?, service: IBinder?) {
|
||||||
if (service is PlayerService.Binder) {
|
if (service is PlayerService.Binder) {
|
||||||
@@ -128,11 +121,7 @@ class MainActivity : ComponentActivity() {
|
|||||||
|
|
||||||
WindowCompat.setDecorFitsSystemWindows(window, false)
|
WindowCompat.setDecorFitsSystemWindows(window, false)
|
||||||
|
|
||||||
val playerBottomSheetAnchor = when {
|
val launchedFromNotification = intent?.extras?.getBoolean("expandPlayerBottomSheet") == true
|
||||||
intent?.extras?.getBoolean("expandPlayerBottomSheet") == true -> expandedAnchor
|
|
||||||
alreadyRunning -> collapsedAnchor
|
|
||||||
else -> dismissedAnchor.also { alreadyRunning = true }
|
|
||||||
}
|
|
||||||
|
|
||||||
setContent {
|
setContent {
|
||||||
val coroutineScope = rememberCoroutineScope()
|
val coroutineScope = rememberCoroutineScope()
|
||||||
@@ -309,7 +298,6 @@ class MainActivity : ComponentActivity() {
|
|||||||
dismissedBound = 0.dp,
|
dismissedBound = 0.dp,
|
||||||
collapsedBound = Dimensions.collapsedPlayer + paddingValues.calculateBottomPadding(),
|
collapsedBound = Dimensions.collapsedPlayer + paddingValues.calculateBottomPadding(),
|
||||||
expandedBound = maxHeight,
|
expandedBound = maxHeight,
|
||||||
initialAnchor = playerBottomSheetAnchor
|
|
||||||
)
|
)
|
||||||
|
|
||||||
val playerAwarePaddingValues = if (playerBottomSheetState.isDismissed) {
|
val playerAwarePaddingValues = if (playerBottomSheetState.isDismissed) {
|
||||||
@@ -342,16 +330,30 @@ class MainActivity : ComponentActivity() {
|
|||||||
)
|
)
|
||||||
|
|
||||||
DisposableEffect(binder?.player) {
|
DisposableEffect(binder?.player) {
|
||||||
binder?.player?.listener(object : Player.Listener {
|
val player = binder?.player ?: return@DisposableEffect onDispose { }
|
||||||
override fun onMediaItemTransition(
|
|
||||||
mediaItem: MediaItem?,
|
if (player.currentMediaItem == null) {
|
||||||
reason: Int
|
if (!playerBottomSheetState.isDismissed) {
|
||||||
) {
|
playerBottomSheetState.dismiss()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (playerBottomSheetState.isDismissed) {
|
||||||
|
if (launchedFromNotification) {
|
||||||
|
intent.replaceExtras(Bundle())
|
||||||
|
playerBottomSheetState.expandSoft()
|
||||||
|
} else {
|
||||||
|
playerBottomSheetState.collapseSoft()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
player.listener(object : Player.Listener {
|
||||||
|
override fun onMediaItemTransition(mediaItem: MediaItem?, reason: Int) {
|
||||||
if (reason == Player.MEDIA_ITEM_TRANSITION_REASON_PLAYLIST_CHANGED && mediaItem != null) {
|
if (reason == Player.MEDIA_ITEM_TRANSITION_REASON_PLAYLIST_CHANGED && mediaItem != null) {
|
||||||
playerBottomSheetState.expand(tween(500))
|
playerBottomSheetState.expand(tween(500))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}) ?: onDispose { }
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
BottomSheetMenu(
|
BottomSheetMenu(
|
||||||
|
|||||||
@@ -82,7 +82,6 @@ fun PlayerView(
|
|||||||
|
|
||||||
val (colorPalette, typography, thumbnailShape) = LocalAppearance.current
|
val (colorPalette, typography, thumbnailShape) = LocalAppearance.current
|
||||||
val binder = LocalPlayerServiceBinder.current
|
val binder = LocalPlayerServiceBinder.current
|
||||||
val context = LocalContext.current
|
|
||||||
val configuration = LocalConfiguration.current
|
val configuration = LocalConfiguration.current
|
||||||
val layoutDirection = LocalLayoutDirection.current
|
val layoutDirection = LocalLayoutDirection.current
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user