From acefd33e2e0089ecb88e54e408deba38bd6db8eb Mon Sep 17 00:00:00 2001
From: Jobobby04 <jobobby04@users.noreply.github.com>
Date: Fri, 6 Nov 2020 14:24:28 -0500
Subject: [PATCH] Cleanup

---
 .../java/exh/md/handlers/ApiMangaParser.kt    |  4 +-
 .../java/exh/md/handlers/FollowsHandler.kt    | 10 ++--
 .../serializers/ApiMangaSerializer.kt         | 48 +++++++++++++++++++
 3 files changed, 54 insertions(+), 8 deletions(-)

diff --git a/app/src/main/java/exh/md/handlers/ApiMangaParser.kt b/app/src/main/java/exh/md/handlers/ApiMangaParser.kt
index 191ebcd0a..0146fb94c 100644
--- a/app/src/main/java/exh/md/handlers/ApiMangaParser.kt
+++ b/app/src/main/java/exh/md/handlers/ApiMangaParser.kt
@@ -71,7 +71,7 @@ class ApiMangaParser(private val langs: List<String>) {
     fun parseIntoMetadata(metadata: MangaDexSearchMetadata, input: Response, forceLatestCover: Boolean) {
         with(metadata) {
             try {
-                val networkApiManga = MdUtil.jsonParser.decodeFromString(ApiMangaSerializer.serializer(), input.body!!.string())
+                val networkApiManga = MdUtil.jsonParser.decodeFromString<ApiMangaSerializer>(input.body!!.string())
                 val networkManga = networkApiManga.manga
                 mdId = MdUtil.getMangaId(input.request.url.toString())
                 mdUrl = input.request.url.toString()
@@ -207,7 +207,7 @@ class ApiMangaParser(private val langs: List<String>) {
 
     fun chapterListParse(jsonData: String): List<SChapter> {
         val now = System.currentTimeMillis()
-        val networkApiManga = MdUtil.jsonParser.decodeFromString(ApiMangaSerializer.serializer(), jsonData)
+        val networkApiManga = MdUtil.jsonParser.decodeFromString<ApiMangaSerializer>(jsonData)
         val networkManga = networkApiManga.manga
         val networkChapters = networkApiManga.chapter
         if (networkChapters.isNullOrEmpty()) {
diff --git a/app/src/main/java/exh/md/handlers/FollowsHandler.kt b/app/src/main/java/exh/md/handlers/FollowsHandler.kt
index bdd5d4df1..662fc4d5c 100644
--- a/app/src/main/java/exh/md/handlers/FollowsHandler.kt
+++ b/app/src/main/java/exh/md/handlers/FollowsHandler.kt
@@ -19,6 +19,7 @@ import exh.metadata.metadata.MangaDexSearchMetadata
 import exh.util.floor
 import kotlinx.coroutines.Dispatchers
 import kotlinx.coroutines.withContext
+import kotlinx.serialization.decodeFromString
 import okhttp3.CacheControl
 import okhttp3.FormBody
 import okhttp3.Headers
@@ -47,12 +48,11 @@ class FollowsHandler(val client: OkHttpClient, val headers: Headers, val prefere
     private fun followsParseMangaPage(response: Response, forceHd: Boolean = false): MetadataMangasPage {
         val followsPageResult = try {
             MdUtil.jsonParser.decodeFromString(
-                FollowsPageResult.serializer(),
                 response.body?.string().orEmpty()
             )
         } catch (e: Exception) {
             XLog.e("error parsing follows", e)
-            FollowsPageResult(emptyList())
+            FollowsPageResult()
         }
 
         if (followsPageResult.result.isEmpty()) {
@@ -78,12 +78,11 @@ class FollowsHandler(val client: OkHttpClient, val headers: Headers, val prefere
     private fun followStatusParse(response: Response): Track {
         val followsPageResult = try {
             MdUtil.jsonParser.decodeFromString(
-                FollowsPageResult.serializer(),
                 response.body?.string().orEmpty()
             )
         } catch (e: Exception) {
             XLog.e("error parsing follows", e)
-            FollowsPageResult(emptyList())
+            FollowsPageResult()
         }
         val track = Track.create(TrackManager.MDLIST)
         if (followsPageResult.result.isEmpty()) {
@@ -173,8 +172,7 @@ class FollowsHandler(val client: OkHttpClient, val headers: Headers, val prefere
                     "${MdUtil.baseUrl}/ajax/actions.ajax.php?function=manga_rating&id=$mangaID&rating=${track.score.toInt()}",
                     headers
                 )
-            )
-                .await()
+            ).await()
 
             withContext(Dispatchers.IO) { response.body?.string().isNullOrEmpty() }
         }
diff --git a/app/src/main/java/exh/md/handlers/serializers/ApiMangaSerializer.kt b/app/src/main/java/exh/md/handlers/serializers/ApiMangaSerializer.kt
index 7484f62a8..ac2e27a44 100644
--- a/app/src/main/java/exh/md/handlers/serializers/ApiMangaSerializer.kt
+++ b/app/src/main/java/exh/md/handlers/serializers/ApiMangaSerializer.kt
@@ -28,6 +28,31 @@ data class MangaSerializer(
     val title: String
 )
 
+@Serializable
+data class MangaSerializerTwo(
+    val artist: List<String>,
+    val author: List<String>,
+    val mainCover: String,
+    val description: String,
+    val publication: Publication,
+    val tags: List<Int>,
+    // val covers: List<String>,
+    val isHentai: Boolean,
+    // val lang_flag: String,
+    // val lang_name: String,
+    val lastChapter: String? = null,
+    val links: LinksSerializer? = null,
+    val rating: RatingSerializerTwo? = null,
+    val title: String
+)
+
+@Serializable
+data class Publication(
+    val language: String,
+    val status: Int,
+    val demographic: Int
+)
+
 @Serializable
 data class LinksSerializer(
     val al: String? = null,
@@ -47,6 +72,13 @@ data class RatingSerializer(
     val users: String? = null
 )
 
+@Serializable
+data class RatingSerializerTwo(
+    val bayesian: Float? = null,
+    val mean: Float? = null,
+    val users: Int? = null
+)
+
 @Serializable
 data class ChapterSerializer(
     val volume: String? = null,
@@ -62,6 +94,22 @@ data class ChapterSerializer(
     val timestamp: Long
 )
 
+@Serializable
+data class ChapterSerializerTwo(
+    val volume: String? = null,
+    val chapter: String? = null,
+    val title: String? = null,
+    val language: String,
+    val groups: List<GroupSerializer> = emptyList(),
+    val timestamp: Long
+)
+
+@Serializable
+data class GroupSerializer(
+    val id: Int,
+    val name: String? = null
+)
+
 @Serializable
 data class CoversResult(
     val covers: List<String> = emptyList(),