Improve workers notifications

pull/367/head
Koitharu 3 years ago
parent 2d171657dc
commit 25e7ab2d8e
No known key found for this signature in database
GPG Key ID: 8E861F8CE6E7CE27

@ -75,7 +75,7 @@ class ImportWorker @AssistedInject constructor(
.setProgress(0, 0, true) .setProgress(0, 0, true)
.setSmallIcon(android.R.drawable.stat_sys_download) .setSmallIcon(android.R.drawable.stat_sys_download)
.setForegroundServiceBehavior(NotificationCompat.FOREGROUND_SERVICE_IMMEDIATE) .setForegroundServiceBehavior(NotificationCompat.FOREGROUND_SERVICE_IMMEDIATE)
.setOngoing(true) .setCategory(NotificationCompat.CATEGORY_PROGRESS)
.build() .build()
return ForegroundInfo(FOREGROUND_NOTIFICATION_ID, notification) return ForegroundInfo(FOREGROUND_NOTIFICATION_ID, notification)

@ -8,7 +8,18 @@ import androidx.annotation.FloatRange
import androidx.core.app.NotificationCompat import androidx.core.app.NotificationCompat
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import androidx.hilt.work.HiltWorker import androidx.hilt.work.HiltWorker
import androidx.work.* import androidx.work.BackoffPolicy
import androidx.work.Constraints
import androidx.work.CoroutineWorker
import androidx.work.ExistingPeriodicWorkPolicy
import androidx.work.ForegroundInfo
import androidx.work.NetworkType
import androidx.work.OneTimeWorkRequestBuilder
import androidx.work.OutOfQuotaPolicy
import androidx.work.PeriodicWorkRequestBuilder
import androidx.work.WorkManager
import androidx.work.WorkerParameters
import androidx.work.workDataOf
import dagger.assisted.Assisted import dagger.assisted.Assisted
import dagger.assisted.AssistedInject import dagger.assisted.AssistedInject
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
@ -66,13 +77,13 @@ class SuggestionsWorker @AssistedInject constructor(
val notification = NotificationCompat.Builder(applicationContext, WORKER_CHANNEL_ID) val notification = NotificationCompat.Builder(applicationContext, WORKER_CHANNEL_ID)
.setContentTitle(title) .setContentTitle(title)
.setPriority(NotificationCompat.PRIORITY_MIN) .setPriority(NotificationCompat.PRIORITY_MIN)
.setCategory(NotificationCompat.CATEGORY_SERVICE)
.setDefaults(0) .setDefaults(0)
.setColor(ContextCompat.getColor(applicationContext, R.color.blue_primary_dark)) .setColor(ContextCompat.getColor(applicationContext, R.color.blue_primary_dark))
.setSilent(true) .setSilent(true)
.setProgress(0, 0, true) .setProgress(0, 0, true)
.setSmallIcon(android.R.drawable.stat_notify_sync) .setSmallIcon(android.R.drawable.stat_notify_sync)
.setForegroundServiceBehavior(NotificationCompat.FOREGROUND_SERVICE_DEFERRED) .setForegroundServiceBehavior(NotificationCompat.FOREGROUND_SERVICE_DEFERRED)
.setOngoing(true)
.build() .build()
return ForegroundInfo(WORKER_NOTIFICATION_ID, notification) return ForegroundInfo(WORKER_NOTIFICATION_ID, notification)

@ -75,6 +75,7 @@ class TrackWorker @AssistedInject constructor(
} finally { } finally {
withContext(NonCancellable) { withContext(NonCancellable) {
logger.flush() logger.flush()
notificationManager.cancel(WORKER_NOTIFICATION_ID)
} }
} }
} }
@ -179,6 +180,7 @@ class TrackWorker @AssistedInject constructor(
), ),
) )
setAutoCancel(true) setAutoCancel(true)
setCategory(NotificationCompat.CATEGORY_PROMO)
setVisibility(if (manga.isNsfw) VISIBILITY_SECRET else VISIBILITY_PUBLIC) setVisibility(if (manga.isNsfw) VISIBILITY_SECRET else VISIBILITY_PUBLIC)
color = colorPrimary color = colorPrimary
setShortcutId(manga.id.toString()) setShortcutId(manga.id.toString())
@ -216,13 +218,13 @@ class TrackWorker @AssistedInject constructor(
val notification = NotificationCompat.Builder(applicationContext, WORKER_CHANNEL_ID) val notification = NotificationCompat.Builder(applicationContext, WORKER_CHANNEL_ID)
.setContentTitle(title) .setContentTitle(title)
.setPriority(NotificationCompat.PRIORITY_MIN) .setPriority(NotificationCompat.PRIORITY_MIN)
.setCategory(NotificationCompat.CATEGORY_SERVICE)
.setDefaults(0) .setDefaults(0)
.setColor(ContextCompat.getColor(applicationContext, R.color.blue_primary_dark)) .setColor(ContextCompat.getColor(applicationContext, R.color.blue_primary_dark))
.setSilent(true) .setSilent(true)
.setProgress(0, 0, true) .setProgress(0, 0, true)
.setSmallIcon(android.R.drawable.stat_notify_sync) .setSmallIcon(android.R.drawable.stat_notify_sync)
.setForegroundServiceBehavior(NotificationCompat.FOREGROUND_SERVICE_DEFERRED) .setForegroundServiceBehavior(NotificationCompat.FOREGROUND_SERVICE_DEFERRED)
.setOngoing(true)
.build() .build()
return ForegroundInfo(WORKER_NOTIFICATION_ID, notification) return ForegroundInfo(WORKER_NOTIFICATION_ID, notification)
} }

Loading…
Cancel
Save