Fixed Notification Ids to be different for Downloader and Player
Fixed multiple start of periodic CheckDownloads
This commit is contained in:
parent
46846bd5c9
commit
cbe3992b01
|
@ -144,13 +144,15 @@ internal class MediaNotificationProvider(context: Context) :
|
||||||
NOTIFICATION_CHANNEL_NAME,
|
NOTIFICATION_CHANNEL_NAME,
|
||||||
NotificationManager.IMPORTANCE_LOW
|
NotificationManager.IMPORTANCE_LOW
|
||||||
)
|
)
|
||||||
|
channel.setShowBadge(false)
|
||||||
|
|
||||||
notificationManager.createNotificationChannel(channel)
|
notificationManager.createNotificationChannel(channel)
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private const val NOTIFICATION_CHANNEL_ID = "org.moire.ultrasonic"
|
private const val NOTIFICATION_CHANNEL_ID = "org.moire.ultrasonic"
|
||||||
private const val NOTIFICATION_CHANNEL_NAME = "Ultrasonic background service"
|
private const val NOTIFICATION_CHANNEL_NAME = "Ultrasonic background service"
|
||||||
private const val NOTIFICATION_ID = 3033
|
private const val NOTIFICATION_ID = 3032
|
||||||
private fun getSmallIconResId(): Int {
|
private fun getSmallIconResId(): Int {
|
||||||
return R.drawable.ic_stat_ultrasonic
|
return R.drawable.ic_stat_ultrasonic
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,6 +46,7 @@ class Downloader(
|
||||||
|
|
||||||
var started: Boolean = false
|
var started: Boolean = false
|
||||||
var shouldStop: Boolean = false
|
var shouldStop: Boolean = false
|
||||||
|
var isPolling: Boolean = false
|
||||||
|
|
||||||
private val downloadQueue = PriorityQueue<DownloadFile>()
|
private val downloadQueue = PriorityQueue<DownloadFile>()
|
||||||
private val activelyDownloading = mutableListOf<DownloadFile>()
|
private val activelyDownloading = mutableListOf<DownloadFile>()
|
||||||
|
@ -67,6 +68,7 @@ class Downloader(
|
||||||
init {
|
init {
|
||||||
// Check downloads if the playlist changed
|
// Check downloads if the playlist changed
|
||||||
rxBusSubscription += RxBus.playlistObservable.subscribe {
|
rxBusSubscription += RxBus.playlistObservable.subscribe {
|
||||||
|
Timber.v("Playlist has changed, checking Downloads...")
|
||||||
checkDownloads()
|
checkDownloads()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -79,10 +81,14 @@ class Downloader(
|
||||||
} catch (all: Exception) {
|
} catch (all: Exception) {
|
||||||
Timber.e(all, "checkDownloads() failed.")
|
Timber.e(all, "checkDownloads() failed.")
|
||||||
} finally {
|
} finally {
|
||||||
if (!shouldStop) {
|
if (!isPolling) {
|
||||||
Handler(Looper.getMainLooper()).postDelayed(this, CHECK_INTERVAL)
|
isPolling = true
|
||||||
} else {
|
if (!shouldStop) {
|
||||||
shouldStop = false
|
Handler(Looper.getMainLooper()).postDelayed(this, CHECK_INTERVAL)
|
||||||
|
} else {
|
||||||
|
shouldStop = false
|
||||||
|
isPolling = false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -98,6 +104,7 @@ class Downloader(
|
||||||
|
|
||||||
@Synchronized
|
@Synchronized
|
||||||
fun start() {
|
fun start() {
|
||||||
|
if (started) return
|
||||||
started = true
|
started = true
|
||||||
|
|
||||||
// Start our loop
|
// Start our loop
|
||||||
|
@ -110,6 +117,7 @@ class Downloader(
|
||||||
}
|
}
|
||||||
|
|
||||||
fun stop() {
|
fun stop() {
|
||||||
|
if (!started) return
|
||||||
started = false
|
started = false
|
||||||
shouldStop = true
|
shouldStop = true
|
||||||
wifiLock?.release()
|
wifiLock?.release()
|
||||||
|
@ -210,6 +218,7 @@ class Downloader(
|
||||||
file.isFailed = false
|
file.isFailed = false
|
||||||
file.downloadTask = DownloadTask(file)
|
file.downloadTask = DownloadTask(file)
|
||||||
file.downloadTask!!.start()
|
file.downloadTask!!.start()
|
||||||
|
Timber.v("startDownloadOnService started downloading file ${file.completeFile}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -313,6 +322,7 @@ class Downloader(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Timber.v("downloadBackground Checking Downloads")
|
||||||
checkDownloads()
|
checkDownloads()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -490,6 +500,7 @@ class Downloader(
|
||||||
inputStream.safeClose()
|
inputStream.safeClose()
|
||||||
outputStream.safeClose()
|
outputStream.safeClose()
|
||||||
CacheCleaner().cleanSpace()
|
CacheCleaner().cleanSpace()
|
||||||
|
Timber.v("DownloadTask checking downloads")
|
||||||
checkDownloads()
|
checkDownloads()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue