feat: banner and cover for airing notifications

This commit is contained in:
aayush262 2024-05-22 00:20:40 +05:30
parent 66805bdf05
commit 039e3d63fe
6 changed files with 18 additions and 10 deletions

View file

@ -111,6 +111,8 @@ data class Notification(
val thread: Thread? = null, val thread: Thread? = null,
@SerialName("comment") @SerialName("comment")
val comment: ThreadComment? = null, val comment: ThreadComment? = null,
val image: String? = null,
val banner: String? = null,
) : java.io.Serializable ) : java.io.Serializable
@Serializable @Serializable

View file

@ -146,7 +146,8 @@ class SubscriptionHelper {
val isAdult: Boolean, val isAdult: Boolean,
val id: Int, val id: Int,
val name: String, val name: String,
val image: String? val image: String?,
val banner: String? = null
) : java.io.Serializable ) : java.io.Serializable
private const val SUBSCRIPTIONS = "subscriptions" private const val SUBSCRIPTIONS = "subscriptions"
@ -188,7 +189,8 @@ class SubscriptionHelper {
media.isAdult, media.isAdult,
media.id, media.id,
media.userPreferredName, media.userPreferredName,
media.cover media.cover,
media.banner
) )
data[media.id] = new data[media.id] = new
} }

View file

@ -122,7 +122,9 @@ class SubscriptionNotificationTask : Task {
SubscriptionStore( SubscriptionStore(
media.name, media.name,
text.first, text.first,
media.id media.id,
image = media.image,
banner = media.banner
) )
) )
PrefManager.setVal(PrefName.UnreadCommentNotifications, PrefManager.setVal(PrefName.UnreadCommentNotifications,
@ -238,9 +240,7 @@ class SubscriptionNotificationTask : Task {
if (newStore.size >= 100) { if (newStore.size >= 100) {
newStore.remove(newStore.minByOrNull { it.time }) newStore.remove(newStore.minByOrNull { it.time })
} }
if (newStore.any { it.title == notification.title && it.content == notification.content}) {
return
}
newStore.add(notification) newStore.add(notification)
PrefManager.setVal(PrefName.SubscriptionNotificationStore, newStore) PrefManager.setVal(PrefName.SubscriptionNotificationStore, newStore)
} }

View file

@ -9,6 +9,8 @@ data class SubscriptionStore(
val mediaId: Int, val mediaId: Int,
val type: String = "SUBSCRIPTION", val type: String = "SUBSCRIPTION",
val time: Long = System.currentTimeMillis(), val time: Long = System.currentTimeMillis(),
val image: String? = "",
val banner: String? = "",
) : java.io.Serializable { ) : java.io.Serializable {
companion object { companion object {
private const val serialVersionUID = 1L private const val serialVersionUID = 1L

View file

@ -235,6 +235,8 @@ class NotificationActivity : AppCompatActivity() {
notificationType = it.type, notificationType = it.type,
context = it.title + ": " + it.content, context = it.title + ": " + it.content,
createdAt = (it.time / 1000L).toInt(), createdAt = (it.time / 1000L).toInt(),
image = it.image,
banner = it.banner
) )
newNotifications += notification newNotifications += notification
} }

View file

@ -32,12 +32,12 @@ class NotificationItem(
return ItemNotificationBinding.bind(view) return ItemNotificationBinding.bind(view)
} }
private fun image(user: Boolean = false, commentNotification: Boolean = false) { private fun image(user: Boolean = false, commentNotification: Boolean = false, newRelease: Boolean = false) {
val cover = if (user) notification.user?.bannerImage val cover = if (user) notification.user?.bannerImage
?: notification.user?.avatar?.medium else notification.media?.bannerImage ?: notification.user?.avatar?.medium else notification.media?.bannerImage
?: notification.media?.coverImage?.large ?: notification.media?.coverImage?.large
blurImage(binding.notificationBannerImage, cover) blurImage(binding.notificationBannerImage, if (newRelease) notification.banner else cover)
val defaultHeight = 153.toPx val defaultHeight = 153.toPx
@ -64,7 +64,7 @@ class NotificationItem(
binding.notificationCover.visibility = View.VISIBLE binding.notificationCover.visibility = View.VISIBLE
binding.notificationCoverUser.visibility = View.VISIBLE binding.notificationCoverUser.visibility = View.VISIBLE
binding.notificationCoverUserContainer.visibility = View.GONE binding.notificationCoverUserContainer.visibility = View.GONE
binding.notificationCover.loadImage(notification.media?.coverImage?.large) binding.notificationCover.loadImage(if (newRelease) notification.image else notification.media?.coverImage?.large)
binding.notificationBannerImage.layoutParams.height = defaultHeight binding.notificationBannerImage.layoutParams.height = defaultHeight
binding.notificationGradiant.layoutParams.height = defaultHeight binding.notificationGradiant.layoutParams.height = defaultHeight
(binding.notificationTextContainer.layoutParams as ViewGroup.MarginLayoutParams).marginStart = (binding.notificationTextContainer.layoutParams as ViewGroup.MarginLayoutParams).marginStart =
@ -334,7 +334,7 @@ class NotificationItem(
} }
NotificationType.SUBSCRIPTION -> { NotificationType.SUBSCRIPTION -> {
image(user = true, commentNotification = true) image(newRelease = true)
binding.notificationCoverUser.setOnClickListener { binding.notificationCoverUser.setOnClickListener {
clickCallback( clickCallback(
notification.mediaId ?: 0, null, NotificationClickType.MEDIA notification.mediaId ?: 0, null, NotificationClickType.MEDIA