From 09b6a967a1a9cc43f3102fb336f48a84fdaf6b31 Mon Sep 17 00:00:00 2001 From: Koitharu Date: Thu, 23 May 2024 16:55:41 +0300 Subject: [PATCH] Refactor descrambling bitmap --- .../kotatsu/core/parser/BitmapImpl.kt | 48 ------------------- .../koitharu/kotatsu/core/util/ext/Http.kt | 3 ++ 2 files changed, 3 insertions(+), 48 deletions(-) delete mode 100644 app/src/main/kotlin/org/koitharu/kotatsu/core/parser/BitmapImpl.kt diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/core/parser/BitmapImpl.kt b/app/src/main/kotlin/org/koitharu/kotatsu/core/parser/BitmapImpl.kt deleted file mode 100644 index b55e8333d..000000000 --- a/app/src/main/kotlin/org/koitharu/kotatsu/core/parser/BitmapImpl.kt +++ /dev/null @@ -1,48 +0,0 @@ -package org.koitharu.kotatsu.core.parser - -import android.graphics.Canvas -import android.graphics.Bitmap as AndroidBitmap -import android.graphics.Rect as AndroidRect -import org.koitharu.kotatsu.parsers.bitmap.Bitmap -import org.koitharu.kotatsu.parsers.bitmap.Rect - -class BitmapImpl private constructor() : Bitmap { - - lateinit var androidBitmap: AndroidBitmap - - private lateinit var canvas: Canvas - - override val height: Int - get() = androidBitmap.height - - override val width: Int - get() = androidBitmap.width - - override fun drawBitmap(sourceBitmap: Bitmap, src: Rect, dst: Rect) { - val androidSourceBitmap = (sourceBitmap as BitmapImpl).androidBitmap - - canvas.drawBitmap(androidSourceBitmap, src.toAndroidRect(), dst.toAndroidRect(), null) - } - - companion object { - fun create(width: Int, height: Int): Bitmap { - val instance = BitmapImpl() - instance.androidBitmap = AndroidBitmap.createBitmap(width, height, AndroidBitmap.Config.ARGB_8888) - instance.canvas = Canvas(instance.androidBitmap) - - return instance - } - - fun create(bitmap: AndroidBitmap): Bitmap { - val instance = BitmapImpl() - instance.androidBitmap = bitmap.copy(AndroidBitmap.Config.ARGB_8888, true) - instance.canvas = Canvas(instance.androidBitmap) - - return instance - } - } -} - -private fun Rect.toAndroidRect(): AndroidRect { - return AndroidRect(left, top, right, bottom) -} diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/core/util/ext/Http.kt b/app/src/main/kotlin/org/koitharu/kotatsu/core/util/ext/Http.kt index 5d384ba88..018d594e1 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/core/util/ext/Http.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/core/util/ext/Http.kt @@ -5,6 +5,7 @@ import okhttp3.HttpUrl import okhttp3.MediaType.Companion.toMediaType import okhttp3.RequestBody.Companion.toRequestBody import okhttp3.Response +import okhttp3.ResponseBody import okhttp3.internal.closeQuietly import okio.IOException import org.json.JSONObject @@ -40,6 +41,8 @@ fun Response.ensureSuccess() = apply { } } +fun Response.requireBody(): ResponseBody = checkNotNull(body) { "Response body is null" } + fun Cookie.newBuilder(): Cookie.Builder = Cookie.Builder().also { c -> c.name(name) c.value(value)