Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
aayush262 2024-03-05 11:13:38 +05:30
commit 9e4684e61c
6 changed files with 66 additions and 4 deletions

View file

@ -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 {

View file

@ -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 {
@ -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

View file

@ -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")
@ -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")

View file

@ -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

View file

@ -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
@ -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)

View file

@ -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