diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/adapter/ChapterListItemAD.kt b/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/adapter/ChapterListItemAD.kt index 41721e951..f309ef29d 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/adapter/ChapterListItemAD.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/adapter/ChapterListItemAD.kt @@ -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 -> { diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/model/ChapterListItem.kt b/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/model/ChapterListItem.kt index e9b987ebb..55cbdccd5 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/model/ChapterListItem.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/model/ChapterListItem.kt @@ -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 {