From c720aed4fc9625df98a4a5b9b60b0e0a26f3b335 Mon Sep 17 00:00:00 2001 From: aayush262 Date: Sat, 2 Mar 2024 12:41:45 +0530 Subject: [PATCH] feat(profile page): WIP --- app/src/main/AndroidManifest.xml | 4 + .../connections/anilist/AnilistQueries.kt | 2 +- .../dantotsu/media/comments/CommentItem.kt | 15 +- .../ani/dantotsu/profile/ProfileActivity.kt | 63 +++++ .../settings/SettingsDialogFragment.kt | 10 +- app/src/main/res/layout/activity_profile.xml | 266 ++++++++++++++++++ 6 files changed, 356 insertions(+), 4 deletions(-) create mode 100644 app/src/main/java/ani/dantotsu/profile/ProfileActivity.kt create mode 100644 app/src/main/res/layout/activity_profile.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 43fd8651e5b..e08f108e137 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -106,6 +106,10 @@ android:name=".settings.ExtensionsActivity" android:windowSoftInputMode="adjustResize|stateHidden" android:parentActivityName=".MainActivity" /> + 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 b9fb3ca68dc..a2e092b4e48 100644 --- a/app/src/main/java/ani/dantotsu/connections/anilist/AnilistQueries.kt +++ b/app/src/main/java/ani/dantotsu/connections/anilist/AnilistQueries.kt @@ -54,7 +54,7 @@ class AnilistQueries { suspend fun getUserProfile(id: Int): Query.UserProfileResponse? { return executeQuery( - """{user:User(id:$id){id,name,about(asHtml:true)avatar{medium,large},bannerImage,isFollowing,isFollower,isBlocked,favourites{anime{nodes{coverImage{extraLarge,large,medium,color}}}manga{nodes{id,coverImage{extraLarge,large,medium,color}}}characters{nodes{id,image{large,medium}}}staff{id,nodes{image{large,medium}}}studios{nodes{id,name}}}statistics{anime{count,meanScore,standardDeviation,minutesWatched,episodesWatched,chaptersRead,volumesRead}manga{count,meanScore,standardDeviation,minutesWatched,episodesWatched,chaptersRead,volumesRead}}siteUrl}}""", + """{user:User(id:$id){id,name,about(asHtml:true)avatar{medium,large},bannerImage,isFollowing,isFollower,isBlocked,favourites{anime{nodes{coverImage{extraLarge,large,medium,color}}}manga{nodes{id,coverImage{extraLarge,large,medium,color}}}characters{nodes{id,image{large,medium}}}staff{nodes{id,image{large,medium}}}studios{nodes{id,name}}}statistics{anime{count,meanScore,standardDeviation,minutesWatched,episodesWatched,chaptersRead,volumesRead}manga{count,meanScore,standardDeviation,minutesWatched,episodesWatched,chaptersRead,volumesRead}}siteUrl}}""", force = true ) } diff --git a/app/src/main/java/ani/dantotsu/media/comments/CommentItem.kt b/app/src/main/java/ani/dantotsu/media/comments/CommentItem.kt index f4655c445f8..246145e78bc 100644 --- a/app/src/main/java/ani/dantotsu/media/comments/CommentItem.kt +++ b/app/src/main/java/ani/dantotsu/media/comments/CommentItem.kt @@ -1,17 +1,22 @@ package ani.dantotsu.media.comments import android.annotation.SuppressLint +import android.content.Intent import android.graphics.Color import android.view.View +import androidx.core.content.ContextCompat import androidx.recyclerview.widget.LinearLayoutManager import ani.dantotsu.R import ani.dantotsu.connections.comments.Comment import ani.dantotsu.connections.comments.CommentsAPI import ani.dantotsu.copyToClipboard import ani.dantotsu.currActivity +import ani.dantotsu.currContext import ani.dantotsu.databinding.ItemCommentsBinding import ani.dantotsu.loadImage +import ani.dantotsu.media.user.ListActivity import ani.dantotsu.openLinkInBrowser +import ani.dantotsu.profile.ProfileActivity import ani.dantotsu.snackString import com.xwray.groupie.GroupieAdapter import com.xwray.groupie.Section @@ -56,6 +61,7 @@ class CommentItem(val comment: Comment, val isUserComment = CommentsAPI.userId == comment.userId val node = markwon.parse(comment.content) val spanned = markwon.render(node) + val levelColor = getAvatarColor(comment.totalVotes, backgroundColor) markwon.setParsedMarkdown(viewBinding.commentText, viewBinding.commentText.setSpoilerText(spanned, markwon)) viewBinding.commentDelete.visibility = if (isUserComment || CommentsAPI.isAdmin || CommentsAPI.isMod) View.VISIBLE else View.GONE viewBinding.commentBanUser.visibility = if ((CommentsAPI.isAdmin || CommentsAPI.isMod) && !isUserComment) View.VISIBLE else View.GONE @@ -94,7 +100,12 @@ class CommentItem(val comment: Comment, } viewBinding.commentUserName.setOnClickListener { - openLinkInBrowser("https://anilist.co/user/${comment.username}") + ContextCompat.startActivity( + currContext()!!, Intent(currContext()!!, ProfileActivity::class.java) + .putExtra("userId", comment.userId.toInt()) + .putExtra("username","[${levelColor.second}]"), null + ) + } viewBinding.commentText.setOnLongClickListener { copyToClipboard(comment.content) @@ -189,7 +200,7 @@ class CommentItem(val comment: Comment, viewBinding.commentUserAvatar comment.profilePictureUrl?.let { viewBinding.commentUserAvatar.loadImage(it) } viewBinding.commentUserName.text = comment.username - val levelColor = getAvatarColor(comment.totalVotes, backgroundColor) + viewBinding.commentUserLevel.text = "[${levelColor.second}]" viewBinding.commentUserLevel.setTextColor(levelColor.first) viewBinding.commentUserTime.text = formatTimestamp(comment.timestamp) diff --git a/app/src/main/java/ani/dantotsu/profile/ProfileActivity.kt b/app/src/main/java/ani/dantotsu/profile/ProfileActivity.kt new file mode 100644 index 00000000000..3feed339c07 --- /dev/null +++ b/app/src/main/java/ani/dantotsu/profile/ProfileActivity.kt @@ -0,0 +1,63 @@ +package ani.dantotsu.profile + +import android.annotation.SuppressLint +import android.content.Intent +import android.os.Bundle +import android.view.View +import androidx.appcompat.app.AppCompatActivity +import androidx.core.content.ContextCompat +import androidx.lifecycle.lifecycleScope +import ani.dantotsu.connections.anilist.Anilist +import ani.dantotsu.databinding.ActivityProfileBinding +import ani.dantotsu.loadImage +import ani.dantotsu.media.user.ListActivity +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.launch +import kotlinx.coroutines.withContext + + +class ProfileActivity : AppCompatActivity(){ + private lateinit var binding: ActivityProfileBinding + @SuppressLint("SetTextI18n") + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + binding = ActivityProfileBinding.inflate(layoutInflater) + setContentView(binding.root) + lifecycleScope.launch(Dispatchers.IO) { + val userid = intent.getIntExtra("userId", 0) + val respond = Anilist.query.getUserProfile(userid) + val user = respond?.data?.user ?: return@launch + val userLevel = intent.getStringExtra("username") + withContext(Dispatchers.Main) { + binding.profileProgressBar.visibility = View.GONE + binding.profileBannerImage.loadImage(user.bannerImage) + binding.profileUserAvatar.loadImage(user.avatar?.medium) + binding.profileUserName.text = "${user.name} $userLevel" + binding.profileUserInfo.text = user.about + binding.profileAnimeList.setOnClickListener { + ContextCompat.startActivity( + this@ProfileActivity, Intent(this@ProfileActivity, ListActivity::class.java) + .putExtra("anime", true) + .putExtra("userId", user.id) + .putExtra("username", user.name), null + ) + } + binding.profileMangaList.setOnClickListener { + ContextCompat.startActivity( + this@ProfileActivity, Intent(this@ProfileActivity, ListActivity::class.java) + .putExtra("anime", false) + .putExtra("userId", user.id) + .putExtra("username", user.name), null + ) + } + binding.profileUserEpisodesWatched.text = user.statistics.anime.episodesWatched.toString() + binding.profileUserChaptersRead.text = user.statistics.manga.chaptersRead.toString() + + binding.profileAnimeListImage.loadImage("https://bit.ly/31bsIHq") + binding.profileMangaListImage.loadImage("https://bit.ly/2ZGfcuG") + } + } + + } + +} \ No newline at end of file diff --git a/app/src/main/java/ani/dantotsu/settings/SettingsDialogFragment.kt b/app/src/main/java/ani/dantotsu/settings/SettingsDialogFragment.kt index 7b349929dc3..2ee606b47f0 100644 --- a/app/src/main/java/ani/dantotsu/settings/SettingsDialogFragment.kt +++ b/app/src/main/java/ani/dantotsu/settings/SettingsDialogFragment.kt @@ -7,10 +7,13 @@ import android.util.TypedValue import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import androidx.core.content.ContextCompat import ani.dantotsu.BottomSheetDialogFragment import ani.dantotsu.MainActivity +import ani.dantotsu.profile.ProfileActivity import ani.dantotsu.R import ani.dantotsu.connections.anilist.Anilist +import ani.dantotsu.currContext import ani.dantotsu.databinding.BottomSheetSettingsBinding import ani.dantotsu.download.anime.OfflineAnimeFragment import ani.dantotsu.download.manga.OfflineMangaFragment @@ -76,7 +79,12 @@ class SettingsDialogFragment : BottomSheetDialogFragment() { Anilist.loginIntent(requireActivity()) } } - + binding.settingsUserAvatar.setOnClickListener{ + ContextCompat.startActivity( + currContext()!!, Intent(currContext()!!, ProfileActivity::class.java) + .putExtra("userId", Anilist.userid), null + ) + } binding.settingsIncognito.isChecked = PrefManager.getVal(PrefName.Incognito) diff --git a/app/src/main/res/layout/activity_profile.xml b/app/src/main/res/layout/activity_profile.xml new file mode 100644 index 00000000000..79d2c796b48 --- /dev/null +++ b/app/src/main/res/layout/activity_profile.xml @@ -0,0 +1,266 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file