feat: better profile page

This commit is contained in:
aayush262 2024-03-16 22:04:57 +05:30
parent 94aae33d10
commit e3f8096749
9 changed files with 204 additions and 197 deletions

View file

@ -1354,7 +1354,7 @@ Page(page:$page,perPage:50) {
suspend fun getFeed(userId: Int?, global: Boolean = false, page: Int = 1, activityId: Int? = null): FeedResponse? { suspend fun getFeed(userId: Int?, global: Boolean = false, page: Int = 1, activityId: Int? = null): FeedResponse? {
val filter = if (activityId != null) "id:$activityId," val filter = if (activityId != null) "id:$activityId,"
else if (userId != null) "userId:$userId," else if (userId != null) "userId:$userId,"
else if (global) "isFollowing:false,hasReplies:true," else if (global) "isFollowing:false,hasRepliesOrTypeText:true,"
else "isFollowing:true,type_not:MESSAGE," else "isFollowing:true,type_not:MESSAGE,"
return executeQuery<FeedResponse>( return executeQuery<FeedResponse>(
"""{Page(page:$page,perPage:$ITEMS_PER_PAGE){activities(${filter}sort:ID_DESC){__typename ... on TextActivity{id userId type replyCount text(asHtml:true)siteUrl isLocked isSubscribed likeCount isLiked isPinned createdAt user{id name bannerImage avatar{medium large}}replies{id userId activityId text(asHtml:true)likeCount isLiked createdAt user{id name bannerImage avatar{medium large}}likes{id name bannerImage avatar{medium large}}}likes{id name bannerImage avatar{medium large}}}... on ListActivity{id userId type replyCount status progress siteUrl isLocked isSubscribed likeCount isLiked isPinned createdAt user{id name bannerImage avatar{medium large}}media{id title{english romaji native userPreferred}bannerImage coverImage{medium large}}replies{id userId activityId text(asHtml:true)likeCount isLiked createdAt user{id name bannerImage avatar{medium large}}likes{id name bannerImage avatar{medium large}}}likes{id name bannerImage avatar{medium large}}}... on MessageActivity{id recipientId messengerId type replyCount likeCount message(asHtml:true)isLocked isSubscribed isLiked isPrivate siteUrl createdAt recipient{id name bannerImage avatar{medium large}}messenger{id name bannerImage avatar{medium large}}replies{id userId activityId text(asHtml:true)likeCount isLiked createdAt user{id name bannerImage avatar{medium large}}likes{id name bannerImage avatar{medium large}}}likes{id name bannerImage avatar{medium large}}}}}}""" """{Page(page:$page,perPage:$ITEMS_PER_PAGE){activities(${filter}sort:ID_DESC){__typename ... on TextActivity{id userId type replyCount text(asHtml:true)siteUrl isLocked isSubscribed likeCount isLiked isPinned createdAt user{id name bannerImage avatar{medium large}}replies{id userId activityId text(asHtml:true)likeCount isLiked createdAt user{id name bannerImage avatar{medium large}}likes{id name bannerImage avatar{medium large}}}likes{id name bannerImage avatar{medium large}}}... on ListActivity{id userId type replyCount status progress siteUrl isLocked isSubscribed likeCount isLiked isPinned createdAt user{id name bannerImage avatar{medium large}}media{id title{english romaji native userPreferred}bannerImage coverImage{medium large}}replies{id userId activityId text(asHtml:true)likeCount isLiked createdAt user{id name bannerImage avatar{medium large}}likes{id name bannerImage avatar{medium large}}}likes{id name bannerImage avatar{medium large}}}... on MessageActivity{id recipientId messengerId type replyCount likeCount message(asHtml:true)isLocked isSubscribed isLiked isPrivate siteUrl createdAt recipient{id name bannerImage avatar{medium large}}messenger{id name bannerImage avatar{medium large}}replies{id userId activityId text(asHtml:true)likeCount isLiked createdAt user{id name bannerImage avatar{medium large}}likes{id name bannerImage avatar{medium large}}}likes{id name bannerImage avatar{medium large}}}}}}"""

View file

@ -23,6 +23,7 @@ import ani.dantotsu.connections.anilist.api.Query
import ani.dantotsu.databinding.ActivityProfileBinding import ani.dantotsu.databinding.ActivityProfileBinding
import ani.dantotsu.initActivity import ani.dantotsu.initActivity
import ani.dantotsu.loadImage import ani.dantotsu.loadImage
import ani.dantotsu.media.user.ListActivity
import ani.dantotsu.navBarHeight import ani.dantotsu.navBarHeight
import ani.dantotsu.openLinkInBrowser import ani.dantotsu.openLinkInBrowser
import ani.dantotsu.others.ImageViewDialog import ani.dantotsu.others.ImageViewDialog
@ -74,6 +75,8 @@ class ProfileActivity : AppCompatActivity(), AppBarLayout.OnOffsetChangedListene
finish() finish()
return@launch return@launch
} }
val following = Anilist.query.userFollowers(userid)?.data?.page?.followers
val followers = Anilist.query.userFollowing(userid)?.data?.page?.following
withContext(Dispatchers.Main) { withContext(Dispatchers.Main) {
binding.profileViewPager.updateLayoutParams<ViewGroup.MarginLayoutParams> { binding.profileViewPager.updateLayoutParams<ViewGroup.MarginLayoutParams> {
bottomMargin = navBarHeight bottomMargin = navBarHeight
@ -181,6 +184,52 @@ class ProfileActivity : AppCompatActivity(), AppBarLayout.OnOffsetChangedListene
mMaxScrollSize = binding.profileAppBar.totalScrollRange mMaxScrollSize = binding.profileAppBar.totalScrollRange
binding.profileAppBar.addOnOffsetChangedListener(this@ProfileActivity) binding.profileAppBar.addOnOffsetChangedListener(this@ProfileActivity)
followers?.count()?.let {
binding.profileFollowerCount.text = it.toString()
}
binding.profileFollowerCountContainer.setOnClickListener {
ContextCompat.startActivity(
this@ProfileActivity,
Intent(this@ProfileActivity, FollowActivity::class.java)
.putExtra("title", "Followers")
.putExtra("userId", user.id),
null
)
}
following?.count()?.let {
binding.profileFollowingCount.text = it.toString()
}
binding.profileFollowingCountContainer.setOnClickListener {
ContextCompat.startActivity(
this@ProfileActivity,
Intent(this@ProfileActivity, FollowActivity::class.java)
.putExtra("title", "Following")
.putExtra("userId", user.id),
null
)
}
binding.profileAnimeCount.text = user.statistics.anime.count.toString()
binding.profileAnimeCountContainer.setOnClickListener {
ContextCompat.startActivity(
this@ProfileActivity, Intent(this@ProfileActivity, ListActivity::class.java)
.putExtra("anime", true)
.putExtra("userId", user.id)
.putExtra("username", user.name), null
)
}
binding.profileMangaCount.text = user.statistics.manga.count.toString()
binding.profileMangaCountContainer.setOnClickListener {
ContextCompat.startActivity(
this@ProfileActivity, Intent(this@ProfileActivity, ListActivity::class.java)
.putExtra("anime", false)
.putExtra("userId", user.id)
.putExtra("username", user.name), null
)
}
} }
} }
} }
@ -211,6 +260,9 @@ class ProfileActivity : AppCompatActivity(), AppBarLayout.OnOffsetChangedListene
.setDuration(duration).start() .setDuration(duration).start()
ObjectAnimator.ofFloat(binding.profileUserAvatarContainer, "translationX", screenWidth) ObjectAnimator.ofFloat(binding.profileUserAvatarContainer, "translationX", screenWidth)
.setDuration(duration).start() .setDuration(duration).start()
ObjectAnimator.ofFloat(binding.profileButtonContainer, "translationX", screenWidth)
.setDuration(duration).start()
binding.profileButtonContainer.updateLayoutParams { height = 0 }
binding.profileBannerImage.pause() binding.profileBannerImage.pause()
} }
if (percentage <= percent && isCollapsed) { if (percentage <= percent && isCollapsed) {
@ -218,8 +270,11 @@ class ProfileActivity : AppCompatActivity(), AppBarLayout.OnOffsetChangedListene
ObjectAnimator.ofFloat(binding.profileUserDataContainer, "translationX", 0f) ObjectAnimator.ofFloat(binding.profileUserDataContainer, "translationX", 0f)
.setDuration(duration).start() .setDuration(duration).start()
ObjectAnimator.ofFloat(binding.profileUserAvatarContainer, "translationX", 0f) ObjectAnimator.ofFloat(binding.profileUserAvatarContainer, "translationX", 0f)
.setDuration(duration) .setDuration(duration).start()
.start() ObjectAnimator.ofFloat(binding.profileButtonContainer, "translationX", 0f)
.setDuration(duration).start()
binding.profileButtonContainer.updateLayoutParams { height = ViewGroup.LayoutParams.WRAP_CONTENT }
if (PrefManager.getVal(PrefName.BannerAnimations)) binding.profileBannerImage.resume() if (PrefManager.getVal(PrefName.BannerAnimations)) binding.profileBannerImage.resume()
} }
} }

View file

@ -87,37 +87,14 @@ class ProfileFragment : Fragment() {
binding.userInfoContainer.visibility = binding.userInfoContainer.visibility =
if (user.about != null) View.VISIBLE else View.GONE if (user.about != null) View.VISIBLE else View.GONE
binding.profileAnimeList.setOnClickListener {
ContextCompat.startActivity(
activity, Intent(activity, ListActivity::class.java)
.putExtra("anime", true)
.putExtra("userId", user.id)
.putExtra("username", user.name), null
)
}
binding.profileMangaList.setOnClickListener {
ContextCompat.startActivity(
activity, Intent(activity, ListActivity::class.java)
.putExtra("anime", false)
.putExtra("userId", user.id)
.putExtra("username", user.name), null
)
}
binding.statsEpisodesWatched.text = user.statistics.anime.episodesWatched.toString() binding.statsEpisodesWatched.text = user.statistics.anime.episodesWatched.toString()
binding.statsDaysWatched.text = binding.statsDaysWatched.text =
(user.statistics.anime.minutesWatched / (24 * 60)).toString() (user.statistics.anime.minutesWatched / (24 * 60)).toString()
binding.statsTotalAnime.text = user.statistics.anime.count.toString()
binding.statsAnimeMeanScore.text = user.statistics.anime.meanScore.toString() binding.statsAnimeMeanScore.text = user.statistics.anime.meanScore.toString()
binding.statsChaptersRead.text = user.statistics.manga.chaptersRead.toString() binding.statsChaptersRead.text = user.statistics.manga.chaptersRead.toString()
binding.statsVolumeRead.text = (user.statistics.manga.volumesRead).toString() binding.statsVolumeRead.text = (user.statistics.manga.volumesRead).toString()
binding.statsTotalManga.text = user.statistics.manga.count.toString()
binding.statsMangaMeanScore.text = user.statistics.manga.meanScore.toString() binding.statsMangaMeanScore.text = user.statistics.manga.meanScore.toString()
model.getListImages().observe(viewLifecycleOwner) {
if (it.isNotEmpty()) {
binding.profileAnimeListImage.loadImage(it[0] ?: "https://bit.ly/31bsIHq")
binding.profileMangaListImage.loadImage(it[1] ?: "https://bit.ly/2ZGfcuG")
}
}
initRecyclerView( initRecyclerView(
model.getAnimeFav(), model.getAnimeFav(),
binding.profileFavAnimeContainer, binding.profileFavAnimeContainer,

View file

@ -33,7 +33,7 @@ import kotlinx.coroutines.withContext
class ActivityItem( class ActivityItem(
private val activity: Activity, private val activity: Activity,
val clickCallback: (Int, type: String) -> Unit, val clickCallback: (Int, type: String) -> Unit,
private val FragActivity: FragmentActivity private val fragActivity: FragmentActivity
) : BindableItem<ItemActivityBinding>() { ) : BindableItem<ItemActivityBinding>() {
private lateinit var binding: ItemActivityBinding private lateinit var binding: ItemActivityBinding
private lateinit var repliesAdapter: GroupieAdapter private lateinit var repliesAdapter: GroupieAdapter
@ -114,7 +114,7 @@ class ActivityItem(
} }
binding.activityLike.setOnLongClickListener{ binding.activityLike.setOnLongClickListener{
UsersDialogFragment().apply { userList(userList) UsersDialogFragment().apply { userList(userList)
show(FragActivity.supportFragmentManager, "dialog") show(fragActivity.supportFragmentManager, "dialog")
} }
true true
} }
@ -127,8 +127,7 @@ class ActivityItem(
binding.activityContent.visibility = View.GONE binding.activityContent.visibility = View.GONE
binding.activityBannerContainer.visibility = View.VISIBLE binding.activityBannerContainer.visibility = View.VISIBLE
binding.activityMediaName.text = activity.media?.title?.userPreferred binding.activityMediaName.text = activity.media?.title?.userPreferred
binding.activityText.text = binding.activityText.text = "${activity.user!!.name} ${activity.status} ${activity.progress ?: activity.media?.title?.userPreferred}"
"""${activity.user!!.name} ${activity.status} ${activity.progress ?: ""}"""
binding.activityCover.loadImage(cover) binding.activityCover.loadImage(cover)
blurImage(binding.activityBannerImage, banner ?: cover) blurImage(binding.activityBannerImage, banner ?: cover)
binding.activityAvatarContainer.setOnClickListener { binding.activityAvatarContainer.setOnClickListener {

View file

@ -102,6 +102,8 @@
android:id="@+id/followSwipeRefresh" android:id="@+id/followSwipeRefresh"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginEnd="12dp"
android:clipChildren="false" android:clipChildren="false"
android:clipToPadding="false"> android:clipToPadding="false">
@ -109,9 +111,8 @@
android:id="@+id/listRecyclerView" android:id="@+id/listRecyclerView"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:nestedScrollingEnabled="true" android:nestedScrollingEnabled="true"
tools:listitem="@layout/item_follower"
android:requiresFadingEdge="vertical" /> android:requiresFadingEdge="vertical" />
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout> </androidx.swiperefreshlayout.widget.SwipeRefreshLayout>

View file

@ -130,6 +130,142 @@
</FrameLayout> </FrameLayout>
</com.google.android.material.appbar.CollapsingToolbarLayout> </com.google.android.material.appbar.CollapsingToolbarLayout>
<LinearLayout
android:id="@+id/profileButtonContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="6dp"
android:layout_marginBottom="6dp"
android:background="?attr/colorSurface"
android:baselineAligned="false"
android:orientation="horizontal"
tools:ignore="HardcodedText">
<View
android:layout_width="3dp"
android:layout_height="match_parent"
android:layout_marginStart="2dp"
android:background="?android:attr/listDivider" />
<LinearLayout
android:id="@+id/profileFollowerCountContainer"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<TextView
android:id="@+id/profileFollowerCount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/poppins_semi_bold"
tools:text="1"
android:textColor="?attr/colorPrimary" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/poppins_semi_bold"
android:text="Follower" />
</LinearLayout>
<View
android:layout_width="3dp"
android:layout_height="match_parent"
android:background="?android:attr/listDivider" />
<LinearLayout
android:id="@+id/profileFollowingCountContainer"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<TextView
android:id="@+id/profileFollowingCount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/poppins_semi_bold"
tools:text="2"
android:textColor="?attr/colorPrimary" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/poppins_semi_bold"
android:text="Following" />
</LinearLayout>
<View
android:layout_width="3dp"
android:layout_height="match_parent"
android:background="?android:attr/listDivider" />
<LinearLayout
android:id="@+id/profileAnimeCountContainer"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<TextView
android:id="@+id/profileAnimeCount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/poppins_semi_bold"
tools:text="3"
android:textColor="?attr/colorPrimary" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/poppins_semi_bold"
android:text="Anime" />
</LinearLayout>
<View
android:layout_width="3dp"
android:layout_height="match_parent"
android:background="?android:attr/listDivider" />
<LinearLayout
android:id="@+id/profileMangaCountContainer"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<TextView
android:id="@+id/profileMangaCount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/poppins_semi_bold"
tools:text="4"
android:textColor="?attr/colorPrimary" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/poppins_semi_bold"
android:text="Manga" />
</LinearLayout>
<View
android:layout_width="3dp"
android:layout_height="match_parent"
android:layout_marginEnd="2dp"
android:background="?android:attr/listDivider" />
</LinearLayout>
</com.google.android.material.appbar.AppBarLayout> </com.google.android.material.appbar.AppBarLayout>
<LinearLayout <LinearLayout

View file

@ -20,6 +20,8 @@
android:id="@+id/feedSwipeRefresh" android:id="@+id/feedSwipeRefresh"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginEnd="12dp"
android:clipChildren="false" android:clipChildren="false"
android:clipToPadding="false"> android:clipToPadding="false">

View file

@ -11,129 +11,6 @@
android:nestedScrollingEnabled="true" android:nestedScrollingEnabled="true"
android:orientation="vertical"> android:orientation="vertical">
<LinearLayout
android:id="@+id/userListContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipToPadding="false"
android:paddingStart="24dp"
android:paddingEnd="24dp">
<com.google.android.material.card.MaterialCardView
android:id="@+id/profileAnimeList"
android:layout_width="match_parent"
android:layout_height="72dp"
android:layout_margin="8dp"
app:boxStrokeColor="@color/text_input_layout_stroke_color"
app:cardCornerRadius="16dp"
app:layout_constrainedWidth="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/profileMangaList"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintWidth_max="256dp"
tools:visibility="visible">
<ImageView
android:id="@+id/profileAnimeListImage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
tools:ignore="ContentDescription"
tools:src="@tools:sample/backgrounds/scenic" />
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:alpha="0.6"
android:background="@color/bg_black" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:fontFamily="@font/poppins_bold"
android:text="@string/anime_list"
android:textAllCaps="true"
android:textColor="@color/bg_white"
android:textSize="16sp" />
<View
android:layout_width="64dp"
android:layout_height="2dp"
android:layout_gravity="center"
android:background="?attr/colorPrimary" />
</LinearLayout>
</com.google.android.material.card.MaterialCardView>
<com.google.android.material.card.MaterialCardView
android:id="@+id/profileMangaList"
android:layout_width="match_parent"
android:layout_height="72dp"
android:layout_margin="8dp"
android:layout_marginBottom="16dp"
app:boxStrokeColor="@color/text_input_layout_stroke_color"
app:cardCornerRadius="16dp"
app:layout_constrainedWidth="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/profileAnimeList"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintWidth_max="256dp"
tools:visibility="visible">
<ImageView
android:id="@+id/profileMangaListImage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
tools:ignore="ContentDescription"
tools:src="@tools:sample/backgrounds/scenic" />
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:alpha="0.6"
android:background="@color/bg_black" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:fontFamily="@font/poppins_bold"
android:text="@string/manga_list"
android:textAllCaps="true"
android:textColor="@color/bg_white"
android:textSize="16sp" />
<View
android:layout_width="64dp"
android:layout_height="2dp"
android:layout_gravity="center"
android:background="?attr/colorPrimary" />
</LinearLayout>
</com.google.android.material.card.MaterialCardView>
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>
<LinearLayout <LinearLayout
android:id="@+id/userStatsContainer" android:id="@+id/userStatsContainer"
@ -206,27 +83,6 @@
android:textAlignment="textEnd" /> android:textAlignment="textEnd" />
</TableRow> </TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="24dp"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:alpha="0.58"
android:text="@string/total_anime"
android:textStyle="bold" />
<TextView
android:id="@+id/statsTotalAnime"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:fontFamily="@font/poppins_bold"
android:textAlignment="textEnd" />
</TableRow>
<TableRow <TableRow
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="24dp" android:layout_height="24dp"
@ -290,26 +146,6 @@
android:textAlignment="textEnd" /> android:textAlignment="textEnd" />
</TableRow> </TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="24dp"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:alpha="0.58"
android:text="@string/total_manga"
android:textStyle="bold" />
<TextView
android:id="@+id/statsTotalManga"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:fontFamily="@font/poppins_bold"
android:textAlignment="textEnd" />
</TableRow>
<TableRow <TableRow
android:layout_width="match_parent" android:layout_width="match_parent"

View file

@ -99,6 +99,7 @@
android:fontFamily="@font/poppins_semi_bold" android:fontFamily="@font/poppins_semi_bold"
android:text="@string/lorem_ipsum" android:text="@string/lorem_ipsum"
android:textAlignment="center" android:textAlignment="center"
tools:visibility="gone"
android:background="?android:colorBackground" android:background="?android:colorBackground"
android:textSize="12sp" /> android:textSize="12sp" />