feat: follow button
This commit is contained in:
parent
5279b0cd65
commit
9b408e7520
6 changed files with 66 additions and 4 deletions
|
@ -44,7 +44,7 @@ android {
|
||||||
applicationIdSuffix ".beta" // keep as beta by popular request
|
applicationIdSuffix ".beta" // keep as beta by popular request
|
||||||
versionNameSuffix "-alpha02"
|
versionNameSuffix "-alpha02"
|
||||||
manifestPlaceholders = [icon_placeholder: "@mipmap/ic_launcher_alpha", icon_placeholder_round: "@mipmap/ic_launcher_alpha_round"]
|
manifestPlaceholders = [icon_placeholder: "@mipmap/ic_launcher_alpha", icon_placeholder_round: "@mipmap/ic_launcher_alpha_round"]
|
||||||
debuggable true
|
debuggable System.getenv("CI") == null
|
||||||
isDefault true
|
isDefault true
|
||||||
}
|
}
|
||||||
debug {
|
debug {
|
||||||
|
|
|
@ -31,6 +31,14 @@ import java.io.Serializable
|
||||||
import kotlin.system.measureTimeMillis
|
import kotlin.system.measureTimeMillis
|
||||||
|
|
||||||
class AnilistQueries {
|
class AnilistQueries {
|
||||||
|
|
||||||
|
suspend fun toggleFollow(id: Int): Query.ToggleFollow? {
|
||||||
|
val response = executeQuery<Query.ToggleFollow>(
|
||||||
|
"""mutation{ToggleFollow(userId:$id){id, isFollowing, isFollower}}"""
|
||||||
|
)
|
||||||
|
return response
|
||||||
|
}
|
||||||
|
|
||||||
suspend fun getUserData(): Boolean {
|
suspend fun getUserData(): Boolean {
|
||||||
val response: Query.Viewer?
|
val response: Query.Viewer?
|
||||||
measureTimeMillis {
|
measureTimeMillis {
|
||||||
|
@ -40,7 +48,6 @@ class AnilistQueries {
|
||||||
val user = response?.data?.user ?: return false
|
val user = response?.data?.user ?: return false
|
||||||
|
|
||||||
PrefManager.setVal(PrefName.AnilistUserName, user.name)
|
PrefManager.setVal(PrefName.AnilistUserName, user.name)
|
||||||
|
|
||||||
Anilist.userid = user.id
|
Anilist.userid = user.id
|
||||||
PrefManager.setVal(PrefName.AnilistUserId, user.id.toString())
|
PrefManager.setVal(PrefName.AnilistUserId, user.id.toString())
|
||||||
Anilist.username = user.name
|
Anilist.username = user.name
|
||||||
|
|
|
@ -139,6 +139,19 @@ class Query {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
data class ToggleFollow(
|
||||||
|
@SerialName("data")
|
||||||
|
val data: Data?
|
||||||
|
) {
|
||||||
|
@Serializable
|
||||||
|
data class Data(
|
||||||
|
@SerialName("ToggleFollow")
|
||||||
|
val toggleFollow: FollowData
|
||||||
|
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class GenreCollection(
|
data class GenreCollection(
|
||||||
@SerialName("data")
|
@SerialName("data")
|
||||||
|
@ -200,7 +213,7 @@ class Query {
|
||||||
@SerialName("bannerImage")
|
@SerialName("bannerImage")
|
||||||
val bannerImage: String?,
|
val bannerImage: String?,
|
||||||
@SerialName("isFollowing")
|
@SerialName("isFollowing")
|
||||||
val isFollowing: Boolean,
|
var isFollowing: Boolean,
|
||||||
@SerialName("isFollower")
|
@SerialName("isFollower")
|
||||||
val isFollower: Boolean,
|
val isFollower: Boolean,
|
||||||
@SerialName("isBlocked")
|
@SerialName("isBlocked")
|
||||||
|
|
|
@ -514,6 +514,12 @@ data class MediaListCollection(
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
data class FollowData(
|
||||||
|
@SerialName("id") var id: Int,
|
||||||
|
@SerialName("isFollowing") var isFollowing: Boolean,
|
||||||
|
)
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class MediaListGroup(
|
data class MediaListGroup(
|
||||||
// Media list entries
|
// Media list entries
|
||||||
|
|
|
@ -21,6 +21,7 @@ import ani.dantotsu.navBarHeight
|
||||||
import ani.dantotsu.others.ImageViewDialog
|
import ani.dantotsu.others.ImageViewDialog
|
||||||
import ani.dantotsu.settings.saving.PrefManager
|
import ani.dantotsu.settings.saving.PrefManager
|
||||||
import ani.dantotsu.settings.saving.PrefName
|
import ani.dantotsu.settings.saving.PrefName
|
||||||
|
import ani.dantotsu.snackString
|
||||||
import ani.dantotsu.statusBarHeight
|
import ani.dantotsu.statusBarHeight
|
||||||
import ani.dantotsu.themes.ThemeManager
|
import ani.dantotsu.themes.ThemeManager
|
||||||
import ani.dantotsu.toast
|
import ani.dantotsu.toast
|
||||||
|
@ -79,7 +80,22 @@ class ProfileActivity : AppCompatActivity() {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
val userLevel = intent.getStringExtra("username") ?: ""
|
val userLevel = intent.getStringExtra("username") ?: ""
|
||||||
|
binding.followButton.visibility = if (user.id == Anilist.userid || Anilist.userid == null) View.GONE else View.VISIBLE
|
||||||
|
binding.followButton.text = if (user.isFollowing) "Unfollow" else "Follow"
|
||||||
|
if (user.isFollowing && user.isFollower) binding.followButton.text = "Mutual"
|
||||||
|
binding.followButton.setOnClickListener {
|
||||||
|
lifecycleScope.launch(Dispatchers.IO) {
|
||||||
|
val res = Anilist.query.toggleFollow(user.id)
|
||||||
|
if (res?.data?.toggleFollow != null) {
|
||||||
|
withContext(Dispatchers.Main) {
|
||||||
|
snackString("Success")
|
||||||
|
user.isFollowing = res.data.toggleFollow.isFollowing
|
||||||
|
binding.followButton.text = if (user.isFollowing) "Unfollow" else "Follow"
|
||||||
|
if (user.isFollowing && user.isFollower) binding.followButton.text = "Mutual"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
binding.profileProgressBar.visibility = View.GONE
|
binding.profileProgressBar.visibility = View.GONE
|
||||||
binding.profileTopContainer.visibility = View.VISIBLE
|
binding.profileTopContainer.visibility = View.VISIBLE
|
||||||
binding.profileBannerImage.loadImage(user.bannerImage)
|
binding.profileBannerImage.loadImage(user.bannerImage)
|
||||||
|
|
|
@ -86,6 +86,26 @@
|
||||||
android:text="@string/username"
|
android:text="@string/username"
|
||||||
android:textSize="18sp" />
|
android:textSize="18sp" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/followButton"
|
||||||
|
style="@style/Widget.Material3.Button.OutlinedButton"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_margin="8dp"
|
||||||
|
android:enabled="true"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:fontFamily="@font/poppins_bold"
|
||||||
|
android:insetTop="0dp"
|
||||||
|
android:insetBottom="0dp"
|
||||||
|
android:padding="8dp"
|
||||||
|
android:text="Follow"
|
||||||
|
android:textSize="16sp"
|
||||||
|
app:cornerRadius="16dp"
|
||||||
|
app:strokeColor="?attr/colorPrimaryContainer"
|
||||||
|
tools:ignore="SpeakableTextPresentCheck" />
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<androidx.viewpager2.widget.ViewPager2
|
<androidx.viewpager2.widget.ViewPager2
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue