From 734cb0be6eeeb484d367ba1cfdbf8cd0076157d3 Mon Sep 17 00:00:00 2001 From: arkon Date: Sun, 3 Dec 2023 16:52:07 -0500 Subject: [PATCH] Show average scores in tracker search results Closes #8280 --- .../java/eu/kanade/presentation/track/TrackerSearch.kt | 8 ++++++++ .../eu/kanade/tachiyomi/data/track/anilist/AnilistApi.kt | 2 ++ .../kanade/tachiyomi/data/track/anilist/AnilistModels.kt | 2 ++ .../eu/kanade/tachiyomi/data/track/bangumi/BangumiApi.kt | 3 +++ .../java/eu/kanade/tachiyomi/data/track/kitsu/KitsuApi.kt | 2 +- .../eu/kanade/tachiyomi/data/track/kitsu/KitsuModels.kt | 2 ++ .../eu/kanade/tachiyomi/data/track/model/TrackSearch.kt | 2 +- .../tachiyomi/data/track/myanimelist/MyAnimeListApi.kt | 4 +++- .../kanade/tachiyomi/data/track/shikimori/ShikimoriApi.kt | 1 + 9 files changed, 23 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/eu/kanade/presentation/track/TrackerSearch.kt b/app/src/main/java/eu/kanade/presentation/track/TrackerSearch.kt index f2aa4fb16e..ea5a810104 100644 --- a/app/src/main/java/eu/kanade/presentation/track/TrackerSearch.kt +++ b/app/src/main/java/eu/kanade/presentation/track/TrackerSearch.kt @@ -193,6 +193,7 @@ fun TrackerSearch( type = it.publishing_type.toLowerCase(Locale.current).capitalize(Locale.current), startDate = it.start_date, status = it.publishing_status.toLowerCase(Locale.current).capitalize(Locale.current), + score = it.score, description = it.summary.trim(), selected = it == selected, onClick = { onSelectedChange(it) }, @@ -218,6 +219,7 @@ private fun SearchResultItem( type: String, startDate: String, status: String, + score: Float, description: String, selected: Boolean, onClick: () -> Unit, @@ -279,6 +281,12 @@ private fun SearchResultItem( text = status, ) } + if (score != -1f) { + SearchResultItemDetails( + title = stringResource(MR.strings.score), + text = score.toString(), + ) + } } } if (description.isNotBlank()) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/anilist/AnilistApi.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/anilist/AnilistApi.kt index b1142c74d5..c1d0a855b0 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/anilist/AnilistApi.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/anilist/AnilistApi.kt @@ -153,6 +153,7 @@ class AnilistApi(val client: OkHttpClient, interceptor: AnilistInterceptor) { |month |day |} + |averageScore |} |} |} @@ -309,6 +310,7 @@ class AnilistApi(val client: OkHttpClient, interceptor: AnilistInterceptor) { struct["status"]!!.jsonPrimitive.contentOrNull ?: "", parseDate(struct, "startDate"), struct["chapters"]!!.jsonPrimitive.intOrNull ?: 0, + struct["averageScore"]?.jsonPrimitive?.intOrNull ?: -1, ) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/anilist/AnilistModels.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/anilist/AnilistModels.kt index e0103371e9..eb2f15ab25 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/anilist/AnilistModels.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/anilist/AnilistModels.kt @@ -19,6 +19,7 @@ data class ALManga( val publishing_status: String, val start_date_fuzzy: Long, val total_chapters: Int, + val average_score: Int, ) { fun toTrack() = TrackSearch.create(TrackerManager.ANILIST).apply { @@ -27,6 +28,7 @@ data class ALManga( total_chapters = this@ALManga.total_chapters cover_url = image_url_lge summary = description?.htmlDecode() ?: "" + score = average_score.toFloat() tracking_url = AnilistApi.mangaUrl(media_id) publishing_status = this@ALManga.publishing_status publishing_type = format diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/BangumiApi.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/BangumiApi.kt index 6762fdcafa..29db49ec54 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/BangumiApi.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/BangumiApi.kt @@ -11,6 +11,7 @@ import eu.kanade.tachiyomi.network.parseAs import kotlinx.serialization.json.Json import kotlinx.serialization.json.JsonObject import kotlinx.serialization.json.contentOrNull +import kotlinx.serialization.json.floatOrNull import kotlinx.serialization.json.int import kotlinx.serialization.json.jsonArray import kotlinx.serialization.json.jsonObject @@ -108,11 +109,13 @@ class BangumiApi( } else { 0 } + val rating = obj["rating"]?.jsonObject?.get("score")?.jsonPrimitive?.floatOrNull ?: -1f return TrackSearch.create(trackId).apply { media_id = obj["id"]!!.jsonPrimitive.long title = obj["name_cn"]!!.jsonPrimitive.content cover_url = coverUrl summary = obj["name"]!!.jsonPrimitive.content + score = rating tracking_url = obj["url"]!!.jsonPrimitive.content total_chapters = totalChapters } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/KitsuApi.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/KitsuApi.kt index 2d54b266be..5406be0adf 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/KitsuApi.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/KitsuApi.kt @@ -279,7 +279,7 @@ class KitsuApi(private val client: OkHttpClient, interceptor: KitsuInterceptor) private const val algoliaAppId = "AWQO5J657S" private const val algoliaFilter = "&facetFilters=%5B%22kind%3Amanga%22%5D&attributesToRetrieve=" + - "%5B%22synopsis%22%2C%22canonicalTitle%22%2C%22chapterCount%22%2C%22" + + "%5B%22synopsis%22%2C%22averageRating%22%2C%22canonicalTitle%22%2C%22chapterCount%22%2C%22" + "posterImage%22%2C%22startDate%22%2C%22subtype%22%2C%22endDate%22%2C%20%22id%22%5D" fun mangaUrl(remoteId: Long): String { diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/KitsuModels.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/KitsuModels.kt index 1cbf16c71c..156f6d8f36 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/KitsuModels.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/KitsuModels.kt @@ -28,6 +28,7 @@ class KitsuSearchManga(obj: JsonObject) { null } private val synopsis = obj["synopsis"]?.jsonPrimitive?.contentOrNull + private val rating = obj["averageRating"]?.jsonPrimitive?.contentOrNull?.toFloatOrNull() private var startDate = obj["startDate"]?.jsonPrimitive?.contentOrNull?.let { val outputDf = SimpleDateFormat("yyyy-MM-dd", Locale.US) outputDf.format(Date(it.toLong() * 1000)) @@ -42,6 +43,7 @@ class KitsuSearchManga(obj: JsonObject) { cover_url = original ?: "" summary = synopsis ?: "" tracking_url = KitsuApi.mangaUrl(media_id) + score = rating ?: -1f publishing_status = if (endDate == null) { "Publishing" } else { diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/model/TrackSearch.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/model/TrackSearch.kt index 2f930b50c1..7151aab621 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/model/TrackSearch.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/model/TrackSearch.kt @@ -20,7 +20,7 @@ class TrackSearch : Track { override var total_chapters: Int = 0 - override var score: Float = 0f + override var score: Float = -1f override var status: Int = 0 diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/myanimelist/MyAnimeListApi.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/myanimelist/MyAnimeListApi.kt index db89bcc11d..444c5512ff 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/myanimelist/MyAnimeListApi.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/myanimelist/MyAnimeListApi.kt @@ -16,6 +16,7 @@ import kotlinx.serialization.json.JsonObject import kotlinx.serialization.json.boolean import kotlinx.serialization.json.contentOrNull import kotlinx.serialization.json.float +import kotlinx.serialization.json.floatOrNull import kotlinx.serialization.json.int import kotlinx.serialization.json.jsonArray import kotlinx.serialization.json.jsonObject @@ -103,7 +104,7 @@ class MyAnimeListApi( .appendPath(id.toString()) .appendQueryParameter( "fields", - "id,title,synopsis,num_chapters,main_picture,status,media_type,start_date", + "id,title,synopsis,num_chapters,mean,main_picture,status,media_type,start_date", ) .build() with(json) { @@ -117,6 +118,7 @@ class MyAnimeListApi( title = obj["title"]!!.jsonPrimitive.content summary = obj["synopsis"]?.jsonPrimitive?.content ?: "" total_chapters = obj["num_chapters"]!!.jsonPrimitive.int + score = obj["mean"]?.jsonPrimitive?.floatOrNull ?: -1f cover_url = obj["main_picture"]?.jsonObject?.get("large")?.jsonPrimitive?.content ?: "" diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/shikimori/ShikimoriApi.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/shikimori/ShikimoriApi.kt index 8ae22f3c97..0a5bba7728 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/shikimori/ShikimoriApi.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/shikimori/ShikimoriApi.kt @@ -107,6 +107,7 @@ class ShikimoriApi( total_chapters = obj["chapters"]!!.jsonPrimitive.int cover_url = baseUrl + obj["image"]!!.jsonObject["preview"]!!.jsonPrimitive.content summary = "" + score = obj["score"]!!.jsonPrimitive.float tracking_url = baseUrl + obj["url"]!!.jsonPrimitive.content publishing_status = obj["status"]!!.jsonPrimitive.content publishing_type = obj["kind"]!!.jsonPrimitive.content