Notification Revival Fix

This commit is contained in:
shabinder 2021-09-04 01:04:10 +05:30
parent e4b47d871a
commit 9525c40e8c
2 changed files with 9 additions and 0 deletions

View File

@ -104,6 +104,7 @@ class ForegroundService : LifecycleService() {
@SuppressLint("WakelockTimeout")
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
super.onStartCommand(intent, flags, startId)
downloadService.reviveIfClosed()
// Send a notification that service is started
Log.i(TAG, "Foreground Service Started.")
startForeground(NOTIFICATION_ID, createNotification())
@ -135,6 +136,7 @@ class ForegroundService : LifecycleService() {
* Function To Download All Tracks Available in a List
**/
fun downloadAllTracks(trackList: List<TrackDetails>) {
downloadService.reviveIfClosed()
trackList.size.also { size ->
total += size
isSingleDownload = (size == 1)

View File

@ -84,6 +84,12 @@ class ParallelExecutor(
coroutineContext.cancel(cause)
}
fun reviveIfClosed() {
if (!service.isActive) {
closeAndReInit()
}
}
fun closeAndReInit(newConcurrentOperationLimit: Int = 4) {
// Close Everything
close()
@ -94,6 +100,7 @@ class ParallelExecutor(
killQueue = Channel(Channel.UNLIMITED)
operationQueue = Channel(Channel.RENDEZVOUS)
concurrentOperationLimit = atomic(newConcurrentOperationLimit)
startOrStopProcessors(expectedCount = this.concurrentOperationLimit.value, actualCount = 0)
}
private fun CoroutineScope.launchProcessor() = launch {