Created different notification when Ultrasonic is only downloading files

Fixed null check
This commit is contained in:
Nite 2021-09-23 15:51:53 +02:00
parent 01aa1fe887
commit be49145aa8
No known key found for this signature in database
GPG Key ID: 1D1AD59B1C6386C1
4 changed files with 26 additions and 9 deletions

View File

@ -33,6 +33,8 @@ class Downloader(
private val localMediaPlayer: LocalMediaPlayer
) : KoinComponent {
val playlist: MutableList<DownloadFile> = ArrayList()
var started: Boolean = false
private val downloadQueue: PriorityQueue<DownloadFile> = PriorityQueue<DownloadFile>()
private val activelyDownloading: MutableList<DownloadFile> = ArrayList()
@ -63,6 +65,7 @@ class Downloader(
}
fun start() {
started = true
if (executorService == null) {
executorService = Executors.newSingleThreadScheduledExecutor()
executorService!!.scheduleWithFixedDelay(
@ -78,10 +81,12 @@ class Downloader(
}
fun stop() {
started = false
executorService?.shutdown()
executorService = null
wifiLock?.release()
wifiLock = null
MediaPlayerService.runningInstance?.notifyDownloaderStopped()
Timber.i("Downloader stopped")
}

View File

@ -157,6 +157,10 @@ class MediaPlayerService : Service() {
}
}
fun notifyDownloaderStopped() {
stopIfIdle()
}
@Synchronized
fun seekTo(position: Int) {
if (jukeboxMediaPlayer.isEnabled) {
@ -582,15 +586,14 @@ class MediaPlayerService : Service() {
// Clear old actions
notificationBuilder!!.clearActions()
// Add actions
val compactActions = addActions(context, notificationBuilder!!, playerState, song)
// Configure shortcut actions
style.setShowActionsInCompactView(*compactActions)
notificationBuilder!!.setStyle(style)
// Set song title, artist and cover if possible
if (song != null) {
// Add actions
val compactActions = addActions(context, notificationBuilder!!, playerState, song)
// Configure shortcut actions
style.setShowActionsInCompactView(*compactActions)
notificationBuilder!!.setStyle(style)
// Set song title, artist and cover
val iconSize = (256 * context.resources.displayMetrics.density).toInt()
val bitmap = BitmapUtils.getAlbumArtBitmapFromDisk(song, iconSize)
notificationBuilder!!.setContentTitle(song.title)
@ -598,6 +601,14 @@ class MediaPlayerService : Service() {
notificationBuilder!!.setLargeIcon(bitmap)
notificationBuilder!!.setSubText(song.album)
}
else if (downloader.started)
{
// No song is playing, but Ultrasonic is downloading files
notificationBuilder!!.setContentTitle(
getString(R.string.notification_downloading_title)
)
}
return notificationBuilder!!.build()
}

View File

@ -199,7 +199,7 @@ object FileUtil {
Locale.ROOT,
"%s/%s",
musicDirectory.path,
if (entry.isDirectory) f.path else f.parent!!
if (entry.isDirectory) f.path else f.parent ?: ""
)
)
} else {

View File

@ -400,6 +400,7 @@
<string name="settings.debug.log_keep">Keep files</string>
<string name="settings.debug.log_delete">Delete files</string>
<string name="settings.debug.log_deleted">Deleted log files.</string>
<string name="notification.downloading_title">Downloading media in the background…</string>
<string name="permissions.access_error">Ultrasonic can\'t access the music file cache. Cache location was reset to the default path.</string>
<string name="permissions.message_box_title">Warning</string>