mirror of
https://github.com/gedoor/legado.git
synced 2024-09-01 09:34:25 +08:00
优化
This commit is contained in:
parent
b5670d8339
commit
c702df43c1
@ -5,10 +5,11 @@ object IntentData {
|
|||||||
private val bigData: MutableMap<String, Any> = mutableMapOf()
|
private val bigData: MutableMap<String, Any> = mutableMapOf()
|
||||||
|
|
||||||
@Synchronized
|
@Synchronized
|
||||||
fun put(key: String, data: Any?) {
|
fun put(key: String, data: Any?): String {
|
||||||
data?.let {
|
data?.let {
|
||||||
bigData[key] = data
|
bigData[key] = data
|
||||||
}
|
}
|
||||||
|
return key
|
||||||
}
|
}
|
||||||
|
|
||||||
@Synchronized
|
@Synchronized
|
||||||
|
@ -99,11 +99,14 @@ class ReadBookActivity : BaseReadBookActivity(),
|
|||||||
private val searchContentActivity = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
|
private val searchContentActivity = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
|
||||||
it ?: return@registerForActivityResult
|
it ?: return@registerForActivityResult
|
||||||
it.data?.let { data ->
|
it.data?.let { data ->
|
||||||
data.getIntExtra("chapterIndex", ReadBook.durChapterIndex).let {
|
val key = data.getLongExtra("key", System.currentTimeMillis())
|
||||||
viewModel.searchContentQuery = data.getStringExtra("query") ?: ""
|
val searchResult = IntentData.get<SearchResult>("searchResult$key")
|
||||||
val searchResultIndex = data.getIntExtra("searchResultIndex", 0)
|
val searchResultList = IntentData.get<List<SearchResult>>("searchResultList$key")
|
||||||
|
if (searchResult != null && searchResultList != null) {
|
||||||
|
viewModel.searchContentQuery = searchResult.query
|
||||||
|
binding.searchMenu.upSearchResultList(searchResultList)
|
||||||
isShowingSearchResult = true
|
isShowingSearchResult = true
|
||||||
binding.searchMenu.updateSearchResultIndex(searchResultIndex)
|
binding.searchMenu.updateSearchResultIndex(searchResultList.indexOf(searchResult))
|
||||||
binding.searchMenu.selectedSearchResult?.let { currentResult ->
|
binding.searchMenu.selectedSearchResult?.let { currentResult ->
|
||||||
skipToSearch(currentResult)
|
skipToSearch(currentResult)
|
||||||
showActionMenu()
|
showActionMenu()
|
||||||
|
@ -10,7 +10,6 @@ import android.view.animation.Animation
|
|||||||
import android.widget.FrameLayout
|
import android.widget.FrameLayout
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
import io.legado.app.R
|
import io.legado.app.R
|
||||||
import io.legado.app.constant.EventBus
|
|
||||||
import io.legado.app.databinding.ViewSearchMenuBinding
|
import io.legado.app.databinding.ViewSearchMenuBinding
|
||||||
import io.legado.app.help.*
|
import io.legado.app.help.*
|
||||||
import io.legado.app.lib.theme.*
|
import io.legado.app.lib.theme.*
|
||||||
@ -46,7 +45,7 @@ class SearchMenu @JvmOverloads constructor(
|
|||||||
private val hasSearchResult: Boolean
|
private val hasSearchResult: Boolean
|
||||||
get() = searchResultList.isNotEmpty()
|
get() = searchResultList.isNotEmpty()
|
||||||
val selectedSearchResult: SearchResult?
|
val selectedSearchResult: SearchResult?
|
||||||
get() = if (searchResultList.isNotEmpty()) searchResultList[currentSearchResultIndex] else null
|
get() = searchResultList.getOrNull(currentSearchResultIndex)
|
||||||
val previousSearchResult: SearchResult
|
val previousSearchResult: SearchResult
|
||||||
get() = searchResultList[lastSearchResultIndex]
|
get() = searchResultList[lastSearchResultIndex]
|
||||||
|
|
||||||
@ -55,17 +54,12 @@ class SearchMenu @JvmOverloads constructor(
|
|||||||
initView()
|
initView()
|
||||||
bindEvent()
|
bindEvent()
|
||||||
updateSearchInfo()
|
updateSearchInfo()
|
||||||
observeSearchResultList()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun observeSearchResultList() {
|
fun upSearchResultList(resultList: List<SearchResult>) {
|
||||||
activity?.let { owner ->
|
searchResultList.clear()
|
||||||
eventObservable<List<SearchResult>>(EventBus.SEARCH_RESULT).observe(owner, {
|
searchResultList.addAll(resultList)
|
||||||
searchResultList.clear()
|
updateSearchInfo()
|
||||||
searchResultList.addAll(it)
|
|
||||||
updateSearchInfo()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun initView() = binding.run {
|
private fun initView() = binding.run {
|
||||||
|
@ -13,6 +13,7 @@ import io.legado.app.data.entities.Book
|
|||||||
import io.legado.app.data.entities.BookChapter
|
import io.legado.app.data.entities.BookChapter
|
||||||
import io.legado.app.databinding.ActivitySearchContentBinding
|
import io.legado.app.databinding.ActivitySearchContentBinding
|
||||||
import io.legado.app.help.BookHelp
|
import io.legado.app.help.BookHelp
|
||||||
|
import io.legado.app.help.IntentData
|
||||||
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
|
||||||
import io.legado.app.lib.theme.primaryTextColor
|
import io.legado.app.lib.theme.primaryTextColor
|
||||||
@ -165,6 +166,11 @@ class SearchContentActivity :
|
|||||||
override fun openSearchResult(searchResult: SearchResult) {
|
override fun openSearchResult(searchResult: SearchResult) {
|
||||||
postEvent(EventBus.SEARCH_RESULT, viewModel.searchResultList as List<SearchResult>)
|
postEvent(EventBus.SEARCH_RESULT, viewModel.searchResultList as List<SearchResult>)
|
||||||
val searchData = Intent()
|
val searchData = Intent()
|
||||||
|
val key = System.currentTimeMillis()
|
||||||
|
IntentData.put("searchResult$key", searchResult)
|
||||||
|
IntentData.put("searchResultList$key", viewModel.searchResultList)
|
||||||
|
searchData.putExtra("key", key)
|
||||||
|
|
||||||
searchData.putExtra("searchResultIndex", viewModel.searchResultList.indexOf(searchResult))
|
searchData.putExtra("searchResultIndex", viewModel.searchResultList.indexOf(searchResult))
|
||||||
searchData.putExtra("chapterIndex", searchResult.chapterIndex)
|
searchData.putExtra("chapterIndex", searchResult.chapterIndex)
|
||||||
searchData.putExtra("contentPosition", searchResult.queryIndexInChapter)
|
searchData.putExtra("contentPosition", searchResult.queryIndexInChapter)
|
||||||
|
Loading…
Reference in New Issue
Block a user