mirror of
https://gitlab.com/ultrasonic/ultrasonic.git
synced 2025-04-26 13:42:15 +03:00
Created different notification when Ultrasonic is only downloading files
Fixed null check
This commit is contained in:
parent
01aa1fe887
commit
be49145aa8
@ -33,6 +33,8 @@ class Downloader(
|
|||||||
private val localMediaPlayer: LocalMediaPlayer
|
private val localMediaPlayer: LocalMediaPlayer
|
||||||
) : KoinComponent {
|
) : KoinComponent {
|
||||||
val playlist: MutableList<DownloadFile> = ArrayList()
|
val playlist: MutableList<DownloadFile> = ArrayList()
|
||||||
|
var started: Boolean = false
|
||||||
|
|
||||||
private val downloadQueue: PriorityQueue<DownloadFile> = PriorityQueue<DownloadFile>()
|
private val downloadQueue: PriorityQueue<DownloadFile> = PriorityQueue<DownloadFile>()
|
||||||
private val activelyDownloading: MutableList<DownloadFile> = ArrayList()
|
private val activelyDownloading: MutableList<DownloadFile> = ArrayList()
|
||||||
|
|
||||||
@ -63,6 +65,7 @@ class Downloader(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun start() {
|
fun start() {
|
||||||
|
started = true
|
||||||
if (executorService == null) {
|
if (executorService == null) {
|
||||||
executorService = Executors.newSingleThreadScheduledExecutor()
|
executorService = Executors.newSingleThreadScheduledExecutor()
|
||||||
executorService!!.scheduleWithFixedDelay(
|
executorService!!.scheduleWithFixedDelay(
|
||||||
@ -78,10 +81,12 @@ class Downloader(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun stop() {
|
fun stop() {
|
||||||
|
started = false
|
||||||
executorService?.shutdown()
|
executorService?.shutdown()
|
||||||
executorService = null
|
executorService = null
|
||||||
wifiLock?.release()
|
wifiLock?.release()
|
||||||
wifiLock = null
|
wifiLock = null
|
||||||
|
MediaPlayerService.runningInstance?.notifyDownloaderStopped()
|
||||||
Timber.i("Downloader stopped")
|
Timber.i("Downloader stopped")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -157,6 +157,10 @@ class MediaPlayerService : Service() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun notifyDownloaderStopped() {
|
||||||
|
stopIfIdle()
|
||||||
|
}
|
||||||
|
|
||||||
@Synchronized
|
@Synchronized
|
||||||
fun seekTo(position: Int) {
|
fun seekTo(position: Int) {
|
||||||
if (jukeboxMediaPlayer.isEnabled) {
|
if (jukeboxMediaPlayer.isEnabled) {
|
||||||
@ -582,15 +586,14 @@ class MediaPlayerService : Service() {
|
|||||||
// Clear old actions
|
// Clear old actions
|
||||||
notificationBuilder!!.clearActions()
|
notificationBuilder!!.clearActions()
|
||||||
|
|
||||||
|
if (song != null) {
|
||||||
// Add actions
|
// Add actions
|
||||||
val compactActions = addActions(context, notificationBuilder!!, playerState, song)
|
val compactActions = addActions(context, notificationBuilder!!, playerState, song)
|
||||||
|
|
||||||
// Configure shortcut actions
|
// Configure shortcut actions
|
||||||
style.setShowActionsInCompactView(*compactActions)
|
style.setShowActionsInCompactView(*compactActions)
|
||||||
notificationBuilder!!.setStyle(style)
|
notificationBuilder!!.setStyle(style)
|
||||||
|
|
||||||
// Set song title, artist and cover if possible
|
// Set song title, artist and cover
|
||||||
if (song != null) {
|
|
||||||
val iconSize = (256 * context.resources.displayMetrics.density).toInt()
|
val iconSize = (256 * context.resources.displayMetrics.density).toInt()
|
||||||
val bitmap = BitmapUtils.getAlbumArtBitmapFromDisk(song, iconSize)
|
val bitmap = BitmapUtils.getAlbumArtBitmapFromDisk(song, iconSize)
|
||||||
notificationBuilder!!.setContentTitle(song.title)
|
notificationBuilder!!.setContentTitle(song.title)
|
||||||
@ -598,6 +601,14 @@ class MediaPlayerService : Service() {
|
|||||||
notificationBuilder!!.setLargeIcon(bitmap)
|
notificationBuilder!!.setLargeIcon(bitmap)
|
||||||
notificationBuilder!!.setSubText(song.album)
|
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()
|
return notificationBuilder!!.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -199,7 +199,7 @@ object FileUtil {
|
|||||||
Locale.ROOT,
|
Locale.ROOT,
|
||||||
"%s/%s",
|
"%s/%s",
|
||||||
musicDirectory.path,
|
musicDirectory.path,
|
||||||
if (entry.isDirectory) f.path else f.parent!!
|
if (entry.isDirectory) f.path else f.parent ?: ""
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
|
@ -400,6 +400,7 @@
|
|||||||
<string name="settings.debug.log_keep">Keep files</string>
|
<string name="settings.debug.log_keep">Keep files</string>
|
||||||
<string name="settings.debug.log_delete">Delete files</string>
|
<string name="settings.debug.log_delete">Delete files</string>
|
||||||
<string name="settings.debug.log_deleted">Deleted log 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.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>
|
<string name="permissions.message_box_title">Warning</string>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user