Skip to content

Commit

Permalink
feat: activity ui tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
aayush2622 committed May 6, 2024
1 parent b187cf0 commit abcf9fc
Show file tree
Hide file tree
Showing 10 changed files with 120 additions and 77 deletions.
15 changes: 2 additions & 13 deletions app/src/main/java/ani/dantotsu/connections/anilist/api/Feed.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,6 @@ data class FeedResponse(
) : java.io.Serializable
}
@Serializable
data class Social(
@SerialName("data")
val data: Data
) : java.io.Serializable {
@Serializable
data class Data(
@SerialName("Page1") val page1: ActivityPage,
@SerialName("Page2") val page2: ActivityPage
) : java.io.Serializable
}
@Serializable
data class ActivityPage(
@SerialName("activities")
val activities: List<Activity>
Expand Down Expand Up @@ -94,9 +83,9 @@ data class ActivityReply(
@SerialName("text")
val text: String,
@SerialName("likeCount")
val likeCount: Int,
var likeCount: Int,
@SerialName("isLiked")
val isLiked: Boolean,
var isLiked: Boolean,
@SerialName("createdAt")
val createdAt: Int,
@SerialName("user")
Expand Down
7 changes: 2 additions & 5 deletions app/src/main/java/ani/dantotsu/home/status/Stories.kt
Original file line number Diff line number Diff line change
Expand Up @@ -445,17 +445,14 @@ class Stories @JvmOverloads constructor(
story.likes?.forEach { i ->
userList.add(User(i.id, i.name.toString(), i.avatar?.medium, i.bannerImage))
}


val likeColor = ContextCompat.getColor(context, R.color.yt_red)
val notLikeColor = ContextCompat.getColor(context, R.color.bg_opp)
binding.activityLikeCount.text = story.likeCount.toString()
binding.activityLike.setColorFilter(if (story.isLiked == true) likeColor else notLikeColor)
binding.statusUserActions.setOnClickListener {
binding.activityLikeContainer.setOnClickListener {
like()
}

binding.statusUserActions.setOnLongClickListener {
binding.activityLikeContainer.setOnLongClickListener {
val context = activity
UsersDialogFragment().apply {
userList(userList)
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/ani/dantotsu/profile/FollowActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,10 @@ class FollowActivity : AppCompatActivity() {

private fun fillList() {
adapter.clear()
val screenWidth = resources.displayMetrics.run { widthPixels / density }
binding.listRecyclerView.layoutManager = when (getLayoutType(selected)) {
0 -> LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false)
1 -> GridLayoutManager(this, 3, GridLayoutManager.VERTICAL, false)
1 -> GridLayoutManager(this, (screenWidth / 120f).toInt(), GridLayoutManager.VERTICAL, false)
else -> LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false)
}
users?.forEach { user ->
Expand Down
28 changes: 13 additions & 15 deletions app/src/main/java/ani/dantotsu/profile/activity/ActivityItem.kt
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class ActivityItem(
when (binding.activityReplies.visibility) {
View.GONE -> {
val replyItems = activity.replies?.map {
ActivityReplyItem(it) { id, type ->
ActivityReplyItem(it,fragActivity) { id, type ->
clickCallback(
id,
type
Expand All @@ -77,8 +77,19 @@ class ActivityItem(
}
}
}
val userList = arrayListOf<User>()
activity.likes?.forEach { i ->
userList.add(User(i.id, i.name.toString(), i.avatar?.medium, i.bannerImage))
}
binding.activityLikeContainer.setOnLongClickListener {
UsersDialogFragment().apply {
userList(userList)
show(fragActivity.supportFragmentManager, "dialog")
}
true
}
binding.activityLikeCount.text = (activity.likeCount ?: 0).toString()
binding.activityLike.setOnClickListener {
binding.activityLikeContainer.setOnClickListener {
val scope = CoroutineScope(Dispatchers.IO + SupervisorJob())
scope.launch {
val res = Anilist.query.toggleLike(activity.id, "ACTIVITY")
Expand All @@ -101,19 +112,6 @@ class ActivityItem(
}
}
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) {
"ListActivity" -> {
val cover = activity.media?.coverImage?.large
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,28 @@ package ani.dantotsu.profile.activity

import android.view.View
import androidx.core.content.ContextCompat
import androidx.fragment.app.FragmentActivity
import ani.dantotsu.R
import ani.dantotsu.buildMarkwon
import ani.dantotsu.connections.anilist.Anilist
import ani.dantotsu.connections.anilist.api.ActivityReply
import ani.dantotsu.databinding.ItemActivityReplyBinding
import ani.dantotsu.loadImage
import ani.dantotsu.profile.User
import ani.dantotsu.profile.UsersDialogFragment
import ani.dantotsu.snackString
import ani.dantotsu.util.AniMarkdown.Companion.getBasicAniHTML
import com.xwray.groupie.viewbinding.BindableItem
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext

class ActivityReplyItem(
private val reply: ActivityReply,
private val clickCallback: (Int, type: String) -> Unit
private val fragActivity: FragmentActivity,
private val clickCallback: (Int, type: String) -> Unit,
) : BindableItem<ItemActivityReplyBinding>() {
private lateinit var binding: ItemActivityReplyBinding

Expand All @@ -28,6 +39,39 @@ class ActivityReplyItem(
binding.activityLike.setColorFilter(if (reply.isLiked) likeColor else notLikeColor)
val markwon = buildMarkwon(binding.root.context)
markwon.setMarkdown(binding.activityContent, getBasicAniHTML(reply.text))
val userList = arrayListOf<User>()
reply.likes?.forEach { i ->
userList.add(User(i.id, i.name.toString(), i.avatar?.medium, i.bannerImage))
}
binding.activityLikeContainer.setOnLongClickListener {
UsersDialogFragment().apply {
userList(userList)
show(fragActivity.supportFragmentManager, "dialog")
}
true
}
binding.activityLikeContainer.setOnClickListener {
val scope = CoroutineScope(Dispatchers.IO + SupervisorJob())
scope.launch {
val res = Anilist.query.toggleLike(reply.id, "ACTIVITY_REPLY")
withContext(Dispatchers.Main) {
if (res != null) {
if (reply.isLiked) {
reply.likeCount = reply.likeCount.minus(1)
} else {
reply.likeCount = reply.likeCount.plus(1)
}
binding.activityLikeCount.text = (reply.likeCount).toString()
reply.isLiked = !reply.isLiked
binding.activityLike.setColorFilter(if (reply.isLiked) likeColor else notLikeColor)

} else {
snackString("Failed to like activity")
}
}
}
}

binding.activityAvatarContainer.setOnClickListener {
clickCallback(reply.userId, "USER")
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/fragment_status.xml
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@


<LinearLayout
android:id="@+id/statusUserActions"
android:id="@+id/activityLikeContainer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center|end"
Expand Down
46 changes: 26 additions & 20 deletions app/src/main/res/layout/item_activity.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,29 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:layout_marginTop="16dp"
android:background="?attr/colorSurface"
android:orientation="vertical">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
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_width="42dp"
android:layout_height="42dp"
android:layout_marginStart="12dp"
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_width="42dp"
android:layout_height="42dp"
android:layout_gravity="center"
app:srcCompat="@drawable/ic_round_add_circle_24"
tools:ignore="ContentDescription,ImageContrastCheck"
Expand All @@ -37,35 +37,45 @@
<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">
android:orientation="horizontal">


<TextView
android:id="@+id/activityUserName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="4dp"
android:fontFamily="@font/poppins_semi_bold"
android:text="Username"
android:textSize="15sp"
tools:ignore="HardcodedText,RtlSymmetry" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="4dp"
android:alpha="0.6"
android:fontFamily="@font/poppins_semi_bold"
android:text=""
android:textSize="16sp"
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:text="@string/time"
android:textSize="14sp"
tools:ignore="HardcodedText" />

</LinearLayout>

<LinearLayout
android:id="@+id/activityLikeContainer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|center"
android:layout_marginEnd="12dp"
android:orientation="vertical"
tools:ignore="UseCompoundDrawables">
Expand Down Expand Up @@ -93,21 +103,18 @@
android:id="@+id/activityContent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="18dp"
android:layout_marginTop="3dp"
android:layout_marginEnd="18dp"
android:layout_marginStart="64dp"
android:background="?android:colorBackground"
android:fontFamily="@font/poppins_semi_bold"
android:text="@string/lorem_ipsum"
android:textAlignment="center"
android:textSize="12sp"
tools:visibility="gone" />
android:textSize="12sp" />

<FrameLayout
android:id="@+id/activityBannerContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp">
android:layout_marginTop="8dp"
android:visibility="gone">

<androidx.cardview.widget.CardView
android:layout_width="match_parent"
Expand Down Expand Up @@ -200,9 +207,8 @@
android:id="@+id/commentRepliesContainer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="start|center_vertical"
android:layout_marginStart="16dp"
android:layout_marginTop="4dp"
android:layout_marginTop="6dp"
android:orientation="horizontal">

<View
Expand Down
Loading

0 comments on commit abcf9fc

Please sign in to comment.