diff --git a/app/src/main/java/com/zionhuang/music/ui/fragments/YouTubePlaylistFragment.kt b/app/src/main/java/com/zionhuang/music/ui/fragments/YouTubePlaylistFragment.kt index 3a736386f..df31853a5 100644 --- a/app/src/main/java/com/zionhuang/music/ui/fragments/YouTubePlaylistFragment.kt +++ b/app/src/main/java/com/zionhuang/music/ui/fragments/YouTubePlaylistFragment.kt @@ -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 @@ -36,6 +37,7 @@ class YouTubePlaylistFragment : BindingFragment() { private val playlistId by lazy { args.playlistId } private val viewModel by viewModels() + private val songsViewModel by activityViewModels() private val playbackViewModel by activityViewModels() private val infoItemAdapter = InfoItemAdapter() @@ -51,12 +53,15 @@ class YouTubePlaylistFragment : BindingFragment() { } 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 + } } }