优化
This commit is contained in:
@@ -3,6 +3,8 @@ package io.legado.app.ui.book.searchContent
|
|||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.view.Menu
|
||||||
|
import android.view.MenuItem
|
||||||
import android.view.MotionEvent
|
import android.view.MotionEvent
|
||||||
import android.widget.EditText
|
import android.widget.EditText
|
||||||
import androidx.activity.viewModels
|
import androidx.activity.viewModels
|
||||||
@@ -18,7 +20,6 @@ import io.legado.app.data.entities.BookChapter
|
|||||||
import io.legado.app.databinding.ActivitySearchContentBinding
|
import io.legado.app.databinding.ActivitySearchContentBinding
|
||||||
import io.legado.app.help.IntentData
|
import io.legado.app.help.IntentData
|
||||||
import io.legado.app.help.book.BookHelp
|
import io.legado.app.help.book.BookHelp
|
||||||
import io.legado.app.help.book.ContentProcessor
|
|
||||||
import io.legado.app.help.book.isLocal
|
import io.legado.app.help.book.isLocal
|
||||||
import io.legado.app.lib.theme.bottomBackground
|
import io.legado.app.lib.theme.bottomBackground
|
||||||
import io.legado.app.lib.theme.getPrimaryTextColor
|
import io.legado.app.lib.theme.getPrimaryTextColor
|
||||||
@@ -71,6 +72,26 @@ class SearchContentActivity :
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onCompatCreateOptionsMenu(menu: Menu): Boolean {
|
||||||
|
menuInflater.inflate(R.menu.content_search, menu)
|
||||||
|
return super.onCompatCreateOptionsMenu(menu)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onMenuOpened(featureId: Int, menu: Menu): Boolean {
|
||||||
|
menu.findItem(R.id.menu_enable_replace)?.isChecked = viewModel.replaceEnabled
|
||||||
|
return super.onMenuOpened(featureId, menu)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onCompatOptionsItemSelected(item: MenuItem): Boolean {
|
||||||
|
when (item.itemId) {
|
||||||
|
R.id.menu_enable_replace -> {
|
||||||
|
viewModel.replaceEnabled = !viewModel.replaceEnabled
|
||||||
|
item.isChecked = viewModel.replaceEnabled
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return super.onCompatOptionsItemSelected(item)
|
||||||
|
}
|
||||||
|
|
||||||
override fun dispatchTouchEvent(ev: MotionEvent): Boolean {
|
override fun dispatchTouchEvent(ev: MotionEvent): Boolean {
|
||||||
if (ev.action == MotionEvent.ACTION_DOWN) {
|
if (ev.action == MotionEvent.ACTION_DOWN) {
|
||||||
currentFocus?.let {
|
currentFocus?.let {
|
||||||
|
|||||||
@@ -10,9 +10,7 @@ import io.legado.app.data.entities.BookChapter
|
|||||||
import io.legado.app.help.book.BookHelp
|
import io.legado.app.help.book.BookHelp
|
||||||
import io.legado.app.help.book.ContentProcessor
|
import io.legado.app.help.book.ContentProcessor
|
||||||
import io.legado.app.help.config.AppConfig
|
import io.legado.app.help.config.AppConfig
|
||||||
import kotlinx.coroutines.Dispatchers
|
|
||||||
import kotlinx.coroutines.ensureActive
|
import kotlinx.coroutines.ensureActive
|
||||||
import kotlinx.coroutines.withContext
|
|
||||||
import kotlin.coroutines.coroutineContext
|
import kotlin.coroutines.coroutineContext
|
||||||
|
|
||||||
class SearchContentViewModel(application: Application) : BaseViewModel(application) {
|
class SearchContentViewModel(application: Application) : BaseViewModel(application) {
|
||||||
@@ -23,6 +21,7 @@ class SearchContentViewModel(application: Application) : BaseViewModel(applicati
|
|||||||
var searchResultCounts = 0
|
var searchResultCounts = 0
|
||||||
val cacheChapterNames = hashSetOf<String>()
|
val cacheChapterNames = hashSetOf<String>()
|
||||||
val searchResultList: MutableList<SearchResult> = mutableListOf()
|
val searchResultList: MutableList<SearchResult> = mutableListOf()
|
||||||
|
var replaceEnabled = false
|
||||||
|
|
||||||
fun initBook(bookUrl: String, success: () -> Unit) {
|
fun initBook(bookUrl: String, success: () -> Unit) {
|
||||||
this.bookUrl = bookUrl
|
this.bookUrl = bookUrl
|
||||||
@@ -51,7 +50,7 @@ class SearchContentViewModel(application: Application) : BaseViewModel(applicati
|
|||||||
}
|
}
|
||||||
coroutineContext.ensureActive()
|
coroutineContext.ensureActive()
|
||||||
val mContent = contentProcessor!!.getContent(
|
val mContent = contentProcessor!!.getContent(
|
||||||
book, chapter, chapterContent
|
book, chapter, chapterContent, useReplace = replaceEnabled
|
||||||
).toString()
|
).toString()
|
||||||
val positions = searchPosition(mContent, query)
|
val positions = searchPosition(mContent, query)
|
||||||
positions.forEachIndexed { index, position ->
|
positions.forEachIndexed { index, position ->
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
tools:ignore="AlwaysShowAction">
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/menu_enable_replace"
|
||||||
|
android:title="@string/replace"
|
||||||
|
android:checkable="true"
|
||||||
|
app:showAsAction="never" />
|
||||||
|
|
||||||
|
</menu>
|
||||||
Reference in New Issue
Block a user