Skip to content

Commit

Permalink
Implemented Snacker
Browse files Browse the repository at this point in the history
  • Loading branch information
debz-g committed Dec 10, 2022
1 parent 077961a commit c4d3d0d
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions app/src/main/java/dev/refox/anitrack/ui/SearchAnimeFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import dev.refox.anitrack.database.*
import dev.refox.anitrack.databinding.FragmentSearchAnimeBinding
import dev.refox.anitrack.models.topAnimeModel.Data
import dev.refox.anitrack.networking.Repository
import dev.refox.anitrack.utils.Snacker
import dev.refox.anitrack.viewmodels.AnimeViewModel
import dev.refox.anitrack.viewmodels.AnimeViewModelFactory

Expand All @@ -35,7 +36,6 @@ class SearchAnimeFragment : Fragment() {
get() = _binding!!



private val repository: Repository by lazy {
Repository()
}
Expand Down Expand Up @@ -64,7 +64,10 @@ class SearchAnimeFragment : Fragment() {
animeViewModel =
ViewModelProvider(this, AnimeViewModelFactory(repository))[AnimeViewModel::class.java]

animesDBViewModel = ViewModelProvider(this, AnimesDBViewModelFactory(animesRepository))[AnimesDBViewModel::class.java]
animesDBViewModel = ViewModelProvider(
this,
AnimesDBViewModelFactory(animesRepository)
)[AnimesDBViewModel::class.java]

animeViewModel.getTopAnime()

Expand All @@ -87,7 +90,7 @@ class SearchAnimeFragment : Fragment() {
animeAdapter.onItemClick = {
val dialog = AnimeDetailsBottomSheet(it)
dialog.setCancelable(true)
dialog.show(parentFragmentManager,"AnimeBottomSheetDialog")
dialog.show(parentFragmentManager, "AnimeBottomSheetDialog")
}

animeAdapter.onItemLongClick = {
Expand All @@ -102,7 +105,8 @@ class SearchAnimeFragment : Fragment() {
)
animeData.id = System.currentTimeMillis()

val longPressDialogBinding = layoutInflater.inflate(R.layout.add_to_lib_dialog, null)
val longPressDialogBinding =
layoutInflater.inflate(R.layout.add_to_lib_dialog, null)
val longPressDialog = Dialog(requireContext())

longPressDialog.setContentView(longPressDialogBinding)
Expand All @@ -113,7 +117,7 @@ class SearchAnimeFragment : Fragment() {
val btnAdd = longPressDialogBinding.findViewById<MaterialCardView>(R.id.btnAdd)
btnAdd.setOnClickListener {
animesDBViewModel.insertAnimes(animeData)
Toast.makeText(context, "Added Anime to your library", Toast.LENGTH_SHORT).show()
Snacker(it, "Anime added to your WatchList").success()
longPressDialog.dismiss()
}
}
Expand Down Expand Up @@ -148,7 +152,7 @@ class SearchAnimeFragment : Fragment() {
animeAdapter.onItemClick = {
val dialog = AnimeDetailsBottomSheet(it)
dialog.setCancelable(true)
dialog.show(parentFragmentManager,"AnimeBottomSheetDialog")
dialog.show(parentFragmentManager, "AnimeBottomSheetDialog")
}

animeAdapter.onItemLongClick = {
Expand All @@ -163,7 +167,8 @@ class SearchAnimeFragment : Fragment() {
)
animeData.id = System.currentTimeMillis()

val longPressDialogBinding = layoutInflater.inflate(R.layout.add_to_lib_dialog, null)
val longPressDialogBinding =
layoutInflater.inflate(R.layout.add_to_lib_dialog, null)
val longPressDialog = Dialog(requireContext())

longPressDialog.setContentView(longPressDialogBinding)
Expand All @@ -174,7 +179,8 @@ class SearchAnimeFragment : Fragment() {
val btnAdd = longPressDialogBinding.findViewById<MaterialCardView>(R.id.btnAdd)
btnAdd.setOnClickListener {
animesDBViewModel.insertAnimes(animeData)
Toast.makeText(context, "Added Anime to your library", Toast.LENGTH_SHORT).show()
Toast.makeText(context, "Added Anime to your library", Toast.LENGTH_SHORT)
.show()
longPressDialog.dismiss()
}
}
Expand Down

0 comments on commit c4d3d0d

Please sign in to comment.