From 36a7a3ebbc5188f6c3527b505696243165e30d47 Mon Sep 17 00:00:00 2001 From: Koitharu Date: Wed, 6 Apr 2022 17:24:10 +0300 Subject: [PATCH] Fix DownloadService foreground notification #50 --- .../koitharu/kotatsu/download/ui/service/DownloadService.kt | 6 +++--- .../download/ui/service/ForegroundNotificationSwitcher.kt | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/org/koitharu/kotatsu/download/ui/service/DownloadService.kt b/app/src/main/java/org/koitharu/kotatsu/download/ui/service/DownloadService.kt index 8dc7a738f..65e6c8b58 100644 --- a/app/src/main/java/org/koitharu/kotatsu/download/ui/service/DownloadService.kt +++ b/app/src/main/java/org/koitharu/kotatsu/download/ui/service/DownloadService.kt @@ -10,6 +10,8 @@ import android.os.PowerManager import android.widget.Toast import androidx.core.content.ContextCompat import androidx.lifecycle.lifecycleScope +import java.util.concurrent.TimeUnit +import kotlin.collections.set import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.mapLatest @@ -33,8 +35,6 @@ import org.koitharu.kotatsu.utils.ext.connectivityManager import org.koitharu.kotatsu.utils.ext.throttle import org.koitharu.kotatsu.utils.ext.toArraySet import org.koitharu.kotatsu.utils.progress.ProgressJob -import java.util.concurrent.TimeUnit -import kotlin.collections.set class DownloadService : BaseService() { @@ -70,7 +70,6 @@ class DownloadService : BaseService() { return if (manga != null) { jobs[startId] = downloadManga(startId, manga, chapters) jobCount.value = jobs.size - Toast.makeText(this, R.string.manga_downloading_, Toast.LENGTH_SHORT).show() START_REDELIVER_INTENT } else { stopSelf(startId) @@ -184,6 +183,7 @@ class DownloadService : BaseService() { intent.putExtra(EXTRA_CHAPTERS_IDS, chaptersIds.toLongArray()) } ContextCompat.startForegroundService(context, intent) + Toast.makeText(context, R.string.manga_downloading_, Toast.LENGTH_SHORT).show() } } diff --git a/app/src/main/java/org/koitharu/kotatsu/download/ui/service/ForegroundNotificationSwitcher.kt b/app/src/main/java/org/koitharu/kotatsu/download/ui/service/ForegroundNotificationSwitcher.kt index 2202ab606..c7d0b0191 100644 --- a/app/src/main/java/org/koitharu/kotatsu/download/ui/service/ForegroundNotificationSwitcher.kt +++ b/app/src/main/java/org/koitharu/kotatsu/download/ui/service/ForegroundNotificationSwitcher.kt @@ -24,9 +24,10 @@ class ForegroundNotificationSwitcher( @Synchronized fun notify(startId: Int, notification: Notification) { if (notifications.isEmpty()) { - handler.postDelayed(StartForegroundRunnable(startId, notification), DEFAULT_DELAY) + StartForegroundRunnable(startId, notification) + } else { + notificationManager.notify(startId, notification) } - notificationManager.notify(startId, notification) notifications[startId] = notification }