mirror of
https://github.com/TeamNewPipe/NewPipe.git
synced 2024-11-22 11:02:35 +01:00
Set channel icon for stream notifications
This commit is contained in:
parent
05cc520665
commit
cb00c57009
@ -83,10 +83,12 @@ class NotificationHelper(val context: Context) {
|
|||||||
// a Target is like a listener for image loading events
|
// a Target is like a listener for image loading events
|
||||||
val target = object : Target {
|
val target = object : Target {
|
||||||
override fun onBitmapLoaded(bitmap: Bitmap, from: Picasso.LoadedFrom) {
|
override fun onBitmapLoaded(bitmap: Bitmap, from: Picasso.LoadedFrom) {
|
||||||
summaryBuilder.setLargeIcon(bitmap) // set only if there is actually one
|
// set channel icon only if there is actually one (for Android versions < 7.0)
|
||||||
|
summaryBuilder.setLargeIcon(bitmap)
|
||||||
|
|
||||||
// Show individual stream notifications
|
// Show individual stream notifications, set channel icon only if there is actually
|
||||||
showStreamNotifications(newStreams, data.listInfo.serviceId)
|
// one
|
||||||
|
showStreamNotifications(newStreams, data.listInfo.serviceId, bitmap)
|
||||||
// Show summary notification
|
// Show summary notification
|
||||||
manager.notify(data.pseudoId, summaryBuilder.build())
|
manager.notify(data.pseudoId, summaryBuilder.build())
|
||||||
|
|
||||||
@ -95,7 +97,7 @@ class NotificationHelper(val context: Context) {
|
|||||||
|
|
||||||
override fun onBitmapFailed(e: Exception, errorDrawable: Drawable) {
|
override fun onBitmapFailed(e: Exception, errorDrawable: Drawable) {
|
||||||
// Show individual stream notifications
|
// Show individual stream notifications
|
||||||
showStreamNotifications(newStreams, data.listInfo.serviceId)
|
showStreamNotifications(newStreams, data.listInfo.serviceId, null)
|
||||||
// Show summary notification
|
// Show summary notification
|
||||||
manager.notify(data.pseudoId, summaryBuilder.build())
|
manager.notify(data.pseudoId, summaryBuilder.build())
|
||||||
iconLoadingTargets.remove(this) // allow it to be garbage-collected
|
iconLoadingTargets.remove(this) // allow it to be garbage-collected
|
||||||
@ -113,20 +115,28 @@ class NotificationHelper(val context: Context) {
|
|||||||
PicassoHelper.loadNotificationIcon(data.avatarUrl).into(target)
|
PicassoHelper.loadNotificationIcon(data.avatarUrl).into(target)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun showStreamNotifications(newStreams: List<StreamInfoItem>, serviceId: Int) {
|
private fun showStreamNotifications(
|
||||||
newStreams.asSequence()
|
newStreams: List<StreamInfoItem>,
|
||||||
.map { it to createStreamNotification(it, serviceId) }
|
serviceId: Int,
|
||||||
.forEach { (stream, notification) ->
|
channelIcon: Bitmap?
|
||||||
|
) {
|
||||||
|
for (stream in newStreams) {
|
||||||
|
val notification = createStreamNotification(stream, serviceId, channelIcon)
|
||||||
manager.notify(stream.url.hashCode(), notification)
|
manager.notify(stream.url.hashCode(), notification)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createStreamNotification(item: StreamInfoItem, serviceId: Int): Notification {
|
private fun createStreamNotification(
|
||||||
|
item: StreamInfoItem,
|
||||||
|
serviceId: Int,
|
||||||
|
channelIcon: Bitmap?
|
||||||
|
): Notification {
|
||||||
return NotificationCompat.Builder(
|
return NotificationCompat.Builder(
|
||||||
context,
|
context,
|
||||||
context.getString(R.string.streams_notification_channel_id)
|
context.getString(R.string.streams_notification_channel_id)
|
||||||
)
|
)
|
||||||
.setSmallIcon(R.drawable.ic_newpipe_triangle_white)
|
.setSmallIcon(R.drawable.ic_newpipe_triangle_white)
|
||||||
|
.setLargeIcon(channelIcon)
|
||||||
.setContentTitle(item.name)
|
.setContentTitle(item.name)
|
||||||
.setContentText(item.uploaderName)
|
.setContentText(item.uploaderName)
|
||||||
.setGroup(item.uploaderUrl)
|
.setGroup(item.uploaderUrl)
|
||||||
|
Loading…
Reference in New Issue
Block a user