Load specific items from a recyclerView

Asked

Viewed 13 times

0

I have an Adapter that loads all data from my list, in my list there is a Boolean field that I will use to filter the favorite items, as I do so that in my recyclerView I select only those that are True?

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
    super.onViewCreated(view, savedInstanceState)
    setupRecyclerView()
    setupObservers()
}

private fun setupRecyclerView() {
    adapter = MoviesAdapter(this)
    binding.moviesRV.layoutManager = GridLayoutManager(requireContext(), 2)
    binding.moviesRV.adapter = adapter
}

private fun setupObservers() {
    viewModel.movies.observe(viewLifecycleOwner, {
        when (it.status) {
            Resource.Status.SUCCESS -> {
                binding.progressBar.visibility = View.GONE
                if (!it.data.isNullOrEmpty()) adapter.setItems(ArrayList(it.data))
            }
            Resource.Status.ERROR ->
                Toast.makeText(context, "Falha na conexão", Toast.LENGTH_SHORT).show()

            Resource.Status.LOADING ->
                binding.progressBar.visibility = View.VISIBLE
        }
    })
}

database

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.