Skip to content

Commit

Permalink
feat: follow button
Browse files Browse the repository at this point in the history
  • Loading branch information
rebelonion committed Mar 5, 2024
1 parent 5279b0c commit 9b408e7
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ android {
applicationIdSuffix ".beta" // keep as beta by popular request
versionNameSuffix "-alpha02"
manifestPlaceholders = [icon_placeholder: "@mipmap/ic_launcher_alpha", icon_placeholder_round: "@mipmap/ic_launcher_alpha_round"]
debuggable true
debuggable System.getenv("CI") == null
isDefault true
}
debug {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ import java.io.Serializable
import kotlin.system.measureTimeMillis

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 {
val response: Query.Viewer?
measureTimeMillis {
Expand All @@ -40,7 +48,6 @@ class AnilistQueries {
val user = response?.data?.user ?: return false

PrefManager.setVal(PrefName.AnilistUserName, user.name)

Anilist.userid = user.id
PrefManager.setVal(PrefName.AnilistUserId, user.id.toString())
Anilist.username = user.name
Expand Down
15 changes: 14 additions & 1 deletion app/src/main/java/ani/dantotsu/connections/anilist/api/Data.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
data class GenreCollection(
@SerialName("data")
Expand Down Expand Up @@ -200,7 +213,7 @@ class Query {
@SerialName("bannerImage")
val bannerImage: String?,
@SerialName("isFollowing")
val isFollowing: Boolean,
var isFollowing: Boolean,
@SerialName("isFollower")
val isFollower: Boolean,
@SerialName("isBlocked")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,12 @@ data class MediaListCollection(

)

@Serializable
data class FollowData(
@SerialName("id") var id: Int,
@SerialName("isFollowing") var isFollowing: Boolean,
)

@Serializable
data class MediaListGroup(
// Media list entries
Expand Down
18 changes: 17 additions & 1 deletion app/src/main/java/ani/dantotsu/profile/ProfileActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import ani.dantotsu.navBarHeight
import ani.dantotsu.others.ImageViewDialog
import ani.dantotsu.settings.saving.PrefManager
import ani.dantotsu.settings.saving.PrefName
import ani.dantotsu.snackString
import ani.dantotsu.statusBarHeight
import ani.dantotsu.themes.ThemeManager
import ani.dantotsu.toast
Expand Down Expand Up @@ -79,7 +80,22 @@ class ProfileActivity : AppCompatActivity() {
}
})
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.profileTopContainer.visibility = View.VISIBLE
binding.profileBannerImage.loadImage(user.bannerImage)
Expand Down
20 changes: 20 additions & 0 deletions app/src/main/res/layout/activity_profile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,26 @@
android:text="@string/username"
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>

<androidx.viewpager2.widget.ViewPager2
Expand Down

0 comments on commit 9b408e7

Please sign in to comment.