Skip to content

Commit

Permalink
feat: activity replies
Browse files Browse the repository at this point in the history
  • Loading branch information
rebelonion committed Mar 11, 2024
1 parent a35887d commit 408737d
Show file tree
Hide file tree
Showing 6 changed files with 182 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/src/main/java/ani/dantotsu/Functions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1110,7 +1110,7 @@ fun logToFile(context: Context, message: String) {
* Builds the markwon instance with all the plugins
* @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)
.usePlugin(object : AbstractMarkwonPlugin() {
override fun configureConfiguration(builder: MarkwonConfiguration.Builder) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ data class Activity(
@SerialName("media")
val media: Media?,
@SerialName("replies")
val replies: List<Reply>?,
val replies: List<ActivityReply>?,
@SerialName("likes")
val likes: List<User>?,
) : java.io.Serializable

@Serializable
data class Reply(
data class ActivityReply(
@SerialName("id")
val id: Int,
@SerialName("userId")
Expand Down
30 changes: 28 additions & 2 deletions app/src/main/java/ani/dantotsu/profile/activity/ActivityItem.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.annotation.SuppressLint
import android.content.Context
import android.view.View
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.LinearLayoutManager
import ani.dantotsu.R
import ani.dantotsu.buildMarkwon
import ani.dantotsu.connections.anilist.Anilist
Expand All @@ -16,6 +17,7 @@ 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.GroupieAdapter
import com.xwray.groupie.viewbinding.BindableItem
import jp.wasabeef.glide.transformations.BlurTransformation
import kotlinx.coroutines.CoroutineScope
Expand All @@ -29,11 +31,19 @@ class ActivityItem(
val clickCallback: (Int, type: String) -> Unit
) : BindableItem<ItemActivityBinding>() {
private lateinit var binding: ItemActivityBinding
private lateinit var repliesAdapter: GroupieAdapter

@SuppressLint("SetTextI18n")
override fun bind(viewBinding: ItemActivityBinding, position: Int) {
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.activityUserAvatar.loadImage(activity.user?.avatar?.medium ?: activity.messenger?.avatar?.medium)
binding.activityTime.text = ActivityItemBuilder.getDateTime(activity.createdAt)
Expand All @@ -42,8 +52,24 @@ class ActivityItem(
binding.activityLike.setColorFilter(if (activity.isLiked == true) likeColor else notLikeColor)
binding.commentRepliesContainer.visibility =
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 {
val scope = CoroutineScope(Dispatchers.IO + SupervisorJob())
scope.launch {
Expand Down Expand Up @@ -106,7 +132,7 @@ class ActivityItem(
binding.activityContent.visibility = View.VISIBLE
if (!(context as android.app.Activity).isDestroyed) {
val markwon = buildMarkwon(context, false)
markwon.setMarkdown(binding.activityContent, activity.message ?: "")
markwon.setMarkdown(binding.activityContent, getBasicAniHTML(activity.message ?: ""))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
}
}
7 changes: 7 additions & 0 deletions app/src/main/res/layout/item_activity.xml
Original file line number Diff line number Diff line change
Expand Up @@ -214,4 +214,11 @@
tools:ignore="HardcodedText" />
</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>
104 changes: 104 additions & 0 deletions app/src/main/res/layout/item_activity_reply.xml
Original file line number Diff line number Diff line change
@@ -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>

0 comments on commit 408737d

Please sign in to comment.