From 7aa0951cdf48e0b7b79ccf13bb542f2a8d61e270 Mon Sep 17 00:00:00 2001 From: aayush262 Date: Sun, 5 May 2024 00:45:46 +0530 Subject: [PATCH] feat: long click "continue Watching" to see hidden items --- .../connections/anilist/AnilistQueries.kt | 10 ++++ .../connections/anilist/AnilistViewModel.kt | 13 +++-- .../java/ani/dantotsu/home/HomeFragment.kt | 32 +++++++++++- app/src/main/res/layout/fragment_home.xml | 52 ++++++++++++++++++- app/src/main/res/values/strings.xml | 1 + 5 files changed, 103 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/ani/dantotsu/connections/anilist/AnilistQueries.kt b/app/src/main/java/ani/dantotsu/connections/anilist/AnilistQueries.kt index 1c8ba03d875..2886e66cd82 100644 --- a/app/src/main/java/ani/dantotsu/connections/anilist/AnilistQueries.kt +++ b/app/src/main/java/ani/dantotsu/connections/anilist/AnilistQueries.kt @@ -413,6 +413,7 @@ class AnilistQueries { suspend fun initHomePage(): Map> { val removeList = PrefManager.getCustomVal("removeList", setOf()) + val removedMedia = ArrayList() val toShow: List = PrefManager.getVal(PrefName.HomeLayout) // anime continue, anime fav, anime planned, manga continue, manga fav, manga planned, recommendations var query = """{""" @@ -465,6 +466,8 @@ class AnilistQueries { if (m.id !in removeList) { m.cameFromContinue = true subMap[m.id] = m + } else { + removedMedia.add(m) } } } @@ -475,6 +478,8 @@ class AnilistQueries { if (m.id !in removeList) { m.cameFromContinue = true subMap[m.id] = m + } else { + removedMedia.add(m) } } } @@ -512,6 +517,8 @@ class AnilistQueries { if (m.id !in removeList) { m.cameFromContinue = true subMap[m.id] = m + } else { + removedMedia.add(m) } } } @@ -542,6 +549,8 @@ class AnilistQueries { val m = Media(i).apply { isFav = true } if (m.id !in removeList) { returnArray.add(m) + } else { + removedMedia.add(m) } } } @@ -643,6 +652,7 @@ class AnilistQueries { list.addAll(0, anilistActivities) returnMap["status"] = ArrayList(list) } + returnMap["hidden"] = removedMedia.distinctBy { it.id } as ArrayList } return returnMap } diff --git a/app/src/main/java/ani/dantotsu/connections/anilist/AnilistViewModel.kt b/app/src/main/java/ani/dantotsu/connections/anilist/AnilistViewModel.kt index 65f26c81e20..ad8a36f8491 100644 --- a/app/src/main/java/ani/dantotsu/connections/anilist/AnilistViewModel.kt +++ b/app/src/main/java/ani/dantotsu/connections/anilist/AnilistViewModel.kt @@ -81,6 +81,15 @@ class AnilistHomeViewModel : ViewModel() { fun getRecommendation(): LiveData> = recommendation + private val userStatus: MutableLiveData> = + MutableLiveData>(null) + + fun getUserStatus(): LiveData> = userStatus + + private val hidden: MutableLiveData> = + MutableLiveData>(null) + + fun getHidden(): LiveData> = hidden @Suppress("UNCHECKED_CAST") suspend fun initHomePage() { val res = Anilist.query.initHomePage() @@ -91,12 +100,10 @@ class AnilistHomeViewModel : ViewModel() { res["favoriteManga"]?.let { mangaFav.postValue(it as ArrayList?) } res["plannedManga"]?.let { mangaPlanned.postValue(it as ArrayList?) } res["recommendations"]?.let { recommendation.postValue(it as ArrayList?) } + res["hidden"]?.let { hidden.postValue(it as ArrayList?) } res["status"]?.let { userStatus.postValue(it as ArrayList?) } } - private val userStatus: MutableLiveData> = - MutableLiveData>(null) - fun getUserStatus(): LiveData> = userStatus suspend fun loadMain(context: FragmentActivity) { Anilist.getSavedToken() diff --git a/app/src/main/java/ani/dantotsu/home/HomeFragment.kt b/app/src/main/java/ani/dantotsu/home/HomeFragment.kt index 9849d810a84..cc3492fa6e4 100644 --- a/app/src/main/java/ani/dantotsu/home/HomeFragment.kt +++ b/app/src/main/java/ani/dantotsu/home/HomeFragment.kt @@ -281,7 +281,6 @@ class HomeFragment : Fragment() { binding.homeFavAnime, binding.homeFavAnimeMore, getString(R.string.fav_anime) - ) initRecyclerView( @@ -376,6 +375,37 @@ class HomeFragment : Fragment() { } } + model.getHidden().observe(viewLifecycleOwner) { + if (it != null) { + if (it.isNotEmpty()) { + binding.homeHiddenItemsRecyclerView.adapter = MediaAdaptor(0, it, requireActivity()) + binding.homeHiddenItemsRecyclerView.layoutManager = LinearLayoutManager( + requireContext(), + LinearLayoutManager.HORIZONTAL, + false + ) + binding.homeContinueWatch.setOnLongClickListener { + binding.homeHiddenItemsContainer.visibility = View.VISIBLE + binding.homeHiddenItemsRecyclerView.layoutAnimation = + LayoutAnimationController(setSlideIn(), 0.25f) + true + } + binding.homeHiddenItemsMore.setSafeOnClickListener { _ -> + ContextCompat.startActivity( + requireActivity(), Intent(requireActivity(), MediaListViewActivity::class.java) + .putExtra("title", getString(R.string.hidden)) + .putExtra("media", it), + null + ) + } + binding.homeHiddenItemsTitle.setOnLongClickListener { + binding.homeHiddenItemsContainer.visibility = View.GONE + true + } + } + } + } + binding.homeUserAvatarContainer.startAnimation(setSlideUp()) model.empty.observe(viewLifecycleOwner) diff --git a/app/src/main/res/layout/fragment_home.xml b/app/src/main/res/layout/fragment_home.xml index f77f7f21c3c..0f7c3b3972a 100644 --- a/app/src/main/res/layout/fragment_home.xml +++ b/app/src/main/res/layout/fragment_home.xml @@ -338,6 +338,56 @@ tools:orientation="horizontal" /> + + + + + + + + + + + + Copy Report Share as file Hide in Home Screen + Hidden