正文搜索百分比 #300
This commit is contained in:
@@ -211,13 +211,23 @@ class SearchContentActivity :
|
|||||||
kotlin.runCatching {
|
kotlin.runCatching {
|
||||||
appDb.bookChapterDao.getChapterList(viewModel.bookUrl).forEach { bookChapter ->
|
appDb.bookChapterDao.getChapterList(viewModel.bookUrl).forEach { bookChapter ->
|
||||||
ensureActive()
|
ensureActive()
|
||||||
|
val totalChapters = viewModel.book?.totalChapterNum
|
||||||
|
?: appDb.bookChapterDao.getChapterCount(viewModel.bookUrl)
|
||||||
|
|
||||||
val searchResults = if (isLocalBook
|
val searchResults = if (isLocalBook
|
||||||
|| viewModel.cacheChapterNames.contains(bookChapter.getFileName())
|
|| viewModel.cacheChapterNames.contains(bookChapter.getFileName())
|
||||||
) {
|
) {
|
||||||
viewModel.searchChapter(query, bookChapter)
|
viewModel.searchChapter(query, bookChapter).map { result ->
|
||||||
|
if (totalChapters > 0) {
|
||||||
|
result.copy(progressPercent = (bookChapter.index + 1).toFloat() / totalChapters * 100f)
|
||||||
|
} else {
|
||||||
|
result
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return@forEach
|
return@forEach
|
||||||
}
|
}
|
||||||
|
|
||||||
ensureActive()
|
ensureActive()
|
||||||
if (searchResults.isNotEmpty()) {
|
if (searchResults.isNotEmpty()) {
|
||||||
viewModel.searchResultList.addAll(searchResults)
|
viewModel.searchResultList.addAll(searchResults)
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package io.legado.app.ui.book.searchContent
|
|||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
import androidx.core.view.isVisible
|
||||||
import io.legado.app.base.adapter.ItemViewHolder
|
import io.legado.app.base.adapter.ItemViewHolder
|
||||||
import io.legado.app.base.adapter.RecyclerAdapter
|
import io.legado.app.base.adapter.RecyclerAdapter
|
||||||
import io.legado.app.databinding.ItemSearchListBinding
|
import io.legado.app.databinding.ItemSearchListBinding
|
||||||
@@ -31,6 +32,13 @@ class SearchContentAdapter(context: Context, val callback: Callback) :
|
|||||||
tvTitle.text = item.getTitleSpannable(textColorInt)
|
tvTitle.text = item.getTitleSpannable(textColorInt)
|
||||||
tvContent.text = item.getContentSpannable(textColorInt, accentColorInt, bgColorInt)
|
tvContent.text = item.getContentSpannable(textColorInt, accentColorInt, bgColorInt)
|
||||||
|
|
||||||
|
if (item.progressPercent > 0) {
|
||||||
|
cdCount.isVisible = true
|
||||||
|
tvCount.text = String.format("%.1f%%", item.progressPercent)
|
||||||
|
} else {
|
||||||
|
tvCount.isVisible = false
|
||||||
|
}
|
||||||
|
|
||||||
cdRoot.setCardBackgroundColor(
|
cdRoot.setCardBackgroundColor(
|
||||||
if (isDur) context.themeColor(com.google.android.material.R.attr.colorSurfaceContainer)
|
if (isDur) context.themeColor(com.google.android.material.R.attr.colorSurfaceContainer)
|
||||||
else context.themeColor(com.google.android.material.R.attr.colorSurface)
|
else context.themeColor(com.google.android.material.R.attr.colorSurface)
|
||||||
|
|||||||
@@ -20,7 +20,8 @@ data class SearchResult(
|
|||||||
val chapterIndex: Int = 0,
|
val chapterIndex: Int = 0,
|
||||||
val pageIndex: Int = 0,
|
val pageIndex: Int = 0,
|
||||||
val queryIndexInResult: Int = 0,
|
val queryIndexInResult: Int = 0,
|
||||||
val queryIndexInChapter: Int = 0
|
val queryIndexInChapter: Int = 0,
|
||||||
|
val progressPercent: Float = 0f
|
||||||
) {
|
) {
|
||||||
|
|
||||||
fun getTitleSpannable(accentColor: Int): SpannableString {
|
fun getTitleSpannable(accentColor: Int): SpannableString {
|
||||||
|
|||||||
@@ -1,19 +1,15 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<com.google.android.material.listitem.ListItemCardView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
android:orientation="vertical"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_margin="8dp">
|
|
||||||
|
|
||||||
<com.google.android.material.listitem.ListItemCardView
|
|
||||||
android:id="@+id/cd_root"
|
android:id="@+id/cd_root"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:checkable="true"
|
android:checkable="true"
|
||||||
app:cardCornerRadius="16dp">
|
app:cardCornerRadius="16dp"
|
||||||
|
android:layout_margin="8dp">
|
||||||
|
|
||||||
<LinearLayout
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:padding="8dp"
|
android:padding="8dp"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
@@ -21,12 +17,40 @@
|
|||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/tvTitle"
|
android:id="@+id/tvTitle"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:paddingBottom="2dp"
|
android:paddingBottom="2dp"
|
||||||
android:textColor="?attr/colorOnSurface"
|
android:textColor="?attr/colorOnSurface"
|
||||||
android:textStyle="bold"
|
android:textStyle="bold"
|
||||||
android:textSize="14sp"/>
|
android:textSize="14sp"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
|
app:layout_constraintEnd_toStartOf="@id/cd_count"/>
|
||||||
|
|
||||||
|
<com.google.android.material.card.MaterialCardView
|
||||||
|
android:id="@+id/cd_count"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:visibility="visible"
|
||||||
|
app:cardCornerRadius="8dp"
|
||||||
|
app:strokeWidth="0dp"
|
||||||
|
app:cardBackgroundColor="?attr/colorSecondaryVariant"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tv_count"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textColor="?attr/colorOnSecondary"
|
||||||
|
android:textSize="10sp"
|
||||||
|
android:padding="4dp"
|
||||||
|
android:textStyle="bold"
|
||||||
|
android:includeFontPadding="false"
|
||||||
|
tools:text="5"
|
||||||
|
tools:ignore="SmallSp" />
|
||||||
|
|
||||||
|
</com.google.android.material.card.MaterialCardView>
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/tvContent"
|
android:id="@+id/tvContent"
|
||||||
@@ -34,12 +58,11 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:textColor="?attr/colorOnSurface"
|
android:textColor="?attr/colorOnSurface"
|
||||||
android:textSize="13sp"
|
android:textSize="13sp"
|
||||||
android:lineSpacingExtra="2dp"/>
|
android:lineSpacingExtra="2dp"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/tvTitle"/>
|
||||||
|
|
||||||
</LinearLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
|
||||||
</com.google.android.material.listitem.ListItemCardView>
|
</com.google.android.material.listitem.ListItemCardView>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
Reference in New Issue
Block a user