Skip to content

Commit

Permalink
refactor: Moved player composables to the mediaplayer folder
Browse files Browse the repository at this point in the history
Signed-off-by: Gabriel Fontán <[email protected]>
  • Loading branch information
BobbyESP committed May 5, 2024
1 parent 488d86b commit 9154046
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ import com.bobbyesp.metadator.presentation.common.NavArgs
import com.bobbyesp.metadator.presentation.common.Route
import com.bobbyesp.metadator.presentation.common.TagEditorParcelableSongParamType
import com.bobbyesp.metadator.presentation.common.routesToNavigate
import com.bobbyesp.metadator.presentation.components.others.CollapsedPlayerHeight
import com.bobbyesp.metadator.presentation.components.others.PlayerAnimationSpec
import com.bobbyesp.metadator.presentation.pages.MediaStorePageViewModel
import com.bobbyesp.metadator.presentation.pages.home.HomePage
import com.bobbyesp.metadator.presentation.pages.mediaplayer.MediaplayerPage
import com.bobbyesp.metadator.presentation.pages.mediaplayer.MediaplayerViewModel
import com.bobbyesp.metadator.presentation.pages.mediaplayer.mediaplayer.CollapsedPlayerHeight
import com.bobbyesp.metadator.presentation.pages.mediaplayer.mediaplayer.PlayerAnimationSpec
import com.bobbyesp.metadator.presentation.pages.utilities.tageditor.ID3MetadataEditorPage
import com.bobbyesp.metadator.presentation.pages.utilities.tageditor.ID3MetadataEditorPageViewModel
import com.bobbyesp.ui.components.bottomsheet.draggable.rememberDraggableBottomSheetState
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import androidx.compose.ui.unit.dp
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.bobbyesp.metadator.presentation.common.LocalPlayerAwareWindowInsets
import com.bobbyesp.metadator.presentation.components.cards.songs.HorizontalSongCard
import com.bobbyesp.metadator.presentation.components.others.mediaplayer.MediaplayerSheet
import com.bobbyesp.metadator.presentation.pages.mediaplayer.mediaplayer.MediaplayerSheet
import com.bobbyesp.ui.components.bottomsheet.draggable.DraggableBottomSheetState
import my.nanihadesuka.compose.LazyColumnScrollbar
import my.nanihadesuka.compose.ScrollbarSelectionActionable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.bobbyesp.metadator.presentation.components.others
package com.bobbyesp.metadator.presentation.pages.mediaplayer.mediaplayer

import androidx.compose.animation.ContentTransform
import androidx.compose.animation.SizeTransform
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.bobbyesp.metadator.presentation.pages.mediaplayer.mediaplayer

import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.ui.Modifier
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.bobbyesp.mediaplayer.service.ConnectionState
import com.bobbyesp.metadator.presentation.pages.mediaplayer.MediaplayerViewModel
import com.bobbyesp.metadator.presentation.pages.mediaplayer.mediaplayer.views.MediaplayerCollapsedContent
import com.bobbyesp.metadator.presentation.pages.mediaplayer.mediaplayer.views.MediaplayerExpandedContent
import com.bobbyesp.ui.components.bottomsheet.draggable.DraggableBottomSheet
import com.bobbyesp.ui.components.bottomsheet.draggable.DraggableBottomSheetState
import kotlinx.coroutines.launch

@Composable
fun MediaplayerSheet(
modifier: Modifier = Modifier, state: DraggableBottomSheetState, viewModel: MediaplayerViewModel
) {
val playingSong =
viewModel.playingSong.collectAsStateWithLifecycle().value?.mediaMetadata ?: return
val connectionState =
viewModel.connectionHandler.connectionState.collectAsStateWithLifecycle().value

LaunchedEffect(connectionState, Unit) {
if (connectionState is ConnectionState.Connected && state.isDismissed) {
launch {
state.collapseSoft()
}
}
}

DraggableBottomSheet(modifier = modifier, state = state, collapsedContent = {
MediaplayerCollapsedContent(
viewModel = viewModel, nowPlaying = playingSong
)
}, backgroundColor = MaterialTheme.colorScheme.surfaceContainerHigh, onDismiss = {
viewModel.dismissPlayer()
}) {
MediaplayerExpandedContent(
viewModel = viewModel,
sheetState = state,
)
}
}


Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.bobbyesp.metadator.presentation.components.others.mediaplayer
package com.bobbyesp.metadator.presentation.pages.mediaplayer.mediaplayer

enum class MediaplayerSheetView {
FULL_PLAYER,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.bobbyesp.metadator.presentation.components.others.mediaplayer
package com.bobbyesp.metadator.presentation.pages.mediaplayer.mediaplayer

import androidx.compose.animation.AnimatedContent
import androidx.compose.animation.core.EaseInOutSine
Expand Down Expand Up @@ -41,8 +41,6 @@ import androidx.compose.ui.unit.dp
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.bobbyesp.metadator.R
import com.bobbyesp.metadator.presentation.components.buttons.PlayPauseAnimatedButton
import com.bobbyesp.metadator.presentation.components.others.AnimatedTextContentTransformation
import com.bobbyesp.metadator.presentation.components.others.SeekToButtonSize
import com.bobbyesp.metadator.presentation.pages.mediaplayer.MediaplayerViewModel
import com.bobbyesp.ui.components.text.MarqueeText
import com.bobbyesp.ui.components.text.MarqueeTextGradientOptions
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.bobbyesp.metadator.presentation.components.others.mediaplayer
package com.bobbyesp.metadator.presentation.pages.mediaplayer.mediaplayer

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.bobbyesp.metadator.presentation.components.others.mediaplayer
package com.bobbyesp.metadator.presentation.pages.mediaplayer.mediaplayer.views

import android.content.res.Configuration.UI_MODE_NIGHT_YES
import android.content.res.Configuration
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.WindowInsetsSides
Expand All @@ -10,59 +10,20 @@ import androidx.compose.foundation.layout.only
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.systemBars
import androidx.compose.foundation.layout.windowInsetsPadding
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.media3.common.MediaItem
import androidx.media3.common.MediaMetadata
import com.bobbyesp.mediaplayer.service.ConnectionState
import com.bobbyesp.metadator.presentation.components.others.CollapsedPlayerHeight
import com.bobbyesp.metadator.presentation.components.others.mediaplayer.views.MediaplayerExpandedContent
import com.bobbyesp.metadator.presentation.components.others.mediaplayer.views.MiniplayerContent
import com.bobbyesp.metadator.presentation.pages.mediaplayer.MediaplayerViewModel
import com.bobbyesp.metadator.presentation.pages.mediaplayer.mediaplayer.CollapsedPlayerHeight
import com.bobbyesp.metadator.presentation.theme.MetadatorTheme
import com.bobbyesp.ui.components.bottomsheet.draggable.DraggableBottomSheet
import com.bobbyesp.ui.components.bottomsheet.draggable.DraggableBottomSheetState
import kotlinx.coroutines.launch

@Composable
fun MediaplayerSheet(
modifier: Modifier = Modifier, state: DraggableBottomSheetState, viewModel: MediaplayerViewModel
) {
val playingSong =
viewModel.playingSong.collectAsStateWithLifecycle().value?.mediaMetadata ?: return
val connectionState =
viewModel.connectionHandler.connectionState.collectAsStateWithLifecycle().value

LaunchedEffect(connectionState, Unit) {
if (connectionState is ConnectionState.Connected && state.isDismissed) {
launch {
state.collapseSoft()
}
}
}

DraggableBottomSheet(modifier = modifier, state = state, collapsedContent = {
MediaplayerCollapsedContent(
viewModel = viewModel, nowPlaying = playingSong
)
}, backgroundColor = MaterialTheme.colorScheme.surfaceContainerHigh, onDismiss = {
viewModel.dismissPlayer()
}) {
MediaplayerExpandedContent(
viewModel = viewModel,
sheetState = state,
)
}
}

@Composable
private fun MediaplayerCollapsedContent(
fun MediaplayerCollapsedContent(
nowPlaying: MediaMetadata,
modifier: Modifier = Modifier,
viewModel: MediaplayerViewModel,
Expand Down Expand Up @@ -93,9 +54,8 @@ private fun MediaplayerCollapsedContent(
}
}


@Preview
@Preview(uiMode = UI_MODE_NIGHT_YES)
@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES)
@Composable
private fun CollapsedContentPrev() {
MetadatorTheme {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.bobbyesp.metadator.presentation.components.others.mediaplayer.views
package com.bobbyesp.metadator.presentation.pages.mediaplayer.mediaplayer.views

import android.content.res.Configuration
import androidx.activity.compose.BackHandler
Expand Down Expand Up @@ -47,10 +47,10 @@ import androidx.compose.ui.unit.dp
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.bobbyesp.metadator.R
import com.bobbyesp.metadator.presentation.components.image.ArtworkAsyncImage
import com.bobbyesp.metadator.presentation.components.others.mediaplayer.MediaplayerSheetView
import com.bobbyesp.metadator.presentation.components.others.mediaplayer.PlayerControls
import com.bobbyesp.metadator.presentation.components.others.mediaplayer.PlayerOptions
import com.bobbyesp.metadator.presentation.pages.mediaplayer.MediaplayerViewModel
import com.bobbyesp.metadator.presentation.pages.mediaplayer.mediaplayer.MediaplayerSheetView
import com.bobbyesp.metadator.presentation.pages.mediaplayer.mediaplayer.PlayerControls
import com.bobbyesp.metadator.presentation.pages.mediaplayer.mediaplayer.PlayerOptions
import com.bobbyesp.ui.components.bottomsheet.draggable.DraggableBottomSheetState
import com.bobbyesp.ui.motion.MotionConstants
import com.bobbyesp.ui.motion.tweenEnter
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.bobbyesp.metadator.presentation.components.others.mediaplayer.views
package com.bobbyesp.metadator.presentation.pages.mediaplayer.mediaplayer.views

import androidx.compose.animation.AnimatedContent
import androidx.compose.animation.core.MutableTransitionState
Expand Down Expand Up @@ -31,7 +31,7 @@ import androidx.compose.ui.unit.sp
import androidx.media3.common.MediaMetadata
import com.bobbyesp.metadator.R
import com.bobbyesp.metadator.presentation.components.image.ArtworkAsyncImage
import com.bobbyesp.metadator.presentation.components.others.AnimatedTextContentTransformation
import com.bobbyesp.metadator.presentation.pages.mediaplayer.mediaplayer.AnimatedTextContentTransformation
import com.bobbyesp.ui.components.button.DynamicButton
import com.bobbyesp.ui.components.text.MarqueeText

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.bobbyesp.metadator.presentation.components.others.mediaplayer.views
package com.bobbyesp.metadator.presentation.pages.mediaplayer.mediaplayer.views

import androidx.activity.compose.BackHandler
import androidx.compose.foundation.layout.Box
Expand Down

0 comments on commit 9154046

Please sign in to comment.