-
-
Save DivS-15/acdf8f8e81b0036a9b68083b72193e50 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@AndroidEntryPoint | |
class VideosFragment : Fragment(R.layout.fragment_popular_videos_list) { | |
private lateinit var _binding: FragmentPopularVideosListBinding | |
private val binding get() = _binding | |
private val viewModel: VideoViewModel by viewModels() | |
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | |
super.onViewCreated(view, savedInstanceState) | |
_binding = FragmentPopularVideosListBinding.bind(view) | |
val adapter = VideoAdapter() | |
binding.apply { | |
videosList.adapter = adapter.withLoadStateFooter( | |
footer = VideoLoadStateAdapter{adapter.retry()} | |
) | |
} | |
viewLifecycleOwner.lifecycleScope.launch { | |
adapter.loadStateFlow.collectLatest { | |
binding.progressBar.isVisible = it.source.append is LoadState.Loading | |
} | |
} | |
viewLifecycleOwner.lifecycleScope.launch { | |
viewLifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) { | |
viewModel.items.collectLatest { | |
adapter.submitData(it) | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment