DMZJ: tweak comments page (#16672)
This commit is contained in:
parent
8f3f400385
commit
b34dfcfa38
@ -6,7 +6,7 @@ ext {
|
|||||||
extName = 'DMZJ'
|
extName = 'DMZJ'
|
||||||
pkgNameSuffix = 'zh.dmzj'
|
pkgNameSuffix = 'zh.dmzj'
|
||||||
extClass = '.Dmzj'
|
extClass = '.Dmzj'
|
||||||
extVersionCode = 40
|
extVersionCode = 41
|
||||||
}
|
}
|
||||||
|
|
||||||
apply from: "$rootDir/common.gradle"
|
apply from: "$rootDir/common.gradle"
|
||||||
|
@ -7,6 +7,7 @@ import eu.kanade.tachiyomi.source.model.SManga
|
|||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
import kotlinx.serialization.json.JsonPrimitive
|
import kotlinx.serialization.json.JsonPrimitive
|
||||||
import okhttp3.Response
|
import okhttp3.Response
|
||||||
|
import org.jsoup.parser.Parser
|
||||||
|
|
||||||
object ApiV3 {
|
object ApiV3 {
|
||||||
|
|
||||||
@ -55,10 +56,14 @@ object ApiV3 {
|
|||||||
|
|
||||||
fun chapterCommentsUrl(path: String) = "$v3apiUrl/viewPoint/0/$path.json"
|
fun chapterCommentsUrl(path: String) = "$v3apiUrl/viewPoint/0/$path.json"
|
||||||
|
|
||||||
fun parseChapterComments(response: Response): List<String> {
|
fun parseChapterComments(response: Response, count: Int): List<String> {
|
||||||
val result: List<ChapterCommentDto> = response.parseAs()
|
val result: List<ChapterCommentDto> = response.parseAs()
|
||||||
(result as MutableList<ChapterCommentDto>).sort()
|
if (result.isEmpty()) return listOf("没有吐槽")
|
||||||
return result.map { it.toString() }
|
val aggregated = result.groupBy({ it.content }, { it.num }).map { (content, likes) ->
|
||||||
|
ChapterCommentDto(Parser.unescapeEntities(content, false), likes.sum())
|
||||||
|
} as ArrayList
|
||||||
|
aggregated.sort()
|
||||||
|
return aggregated.take(count).map { it.toString() }
|
||||||
}
|
}
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
@ -108,8 +113,8 @@ object ApiV3 {
|
|||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
class ChapterCommentDto(
|
class ChapterCommentDto(
|
||||||
private val content: String,
|
val content: String,
|
||||||
private val num: Int,
|
val num: Int,
|
||||||
) : Comparable<ChapterCommentDto> {
|
) : Comparable<ChapterCommentDto> {
|
||||||
override fun toString() = if (num > 0) "$content [+$num]" else content
|
override fun toString() = if (num > 0) "$content [+$num]" else content
|
||||||
override fun compareTo(other: ChapterCommentDto) = other.num.compareTo(num) // descending
|
override fun compareTo(other: ChapterCommentDto) = other.num.compareTo(num) // descending
|
||||||
|
@ -26,9 +26,7 @@ object CommentsInterceptor : Interceptor {
|
|||||||
val response = chain.proceed(request)
|
val response = chain.proceed(request)
|
||||||
if (request.tag(Tag::class) == null) return response
|
if (request.tag(Tag::class) == null) return response
|
||||||
|
|
||||||
val comments = ApiV3.parseChapterComments(response)
|
val comments = ApiV3.parseChapterComments(response, MAX_HEIGHT / (UNIT * 2))
|
||||||
.take(MAX_HEIGHT / (UNIT * 2))
|
|
||||||
.ifEmpty { listOf("没有吐槽") }
|
|
||||||
|
|
||||||
val paint = TextPaint().apply {
|
val paint = TextPaint().apply {
|
||||||
color = Color.BLACK
|
color = Color.BLACK
|
||||||
|
Loading…
x
Reference in New Issue
Block a user