From cfb8c3c7338043ee47d37fc6807e0d56c4150c0a Mon Sep 17 00:00:00 2001 From: rebelonion <87634197+rebelonion@users.noreply.github.com> Date: Sun, 17 Mar 2024 01:00:08 -0500 Subject: [PATCH] feat: toggle fav --- .../connections/anilist/AnilistMutations.kt | 17 +++++++++++++++++ .../ani/dantotsu/profile/ProfileActivity.kt | 10 ++++++---- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/ani/dantotsu/connections/anilist/AnilistMutations.kt b/app/src/main/java/ani/dantotsu/connections/anilist/AnilistMutations.kt index 686381f1..c2b8eb24 100644 --- a/app/src/main/java/ani/dantotsu/connections/anilist/AnilistMutations.kt +++ b/app/src/main/java/ani/dantotsu/connections/anilist/AnilistMutations.kt @@ -13,6 +13,23 @@ class AnilistMutations { executeQuery(query, variables) } + suspend fun toggleFav(type: FavType, id: Int): Boolean { + val filter = when (type) { + FavType.ANIME -> "animeId" + FavType.MANGA -> "mangaId" + FavType.CHARACTER -> "characterId" + FavType.STAFF -> "staffId" + FavType.STUDIO -> "studioId" + } + val query = """mutation{ToggleFavourite($filter:$id){anime{pageInfo{total}}}}""" + val result = executeQuery(query) + return result?.get("errors") == null && result != null + } + + enum class FavType { + ANIME, MANGA, CHARACTER, STAFF, STUDIO + } + suspend fun editList( mediaID: Int, progress: Int? = null, diff --git a/app/src/main/java/ani/dantotsu/profile/ProfileActivity.kt b/app/src/main/java/ani/dantotsu/profile/ProfileActivity.kt index 9ea5b747..e56e9c0d 100644 --- a/app/src/main/java/ani/dantotsu/profile/ProfileActivity.kt +++ b/app/src/main/java/ani/dantotsu/profile/ProfileActivity.kt @@ -75,8 +75,8 @@ class ProfileActivity : AppCompatActivity(), AppBarLayout.OnOffsetChangedListene finish() return@launch } - val following = respond.data.followingPage?.pageInfo?.total?:0 - val followers = respond.data.followerPage?.pageInfo?.total?:0 + val following = respond.data.followingPage?.pageInfo?.total ?: 0 + val followers = respond.data.followerPage?.pageInfo?.total ?: 0 withContext(Dispatchers.Main) { binding.profileViewPager.updateLayoutParams { bottomMargin = navBarHeight @@ -221,7 +221,7 @@ class ProfileActivity : AppCompatActivity(), AppBarLayout.OnOffsetChangedListene binding.profileMangaCount.text = user.statistics.manga.count.toString() binding.profileMangaCountContainer.setOnClickListener { ContextCompat.startActivity( - this@ProfileActivity, Intent(this@ProfileActivity, ListActivity::class.java) + this@ProfileActivity, Intent(this@ProfileActivity, ListActivity::class.java) .putExtra("anime", false) .putExtra("userId", user.id) .putExtra("username", user.name), null @@ -270,7 +270,9 @@ class ProfileActivity : AppCompatActivity(), AppBarLayout.OnOffsetChangedListene .setDuration(duration).start() ObjectAnimator.ofFloat(binding.profileButtonContainer, "translationX", 0f) .setDuration(duration).start() - binding.profileButtonContainer.updateLayoutParams { height = ViewGroup.LayoutParams.WRAP_CONTENT } + binding.profileButtonContainer.updateLayoutParams { + height = ViewGroup.LayoutParams.WRAP_CONTENT + } if (PrefManager.getVal(PrefName.BannerAnimations)) binding.profileBannerImage.resume() }