Skip to content

Commit

Permalink
feat(profile page): WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
aayush2622 committed Mar 2, 2024
1 parent 00dad2a commit c720aed
Show file tree
Hide file tree
Showing 6 changed files with 356 additions and 4 deletions.
4 changes: 4 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@
android:name=".settings.ExtensionsActivity"
android:windowSoftInputMode="adjustResize|stateHidden"
android:parentActivityName=".MainActivity" />
<activity
android:name=".profile.ProfileActivity"
android:windowSoftInputMode="adjustResize|stateHidden"
android:parentActivityName=".MainActivity" />
<activity
android:name=".others.imagesearch.ImageSearchActivity"
android:parentActivityName=".MainActivity" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}
Expand Down
15 changes: 13 additions & 2 deletions app/src/main/java/ani/dantotsu/media/comments/CommentItem.kt
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
63 changes: 63 additions & 0 deletions app/src/main/java/ani/dantotsu/profile/ProfileActivity.kt
Original file line number Diff line number Diff line change
@@ -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")
}
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down
Loading

0 comments on commit c720aed

Please sign in to comment.