Browse Source

MangaUpdates tweaks (#7205)

* MangaUpdates tweaks

* Review changes

Co-authored-by: arkon <[email protected]>

* Use built in functions instead of Jsoup

Co-authored-by: arkon <[email protected]>
Andreas 2 years ago
parent
commit
c8468c29f1

+ 9 - 2
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<String> = (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<String> = _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
     }

+ 1 - 1
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(

+ 2 - 2
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
     }
 }

+ 3 - 2
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 = [email protected] ?: 0L
-        title = [email protected] ?: ""
+        title = [email protected]?.htmlDecode() ?: ""
         total_chapters = 0
         cover_url = [email protected]?.url?.original ?: ""
-        summary = [email protected] ?: ""
+        summary = [email protected]?.htmlDecode() ?: ""
         tracking_url = [email protected] ?: ""
         publishing_status = ""
         publishing_type = [email protected]()

+ 13 - 0
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()
+    }
+}