feat: activity replies
This commit is contained in:
parent
a35887d4ac
commit
408737d510
6 changed files with 182 additions and 5 deletions
|
@ -1110,7 +1110,7 @@ fun logToFile(context: Context, message: String) {
|
||||||
* Builds the markwon instance with all the plugins
|
* Builds the markwon instance with all the plugins
|
||||||
* @return the markwon instance
|
* @return the markwon instance
|
||||||
*/
|
*/
|
||||||
fun buildMarkwon(activity: Activity, userInputContent: Boolean = true): Markwon {
|
fun buildMarkwon(activity: Context, userInputContent: Boolean = true): Markwon {
|
||||||
val markwon = Markwon.builder(activity)
|
val markwon = Markwon.builder(activity)
|
||||||
.usePlugin(object : AbstractMarkwonPlugin() {
|
.usePlugin(object : AbstractMarkwonPlugin() {
|
||||||
override fun configureConfiguration(builder: MarkwonConfiguration.Builder) {
|
override fun configureConfiguration(builder: MarkwonConfiguration.Builder) {
|
||||||
|
|
|
@ -70,13 +70,13 @@ data class Activity(
|
||||||
@SerialName("media")
|
@SerialName("media")
|
||||||
val media: Media?,
|
val media: Media?,
|
||||||
@SerialName("replies")
|
@SerialName("replies")
|
||||||
val replies: List<Reply>?,
|
val replies: List<ActivityReply>?,
|
||||||
@SerialName("likes")
|
@SerialName("likes")
|
||||||
val likes: List<User>?,
|
val likes: List<User>?,
|
||||||
) : java.io.Serializable
|
) : java.io.Serializable
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class Reply(
|
data class ActivityReply(
|
||||||
@SerialName("id")
|
@SerialName("id")
|
||||||
val id: Int,
|
val id: Int,
|
||||||
@SerialName("userId")
|
@SerialName("userId")
|
||||||
|
|
|
@ -4,6 +4,7 @@ import android.annotation.SuppressLint
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import ani.dantotsu.R
|
import ani.dantotsu.R
|
||||||
import ani.dantotsu.buildMarkwon
|
import ani.dantotsu.buildMarkwon
|
||||||
import ani.dantotsu.connections.anilist.Anilist
|
import ani.dantotsu.connections.anilist.Anilist
|
||||||
|
@ -16,6 +17,7 @@ import com.bumptech.glide.Glide
|
||||||
import com.bumptech.glide.load.engine.DiskCacheStrategy
|
import com.bumptech.glide.load.engine.DiskCacheStrategy
|
||||||
import com.bumptech.glide.load.model.GlideUrl
|
import com.bumptech.glide.load.model.GlideUrl
|
||||||
import com.bumptech.glide.request.RequestOptions
|
import com.bumptech.glide.request.RequestOptions
|
||||||
|
import com.xwray.groupie.GroupieAdapter
|
||||||
import com.xwray.groupie.viewbinding.BindableItem
|
import com.xwray.groupie.viewbinding.BindableItem
|
||||||
import jp.wasabeef.glide.transformations.BlurTransformation
|
import jp.wasabeef.glide.transformations.BlurTransformation
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
@ -29,11 +31,19 @@ class ActivityItem(
|
||||||
val clickCallback: (Int, type: String) -> Unit
|
val clickCallback: (Int, type: String) -> Unit
|
||||||
) : BindableItem<ItemActivityBinding>() {
|
) : BindableItem<ItemActivityBinding>() {
|
||||||
private lateinit var binding: ItemActivityBinding
|
private lateinit var binding: ItemActivityBinding
|
||||||
|
private lateinit var repliesAdapter: GroupieAdapter
|
||||||
|
|
||||||
@SuppressLint("SetTextI18n")
|
@SuppressLint("SetTextI18n")
|
||||||
override fun bind(viewBinding: ItemActivityBinding, position: Int) {
|
override fun bind(viewBinding: ItemActivityBinding, position: Int) {
|
||||||
binding = viewBinding
|
binding = viewBinding
|
||||||
|
|
||||||
|
repliesAdapter = GroupieAdapter()
|
||||||
|
binding.activityReplies.adapter = repliesAdapter
|
||||||
|
binding.activityReplies.layoutManager = LinearLayoutManager(
|
||||||
|
binding.root.context,
|
||||||
|
LinearLayoutManager.VERTICAL,
|
||||||
|
false
|
||||||
|
)
|
||||||
binding.activityUserName.text = activity.user?.name ?: activity.messenger?.name
|
binding.activityUserName.text = activity.user?.name ?: activity.messenger?.name
|
||||||
binding.activityUserAvatar.loadImage(activity.user?.avatar?.medium ?: activity.messenger?.avatar?.medium)
|
binding.activityUserAvatar.loadImage(activity.user?.avatar?.medium ?: activity.messenger?.avatar?.medium)
|
||||||
binding.activityTime.text = ActivityItemBuilder.getDateTime(activity.createdAt)
|
binding.activityTime.text = ActivityItemBuilder.getDateTime(activity.createdAt)
|
||||||
|
@ -42,8 +52,24 @@ class ActivityItem(
|
||||||
binding.activityLike.setColorFilter(if (activity.isLiked == true) likeColor else notLikeColor)
|
binding.activityLike.setColorFilter(if (activity.isLiked == true) likeColor else notLikeColor)
|
||||||
binding.commentRepliesContainer.visibility =
|
binding.commentRepliesContainer.visibility =
|
||||||
if (activity.replyCount > 0) View.VISIBLE else View.GONE
|
if (activity.replyCount > 0) View.VISIBLE else View.GONE
|
||||||
binding.activityLikeCount.text = (activity.likeCount?:0).toString()
|
binding.commentRepliesContainer.setOnClickListener {
|
||||||
|
when (binding.activityReplies.visibility) {
|
||||||
|
View.GONE -> {
|
||||||
|
repliesAdapter.addAll(
|
||||||
|
activity.replies?.map { ActivityReplyItem(it) } ?: emptyList()
|
||||||
|
)
|
||||||
|
binding.activityReplies.visibility = View.VISIBLE
|
||||||
|
binding.commentTotalReplies.text = "Hide replies"
|
||||||
|
}
|
||||||
|
else -> {
|
||||||
|
repliesAdapter.clear()
|
||||||
|
binding.activityReplies.visibility = View.GONE
|
||||||
|
binding.commentTotalReplies.text = "View replies"
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
binding.activityLikeCount.text = (activity.likeCount?:0).toString()
|
||||||
binding.activityLike.setOnClickListener {
|
binding.activityLike.setOnClickListener {
|
||||||
val scope = CoroutineScope(Dispatchers.IO + SupervisorJob())
|
val scope = CoroutineScope(Dispatchers.IO + SupervisorJob())
|
||||||
scope.launch {
|
scope.launch {
|
||||||
|
@ -106,7 +132,7 @@ class ActivityItem(
|
||||||
binding.activityContent.visibility = View.VISIBLE
|
binding.activityContent.visibility = View.VISIBLE
|
||||||
if (!(context as android.app.Activity).isDestroyed) {
|
if (!(context as android.app.Activity).isDestroyed) {
|
||||||
val markwon = buildMarkwon(context, false)
|
val markwon = buildMarkwon(context, false)
|
||||||
markwon.setMarkdown(binding.activityContent, activity.message ?: "")
|
markwon.setMarkdown(binding.activityContent, getBasicAniHTML(activity.message ?: ""))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,40 @@
|
||||||
|
package ani.dantotsu.profile.activity
|
||||||
|
|
||||||
|
import android.view.View
|
||||||
|
import androidx.core.content.ContextCompat
|
||||||
|
import ani.dantotsu.R
|
||||||
|
import ani.dantotsu.buildMarkwon
|
||||||
|
import ani.dantotsu.connections.anilist.api.ActivityReply
|
||||||
|
import ani.dantotsu.databinding.ItemActivityReplyBinding
|
||||||
|
import ani.dantotsu.loadImage
|
||||||
|
import ani.dantotsu.util.AniMarkdown.Companion.getBasicAniHTML
|
||||||
|
import com.xwray.groupie.viewbinding.BindableItem
|
||||||
|
|
||||||
|
class ActivityReplyItem(
|
||||||
|
private val reply: ActivityReply
|
||||||
|
) : BindableItem<ItemActivityReplyBinding>() {
|
||||||
|
private lateinit var binding: ItemActivityReplyBinding
|
||||||
|
|
||||||
|
override fun bind(viewBinding: ItemActivityReplyBinding, position: Int) {
|
||||||
|
binding = viewBinding
|
||||||
|
|
||||||
|
binding.activityUserAvatar.loadImage(reply.user.avatar?.medium)
|
||||||
|
binding.activityUserName.text = reply.user.name
|
||||||
|
binding.activityTime.text = ActivityItemBuilder.getDateTime(reply.createdAt)
|
||||||
|
binding.activityLikeCount.text = reply.likeCount.toString()
|
||||||
|
val likeColor = ContextCompat.getColor(binding.root.context, R.color.yt_red)
|
||||||
|
val notLikeColor = ContextCompat.getColor(binding.root.context, R.color.bg_opp)
|
||||||
|
binding.activityLike.setColorFilter(if (reply.isLiked) likeColor else notLikeColor)
|
||||||
|
val markwon = buildMarkwon(binding.root.context)
|
||||||
|
markwon.setMarkdown(binding.activityContent, getBasicAniHTML(reply.text))
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getLayout(): Int {
|
||||||
|
return R.layout.item_activity_reply
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun initializeViewBinding(view: View): ItemActivityReplyBinding {
|
||||||
|
return ItemActivityReplyBinding.bind(view)
|
||||||
|
}
|
||||||
|
}
|
|
@ -214,4 +214,11 @@
|
||||||
tools:ignore="HardcodedText" />
|
tools:ignore="HardcodedText" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
|
android:id="@+id/activityReplies"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:visibility="gone"
|
||||||
|
android:layout_marginStart="16dp"/>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
104
app/src/main/res/layout/item_activity_reply.xml
Normal file
104
app/src/main/res/layout/item_activity_reply.xml
Normal file
|
@ -0,0 +1,104 @@
|
||||||
|
<?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:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="16dp"
|
||||||
|
android:layout_marginStart="8dp"
|
||||||
|
android:background="?attr/colorSurface"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<com.google.android.material.card.MaterialCardView
|
||||||
|
android:id="@+id/activityAvatarContainer"
|
||||||
|
android:layout_width="64dp"
|
||||||
|
android:layout_height="64dp"
|
||||||
|
android:layout_gravity="start|center_vertical"
|
||||||
|
android:layout_marginStart="16dp"
|
||||||
|
android:backgroundTint="@color/transparent"
|
||||||
|
app:cardCornerRadius="64dp"
|
||||||
|
app:strokeColor="@color/transparent">
|
||||||
|
|
||||||
|
<com.google.android.material.imageview.ShapeableImageView
|
||||||
|
android:id="@+id/activityUserAvatar"
|
||||||
|
android:layout_width="64dp"
|
||||||
|
android:layout_height="64dp"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
app:srcCompat="@drawable/ic_round_add_circle_24"
|
||||||
|
tools:ignore="ContentDescription,ImageContrastCheck"
|
||||||
|
tools:tint="@color/transparent" />
|
||||||
|
|
||||||
|
</com.google.android.material.card.MaterialCardView>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center_vertical"
|
||||||
|
android:layout_marginStart="8dp"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/activityUserName"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:fontFamily="@font/poppins_semi_bold"
|
||||||
|
android:text="Username"
|
||||||
|
android:textSize="15sp"
|
||||||
|
tools:ignore="HardcodedText,RtlSymmetry" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/activityTime"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:fontFamily="@font/poppins_semi_bold"
|
||||||
|
android:text="Wed,06 March 2024, 7:00PM"
|
||||||
|
android:textSize="14sp"
|
||||||
|
tools:ignore="HardcodedText" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="end|center"
|
||||||
|
android:layout_marginEnd="16dp"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/activityLike"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:src="@drawable/ic_round_favorite_24"
|
||||||
|
tools:ignore="ContentDescription" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/activityLikeCount"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:fontFamily="@font/poppins_semi_bold"
|
||||||
|
android:textSize="15sp"
|
||||||
|
tools:text="12" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/activityContent"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="16dp"
|
||||||
|
android:layout_marginTop="8dp"
|
||||||
|
android:layout_marginEnd="16dp"
|
||||||
|
android:fontFamily="@font/poppins_semi_bold"
|
||||||
|
android:text="@string/lorem_ipsum"
|
||||||
|
android:textAlignment="center"
|
||||||
|
android:textSize="14sp" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
Loading…
Add table
Add a link
Reference in a new issue