From c8468c29f1b65ce5e3a3680b3f095cf003d2f89d Mon Sep 17 00:00:00 2001 From: Andreas Date: Sun, 29 May 2022 00:36:28 +0200 Subject: [PATCH] MangaUpdates tweaks (#7205) * MangaUpdates tweaks * Review changes Co-authored-by: arkon <4098258+arkon@users.noreply.github.com> * Use built in functions instead of Jsoup Co-authored-by: arkon <4098258+arkon@users.noreply.github.com> --- .../data/track/mangaupdates/MangaUpdates.kt | 11 +++++++++-- .../data/track/mangaupdates/MangaUpdatesApi.kt | 2 +- .../tachiyomi/data/track/mangaupdates/dto/Rating.kt | 4 ++-- .../tachiyomi/data/track/mangaupdates/dto/Record.kt | 5 +++-- .../kanade/tachiyomi/util/lang/StringExtensions.kt | 13 +++++++++++++ 5 files changed, 28 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/mangaupdates/MangaUpdates.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/mangaupdates/MangaUpdates.kt index 8fce9b705b..04c25c0023 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/mangaupdates/MangaUpdates.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/mangaupdates/MangaUpdates.kt @@ -52,11 +52,18 @@ class MangaUpdates(private val context: Context, id: Int) : TrackService(id) { override fun getCompletionStatus(): Int = COMPLETE_LIST - override fun getScoreList(): List = (0..10).map(Int::toString) + private val _scoreList = (0..9).flatMap { i -> (0..9).map { j -> "$i.$j" } } + listOf("10.0") - override fun displayScore(track: Track): String = track.score.toInt().toString() + override fun getScoreList(): List = _scoreList + + override fun indexToScore(index: Int): Float = _scoreList[index].toFloat() + + override fun displayScore(track: Track): String = track.score.toString() override suspend fun update(track: Track, didReadChapter: Boolean): Track { + if (track.status != COMPLETE_LIST && didReadChapter) { + track.status = READING_LIST + } api.updateSeriesListItem(track) return track } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/mangaupdates/MangaUpdatesApi.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/mangaupdates/MangaUpdatesApi.kt index 1cc28b7a41..9e7404d08d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/mangaupdates/MangaUpdatesApi.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/mangaupdates/MangaUpdatesApi.kt @@ -125,7 +125,7 @@ class MangaUpdatesApi( suspend fun updateSeriesRating(track: Track) { if (track.score != 0f) { val body = buildJsonObject { - put("rating", track.score.toInt()) + put("rating", track.score) } authClient.newCall( PUT( diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/mangaupdates/dto/Rating.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/mangaupdates/dto/Rating.kt index 0de945dd35..b550a37f40 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/mangaupdates/dto/Rating.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/mangaupdates/dto/Rating.kt @@ -5,11 +5,11 @@ import kotlinx.serialization.Serializable @Serializable data class Rating( - val rating: Int? = null, + val rating: Float? = null, ) fun Rating.copyTo(track: Track): Track { return track.apply { - this.score = rating?.toFloat() ?: 0f + this.score = rating ?: 0f } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/mangaupdates/dto/Record.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/mangaupdates/dto/Record.kt index 6790290aa1..60dc5f0cb4 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/mangaupdates/dto/Record.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/mangaupdates/dto/Record.kt @@ -1,6 +1,7 @@ package eu.kanade.tachiyomi.data.track.mangaupdates.dto import eu.kanade.tachiyomi.data.track.model.TrackSearch +import eu.kanade.tachiyomi.util.lang.htmlDecode import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -25,10 +26,10 @@ data class Record( fun Record.toTrackSearch(id: Int): TrackSearch { return TrackSearch.create(id).apply { media_id = this@toTrackSearch.seriesId ?: 0L - title = this@toTrackSearch.title ?: "" + title = this@toTrackSearch.title?.htmlDecode() ?: "" total_chapters = 0 cover_url = this@toTrackSearch.image?.url?.original ?: "" - summary = this@toTrackSearch.description ?: "" + summary = this@toTrackSearch.description?.htmlDecode() ?: "" tracking_url = this@toTrackSearch.url ?: "" publishing_status = "" publishing_type = this@toTrackSearch.type.toString() diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/lang/StringExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/util/lang/StringExtensions.kt index d03cb92ca1..d751950767 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/lang/StringExtensions.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/lang/StringExtensions.kt @@ -1,5 +1,7 @@ package eu.kanade.tachiyomi.util.lang +import android.os.Build +import android.text.Html import net.greypanther.natsort.CaseInsensitiveSimpleNaturalComparator import java.nio.charset.StandardCharsets import kotlin.math.floor @@ -57,3 +59,14 @@ fun String.takeBytes(n: Int): String { bytes.decodeToString(endIndex = n).replace("\uFFFD", "") } } + +/** + * HTML-decode the string + */ +fun String.htmlDecode(): String { + return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + Html.fromHtml(this, Html.FROM_HTML_MODE_LEGACY).toString() + } else { + Html.fromHtml(this).toString() + } +}