Created
January 8, 2021 15:43
-
-
Save ngallazzi/246cd98688bf5095f3c31afc4095bbc8 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
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
booksAdapter = BookAdapter(requireContext(), object : BookAdapter.ActionClickListener { | |
override fun bookmark(book: BookWithStatus) { | |
booksViewModel.bookmark(book) | |
} | |
override fun unbookmark(book: BookWithStatus) { | |
booksViewModel.unbookmark(book) | |
} | |
}) | |
booksViewModel.getBooks("Robert C. Martin") | |
} | |
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | |
super.onViewCreated(view, savedInstanceState) | |
booksViewModel.books.observe(viewLifecycleOwner, { | |
booksAdapter.submitUpdate(it) | |
}) | |
booksViewModel.dataLoading.observe(viewLifecycleOwner, { loading -> | |
when (loading) { | |
true -> LayoutUtils.crossFade(pbLoading, rvBooks) | |
false -> LayoutUtils.crossFade(rvBooks, pbLoading) | |
} | |
}) | |
rvBooks.apply { | |
layoutManager = | |
GridLayoutManager(requireContext(), COLUMNS_COUNT) | |
adapter = booksAdapter | |
} | |
booksViewModel.error.observe(viewLifecycleOwner, { | |
Toast.makeText( | |
requireContext(), | |
getString(R.string.an_error_has_occurred, it), | |
Toast.LENGTH_SHORT | |
).show() | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment