This commit is contained in:
rebelonion 2024-03-02 01:15:54 -06:00
commit 533148069f
6 changed files with 356 additions and 4 deletions

View file

@ -54,7 +54,7 @@ class AnilistQueries {
suspend fun getUserProfile(id: Int): Query.UserProfileResponse? {
return executeQuery<Query.UserProfileResponse>(
"""{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
)
}

View file

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

View file

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

View file

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