From 12390f5b8a1c3a0a1cb28b68884be0d6d7f01a73 Mon Sep 17 00:00:00 2001 From: Niko Diamadis Date: Thu, 14 Mar 2024 06:43:06 +0100 Subject: [PATCH] Remove Picasso request handler --- .../picasso/PicassoDataRequestHandler.kt | 39 ------------------- 1 file changed, 39 deletions(-) delete mode 100644 app/src/main/kotlin/com/github/gotify/picasso/PicassoDataRequestHandler.kt diff --git a/app/src/main/kotlin/com/github/gotify/picasso/PicassoDataRequestHandler.kt b/app/src/main/kotlin/com/github/gotify/picasso/PicassoDataRequestHandler.kt deleted file mode 100644 index 091fb6f..0000000 --- a/app/src/main/kotlin/com/github/gotify/picasso/PicassoDataRequestHandler.kt +++ /dev/null @@ -1,39 +0,0 @@ -package com.github.gotify.picasso - -import android.graphics.BitmapFactory -import android.util.Base64 -import com.squareup.picasso.Picasso -import com.squareup.picasso.Request -import com.squareup.picasso.RequestHandler -import org.tinylog.kotlin.Logger - -/** - * Adapted from https://github.com/square/picasso/issues/1395#issuecomment-220929377 By - * https://github.com/SmartDengg - */ -internal class PicassoDataRequestHandler : RequestHandler() { - companion object { - private const val DATA_SCHEME = "data" - } - - override fun canHandleRequest(data: Request): Boolean { - val scheme = data.uri.scheme - return DATA_SCHEME.equals(scheme, ignoreCase = true) - } - - override fun load(request: Request, networkPolicy: Int): Result { - val uri = request.uri.toString() - val imageDataBytes = uri.substring(uri.indexOf(",") + 1) - val bytes = Base64.decode(imageDataBytes.toByteArray(), Base64.DEFAULT) - val bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.size) - - if (bitmap == null) { - val show = if (uri.length > 50) uri.take(50) + "..." else uri - val malformed = RuntimeException("Malformed data uri: $show") - Logger.error(malformed, "Could not load image") - throw malformed - } - - return Result(bitmap, Picasso.LoadedFrom.NETWORK) - } -}