From 879d41f255f116bc5b8b97345a7e06026bb14c1d Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 5 Aug 2019 10:56:03 +0800 Subject: [PATCH] up --- .../io/legado/app/data/entities/SearchBook.kt | 13 ++++++++ .../io/legado/app/ui/search/SearchAdapter.kt | 32 +++++++++++++++++++ .../io/legado/app/utils/StringExtensions.kt | 4 +-- app/src/main/res/layout/item_search.xml | 14 +++++--- 4 files changed, 56 insertions(+), 7 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 71db1dc8b..66965ea8c 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 @@ -8,6 +8,7 @@ import androidx.room.Index import androidx.room.PrimaryKey import io.legado.app.utils.GSON import io.legado.app.utils.fromJsonObject +import io.legado.app.utils.splitNotBlank import kotlinx.android.parcel.IgnoredOnParcel import kotlinx.android.parcel.Parcelize @@ -56,4 +57,16 @@ data class SearchBook( variableMap?.put(key, value) variable = GSON.toJson(variableMap) } + + fun getKindList(): List { + val kindList = arrayListOf() + wordCount?.let { + if (it.isNotBlank()) kindList.add(it) + } + kind?.let { + val kinds = it.splitNotBlank(",", "\n") + kindList.addAll(kinds) + } + return kindList + } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/search/SearchAdapter.kt b/app/src/main/java/io/legado/app/ui/search/SearchAdapter.kt index 196b6edd0..d9df3bb43 100644 --- a/app/src/main/java/io/legado/app/ui/search/SearchAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/search/SearchAdapter.kt @@ -9,6 +9,8 @@ import androidx.recyclerview.widget.RecyclerView import io.legado.app.R import io.legado.app.data.entities.SearchBook import io.legado.app.help.ImageLoader +import io.legado.app.utils.gone +import io.legado.app.utils.visible import kotlinx.android.synthetic.main.item_bookshelf_list.view.iv_cover import kotlinx.android.synthetic.main.item_bookshelf_list.view.tv_name import kotlinx.android.synthetic.main.item_search.view.* @@ -50,6 +52,36 @@ class SearchAdapter : PagedListAdapter(D tv_name.text = String.format("%s(%s)", searchBook.name, searchBook.author) tv_lasted.text = context.getString(R.string.book_search_last, searchBook.latestChapterTitle) tv_introduce.text = searchBook.intro + val kinds = searchBook.getKindList() + if (kinds.isEmpty()) { + ll_kind.gone() + } else { + ll_kind.visible() + for (index in 0..2) { + if (kinds.size > index) { + when (index) { + 0 -> { + tv_kind.text = kinds[index] + tv_kind.visible() + } + 1 -> { + tv_kind_1.text = kinds[index] + tv_kind_1.visible() + } + 2 -> { + tv_kind_2.text = kinds[index] + tv_kind_2.visible() + } + } + } else { + when (index) { + 0 -> tv_kind.gone() + 1 -> tv_kind_1.gone() + 2 -> tv_kind_2.gone() + } + } + } + } searchBook.coverUrl.let { ImageLoader.load(context, it)//Glide自动识别http://和file:// .placeholder(R.drawable.img_cover_default) diff --git a/app/src/main/java/io/legado/app/utils/StringExtensions.kt b/app/src/main/java/io/legado/app/utils/StringExtensions.kt index 580d8a10f..0100b5f9f 100644 --- a/app/src/main/java/io/legado/app/utils/StringExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/StringExtensions.kt @@ -23,8 +23,8 @@ fun String?.htmlFormat(): String = if (this.isNullOrBlank()) "" else .replace("^[\\n\\s]+".toRegex(), "  ")//移除开头空行,并增加段前缩进2个汉字 .replace("[\\n\\s]+$".toRegex(), "") //移除尾部空行 -fun String.splitNotBlank(delimiter: String): Array = run { - this.split(delimiter).map { it.trim() }.filterNot { it.isBlank() }.toTypedArray() +fun String.splitNotBlank(vararg delimiter: String): Array = run { + this.split(*delimiter).map { it.trim() }.filterNot { it.isBlank() }.toTypedArray() } fun String.splitNotBlank(regex: Regex, limit: Int = 0): Array = run { diff --git a/app/src/main/res/layout/item_search.xml b/app/src/main/res/layout/item_search.xml index 57d9b033f..a106d8601 100644 --- a/app/src/main/res/layout/item_search.xml +++ b/app/src/main/res/layout/item_search.xml @@ -7,8 +7,8 @@ @@ -58,6 +60,8 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginEnd="6dp" + android:paddingLeft="3dp" + android:paddingRight="3dp" android:singleLine="true" android:text="@string/app_name" /> @@ -66,6 +70,8 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginEnd="6dp" + android:paddingLeft="3dp" + android:paddingRight="3dp" android:singleLine="true" android:text="@string/app_name" /> @@ -85,10 +91,8 @@