feat: activity ui tweaks
This commit is contained in:
parent
b187cf06be
commit
abcf9fcbef
10 changed files with 120 additions and 77 deletions
|
@ -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 ->
|
||||
|
|
|
@ -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
|
||||
|
@ -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")
|
||||
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
@ -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")
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue