From efba76380a1ecb5ee600706570272cf09e635a2e Mon Sep 17 00:00:00 2001 From: Jobobby04 Date: Sun, 4 Jul 2021 17:14:07 -0400 Subject: [PATCH] Reader cleanup --- .../eu/kanade/tachiyomi/source/LocalSource.kt | 55 ++++++++----------- .../tachiyomi/source/online/all/EHentai.kt | 1 + .../java/exh/debug/SettingsDebugController.kt | 29 +++++----- 3 files changed, 38 insertions(+), 47 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/source/LocalSource.kt b/app/src/main/java/eu/kanade/tachiyomi/source/LocalSource.kt index 7f32adeca..746c62983 100755 --- a/app/src/main/java/eu/kanade/tachiyomi/source/LocalSource.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/source/LocalSource.kt @@ -2,7 +2,6 @@ package eu.kanade.tachiyomi.source import android.content.Context import com.github.junrar.Archive -import com.google.gson.JsonParser import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.source.model.Filter @@ -17,8 +16,11 @@ import eu.kanade.tachiyomi.util.storage.DiskUtil import eu.kanade.tachiyomi.util.storage.EpubFile import eu.kanade.tachiyomi.util.system.ImageUtil import kotlinx.serialization.Serializable +import kotlinx.serialization.decodeFromString import kotlinx.serialization.encodeToString import kotlinx.serialization.json.Json +import okio.buffer +import okio.source import rx.Observable import timber.log.Timber import uy.kohesive.injekt.Injekt @@ -169,29 +171,13 @@ class LocalSource(private val context: Context) : CatalogueSource { @Serializable data class MangaJson( - val title: String, - val author: String?, - val artist: String?, - val description: String?, - val genre: List?, - val status: Int - ) { - - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (javaClass != other?.javaClass) return false - - other as MangaJson - - if (title != other.title) return false - - return true - } - - override fun hashCode(): Int { - return title.hashCode() - } - } + val title: String? = null, + val author: String? = null, + val artist: String? = null, + val description: String? = null, + val genre: List? = null, + val status: Int? = null + ) // SY <-- override fun fetchLatestUpdates(page: Int) = fetchSearchManga(page, "", LATEST_FILTERS) @@ -203,16 +189,19 @@ class LocalSource(private val context: Context) : CatalogueSource { .flatten() .firstOrNull { it.extension == "json" } ?.apply { - val reader = this.inputStream().bufferedReader() - val json = JsonParser.parseReader(reader).asJsonObject + val json = json.decodeFromString( + this.inputStream() + .source() + .buffer() + .use { it.readUtf8() } + ) - manga.title = json["title"]?.asString ?: manga.title - manga.author = json["author"]?.asString ?: manga.author - manga.artist = json["artist"]?.asString ?: manga.artist - manga.description = json["description"]?.asString ?: manga.description - manga.genre = json["genre"]?.asJsonArray?.joinToString(", ") { it.asString } - ?: manga.genre - manga.status = json["status"]?.asInt ?: manga.status + manga.title = json.title ?: manga.title + manga.author = json.author ?: manga.author + manga.artist = json.artist ?: manga.artist + manga.description = json.description ?: manga.description + manga.genre = json.genre?.joinToString(", ") ?: manga.genre + manga.status = json.status ?: manga.status } return Observable.just(manga) diff --git a/app/src/main/java/eu/kanade/tachiyomi/source/online/all/EHentai.kt b/app/src/main/java/eu/kanade/tachiyomi/source/online/all/EHentai.kt index 8c346b57c..96175650d 100755 --- a/app/src/main/java/eu/kanade/tachiyomi/source/online/all/EHentai.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/source/online/all/EHentai.kt @@ -126,6 +126,7 @@ class EHentai( val linkElement = body.selectFirst(".gl3c > a, .gl2e > div > a") val infoElement = body.selectFirst(".gl3e") + // why is column2 null val favElement = column2.children().find { it.attr("style").startsWith("border-color") } val infoElements = infoElement?.select("div") val parsedTags = mutableListOf() diff --git a/app/src/main/java/exh/debug/SettingsDebugController.kt b/app/src/main/java/exh/debug/SettingsDebugController.kt index 4ba8d2935..bfa725768 100644 --- a/app/src/main/java/exh/debug/SettingsDebugController.kt +++ b/app/src/main/java/exh/debug/SettingsDebugController.kt @@ -3,12 +3,9 @@ package exh.debug import android.annotation.SuppressLint import android.app.Activity import android.util.Log -import android.widget.HorizontalScrollView -import android.widget.TextView import androidx.core.text.HtmlCompat import androidx.preference.PreferenceScreen import com.afollestad.materialdialogs.MaterialDialog -import com.afollestad.materialdialogs.customview.customView import eu.kanade.tachiyomi.ui.setting.SettingsController import eu.kanade.tachiyomi.util.preference.defaultValue import eu.kanade.tachiyomi.util.preference.onClick @@ -36,22 +33,26 @@ class SettingsDebugController : SettingsController() { isPersistent = false onClick { - val view = TextView(context) - view.setHorizontallyScrolling(true) - view.setTextIsSelectable(true) - - val hView = HorizontalScrollView(context) - hView.addView(view) - try { val result = it.call(DebugFunctions) - view.text = "Function returned result:\n\n$result" + val text = "Function returned result:\n\n$result" MaterialDialog(context) - .customView(view = hView, scrollable = true) + .title(text = title.toString()) + .message(text = text) { + messageTextView.apply { + setHorizontallyScrolling(true) + setTextIsSelectable(true) + } + } } catch (t: Throwable) { - view.text = "Function threw exception:\n\n${Log.getStackTraceString(t)}" + val text = "Function threw exception:\n\n${Log.getStackTraceString(t)}" MaterialDialog(context) - .customView(view = hView, scrollable = true) + .message(text = text) { + messageTextView.apply { + setHorizontallyScrolling(true) + setTextIsSelectable(true) + } + } }.show() } }