feat: comment notifications in notification section
This commit is contained in:
parent
25b85569fe
commit
c47d1afa1a
13 changed files with 201 additions and 65 deletions
|
@ -79,6 +79,10 @@ class ActivityItemBuilder {
|
|||
NotificationType.MEDIA_DELETION -> {
|
||||
"${notification.deletedMediaTitle} has been deleted from the site"
|
||||
}
|
||||
|
||||
NotificationType.COMMENT_REPLY -> {
|
||||
notification.context ?: "You should not see this"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@ import ani.dantotsu.databinding.FragmentFeedBinding
|
|||
import ani.dantotsu.media.MediaDetailsActivity
|
||||
import ani.dantotsu.profile.ProfileActivity
|
||||
import ani.dantotsu.snackString
|
||||
import ani.dantotsu.util.Logger
|
||||
import com.xwray.groupie.GroupieAdapter
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
|
@ -80,7 +81,8 @@ class FeedFragment : Fragment() {
|
|||
binding.listRecyclerView.setOnTouchListener { _, event ->
|
||||
if (event?.action == MotionEvent.ACTION_UP) {
|
||||
if (activityList.size % AnilistQueries.ITEMS_PER_PAGE != 0 && !global) {
|
||||
snackString("No more activities")
|
||||
//snackString("No more activities") fix spam?
|
||||
Logger.log("No more activities")
|
||||
} else if (!scrollView.canScrollVertically(1) && !binding.feedRefresh.isVisible
|
||||
&& binding.listRecyclerView.adapter!!.itemCount != 0 &&
|
||||
(binding.listRecyclerView.layoutManager as LinearLayoutManager).findLastVisibleItemPosition() == (binding.listRecyclerView.adapter!!.itemCount - 1)
|
||||
|
|
|
@ -18,6 +18,7 @@ import ani.dantotsu.databinding.ActivityFollowBinding
|
|||
import ani.dantotsu.initActivity
|
||||
import ani.dantotsu.media.MediaDetailsActivity
|
||||
import ani.dantotsu.navBarHeight
|
||||
import ani.dantotsu.notifications.comment.CommentStore
|
||||
import ani.dantotsu.profile.ProfileActivity
|
||||
import ani.dantotsu.settings.saving.PrefManager
|
||||
import ani.dantotsu.settings.saving.PrefName
|
||||
|
@ -29,6 +30,7 @@ import com.xwray.groupie.GroupieAdapter
|
|||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import java.util.Locale
|
||||
|
||||
class NotificationActivity : AppCompatActivity() {
|
||||
private lateinit var binding: ActivityFollowBinding
|
||||
|
@ -73,7 +75,25 @@ class NotificationActivity : AppCompatActivity() {
|
|||
notifications.filter { it.id == activityId }
|
||||
} else {
|
||||
notifications
|
||||
}.toMutableList()
|
||||
val commentStore = PrefManager.getNullableVal<List<CommentStore>>(
|
||||
PrefName.CommentNotificationStore,
|
||||
null
|
||||
) ?: listOf()
|
||||
commentStore.forEach {
|
||||
val notification = Notification(
|
||||
"COMMENT_REPLY",
|
||||
System.currentTimeMillis().toInt(),
|
||||
commentId = it.commentId,
|
||||
notificationType = "COMMENT_REPLY",
|
||||
mediaId = it.mediaId,
|
||||
context = it.title + "\n" + it.content,
|
||||
createdAt = (it.time / 1000L).toInt(),
|
||||
)
|
||||
notificationList = notificationList + notification
|
||||
}
|
||||
notificationList = notificationList.sortedByDescending { it.createdAt }
|
||||
|
||||
adapter.update(notificationList.map { NotificationItem(it, ::onNotificationClick) })
|
||||
}
|
||||
withContext(Dispatchers.Main) {
|
||||
|
@ -81,7 +101,8 @@ class NotificationActivity : AppCompatActivity() {
|
|||
binding.listRecyclerView.setOnTouchListener { _, event ->
|
||||
if (event?.action == MotionEvent.ACTION_UP) {
|
||||
if (adapter.itemCount % AnilistQueries.ITEMS_PER_PAGE != 0) {
|
||||
snackString("No more notifications")
|
||||
//snackString("No more notifications") fix spam?
|
||||
Logger.log("No more notifications")
|
||||
} else if (!binding.listRecyclerView.canScrollVertically(1) && !binding.followRefresh.isVisible
|
||||
&& binding.listRecyclerView.adapter!!.itemCount != 0 &&
|
||||
(binding.listRecyclerView.layoutManager as LinearLayoutManager).findLastVisibleItemPosition() == (binding.listRecyclerView.adapter!!.itemCount - 1)
|
||||
|
@ -105,7 +126,6 @@ class NotificationActivity : AppCompatActivity() {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun loadPage(onFinish: () -> Unit = {}) {
|
||||
lifecycleScope.launch(Dispatchers.IO) {
|
||||
val res = Anilist.query.getNotifications(Anilist.userid ?: 0, page)
|
||||
|
@ -120,7 +140,7 @@ class NotificationActivity : AppCompatActivity() {
|
|||
}
|
||||
}
|
||||
|
||||
private fun onNotificationClick(id: Int, type: NotificationClickType) {
|
||||
private fun onNotificationClick(id: Int, optional: Int?, type: NotificationClickType) {
|
||||
when (type) {
|
||||
NotificationClickType.USER -> {
|
||||
ContextCompat.startActivity(
|
||||
|
@ -143,6 +163,16 @@ class NotificationActivity : AppCompatActivity() {
|
|||
)
|
||||
}
|
||||
|
||||
NotificationClickType.COMMENT -> {
|
||||
ContextCompat.startActivity(this, Intent(this, MediaDetailsActivity::class.java)
|
||||
.putExtra("FRAGMENT_TO_LOAD", "COMMENTS")
|
||||
.putExtra("mediaId", id)
|
||||
.putExtra("commentId", optional ?: -1),
|
||||
null
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
NotificationClickType.UNDEFINED -> {
|
||||
// Do nothing
|
||||
}
|
||||
|
@ -151,7 +181,7 @@ class NotificationActivity : AppCompatActivity() {
|
|||
|
||||
companion object {
|
||||
enum class NotificationClickType {
|
||||
USER, MEDIA, ACTIVITY, UNDEFINED
|
||||
USER, MEDIA, ACTIVITY, COMMENT, UNDEFINED
|
||||
}
|
||||
}
|
||||
}
|
|
@ -14,7 +14,7 @@ import com.xwray.groupie.viewbinding.BindableItem
|
|||
|
||||
class NotificationItem(
|
||||
private val notification: Notification,
|
||||
val clickCallback: (Int, NotificationClickType) -> Unit
|
||||
val clickCallback: (Int, Int?, NotificationClickType) -> Unit
|
||||
) : BindableItem<ItemNotificationBinding>() {
|
||||
private lateinit var binding: ItemNotificationBinding
|
||||
override fun bind(viewBinding: ItemNotificationBinding, position: Int) {
|
||||
|
@ -31,7 +31,7 @@ class NotificationItem(
|
|||
return ItemNotificationBinding.bind(view)
|
||||
}
|
||||
|
||||
private fun image(user: Boolean = false) {
|
||||
private fun image(user: Boolean = false, commentNotification: Boolean = false) {
|
||||
|
||||
val cover = if (user) notification.user?.bannerImage
|
||||
?: notification.user?.avatar?.medium else notification.media?.bannerImage
|
||||
|
@ -52,7 +52,13 @@ class NotificationItem(
|
|||
binding.notificationCover.visibility = View.GONE
|
||||
binding.notificationCoverUser.visibility = View.VISIBLE
|
||||
binding.notificationCoverUserContainer.visibility = View.VISIBLE
|
||||
binding.notificationCoverUser.loadImage(notification.user?.avatar?.large)
|
||||
if (commentNotification) {
|
||||
binding.notificationCoverUser.setImageResource(R.drawable.ic_dantotsu_round)
|
||||
binding.notificationCoverUser.scaleX = 1.4f
|
||||
binding.notificationCoverUser.scaleY = 1.4f
|
||||
} else {
|
||||
binding.notificationCoverUser.loadImage(notification.user?.avatar?.large)
|
||||
}
|
||||
binding.notificationBannerImage.layoutParams.height = userHeight
|
||||
} else {
|
||||
binding.notificationCover.visibility = View.VISIBLE
|
||||
|
@ -75,12 +81,12 @@ class NotificationItem(
|
|||
image(true)
|
||||
binding.notificationCoverUser.setOnClickListener {
|
||||
clickCallback(
|
||||
notification.user?.id ?: 0, NotificationClickType.USER
|
||||
notification.user?.id ?: 0, null, NotificationClickType.USER
|
||||
)
|
||||
}
|
||||
binding.notificationBannerImage.setOnClickListener {
|
||||
clickCallback(
|
||||
notification.activityId ?: 0, NotificationClickType.ACTIVITY
|
||||
notification.activityId ?: 0, null, NotificationClickType.ACTIVITY
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -90,12 +96,12 @@ class NotificationItem(
|
|||
image(true)
|
||||
binding.notificationCoverUser.setOnClickListener {
|
||||
clickCallback(
|
||||
notification.user?.id ?: 0, NotificationClickType.USER
|
||||
notification.user?.id ?: 0, null, NotificationClickType.USER
|
||||
)
|
||||
}
|
||||
binding.notificationBannerImage.setOnClickListener {
|
||||
clickCallback(
|
||||
notification.activityId ?: 0, NotificationClickType.ACTIVITY
|
||||
notification.activityId ?: 0, null, NotificationClickType.ACTIVITY
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -105,12 +111,12 @@ class NotificationItem(
|
|||
image(true)
|
||||
binding.notificationCoverUser.setOnClickListener {
|
||||
clickCallback(
|
||||
notification.user?.id ?: 0, NotificationClickType.USER
|
||||
notification.user?.id ?: 0, null, NotificationClickType.USER
|
||||
)
|
||||
}
|
||||
binding.notificationBannerImage.setOnClickListener {
|
||||
clickCallback(
|
||||
notification.userId ?: 0, NotificationClickType.USER
|
||||
notification.userId ?: 0, null, NotificationClickType.USER
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -120,12 +126,12 @@ class NotificationItem(
|
|||
image(true)
|
||||
binding.notificationCoverUser.setOnClickListener {
|
||||
clickCallback(
|
||||
notification.user?.id ?: 0, NotificationClickType.USER
|
||||
notification.user?.id ?: 0, null, NotificationClickType.USER
|
||||
)
|
||||
}
|
||||
binding.notificationBannerImage.setOnClickListener {
|
||||
clickCallback(
|
||||
notification.activityId ?: 0, NotificationClickType.ACTIVITY
|
||||
notification.activityId ?: 0, null, NotificationClickType.ACTIVITY
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -135,12 +141,12 @@ class NotificationItem(
|
|||
image(true)
|
||||
binding.notificationCoverUser.setOnClickListener {
|
||||
clickCallback(
|
||||
notification.user?.id ?: 0, NotificationClickType.USER
|
||||
notification.user?.id ?: 0, null, NotificationClickType.USER
|
||||
)
|
||||
}
|
||||
binding.notificationBannerImage.setOnClickListener {
|
||||
clickCallback(
|
||||
notification.user?.id ?: 0, NotificationClickType.USER
|
||||
notification.user?.id ?: 0, null, NotificationClickType.USER
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -150,12 +156,12 @@ class NotificationItem(
|
|||
image(true)
|
||||
binding.notificationCoverUser.setOnClickListener {
|
||||
clickCallback(
|
||||
notification.user?.id ?: 0, NotificationClickType.USER
|
||||
notification.user?.id ?: 0, null, NotificationClickType.USER
|
||||
)
|
||||
}
|
||||
binding.notificationBannerImage.setOnClickListener {
|
||||
clickCallback(
|
||||
notification.user?.id ?: 0, NotificationClickType.USER
|
||||
notification.user?.id ?: 0, null, NotificationClickType.USER
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -165,12 +171,12 @@ class NotificationItem(
|
|||
image(true)
|
||||
binding.notificationCoverUser.setOnClickListener {
|
||||
clickCallback(
|
||||
notification.user?.id ?: 0, NotificationClickType.USER
|
||||
notification.user?.id ?: 0, null, NotificationClickType.USER
|
||||
)
|
||||
}
|
||||
binding.notificationBannerImage.setOnClickListener {
|
||||
clickCallback(
|
||||
notification.user?.id ?: 0, NotificationClickType.USER
|
||||
notification.user?.id ?: 0, null, NotificationClickType.USER
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -180,7 +186,7 @@ class NotificationItem(
|
|||
image()
|
||||
binding.notificationBannerImage.setOnClickListener {
|
||||
clickCallback(
|
||||
notification.media?.id ?: 0, NotificationClickType.MEDIA
|
||||
notification.media?.id ?: 0, null, NotificationClickType.MEDIA
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -190,12 +196,12 @@ class NotificationItem(
|
|||
binding.notificationCover.loadImage(notification.user?.avatar?.large)
|
||||
binding.notificationCoverUser.setOnClickListener {
|
||||
clickCallback(
|
||||
notification.user?.id ?: 0, NotificationClickType.USER
|
||||
notification.user?.id ?: 0, null, NotificationClickType.USER
|
||||
)
|
||||
}
|
||||
binding.notificationBannerImage.setOnClickListener {
|
||||
clickCallback(
|
||||
notification.activityId ?: 0, NotificationClickType.ACTIVITY
|
||||
notification.activityId ?: 0, null, NotificationClickType.ACTIVITY
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -205,12 +211,12 @@ class NotificationItem(
|
|||
image(true)
|
||||
binding.notificationCoverUser.setOnClickListener {
|
||||
clickCallback(
|
||||
notification.user?.id ?: 0, NotificationClickType.USER
|
||||
notification.user?.id ?: 0, null, NotificationClickType.USER
|
||||
)
|
||||
}
|
||||
binding.notificationBannerImage.setOnClickListener {
|
||||
clickCallback(
|
||||
notification.activityId ?: 0, NotificationClickType.ACTIVITY
|
||||
notification.activityId ?: 0, null, NotificationClickType.ACTIVITY
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -220,12 +226,12 @@ class NotificationItem(
|
|||
image(true)
|
||||
binding.notificationCoverUser.setOnClickListener {
|
||||
clickCallback(
|
||||
notification.user?.id ?: 0, NotificationClickType.USER
|
||||
notification.user?.id ?: 0, null, NotificationClickType.USER
|
||||
)
|
||||
}
|
||||
binding.notificationBannerImage.setOnClickListener {
|
||||
clickCallback(
|
||||
notification.user?.id ?: 0, NotificationClickType.USER
|
||||
notification.user?.id ?: 0, null, NotificationClickType.USER
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -235,12 +241,12 @@ class NotificationItem(
|
|||
image(true)
|
||||
binding.notificationCoverUser.setOnClickListener {
|
||||
clickCallback(
|
||||
notification.user?.id ?: 0, NotificationClickType.USER
|
||||
notification.user?.id ?: 0, null, NotificationClickType.USER
|
||||
)
|
||||
}
|
||||
binding.notificationBannerImage.setOnClickListener {
|
||||
clickCallback(
|
||||
notification.user?.id ?: 0, NotificationClickType.USER
|
||||
notification.user?.id ?: 0, null, NotificationClickType.USER
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -250,12 +256,12 @@ class NotificationItem(
|
|||
image(true)
|
||||
binding.notificationCoverUser.setOnClickListener {
|
||||
clickCallback(
|
||||
notification.user?.id ?: 0, NotificationClickType.USER
|
||||
notification.user?.id ?: 0, null, NotificationClickType.USER
|
||||
)
|
||||
}
|
||||
binding.notificationBannerImage.setOnClickListener {
|
||||
clickCallback(
|
||||
notification.activityId ?: 0, NotificationClickType.ACTIVITY
|
||||
notification.activityId ?: 0, null, NotificationClickType.ACTIVITY
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -265,7 +271,7 @@ class NotificationItem(
|
|||
image()
|
||||
binding.notificationBannerImage.setOnClickListener {
|
||||
clickCallback(
|
||||
notification.media?.id ?: 0, NotificationClickType.MEDIA
|
||||
notification.media?.id ?: 0, null, NotificationClickType.MEDIA
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -275,7 +281,7 @@ class NotificationItem(
|
|||
image()
|
||||
binding.notificationBannerImage.setOnClickListener {
|
||||
clickCallback(
|
||||
notification.media?.id ?: 0, NotificationClickType.MEDIA
|
||||
notification.media?.id ?: 0, null, NotificationClickType.MEDIA
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -285,7 +291,7 @@ class NotificationItem(
|
|||
image()
|
||||
binding.notificationBannerImage.setOnClickListener {
|
||||
clickCallback(
|
||||
notification.media?.id ?: 0, NotificationClickType.MEDIA
|
||||
notification.media?.id ?: 0, null, NotificationClickType.MEDIA
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -293,6 +299,17 @@ class NotificationItem(
|
|||
NotificationType.MEDIA_DELETION -> {
|
||||
binding.notificationCover.visibility = View.GONE
|
||||
}
|
||||
|
||||
NotificationType.COMMENT_REPLY -> {
|
||||
image(user = true, commentNotification = true)
|
||||
if (notification.commentId != null && notification.mediaId != null) {
|
||||
binding.notificationBannerImage.setOnClickListener {
|
||||
clickCallback(
|
||||
notification.mediaId, notification.commentId, NotificationClickType.COMMENT
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue