Refactor chapters description

This commit is contained in:
Koitharu
2024-01-18 10:56:41 +02:00
parent eafd878413
commit 796af6b811
2 changed files with 23 additions and 8 deletions

View File

@@ -26,7 +26,7 @@ fun chapterListItemAD(
bind { payloads ->
if (payloads.isEmpty()) {
binding.textViewTitle.text = item.chapter.name
binding.textViewDescription.textAndVisible = item.description()
binding.textViewDescription.textAndVisible = item.description
}
when {
item.isCurrent -> {

View File

@@ -1,6 +1,7 @@
package org.koitharu.kotatsu.details.ui.model
import android.text.format.DateUtils
import org.jsoup.internal.StringUtil.StringJoiner
import org.koitharu.kotatsu.list.ui.model.ListModel
import org.koitharu.kotatsu.parsers.model.MangaChapter
@@ -10,6 +11,14 @@ data class ChapterListItem(
private val uploadDateMs: Long,
) : ListModel {
var description: String? = null
private set
get() {
if (field != null) return field
field = buildDescription()
return field
}
var uploadDate: CharSequence? = null
private set
get() {
@@ -38,14 +47,20 @@ data class ChapterListItem(
val isNew: Boolean
get() = hasFlag(FLAG_NEW)
fun description(): CharSequence {
val number = chapter.number.toString()
val scanlator = chapter.scanlator?.takeUnless { it.isBlank() }
return when {
uploadDate != null && scanlator != null -> "#$number$uploadDate$scanlator"
scanlator != null -> "#$number$scanlator"
else -> "#$number$uploadDate"
private fun buildDescription(): String {
val joiner = StringJoiner("")
if (chapter.number != 0) {
joiner.add("#").append(chapter.number.toString())
}
uploadDate?.let { date ->
joiner.add(date.toString())
}
chapter.scanlator?.let { scanlator ->
if (scanlator.isNotBlank()) {
joiner.add(scanlator)
}
}
return joiner.complete()
}
private fun hasFlag(flag: Int): Boolean {