Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace Picasso with Coil #337

Merged
merged 7 commits into from
Apr 21, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions app/src/main/kotlin/com/github/gotify/CoilHandler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import coil.disk.DiskCache
import coil.request.ImageRequest
import com.github.gotify.api.CertUtils
import com.github.gotify.client.model.Application
import kotlinx.coroutines.runBlocking
import okhttp3.OkHttpClient
import org.tinylog.kotlin.Logger
import java.io.IOException
Expand All @@ -31,14 +32,18 @@ internal class CoilHandler(private val context: Context, private val settings: S
}

@Throws(IOException::class)
suspend fun getImageFromUrl(url: String?): Bitmap {
fun getImageFromUrl(url: String?): Bitmap {
val request = ImageRequest.Builder(context)
.data(url)
.build()
return (imageLoader.execute(request).drawable as BitmapDrawable).bitmap
val imageResult: Bitmap
runBlocking {
imageResult = (imageLoader.execute(request).drawable as BitmapDrawable).bitmap
}
return imageResult
cyb3rko marked this conversation as resolved.
Show resolved Hide resolved
}

suspend fun getIcon(app: Application?): Bitmap {
fun getIcon(app: Application?): Bitmap {
if (app == null) {
return BitmapFactory.decodeResource(context.resources, R.drawable.gotify)
}
Expand Down
17 changes: 5 additions & 12 deletions app/src/main/kotlin/com/github/gotify/service/WebSocketService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import com.github.gotify.messages.IntentUrlDialogActivity
import com.github.gotify.messages.MessagesActivity
import com.github.gotify.CoilHandler
import io.noties.markwon.Markwon
import kotlinx.coroutines.runBlocking
import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.atomic.AtomicLong
import org.tinylog.kotlin.Logger
Expand Down Expand Up @@ -378,15 +377,11 @@ internal class WebSocketService : Service() {
showNotificationGroup(channelId)
}

val largeIcon = runBlocking {
coilHandler.getIcon(appIdToApp[appId])
}

b.setAutoCancel(true)
.setDefaults(Notification.DEFAULT_ALL)
.setWhen(System.currentTimeMillis())
.setSmallIcon(R.drawable.ic_gotify)
.setLargeIcon(largeIcon)
.setLargeIcon(coilHandler.getIcon(appIdToApp[appId]))
.setTicker("${getString(R.string.app_name)} - $title")
.setGroup(NotificationSupport.Group.MESSAGES)
.setContentTitle(title)
Expand All @@ -413,12 +408,10 @@ internal class WebSocketService : Service() {

if (notificationImageUrl != null) {
try {
runBlocking {
b.setStyle(
NotificationCompat.BigPictureStyle()
.bigPicture(coilHandler.getImageFromUrl(notificationImageUrl))
)
}
b.setStyle(
NotificationCompat.BigPictureStyle()
.bigPicture(coilHandler.getImageFromUrl(notificationImageUrl))
)
} catch (e: Exception) {
Logger.error(e, "Error loading bigImageUrl")
}
Expand Down