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