Skip to content

Commit

Permalink
added check if article is already favorited
Browse files Browse the repository at this point in the history
  • Loading branch information
rafsanahmad committed Nov 14, 2021
1 parent 8e36c58 commit 959996b
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions app/src/main/java/com/rafsan/newsapp/ui/details/DetailsFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class DetailsFragment : BaseFragment<FragmentDetailsBinding>() {
super.onViewCreated(view, savedInstanceState)
viewModel = (activity as MainActivity).mainViewModel
setupUI(view)
setupObserver();
}

private fun setupUI(view: View) {
Expand All @@ -51,4 +52,13 @@ class DetailsFragment : BaseFragment<FragmentDetailsBinding>() {
Snackbar.make(view, "News article saved successfully", Snackbar.LENGTH_SHORT).show()
}
}

private fun setupObserver() {
viewModel.getFavoriteNews().observe(viewLifecycleOwner, { news ->
val isAlreadyFavorite = news.any {
it.title == args.news.title
}
if (isAlreadyFavorite) binding.fab.visibility = View.GONE
})
}
}

0 comments on commit 959996b

Please sign in to comment.