diff --git a/app/src/main/java/ani/dantotsu/App.kt b/app/src/main/java/ani/dantotsu/App.kt index ecc2addd..64b9d000 100644 --- a/app/src/main/java/ani/dantotsu/App.kt +++ b/app/src/main/java/ani/dantotsu/App.kt @@ -13,7 +13,7 @@ import ani.dantotsu.aniyomi.anime.custom.AppModule import ani.dantotsu.aniyomi.anime.custom.PreferenceModule import ani.dantotsu.connections.comments.CommentsAPI import ani.dantotsu.connections.crashlytics.CrashlyticsInterface -import ani.dantotsu.notifications.CommentNotificationWorker +import ani.dantotsu.notifications.comment.CommentNotificationWorker import ani.dantotsu.notifications.anilist.AnilistNotificationWorker import ani.dantotsu.others.DisabledReports import ani.dantotsu.parsers.AnimeSources @@ -134,7 +134,8 @@ class App : MultiDexApplication() { // CommentNotificationWorker val commentInterval = CommentNotificationWorker.checkIntervals[PrefManager.getVal(PrefName.CommentNotificationInterval)] if (commentInterval.toInt() != 0) { - val recurringWork = PeriodicWorkRequest.Builder(CommentNotificationWorker::class.java, + val recurringWork = PeriodicWorkRequest.Builder( + CommentNotificationWorker::class.java, commentInterval, java.util.concurrent.TimeUnit.MINUTES) .setConstraints(constraints) .build() @@ -146,7 +147,8 @@ class App : MultiDexApplication() { } else { androidx.work.WorkManager.getInstance(this).cancelUniqueWork(CommentNotificationWorker.WORK_NAME) //run once - androidx.work.WorkManager.getInstance(this).enqueue(OneTimeWorkRequest.Companion.from(CommentNotificationWorker::class.java)) + androidx.work.WorkManager.getInstance(this).enqueue(OneTimeWorkRequest.Companion.from( + CommentNotificationWorker::class.java)) } // AnilistNotificationWorker diff --git a/app/src/main/java/ani/dantotsu/connections/anilist/AnilistQueries.kt b/app/src/main/java/ani/dantotsu/connections/anilist/AnilistQueries.kt index 68f18f39..272bf016 100644 --- a/app/src/main/java/ani/dantotsu/connections/anilist/AnilistQueries.kt +++ b/app/src/main/java/ani/dantotsu/connections/anilist/AnilistQueries.kt @@ -54,6 +54,8 @@ class AnilistQueries { Anilist.chapterRead = user.statistics?.manga?.chaptersRead Anilist.adult = user.options?.displayAdultContent ?: false Anilist.unreadNotificationCount = user.unreadNotificationCount ?: 0 + val unread = PrefManager.getVal(PrefName.UnreadCommentNotifications) + Anilist.unreadNotificationCount += unread return true } @@ -1392,7 +1394,10 @@ Page(page:$page,perPage:50) { """{User(id:$id){unreadNotificationCount}Page(page:$page,perPage:$ITEMS_PER_PAGE){notifications(resetNotificationCount:$reset){__typename...on AiringNotification{id,type,animeId,episode,contexts,createdAt,media{id,title{romaji,english,native,userPreferred}bannerImage,coverImage{medium,large}},}...on FollowingNotification{id,userId,type,context,createdAt,user{id,name,bannerImage,avatar{medium,large,}}}...on ActivityMessageNotification{id,userId,type,activityId,context,createdAt,message{id}user{id,name,bannerImage,avatar{medium,large,}}}...on ActivityMentionNotification{id,userId,type,activityId,context,createdAt,activity{__typename}user{id,name,bannerImage,avatar{medium,large,}}}...on ActivityReplyNotification{id,userId,type,activityId,context,createdAt,activity{__typename}user{id,name,bannerImage,avatar{medium,large,}}}...on ActivityReplySubscribedNotification{id,userId,type,activityId,context,createdAt,activity{__typename}user{id,name,bannerImage,avatar{medium,large,}}}...on ActivityLikeNotification{id,userId,type,activityId,context,createdAt,activity{__typename}user{id,name,bannerImage,avatar{medium,large,}}}...on ActivityReplyLikeNotification{id,userId,type,activityId,context,createdAt,activity{__typename}user{id,name,bannerImage,avatar{medium,large,}}}...on ThreadCommentMentionNotification{id,userId,type,commentId,context,createdAt,thread{id}comment{id}user{id,name,bannerImage,avatar{medium,large,}}}...on ThreadCommentReplyNotification{id,userId,type,commentId,context,createdAt,thread{id}comment{id}user{id,name,bannerImage,avatar{medium,large,}}}...on ThreadCommentSubscribedNotification{id,userId,type,commentId,context,createdAt,thread{id}comment{id}user{id,name,bannerImage,avatar{medium,large,}}}...on ThreadCommentLikeNotification{id,userId,type,commentId,context,createdAt,thread{id}comment{id}user{id,name,bannerImage,avatar{medium,large,}}}...on ThreadLikeNotification{id,userId,type,threadId,context,createdAt,thread{id}comment{id}user{id,name,bannerImage,avatar{medium,large,}}}...on RelatedMediaAdditionNotification{id,type,context,createdAt,media{id,title{romaji,english,native,userPreferred}bannerImage,coverImage{medium,large}}}...on MediaDataChangeNotification{id,type,mediaId,context,reason,createdAt,media{id,title{romaji,english,native,userPreferred}bannerImage,coverImage{medium,large}}}...on MediaMergeNotification{id,type,mediaId,deletedMediaTitles,context,reason,createdAt,media{id,title{romaji,english,native,userPreferred}bannerImage,coverImage{medium,large}}}...on MediaDeletionNotification{id,type,deletedMediaTitle,context,reason,createdAt,}}}}""", force = true ) - if (res != null) { + if (res != null && resetNotification) { + val commentNotifications = PrefManager.getVal(PrefName.UnreadCommentNotifications, 0) + res.data.user.unreadNotificationCount += commentNotifications + PrefManager.setVal(PrefName.UnreadCommentNotifications, 0) Anilist.unreadNotificationCount = 0 } return res diff --git a/app/src/main/java/ani/dantotsu/connections/anilist/api/Notification.kt b/app/src/main/java/ani/dantotsu/connections/anilist/api/Notification.kt index 073fadc1..f526078a 100644 --- a/app/src/main/java/ani/dantotsu/connections/anilist/api/Notification.kt +++ b/app/src/main/java/ani/dantotsu/connections/anilist/api/Notification.kt @@ -20,7 +20,9 @@ enum class NotificationType(val value: String) { RELATED_MEDIA_ADDITION("RELATED_MEDIA_ADDITION"), MEDIA_DATA_CHANGE("MEDIA_DATA_CHANGE"), MEDIA_MERGE("MEDIA_MERGE"), - MEDIA_DELETION("MEDIA_DELETION") + MEDIA_DELETION("MEDIA_DELETION"), + //custom + COMMENT_REPLY("COMMENT_REPLY"), } @Serializable @@ -40,7 +42,7 @@ data class NotificationResponse( @Serializable data class NotificationUser( @SerialName("unreadNotificationCount") - val unreadNotificationCount: Int, + var unreadNotificationCount: Int, ) : java.io.Serializable @Serializable @@ -56,41 +58,41 @@ data class Notification( @SerialName("id") val id: Int, @SerialName("userId") - val userId: Int?, + val userId: Int? = null, @SerialName("CommentId") val commentId: Int?, @SerialName("type") val notificationType: String, @SerialName("activityId") - val activityId: Int?, + val activityId: Int? = null, @SerialName("animeId") - val mediaId: Int?, + val mediaId: Int? = null, @SerialName("episode") - val episode: Int?, + val episode: Int? = null, @SerialName("contexts") - val contexts: List?, + val contexts: List? = null, @SerialName("context") - val context: String?, + val context: String? = null, @SerialName("reason") - val reason: String?, + val reason: String? = null, @SerialName("deletedMediaTitle") - val deletedMediaTitle: String?, + val deletedMediaTitle: String? = null, @SerialName("deletedMediaTitles") - val deletedMediaTitles: List?, + val deletedMediaTitles: List? = null, @SerialName("createdAt") val createdAt: Int, @SerialName("media") - val media: ani.dantotsu.connections.anilist.api.Media?, + val media: ani.dantotsu.connections.anilist.api.Media? = null, @SerialName("user") - val user: ani.dantotsu.connections.anilist.api.User?, + val user: ani.dantotsu.connections.anilist.api.User? = null, @SerialName("message") - val message: MessageActivity?, + val message: MessageActivity? = null, @SerialName("activity") - val activity: ActivityUnion?, + val activity: ActivityUnion? = null, @SerialName("Thread") - val thread: Thread?, + val thread: Thread? = null, @SerialName("comment") - val comment: ThreadComment?, + val comment: ThreadComment? = null, ) : java.io.Serializable @Serializable diff --git a/app/src/main/java/ani/dantotsu/media/comments/CommentsFragment.kt b/app/src/main/java/ani/dantotsu/media/comments/CommentsFragment.kt index c3583183..5900b32a 100644 --- a/app/src/main/java/ani/dantotsu/media/comments/CommentsFragment.kt +++ b/app/src/main/java/ani/dantotsu/media/comments/CommentsFragment.kt @@ -33,6 +33,7 @@ import ani.dantotsu.settings.saving.PrefManager import ani.dantotsu.settings.saving.PrefName import ani.dantotsu.snackString import ani.dantotsu.toast +import ani.dantotsu.util.Logger import com.bumptech.glide.Glide import com.xwray.groupie.GroupieAdapter import com.xwray.groupie.Section @@ -197,7 +198,8 @@ class CommentsFragment : Fragment() { } } } else { - snackString("No more comments") + //snackString("No more comments") fix spam? + Logger.log("No more comments") } } } diff --git a/app/src/main/java/ani/dantotsu/notifications/CommentNotificationWorker.kt b/app/src/main/java/ani/dantotsu/notifications/comment/CommentNotificationWorker.kt similarity index 84% rename from app/src/main/java/ani/dantotsu/notifications/CommentNotificationWorker.kt rename to app/src/main/java/ani/dantotsu/notifications/comment/CommentNotificationWorker.kt index f07e169a..c3276d67 100644 --- a/app/src/main/java/ani/dantotsu/notifications/CommentNotificationWorker.kt +++ b/app/src/main/java/ani/dantotsu/notifications/comment/CommentNotificationWorker.kt @@ -1,4 +1,4 @@ -package ani.dantotsu.notifications +package ani.dantotsu.notifications.comment import android.Manifest import android.app.PendingIntent @@ -59,8 +59,12 @@ class CommentNotificationWorker(appContext: Context, workerParams: WorkerParamet if (newRecentGlobal != null) { PrefManager.setVal(PrefName.RecentGlobalNotification, newRecentGlobal) } + if (notifications.isNullOrEmpty()) return@launch + PrefManager.setVal(PrefName.UnreadCommentNotifications, + PrefManager.getVal(PrefName.UnreadCommentNotifications) + (notifications?.size ?: 0) + ) - notifications?.forEach { + notifications.forEach { val type: NotificationType = when (it.type) { 1 -> NotificationType.COMMENT_REPLY 2 -> NotificationType.COMMENT_WARNING @@ -72,6 +76,15 @@ class CommentNotificationWorker(appContext: Context, workerParams: WorkerParamet NotificationType.COMMENT_WARNING -> { val title = "You received a warning" val message = it.content ?: "Be more thoughtful with your comments" + + val commentStore = CommentStore( + title, + message, + it.mediaId, + it.commentId + ) + addNotificationToStore(commentStore) + createNotification( NotificationType.COMMENT_WARNING, message, @@ -87,6 +100,15 @@ class CommentNotificationWorker(appContext: Context, workerParams: WorkerParamet val title = "New CommentNotificationWorker Reply" val mediaName = names[it.mediaId]?.title ?: "Unknown" val message = "${it.username} replied to your comment in $mediaName" + + val commentStore = CommentStore( + title, + message, + it.mediaId, + it.commentId + ) + addNotificationToStore(commentStore) + createNotification( NotificationType.COMMENT_REPLY, message, @@ -101,6 +123,15 @@ class CommentNotificationWorker(appContext: Context, workerParams: WorkerParamet NotificationType.APP_GLOBAL -> { val title = "Update from Dantotsu" val message = it.content ?: "New feature available" + + val commentStore = CommentStore( + title, + message, + null, + null + ) + addNotificationToStore(commentStore) + createNotification( NotificationType.APP_GLOBAL, message, @@ -144,6 +175,22 @@ class CommentNotificationWorker(appContext: Context, workerParams: WorkerParamet return Result.success() } + private fun addNotificationToStore(notification: CommentStore) { + val notificationStore = PrefManager.getNullableVal>( + PrefName.CommentNotificationStore, + null + ) ?: listOf() + val newStore = notificationStore.toMutableList() + if (newStore.size > 10) { + newStore.remove(newStore.minByOrNull { it.time }) + } + if (newStore.any { it.content == notification.content }) { + return + } + newStore.add(notification) + PrefManager.setVal(PrefName.CommentNotificationStore, newStore) + } + private fun createNotification( notificationType: NotificationType, message: String, @@ -153,8 +200,10 @@ class CommentNotificationWorker(appContext: Context, workerParams: WorkerParamet color: String, imageUrl: String ): android.app.Notification? { - Logger.log("Creating notification of type $notificationType" + - ", message: $message, title: $title, mediaId: $mediaId, commentId: $commentId") + Logger.log( + "Creating notification of type $notificationType" + + ", message: $message, title: $title, mediaId: $mediaId, commentId: $commentId" + ) val notification = when (notificationType) { NotificationType.COMMENT_WARNING -> { val intent = Intent(applicationContext, MainActivity::class.java).apply { @@ -269,6 +318,6 @@ class CommentNotificationWorker(appContext: Context, workerParams: WorkerParamet companion object { val checkIntervals = arrayOf(0L, 720, 1440) - const val WORK_NAME = "ani.dantotsu.notifications.CommentNotificationWorker" + const val WORK_NAME = "ani.dantotsu.notifications.comment.CommentNotificationWorker" } } \ No newline at end of file diff --git a/app/src/main/java/ani/dantotsu/notifications/comment/CommentStore.kt b/app/src/main/java/ani/dantotsu/notifications/comment/CommentStore.kt new file mode 100644 index 00000000..bc6ab98b --- /dev/null +++ b/app/src/main/java/ani/dantotsu/notifications/comment/CommentStore.kt @@ -0,0 +1,20 @@ +package ani.dantotsu.notifications.comment + +import kotlinx.serialization.Serializable + + +@Suppress("INAPPROPRIATE_CONST_NAME") +@Serializable +data class CommentStore( + val title: String, + val content: String, + val mediaId: Int? = null, + val commentId: Int? = null, + val time: Long = System.currentTimeMillis(), +) : java.io.Serializable { + companion object { + + @Suppress("INAPPROPRIATE_CONST_NAME") + private const val serialVersionUID = 1L + } +} \ No newline at end of file diff --git a/app/src/main/java/ani/dantotsu/notifications/MediaNameFetch.kt b/app/src/main/java/ani/dantotsu/notifications/comment/MediaNameFetch.kt similarity index 98% rename from app/src/main/java/ani/dantotsu/notifications/MediaNameFetch.kt rename to app/src/main/java/ani/dantotsu/notifications/comment/MediaNameFetch.kt index 47345104..15e0e7e6 100644 --- a/app/src/main/java/ani/dantotsu/notifications/MediaNameFetch.kt +++ b/app/src/main/java/ani/dantotsu/notifications/comment/MediaNameFetch.kt @@ -1,4 +1,4 @@ -package ani.dantotsu.notifications +package ani.dantotsu.notifications.comment import ani.dantotsu.client import com.google.gson.Gson diff --git a/app/src/main/java/ani/dantotsu/profile/activity/ActivityItemBuilder.kt b/app/src/main/java/ani/dantotsu/profile/activity/ActivityItemBuilder.kt index d810258b..ef50027e 100644 --- a/app/src/main/java/ani/dantotsu/profile/activity/ActivityItemBuilder.kt +++ b/app/src/main/java/ani/dantotsu/profile/activity/ActivityItemBuilder.kt @@ -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" + } } } diff --git a/app/src/main/java/ani/dantotsu/profile/activity/FeedFragment.kt b/app/src/main/java/ani/dantotsu/profile/activity/FeedFragment.kt index f13d93e1..7ef09eb5 100644 --- a/app/src/main/java/ani/dantotsu/profile/activity/FeedFragment.kt +++ b/app/src/main/java/ani/dantotsu/profile/activity/FeedFragment.kt @@ -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) diff --git a/app/src/main/java/ani/dantotsu/profile/activity/NotificationActivity.kt b/app/src/main/java/ani/dantotsu/profile/activity/NotificationActivity.kt index 01dac01f..4c21bd48 100644 --- a/app/src/main/java/ani/dantotsu/profile/activity/NotificationActivity.kt +++ b/app/src/main/java/ani/dantotsu/profile/activity/NotificationActivity.kt @@ -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>( + 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 } } } \ No newline at end of file diff --git a/app/src/main/java/ani/dantotsu/profile/activity/NotificationItem.kt b/app/src/main/java/ani/dantotsu/profile/activity/NotificationItem.kt index cc9a5270..961d4c1a 100644 --- a/app/src/main/java/ani/dantotsu/profile/activity/NotificationItem.kt +++ b/app/src/main/java/ani/dantotsu/profile/activity/NotificationItem.kt @@ -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() { 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 + ) + } + } + } } } diff --git a/app/src/main/java/ani/dantotsu/settings/SettingsActivity.kt b/app/src/main/java/ani/dantotsu/settings/SettingsActivity.kt index 1df64f08..907ba068 100644 --- a/app/src/main/java/ani/dantotsu/settings/SettingsActivity.kt +++ b/app/src/main/java/ani/dantotsu/settings/SettingsActivity.kt @@ -47,7 +47,7 @@ import ani.dantotsu.initActivity import ani.dantotsu.loadImage import ani.dantotsu.util.Logger import ani.dantotsu.navBarHeight -import ani.dantotsu.notifications.CommentNotificationWorker +import ani.dantotsu.notifications.comment.CommentNotificationWorker import ani.dantotsu.notifications.anilist.AnilistNotificationWorker import ani.dantotsu.openLinkInBrowser import ani.dantotsu.others.AppUpdater diff --git a/app/src/main/java/ani/dantotsu/settings/saving/Preferences.kt b/app/src/main/java/ani/dantotsu/settings/saving/Preferences.kt index a429392b..9b2beb3c 100644 --- a/app/src/main/java/ani/dantotsu/settings/saving/Preferences.kt +++ b/app/src/main/java/ani/dantotsu/settings/saving/Preferences.kt @@ -3,6 +3,7 @@ package ani.dantotsu.settings.saving import android.graphics.Color import ani.dantotsu.connections.comments.AuthResponse import ani.dantotsu.connections.mal.MAL +import ani.dantotsu.notifications.comment.CommentStore import ani.dantotsu.settings.saving.internal.Location import ani.dantotsu.settings.saving.internal.Pref @@ -171,6 +172,8 @@ enum class PrefName(val data: Pref) { //TODO: Split this into multiple files CommentTokenExpiry(Pref(Location.Irrelevant, Long::class, 0L)), LogToFile(Pref(Location.Irrelevant, Boolean::class, false)), RecentGlobalNotification(Pref(Location.Irrelevant, Int::class, 0)), + CommentNotificationStore(Pref(Location.Irrelevant, List::class, listOf())), + UnreadCommentNotifications(Pref(Location.Irrelevant, Int::class, 0)), //Protected DiscordToken(Pref(Location.Protected, String::class, "")),