pull/32/head
kunfei 5 years ago
parent 3116753825
commit 879d41f255
  1. 13
      app/src/main/java/io/legado/app/data/entities/SearchBook.kt
  2. 32
      app/src/main/java/io/legado/app/ui/search/SearchAdapter.kt
  3. 4
      app/src/main/java/io/legado/app/utils/StringExtensions.kt
  4. 14
      app/src/main/res/layout/item_search.xml

@ -8,6 +8,7 @@ import androidx.room.Index
import androidx.room.PrimaryKey import androidx.room.PrimaryKey
import io.legado.app.utils.GSON import io.legado.app.utils.GSON
import io.legado.app.utils.fromJsonObject import io.legado.app.utils.fromJsonObject
import io.legado.app.utils.splitNotBlank
import kotlinx.android.parcel.IgnoredOnParcel import kotlinx.android.parcel.IgnoredOnParcel
import kotlinx.android.parcel.Parcelize import kotlinx.android.parcel.Parcelize
@ -56,4 +57,16 @@ data class SearchBook(
variableMap?.put(key, value) variableMap?.put(key, value)
variable = GSON.toJson(variableMap) variable = GSON.toJson(variableMap)
} }
fun getKindList(): List<String> {
val kindList = arrayListOf<String>()
wordCount?.let {
if (it.isNotBlank()) kindList.add(it)
}
kind?.let {
val kinds = it.splitNotBlank(",", "\n")
kindList.addAll(kinds)
}
return kindList
}
} }

@ -9,6 +9,8 @@ import androidx.recyclerview.widget.RecyclerView
import io.legado.app.R import io.legado.app.R
import io.legado.app.data.entities.SearchBook import io.legado.app.data.entities.SearchBook
import io.legado.app.help.ImageLoader 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.iv_cover
import kotlinx.android.synthetic.main.item_bookshelf_list.view.tv_name import kotlinx.android.synthetic.main.item_bookshelf_list.view.tv_name
import kotlinx.android.synthetic.main.item_search.view.* import kotlinx.android.synthetic.main.item_search.view.*
@ -50,6 +52,36 @@ class SearchAdapter : PagedListAdapter<SearchBook, SearchAdapter.MyViewHolder>(D
tv_name.text = String.format("%s(%s)", searchBook.name, searchBook.author) tv_name.text = String.format("%s(%s)", searchBook.name, searchBook.author)
tv_lasted.text = context.getString(R.string.book_search_last, searchBook.latestChapterTitle) tv_lasted.text = context.getString(R.string.book_search_last, searchBook.latestChapterTitle)
tv_introduce.text = searchBook.intro 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 { searchBook.coverUrl.let {
ImageLoader.load(context, it)//Glide自动识别http://和file:// ImageLoader.load(context, it)//Glide自动识别http://和file://
.placeholder(R.drawable.img_cover_default) .placeholder(R.drawable.img_cover_default)

@ -23,8 +23,8 @@ fun String?.htmlFormat(): String = if (this.isNullOrBlank()) "" else
.replace("^[\\n\\s]+".toRegex(), "  ")//移除开头空行,并增加段前缩进2个汉字 .replace("^[\\n\\s]+".toRegex(), "  ")//移除开头空行,并增加段前缩进2个汉字
.replace("[\\n\\s]+$".toRegex(), "") //移除尾部空行 .replace("[\\n\\s]+$".toRegex(), "") //移除尾部空行
fun String.splitNotBlank(delimiter: String): Array<String> = run { fun String.splitNotBlank(vararg delimiter: String): Array<String> = run {
this.split(delimiter).map { it.trim() }.filterNot { it.isBlank() }.toTypedArray() this.split(*delimiter).map { it.trim() }.filterNot { it.isBlank() }.toTypedArray()
} }
fun String.splitNotBlank(regex: Regex, limit: Int = 0): Array<String> = run { fun String.splitNotBlank(regex: Regex, limit: Int = 0): Array<String> = run {

@ -7,8 +7,8 @@
<io.legado.app.ui.widget.image.CoverImageView <io.legado.app.ui.widget.image.CoverImageView
android:id="@+id/iv_cover" android:id="@+id/iv_cover"
android:layout_width="60dp" android:layout_width="70dp"
android:layout_height="80dp" android:layout_height="100dp"
android:layout_margin="8dp" android:layout_margin="8dp"
android:contentDescription="@string/img_cover" android:contentDescription="@string/img_cover"
android:scaleType="centerCrop" android:scaleType="centerCrop"
@ -50,6 +50,8 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginEnd="6dp" android:layout_marginEnd="6dp"
android:paddingLeft="3dp"
android:paddingRight="3dp"
android:singleLine="true" android:singleLine="true"
android:text="@string/app_name" /> android:text="@string/app_name" />
@ -58,6 +60,8 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginEnd="6dp" android:layout_marginEnd="6dp"
android:paddingLeft="3dp"
android:paddingRight="3dp"
android:singleLine="true" android:singleLine="true"
android:text="@string/app_name" /> android:text="@string/app_name" />
@ -66,6 +70,8 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginEnd="6dp" android:layout_marginEnd="6dp"
android:paddingLeft="3dp"
android:paddingRight="3dp"
android:singleLine="true" android:singleLine="true"
android:text="@string/app_name" /> android:text="@string/app_name" />
@ -85,10 +91,8 @@
<TextView <TextView
android:id="@+id/tv_introduce" android:id="@+id/tv_introduce"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="0dp" android:layout_height="wrap_content"
android:layout_weight="1"
android:ellipsize="end" android:ellipsize="end"
android:lines="1"
android:text="简介" android:text="简介"
android:textColor="@color/tv_text_default" android:textColor="@color/tv_text_default"
android:textSize="12sp" /> android:textSize="12sp" />

Loading…
Cancel
Save