Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -13,6 +13,7 @@ import io.legado.app.utils.getPrefBoolean
|
|||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.ExecutorCoroutineDispatcher
|
import kotlinx.coroutines.ExecutorCoroutineDispatcher
|
||||||
import kotlinx.coroutines.asCoroutineDispatcher
|
import kotlinx.coroutines.asCoroutineDispatcher
|
||||||
|
import kotlinx.coroutines.ensureActive
|
||||||
import kotlinx.coroutines.isActive
|
import kotlinx.coroutines.isActive
|
||||||
import splitties.init.appCtx
|
import splitties.init.appCtx
|
||||||
import java.util.concurrent.Executors
|
import java.util.concurrent.Executors
|
||||||
@@ -76,7 +77,7 @@ class SearchModel(private val scope: CoroutineScope, private val callBack: CallB
|
|||||||
}
|
}
|
||||||
searchIndex++
|
searchIndex++
|
||||||
val source = bookSourceList[searchIndex]
|
val source = bookSourceList[searchIndex]
|
||||||
searchPool?.let { searchPool ->
|
val searchPool = searchPool ?: return
|
||||||
val task = WebBook.searchBook(
|
val task = WebBook.searchBook(
|
||||||
scope,
|
scope,
|
||||||
source,
|
source,
|
||||||
@@ -86,14 +87,15 @@ class SearchModel(private val scope: CoroutineScope, private val callBack: CallB
|
|||||||
executeContext = searchPool
|
executeContext = searchPool
|
||||||
).timeout(30000L)
|
).timeout(30000L)
|
||||||
.onSuccess {
|
.onSuccess {
|
||||||
|
ensureActive()
|
||||||
onSuccess(searchId, it)
|
onSuccess(searchId, it)
|
||||||
}
|
}
|
||||||
.onFinally {
|
.onFinally {
|
||||||
|
ensureActive()
|
||||||
onFinally(searchId)
|
onFinally(searchId)
|
||||||
}
|
}
|
||||||
tasks.add(task)
|
tasks.add(task)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Synchronized
|
@Synchronized
|
||||||
private fun onSuccess(searchId: Long, items: ArrayList<SearchBook>) {
|
private fun onSuccess(searchId: Long, items: ArrayList<SearchBook>) {
|
||||||
|
|||||||
@@ -282,18 +282,16 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
|
|||||||
private fun receiptIntent(intent: Intent? = null) {
|
private fun receiptIntent(intent: Intent? = null) {
|
||||||
val searchScope = intent?.getStringExtra("searchScope")
|
val searchScope = intent?.getStringExtra("searchScope")
|
||||||
searchScope?.let {
|
searchScope?.let {
|
||||||
viewModel.searchScope.update(searchScope)
|
viewModel.searchScope.update(searchScope, false)
|
||||||
}
|
}
|
||||||
val key = intent?.getStringExtra("key")
|
val key = intent?.getStringExtra("key")
|
||||||
if (key.isNullOrBlank()) {
|
if (key.isNullOrBlank()) {
|
||||||
searchView.findViewById<TextView>(androidx.appcompat.R.id.search_src_text)
|
searchView.findViewById<TextView>(androidx.appcompat.R.id.search_src_text)
|
||||||
.requestFocus()
|
.requestFocus()
|
||||||
} else {
|
} else {
|
||||||
searchView.post {
|
|
||||||
searchView.setQuery(key, true)
|
searchView.setQuery(key, true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 滚动到底部事件
|
* 滚动到底部事件
|
||||||
|
|||||||
@@ -31,9 +31,9 @@ data class SearchScope(private var scope: String) {
|
|||||||
|
|
||||||
val stateLiveData = MutableLiveData(scope)
|
val stateLiveData = MutableLiveData(scope)
|
||||||
|
|
||||||
fun update(scope: String) {
|
fun update(scope: String, postValue: Boolean = true) {
|
||||||
this.scope = scope
|
this.scope = scope
|
||||||
stateLiveData.postValue(scope)
|
if (postValue) stateLiveData.postValue(scope)
|
||||||
save()
|
save()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user