Refactor notification manga cover logic, decrease size

This commit is contained in:
arkon 2020-02-17 16:14:15 -05:00
parent f03c49850b
commit 10272ef395

View file

@ -5,6 +5,7 @@ import android.app.PendingIntent
import android.app.Service import android.app.Service
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.graphics.Bitmap
import android.graphics.BitmapFactory import android.graphics.BitmapFactory
import android.os.Build import android.os.Build
import android.os.IBinder import android.os.IBinder
@ -122,6 +123,8 @@ class LibraryUpdateService(
*/ */
const val KEY_TARGET = "target" const val KEY_TARGET = "target"
private const val NOTIF_ICON_SIZE = 192
/** /**
* Returns the status of the service. * Returns the status of the service.
* *
@ -454,21 +457,22 @@ class LibraryUpdateService(
* @param updates a list of manga with new updates. * @param updates a list of manga with new updates.
*/ */
private fun showUpdateNotifications(updates: List<Pair<Manga, Array<Chapter>>>) { private fun showUpdateNotifications(updates: List<Pair<Manga, Array<Chapter>>>) {
if (updates.isEmpty()) {
return
}
NotificationManagerCompat.from(this).apply { NotificationManagerCompat.from(this).apply {
// Group notification // Parent group notification
notify(Notifications.ID_NEW_CHAPTERS, notification(Notifications.CHANNEL_NEW_CHAPTERS) { notify(Notifications.ID_NEW_CHAPTERS, notification(Notifications.CHANNEL_NEW_CHAPTERS) {
setContentTitle(getString(R.string.notification_new_chapters)) setContentTitle(getString(R.string.notification_new_chapters))
if (updates.size > 1) { if (updates.size == 1) {
setContentText(resources.getQuantityString(R.plurals setContentText(updates.first().first.title)
.notification_new_chapters_text, } else {
updates.size, updates.size)) setContentText(resources.getQuantityString(R.plurals.notification_new_chapters_text, updates.size, updates.size))
setStyle(NotificationCompat.BigTextStyle().bigText(updates.joinToString("\n") { setStyle(NotificationCompat.BigTextStyle().bigText(updates.joinToString("\n") {
it.first.title.chop(45) it.first.title
})) }))
} }
else {
setContentText(updates.first().first.title.chop(45))
}
setSmallIcon(R.drawable.ic_tachi) setSmallIcon(R.drawable.ic_tachi)
setLargeIcon(notificationBitmap) setLargeIcon(notificationBitmap)
@ -503,12 +507,10 @@ class LibraryUpdateService(
setStyle(NotificationCompat.BigTextStyle().bigText(chaptersNames)) setStyle(NotificationCompat.BigTextStyle().bigText(chaptersNames))
setSmallIcon(R.drawable.ic_tachi) setSmallIcon(R.drawable.ic_tachi)
try {
val icon = Glide.with(this@LibraryUpdateService) val icon = getMangaIcon(manga)
.asBitmap().load(manga).dontTransform().centerCrop().circleCrop() if (icon != null) {
.override(256, 256).submit().get()
setLargeIcon(icon) setLargeIcon(icon)
} catch (e: Exception) {
} }
setGroup(Notifications.GROUP_NEW_CHAPTERS) setGroup(Notifications.GROUP_NEW_CHAPTERS)
@ -537,6 +539,22 @@ class LibraryUpdateService(
notificationManager.cancel(Notifications.ID_LIBRARY_PROGRESS) notificationManager.cancel(Notifications.ID_LIBRARY_PROGRESS)
} }
private fun getMangaIcon(manga: Manga): Bitmap? {
return try {
Glide.with(this)
.asBitmap()
.load(manga)
.dontTransform()
.centerCrop()
.circleCrop()
.override(NOTIF_ICON_SIZE, NOTIF_ICON_SIZE)
.submit()
.get()
} catch (e: Exception) {
null
}
}
/** /**
* Returns an intent to open the main activity. * Returns an intent to open the main activity.
*/ */