Skip to content

Commit

Permalink
Implemented swiping miniplayer actions
Browse files Browse the repository at this point in the history
  • Loading branch information
maxrave-dev committed Apr 25, 2024
1 parent 5951997 commit 80ffb83
Show file tree
Hide file tree
Showing 6 changed files with 186 additions and 87 deletions.
12 changes: 11 additions & 1 deletion app/src/main/java/com/maxrave/simpmusic/ui/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ class MainActivity : AppCompatActivity() {
val navController = navHostFragment?.findNavController()
binding.miniplayer.setContent {
AppTheme {
MiniPlayer(sharedViewModel = viewModel) {
MiniPlayer(sharedViewModel = viewModel, onClose = { onCloseMiniplayer() }) {
val bundle = Bundle()
bundle.putString("type", Config.MINIPLAYER_CLICK)
navController?.navigateSafe(R.id.action_global_nowPlayingFragment, bundle)
Expand Down Expand Up @@ -687,6 +687,9 @@ class MainActivity : AppCompatActivity() {
}
}
}
val job2 = launch {
viewModel
}
job1.join()
}
lifecycleScope.launch {
Expand Down Expand Up @@ -922,6 +925,13 @@ class MainActivity : AppCompatActivity() {
super.onConfigurationChanged(newConfig)
viewModel.activityRecreate()
}

fun onCloseMiniplayer() {
viewModel.stopPlayer()
viewModel.isServiceRunning.postValue(false)
viewModel.videoId.postValue(null)
binding.miniplayer.visibility = View.GONE
}
}

val LocalPlayerAwareWindowInsets =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ import com.maxrave.simpmusic.extension.navigateSafe
import com.maxrave.simpmusic.extension.toListName
import com.maxrave.simpmusic.viewModel.SharedViewModel
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking

@AndroidEntryPoint
class InfoFragment: BottomSheetDialogFragment(){
Expand Down Expand Up @@ -74,7 +76,7 @@ class InfoFragment: BottomSheetDialogFragment(){

@UnstableApi
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
if (viewModel.nowPlayingMediaItem.value != null) {
if (runBlocking { viewModel.nowPlayingMediaItem.first() } != null) {
if (viewModel.simpleMediaServiceHandler != null) {
val data = viewModel.simpleMediaServiceHandler!!.catalogMetadata[viewModel.getCurrentMediaItemIndex()]
with(binding){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ class NowPlayingFragment : Fragment() {
// binding.progressSong.value = viewModel.progress.value * 100
// }
if (videoId == null) {
videoId = viewModel.nowPlayingMediaItem.value?.mediaId
videoId = runBlocking { viewModel.nowPlayingMediaItem.first()?.mediaId }
viewModel.videoId.postValue(videoId)
}
updateUIfromCurrentMediaItem(viewModel.getCurrentMediaItem())
Expand Down Expand Up @@ -1394,7 +1394,7 @@ class NowPlayingFragment : Fragment() {
findNavController().navigateSafe(R.id.action_global_infoFragment)
}
binding.cbFavorite.setOnClickListener {
viewModel.nowPlayingMediaItem.value?.let { nowPlayingSong ->
runBlocking { viewModel.nowPlayingMediaItem.first() }?.let { nowPlayingSong ->
viewModel.updateLikeStatus(
nowPlayingSong.mediaId,
!runBlocking { viewModel.liked.first() },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,15 @@ class QueueFragment: BottomSheetDialogFragment() {
}
}
val job2 = launch {
updateNowPlaying()
viewModel.nowPlayingMediaItem.collect {
if (it != null){
binding.ivThumbnail.load(it.mediaMetadata.artworkUri)
binding.tvSongTitle.text = it.mediaMetadata.title
binding.tvSongTitle.isSelected = true
binding.tvSongArtist.text = it.mediaMetadata.artist
binding.tvSongArtist.isSelected = true
}
}
}
val job3 = launch {
viewModel.simpleMediaServiceHandler?.currentSongIndex?.collect{ index ->
Expand Down Expand Up @@ -239,15 +247,4 @@ class QueueFragment: BottomSheetDialogFragment() {
}
})
}
private fun updateNowPlaying(){
viewModel.nowPlayingMediaItem.observe(viewLifecycleOwner) {
if (it != null){
binding.ivThumbnail.load(it.mediaMetadata.artworkUri)
binding.tvSongTitle.text = it.mediaMetadata.title
binding.tvSongTitle.isSelected = true
binding.tvSongArtist.text = it.mediaMetadata.artist
binding.tvSongArtist.isSelected = true
}
}
}
}
Loading

0 comments on commit 80ffb83

Please sign in to comment.