Skip to content

Commit

Permalink
Use PlayerNotificationManager.createWithNotificationChannel to create…
Browse files Browse the repository at this point in the history
… the notification channel
  • Loading branch information
marceltex authored and dturner committed Jun 12, 2020
1 parent c47423a commit bd3a6a3
Showing 1 changed file with 2 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,10 @@ class UampNotificationManager(
init {
val mediaController = MediaControllerCompat(context, sessionToken)

if (shouldCreateNowPlayingChannel()) {
createNowPlayingChannel()
}

notificationManager = PlayerNotificationManager(
notificationManager = PlayerNotificationManager.createWithNotificationChannel(
context,
NOW_PLAYING_CHANNEL,
R.string.notification_channel,
NOW_PLAYING_NOTIFICATION,
DescriptionAdapter(mediaController),
notificationListener
Expand All @@ -88,25 +85,6 @@ class UampNotificationManager(
notificationManager.setPlayer(player)
}

private fun shouldCreateNowPlayingChannel() =
Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && !nowPlayingChannelExists()

@RequiresApi(Build.VERSION_CODES.O)
private fun nowPlayingChannelExists() =
platformNotificationManager.getNotificationChannel(NOW_PLAYING_CHANNEL) != null

@RequiresApi(Build.VERSION_CODES.O)
private fun createNowPlayingChannel() {
val notificationChannel = NotificationChannel(NOW_PLAYING_CHANNEL,
context.getString(R.string.notification_channel),
NotificationManager.IMPORTANCE_LOW)
.apply {
description = context.getString(R.string.notification_channel_description)
}

platformNotificationManager.createNotificationChannel(notificationChannel)
}

private inner class DescriptionAdapter(private val controller: MediaControllerCompat) :
PlayerNotificationManager.MediaDescriptionAdapter {

Expand Down

0 comments on commit bd3a6a3

Please sign in to comment.