65 lines
2.4 KiB
Kotlin
65 lines
2.4 KiB
Kotlin
/*
|
|
* Copyright (c) 2019 Hemanth Savarala.
|
|
*
|
|
* Licensed under the GNU General Public License v3
|
|
*
|
|
* This is free software: you can redistribute it and/or modify it under
|
|
* the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation either version 3 of the License, or (at your option) any later version.
|
|
*
|
|
* This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
* See the GNU General Public License for more details.
|
|
*/
|
|
|
|
package code.name.monkey.retromusic.service.notification
|
|
|
|
|
|
import android.app.NotificationChannel
|
|
import android.app.NotificationManager
|
|
import android.content.Context
|
|
import androidx.annotation.RequiresApi
|
|
import androidx.core.app.NotificationCompat
|
|
import code.name.monkey.retromusic.R
|
|
import code.name.monkey.retromusic.model.Song
|
|
|
|
|
|
abstract class PlayingNotification(context: Context) :
|
|
NotificationCompat.Builder(context, NOTIFICATION_CHANNEL_ID) {
|
|
|
|
abstract fun updateMetadata(song: Song, onUpdate: () -> Unit)
|
|
|
|
abstract fun setPlaying(isPlaying: Boolean)
|
|
|
|
abstract fun updateFavorite(song: Song, onUpdate: () -> Unit)
|
|
|
|
companion object {
|
|
const val NOTIFICATION_CONTROLS_SIZE_MULTIPLIER = 1.0f
|
|
internal const val NOTIFICATION_CHANNEL_ID = "playing_notification"
|
|
const val NOTIFICATION_ID = 1
|
|
|
|
|
|
@RequiresApi(26)
|
|
fun createNotificationChannel(
|
|
context: Context,
|
|
notificationManager: NotificationManager
|
|
) {
|
|
var notificationChannel: NotificationChannel? = notificationManager
|
|
.getNotificationChannel(NOTIFICATION_CHANNEL_ID)
|
|
if (notificationChannel == null) {
|
|
notificationChannel = NotificationChannel(
|
|
NOTIFICATION_CHANNEL_ID,
|
|
context.getString(R.string.playing_notification_name),
|
|
NotificationManager.IMPORTANCE_LOW
|
|
)
|
|
notificationChannel.description =
|
|
context.getString(R.string.playing_notification_description)
|
|
notificationChannel.enableLights(false)
|
|
notificationChannel.enableVibration(false)
|
|
notificationChannel.setShowBadge(false)
|
|
|
|
notificationManager.createNotificationChannel(notificationChannel)
|
|
}
|
|
}
|
|
}
|
|
} |