Skip to content

Commit

Permalink
[Fix] YouTubePlaylistFragment missing streamPopupMenuListener
Browse files Browse the repository at this point in the history
  • Loading branch information
z-huang committed Apr 11, 2022
1 parent 98cd92d commit f3f12dc
Showing 1 changed file with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import com.zionhuang.music.ui.adapters.InfoItemAdapter
import com.zionhuang.music.ui.adapters.LoadStateAdapter
import com.zionhuang.music.ui.fragments.base.BindingFragment
import com.zionhuang.music.viewmodels.PlaybackViewModel
import com.zionhuang.music.viewmodels.SongsViewModel
import com.zionhuang.music.viewmodels.YouTubePlaylistViewModel
import com.zionhuang.music.youtube.NewPipeYouTubeHelper
import kotlinx.coroutines.flow.collectLatest
Expand All @@ -36,6 +37,7 @@ class YouTubePlaylistFragment : BindingFragment<LayoutRecyclerviewBinding>() {
private val playlistId by lazy { args.playlistId }

private val viewModel by viewModels<YouTubePlaylistViewModel>()
private val songsViewModel by activityViewModels<SongsViewModel>()
private val playbackViewModel by activityViewModels<PlaybackViewModel>()

private val infoItemAdapter = InfoItemAdapter()
Expand All @@ -51,12 +53,15 @@ class YouTubePlaylistFragment : BindingFragment<LayoutRecyclerviewBinding>() {
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
infoItemAdapter.addLoadStateListener { loadState ->
binding.progressBar.isVisible = loadState.refresh is LoadState.Loading
binding.btnRetry.isVisible = loadState.refresh is LoadState.Error
binding.errorMsg.isVisible = loadState.refresh is LoadState.Error
if (loadState.refresh is LoadState.Error) {
binding.errorMsg.text = (loadState.refresh as LoadState.Error).error.localizedMessage
infoItemAdapter.apply {
streamMenuListener = songsViewModel.streamPopupMenuListener
addLoadStateListener { loadState ->
binding.progressBar.isVisible = loadState.refresh is LoadState.Loading
binding.btnRetry.isVisible = loadState.refresh is LoadState.Error
binding.errorMsg.isVisible = loadState.refresh is LoadState.Error
if (loadState.refresh is LoadState.Error) {
binding.errorMsg.text = (loadState.refresh as LoadState.Error).error.localizedMessage
}
}
}

Expand Down

0 comments on commit f3f12dc

Please # to comment.