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

View File

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