Improve download notification

remotes/weblate/feature/pagecrop
Koitharu 6 years ago
parent 9e8367e45e
commit c4f712be3a

@ -8,6 +8,7 @@ import android.content.Context
import android.graphics.drawable.Drawable import android.graphics.drawable.Drawable
import android.os.Build import android.os.Build
import androidx.core.app.NotificationCompat import androidx.core.app.NotificationCompat
import androidx.core.content.ContextCompat
import androidx.core.graphics.drawable.toBitmap import androidx.core.graphics.drawable.toBitmap
import org.koitharu.kotatsu.R import org.koitharu.kotatsu.R
import org.koitharu.kotatsu.core.model.Manga import org.koitharu.kotatsu.core.model.Manga
@ -31,9 +32,13 @@ class DownloadNotification(private val context: Context) {
NotificationManager.IMPORTANCE_LOW NotificationManager.IMPORTANCE_LOW
) )
channel.enableVibration(false) channel.enableVibration(false)
channel.enableLights(false)
channel.setSound(null, null)
manager.createNotificationChannel(channel) manager.createNotificationChannel(channel)
} }
builder.setOnlyAlertOnce(true) builder.setOnlyAlertOnce(true)
builder.setDefaults(0)
builder.color = ContextCompat.getColor(context, R.color.blue_primary)
} }
fun fillFrom(manga: Manga) { fun fillFrom(manga: Manga) {
@ -70,6 +75,7 @@ class DownloadNotification(private val context: Context) {
builder.setContentText(e.getDisplayMessage(context.resources)) builder.setContentText(e.getDisplayMessage(context.resources))
builder.setAutoCancel(true) builder.setAutoCancel(true)
builder.setContentIntent(null) builder.setContentIntent(null)
builder.setCategory(NotificationCompat.CATEGORY_ERROR)
} }
fun setLargeIcon(icon: Drawable?) { fun setLargeIcon(icon: Drawable?) {
@ -83,6 +89,7 @@ class DownloadNotification(private val context: Context) {
val percent = (progress / max.toFloat() * 100).roundToInt() val percent = (progress / max.toFloat() * 100).roundToInt()
builder.setProgress(max, progress, false) builder.setProgress(max, progress, false)
builder.setContentText("%d%%".format(percent)) builder.setContentText("%d%%".format(percent))
builder.setCategory(NotificationCompat.CATEGORY_PROGRESS)
} }
fun setPostProcessing() { fun setPostProcessing() {
@ -96,6 +103,7 @@ class DownloadNotification(private val context: Context) {
builder.setContentIntent(createIntent(context, manga)) builder.setContentIntent(createIntent(context, manga))
builder.setAutoCancel(true) builder.setAutoCancel(true)
builder.setSmallIcon(android.R.drawable.stat_sys_download_done) builder.setSmallIcon(android.R.drawable.stat_sys_download_done)
builder.setCategory(null)
} }
fun setCancelling() { fun setCancelling() {

Loading…
Cancel
Save