From 4e4b700c41b5c82bca52d293652faf356de00169 Mon Sep 17 00:00:00 2001 From: gedoor Date: Tue, 29 Jun 2021 08:53:29 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=AE=80=E4=BB=8B=E5=A4=9A?= =?UTF-8?q?=E4=BA=86=E5=87=A0=E4=B8=AA=E7=A9=BA=E6=A0=BC=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98,=E6=98=AF=E5=9B=A0=E4=B8=BA=E6=A0=BC=E5=BC=8F?= =?UTF-8?q?=E8=AF=9D=E5=81=9A=E4=BA=86=E7=BC=A9=E8=BF=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/data/entities/SearchBook.kt | 15 +++++++++++++-- .../app/ui/book/explore/ExploreShowAdapter.kt | 6 +----- .../legado/app/ui/book/search/SearchAdapter.kt | 18 ++---------------- 3 files changed, 16 insertions(+), 23 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/entities/SearchBook.kt b/app/src/main/java/io/legado/app/data/entities/SearchBook.kt index fb3ef7154..17ddf9dff 100644 --- a/app/src/main/java/io/legado/app/data/entities/SearchBook.kt +++ b/app/src/main/java/io/legado/app/data/entities/SearchBook.kt @@ -1,7 +1,9 @@ package io.legado.app.data.entities +import android.content.Context import android.os.Parcelable import androidx.room.* +import io.legado.app.R import io.legado.app.utils.GSON import io.legado.app.utils.fromJsonObject import kotlinx.parcelize.IgnoredOnParcel @@ -74,7 +76,7 @@ data class SearchBook( fun addOrigin(origin: String) { origins.add(origin) } - + fun getDisplayLastChapterTitle(): String { latestChapterTitle?.let { if (it.isNotEmpty()) { @@ -83,7 +85,16 @@ data class SearchBook( } return "无最新章节" } - + + fun trimIntro(context: Context): String { + val trimIntro = intro?.trim() + return if (trimIntro.isNullOrEmpty()) { + context.getString(R.string.intro_show_null) + } else { + context.getString(R.string.intro_show, trimIntro) + } + } + fun toBook() = Book( name = name, author = author, diff --git a/app/src/main/java/io/legado/app/ui/book/explore/ExploreShowAdapter.kt b/app/src/main/java/io/legado/app/ui/book/explore/ExploreShowAdapter.kt index 9c0e521b7..99d6b9285 100644 --- a/app/src/main/java/io/legado/app/ui/book/explore/ExploreShowAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/explore/ExploreShowAdapter.kt @@ -34,11 +34,7 @@ class ExploreShowAdapter(context: Context, val callBack: CallBack) : tvLasted.text = context.getString(R.string.lasted_show, item.latestChapterTitle) tvLasted.visible() } - if (item.intro.isNullOrEmpty()) { - tvIntroduce.text = context.getString(R.string.intro_show_null) - } else { - tvIntroduce.text = context.getString(R.string.intro_show, item.intro) - } + tvIntroduce.text = item.trimIntro(context) val kinds = item.getKindList() if (kinds.isEmpty()) { llKind.gone() diff --git a/app/src/main/java/io/legado/app/ui/book/search/SearchAdapter.kt b/app/src/main/java/io/legado/app/ui/book/search/SearchAdapter.kt index 70de12ac1..a1c617b08 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/SearchAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/SearchAdapter.kt @@ -79,13 +79,7 @@ class SearchAdapter(context: Context, val callBack: CallBack) : tvAuthor.text = context.getString(R.string.author_show, searchBook.author) bvOriginCount.setBadgeCount(searchBook.origins.size) upLasted(binding, searchBook.latestChapterTitle) - if (searchBook.intro.isNullOrEmpty()) { - tvIntroduce.text = - context.getString(R.string.intro_show_null) - } else { - tvIntroduce.text = - context.getString(R.string.intro_show, searchBook.intro) - } + tvIntroduce.text = searchBook.trimIntro(context) upKind(binding, searchBook.getKindList()) ivCover.load(searchBook.coverUrl, searchBook.name, searchBook.author) @@ -98,15 +92,7 @@ class SearchAdapter(context: Context, val callBack: CallBack) : when (it) { "origins" -> bvOriginCount.setBadgeCount(searchBook.origins.size) "last" -> upLasted(binding, searchBook.latestChapterTitle) - "intro" -> { - if (searchBook.intro.isNullOrEmpty()) { - tvIntroduce.text = - context.getString(R.string.intro_show_null) - } else { - tvIntroduce.text = - context.getString(R.string.intro_show, searchBook.intro) - } - } + "intro" -> tvIntroduce.text = searchBook.trimIntro(context) "kind" -> upKind(binding, searchBook.getKindList()) "cover" -> ivCover.load( searchBook.coverUrl,