Load channel thumbnail

This commit is contained in:
Isira Seneviratne 2023-08-11 07:21:14 +05:30
parent 9b27f60252
commit 9bffd93d7c

View File

@ -149,6 +149,8 @@ class NotificationWorker(appContext: Context, parameters: WorkerParameters) :
.setGroupSummary(true) .setGroupSummary(true)
.setStyle(summary) .setStyle(summary)
.setGroupAlertBehavior(NotificationCompat.GROUP_ALERT_SUMMARY) .setGroupAlertBehavior(NotificationCompat.GROUP_ALERT_SUMMARY)
// Show channel avatar on Android versions below 7.0.
.setLargeIcon(downloadImage(streams[0].uploaderAvatar))
.build() .build()
// Create stream notifications. These are automatically grouped on Android 7.0 and later. // Create stream notifications. These are automatically grouped on Android 7.0 and later.
@ -175,30 +177,33 @@ class NotificationWorker(appContext: Context, parameters: WorkerParameters) :
val pendingIntent = PendingIntentCompat val pendingIntent = PendingIntentCompat
.getActivity(applicationContext, notificationId, intent, FLAG_UPDATE_CURRENT, false) .getActivity(applicationContext, notificationId, intent, FLAG_UPDATE_CURRENT, false)
// Load stream thumbnails if the relevant toggle is enabled.
val thumbnail = downloadImage(stream.thumbnail)
val notificationBuilder = createNotificationBuilder(group) val notificationBuilder = createNotificationBuilder(group)
.setContentTitle(stream.title) .setContentTitle(stream.title)
.setContentText(stream.uploaderName) .setContentText(stream.uploaderName)
// The intent that will fire when the user taps the notification // The intent that will fire when the user taps the notification
.setContentIntent(pendingIntent) .setContentIntent(pendingIntent)
.setSilent(true) .setSilent(true)
.setLargeIcon(thumbnail)
// Load stream thumbnails if the relevant toggle is enabled. .setStyle(
if (PreferenceHelper.getBoolean(PreferenceKeys.SHOW_STREAM_THUMBNAILS, false)) { NotificationCompat.BigPictureStyle()
val thumbnail = ImageHelper.getImage(applicationContext, stream.thumbnail) .bigPicture(thumbnail)
.drawable?.toBitmap() .bigLargeIcon(null as Bitmap?) // Hides the icon when expanding
)
notificationBuilder
.setLargeIcon(thumbnail)
.setStyle(
NotificationCompat.BigPictureStyle()
.bigPicture(thumbnail)
.bigLargeIcon(null as Bitmap?) // Hides the icon when expanding
)
}
return Triple(notificationId, stream.uploaded, notificationBuilder.build()) return Triple(notificationId, stream.uploaded, notificationBuilder.build())
} }
private suspend fun downloadImage(url: String?): Bitmap? {
return if (PreferenceHelper.getBoolean(PreferenceKeys.SHOW_STREAM_THUMBNAILS, false)) {
ImageHelper.getImage(applicationContext, url).drawable?.toBitmap()
} else {
null
}
}
private fun createNotificationBuilder(group: String): NotificationCompat.Builder { private fun createNotificationBuilder(group: String): NotificationCompat.Builder {
return NotificationCompat.Builder(applicationContext, PUSH_CHANNEL_ID) return NotificationCompat.Builder(applicationContext, PUSH_CHANNEL_ID)
.setSmallIcon(R.drawable.ic_launcher_lockscreen) .setSmallIcon(R.drawable.ic_launcher_lockscreen)