feat: long tap like button to see users

This commit is contained in:
aayush262 2024-03-15 18:32:51 +05:30
parent c5abfa15e0
commit 5dbc01dba3
11 changed files with 186 additions and 41 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,type:TEXT," else if (global) "isFollowing:false,hasReplies: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

@ -1,18 +1,12 @@
package ani.dantotsu.profile package ani.dantotsu.profile
import android.app.Activity
import android.content.Context
import android.view.View import android.view.View
import ani.dantotsu.R import ani.dantotsu.R
import ani.dantotsu.blurImage import ani.dantotsu.blurImage
import ani.dantotsu.databinding.ItemFollowerBinding import ani.dantotsu.databinding.ItemFollowerBinding
import ani.dantotsu.loadImage import ani.dantotsu.loadImage
import com.bumptech.glide.Glide
import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.bumptech.glide.load.model.GlideUrl
import com.bumptech.glide.request.RequestOptions
import com.xwray.groupie.viewbinding.BindableItem import com.xwray.groupie.viewbinding.BindableItem
import jp.wasabeef.glide.transformations.BlurTransformation
class FollowerItem( class FollowerItem(
private val id: Int, private val id: Int,

View file

@ -43,7 +43,7 @@ import kotlin.math.abs
class ProfileActivity : AppCompatActivity(), AppBarLayout.OnOffsetChangedListener { class ProfileActivity : AppCompatActivity(), AppBarLayout.OnOffsetChangedListener {
lateinit var binding: ActivityProfileBinding lateinit var binding: ActivityProfileBinding
private var selected: Int = 1 private var selected: Int = 0
private lateinit var navBar: AnimatedBottomBar private lateinit var navBar: AnimatedBottomBar
@SuppressLint("SetTextI18n") @SuppressLint("SetTextI18n")
@ -59,8 +59,8 @@ class ProfileActivity : AppCompatActivity(), AppBarLayout.OnOffsetChangedListene
val feedTab = navBar.createTab(R.drawable.ic_round_filter_24, "Feed") val feedTab = navBar.createTab(R.drawable.ic_round_filter_24, "Feed")
val profileTab = navBar.createTab(R.drawable.ic_round_person_24, "Profile") val profileTab = navBar.createTab(R.drawable.ic_round_person_24, "Profile")
val statsTab = navBar.createTab(R.drawable.ic_stats_24, "Stats") val statsTab = navBar.createTab(R.drawable.ic_stats_24, "Stats")
navBar.addTab(feedTab)
navBar.addTab(profileTab) navBar.addTab(profileTab)
navBar.addTab(feedTab)
navBar.addTab(statsTab) navBar.addTab(statsTab)
navBar.visibility = View.GONE navBar.visibility = View.GONE
binding.profileViewPager.isUserInputEnabled = false binding.profileViewPager.isUserInputEnabled = false
@ -117,7 +117,7 @@ class ProfileActivity : AppCompatActivity(), AppBarLayout.OnOffsetChangedListene
} }
} }
binding.profileProgressBar.visibility = View.GONE binding.profileProgressBar.visibility = View.GONE
binding.profileTopContainer.visibility = View.VISIBLE binding.profileAppBar.visibility = View.VISIBLE
binding.profileMenuButton.setOnClickListener { binding.profileMenuButton.setOnClickListener {
val popup = PopupMenu(this@ProfileActivity, binding.profileMenuButton) val popup = PopupMenu(this@ProfileActivity, binding.profileMenuButton)
popup.menuInflater.inflate(R.menu.menu_profile, popup.menu) popup.menuInflater.inflate(R.menu.menu_profile, popup.menu)
@ -240,8 +240,8 @@ class ProfileActivity : AppCompatActivity(), AppBarLayout.OnOffsetChangedListene
override fun getItemCount(): Int = 3 override fun getItemCount(): Int = 3
override fun createFragment(position: Int): Fragment = when (position) { override fun createFragment(position: Int): Fragment = when (position) {
0 -> FeedFragment.newInstance(user.id, false, -1) 0 -> ProfileFragment.newInstance(user)
1 -> ProfileFragment.newInstance(user) 1 -> FeedFragment.newInstance(user.id, false, -1)
2 -> StatsFragment.newInstance(user) 2 -> StatsFragment.newInstance(user)
else -> ProfileFragment.newInstance(user) else -> ProfileFragment.newInstance(user)
} }

View file

@ -0,0 +1,8 @@
package ani.dantotsu.profile
data class User(
val id: Int,
val name: String,
val pfp: String?,
val banner: String?,
)

View file

@ -0,0 +1,41 @@
package ani.dantotsu.profile
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.LinearLayoutManager
import ani.dantotsu.BottomSheetDialogFragment
import ani.dantotsu.databinding.BottomSheetUsersBinding
import ani.dantotsu.profile.activity.UsersAdapter
import ani.dantotsu.settings.DevelopersAdapter
class UsersDialogFragment : BottomSheetDialogFragment() {
private var _binding: BottomSheetUsersBinding? = null
private val binding get() = _binding!!
private var userList = arrayListOf<User>()
fun userList(user: ArrayList<User>){
userList = user
}
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
_binding = BottomSheetUsersBinding.inflate(inflater, container, false)
return binding.root
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding.usersRecyclerView.adapter = UsersAdapter(userList)
binding.usersRecyclerView.layoutManager = LinearLayoutManager(requireContext())
}
override fun onDestroy() {
_binding = null
super.onDestroy()
}
}

View file

@ -1,9 +1,9 @@
package ani.dantotsu.profile.activity package ani.dantotsu.profile.activity
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.content.Context
import android.view.View import android.view.View
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import androidx.fragment.app.FragmentActivity
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import ani.dantotsu.R import ani.dantotsu.R
import ani.dantotsu.blurImage import ani.dantotsu.blurImage
@ -12,6 +12,8 @@ import ani.dantotsu.connections.anilist.Anilist
import ani.dantotsu.connections.anilist.api.Activity import ani.dantotsu.connections.anilist.api.Activity
import ani.dantotsu.databinding.ItemActivityBinding import ani.dantotsu.databinding.ItemActivityBinding
import ani.dantotsu.loadImage import ani.dantotsu.loadImage
import ani.dantotsu.profile.User
import ani.dantotsu.profile.UsersDialogFragment
import ani.dantotsu.snackString import ani.dantotsu.snackString
import ani.dantotsu.util.AniMarkdown.Companion.getBasicAniHTML import ani.dantotsu.util.AniMarkdown.Companion.getBasicAniHTML
import com.bumptech.glide.Glide import com.bumptech.glide.Glide
@ -29,7 +31,8 @@ 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
) : BindableItem<ItemActivityBinding>() { ) : BindableItem<ItemActivityBinding>() {
private lateinit var binding: ItemActivityBinding private lateinit var binding: ItemActivityBinding
private lateinit var repliesAdapter: GroupieAdapter private lateinit var repliesAdapter: GroupieAdapter
@ -102,8 +105,18 @@ class ActivityItem(
} }
} }
} }
val context = binding.root.context val context = binding.root.context
val userList = arrayListOf<User>()
activity.likes?.forEach{ i ->
userList.add(User(i.id, i.name.toString(), i.avatar?.medium, i.bannerImage))
}
binding.activityLike.setOnLongClickListener{
UsersDialogFragment().apply { userList(userList)
show(FragActivity.supportFragmentManager, "dialog")
}
true
}
when (activity.typename) { when (activity.typename) {
"ListActivity" -> { "ListActivity" -> {

View file

@ -72,7 +72,7 @@ class FeedFragment : Fragment() {
val filtered = activityList.filterNot { //filter out messages that are not directed to the user val filtered = activityList.filterNot { //filter out messages that are not directed to the user
it.recipient?.id != null && it.recipient.id != Anilist.userid it.recipient?.id != null && it.recipient.id != Anilist.userid
} }
adapter.update(filtered.map { ActivityItem(it, ::onActivityClick) }) adapter.update(filtered.map { ActivityItem(it, ::onActivityClick,requireActivity()) })
} }
binding.listProgressBar.visibility = ViewGroup.GONE binding.listProgressBar.visibility = ViewGroup.GONE
val scrollView = binding.listRecyclerView val scrollView = binding.listRecyclerView
@ -95,7 +95,7 @@ class FeedFragment : Fragment() {
val filtered = activities.filterNot { val filtered = activities.filterNot {
it.recipient?.id != null && it.recipient.id != Anilist.userid it.recipient?.id != null && it.recipient.id != Anilist.userid
} }
adapter.addAll(filtered.map { ActivityItem(it, ::onActivityClick) }) adapter.addAll(filtered.map { ActivityItem(it, ::onActivityClick,requireActivity()) })
} }
binding.feedRefresh.visibility = ViewGroup.GONE binding.feedRefresh.visibility = ViewGroup.GONE
} }

View file

@ -0,0 +1,49 @@
package ani.dantotsu.profile.activity
import android.content.Intent
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.RecyclerView
import ani.dantotsu.databinding.ItemFollowerBinding
import ani.dantotsu.loadImage
import ani.dantotsu.profile.ProfileActivity
import ani.dantotsu.profile.User
import ani.dantotsu.setAnimation
class UsersAdapter(private val user: ArrayList<User>) : RecyclerView.Adapter<UsersAdapter.UsersViewHolder>() {
inner class UsersViewHolder(val binding: ItemFollowerBinding) :
RecyclerView.ViewHolder(binding.root) {
init {
itemView.setOnClickListener {
ContextCompat.startActivity(
binding.root.context, Intent(binding.root.context, ProfileActivity::class.java)
.putExtra("userId", user[bindingAdapterPosition].id), null
)
}
}
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): UsersViewHolder {
return UsersViewHolder(
ItemFollowerBinding.inflate(
LayoutInflater.from(parent.context),
parent,
false
)
)
}
override fun onBindViewHolder(holder: UsersViewHolder, position: Int) {
val b = holder.binding
setAnimation(b.root.context, b.root)
val user = user[position]
b.profileUserAvatar.loadImage(user.pfp)
b.profileBannerImage.loadImage(user.banner)
b.profileUserName.text = user.name
}
override fun getItemCount(): Int = user.size
}

View file

@ -23,9 +23,12 @@
android:id="@+id/profileAppBar" android:id="@+id/profileAppBar"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:translationZ="5dp"> android:translationZ="5dp"
android:visibility="gone"
tools:visibility="visible">
<com.google.android.material.appbar.CollapsingToolbarLayout <com.google.android.material.appbar.CollapsingToolbarLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:fitsSystemWindows="false" android:fitsSystemWindows="false"
@ -33,12 +36,8 @@
app:layout_scrollFlags="scroll|exitUntilCollapsed|snap"> app:layout_scrollFlags="scroll|exitUntilCollapsed|snap">
<FrameLayout <FrameLayout
android:id="@+id/profileTopContainer"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content">
android:orientation="vertical"
android:visibility="gone"
tools:visibility="visible">
<com.flaviofaria.kenburnsview.KenBurnsView <com.flaviofaria.kenburnsview.KenBurnsView
android:id="@+id/profileBannerImage" android:id="@+id/profileBannerImage"
@ -69,8 +68,8 @@
android:layout_height="82dp" android:layout_height="82dp"
android:layout_gravity="center" android:layout_gravity="center"
android:backgroundTint="@color/transparent" android:backgroundTint="@color/transparent"
app:strokeColor="@color/transparent" app:cardCornerRadius="64dp"
app:cardCornerRadius="64dp"> app:strokeColor="@color/transparent">
<com.google.android.material.imageview.ShapeableImageView <com.google.android.material.imageview.ShapeableImageView
android:id="@+id/profileUserAvatar" android:id="@+id/profileUserAvatar"
@ -131,22 +130,21 @@
</FrameLayout> </FrameLayout>
</com.google.android.material.appbar.CollapsingToolbarLayout> </com.google.android.material.appbar.CollapsingToolbarLayout>
</com.google.android.material.appbar.AppBarLayout> </com.google.android.material.appbar.AppBarLayout>
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical"
android:layout_marginBottom="72dp" android:layout_marginBottom="72dp"
android:orientation="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior"> app:layout_behavior="@string/appbar_scrolling_view_behavior">
<androidx.viewpager2.widget.ViewPager2 <androidx.viewpager2.widget.ViewPager2
android:id="@+id/profileViewPager" android:id="@+id/profileViewPager"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:nestedScrollingEnabled="true" android:nestedScrollingEnabled="true"
tools:ignore="SpeakableTextPresentCheck" /> tools:ignore="SpeakableTextPresentCheck" />
</LinearLayout> </LinearLayout>

View file

@ -0,0 +1,40 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:background="@drawable/bottom_sheet_background"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<androidx.cardview.widget.CardView
android:layout_width="32dp"
android:layout_height="4dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="14dp"
app:cardBackgroundColor="?attr/colorPrimary"
app:cardCornerRadius="2dp"
app:cardElevation="0dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="48dp"
android:fontFamily="@font/poppins"
android:gravity="bottom|center_horizontal"
android:text="Liked By"
android:textSize="20sp"
android:textStyle="bold" />
<ani.dantotsu.FadingEdgeRecyclerView
android:id="@+id/usersRecyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipToPadding="false"
android:padding="16dp"
android:requiresFadingEdge="vertical"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:itemCount="10"
tools:listitem="@layout/item_follower"
tools:orientation="vertical" />
</LinearLayout>

View file

@ -18,7 +18,7 @@
android:layout_width="64dp" android:layout_width="64dp"
android:layout_height="64dp" android:layout_height="64dp"
android:layout_gravity="start|center_vertical" android:layout_gravity="start|center_vertical"
android:layout_marginStart="16dp" android:layout_marginStart="12dp"
android:backgroundTint="@color/transparent" android:backgroundTint="@color/transparent"
app:cardCornerRadius="64dp" app:cardCornerRadius="64dp"
app:strokeColor="@color/transparent"> app:strokeColor="@color/transparent">
@ -66,8 +66,9 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="end|center" android:layout_gravity="end|center"
android:layout_marginEnd="16dp" android:layout_marginEnd="12dp"
android:orientation="vertical"> android:orientation="vertical"
tools:ignore="UseCompoundDrawables">
<ImageView <ImageView
android:id="@+id/activityLike" android:id="@+id/activityLike"
@ -92,13 +93,14 @@
android:id="@+id/activityContent" android:id="@+id/activityContent"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="16dp" android:layout_marginStart="18dp"
android:layout_marginTop="8dp" android:layout_marginEnd="18dp"
android:layout_marginEnd="16dp" android:layout_marginTop="3dp"
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"
android:textSize="14sp" /> android:background="?android:colorBackground"
android:textSize="12sp" />
<FrameLayout <FrameLayout
android:id="@+id/activityBannerContainer" android:id="@+id/activityBannerContainer"