Merge remote-tracking branch 'upstream/master'

pull/1502/head
Xwite 3 years ago
commit 61708f1e1c
  1. 3
      app/src/main/java/io/legado/app/help/IntentData.kt
  2. 13
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
  3. 36
      app/src/main/java/io/legado/app/ui/book/read/SearchMenu.kt
  4. 10
      app/src/main/java/io/legado/app/ui/book/searchContent/SearchContentActivity.kt
  5. 1
      app/src/main/java/io/legado/app/ui/book/searchContent/SearchContentAdapter.kt
  6. 1
      app/src/main/java/io/legado/app/ui/book/searchContent/SearchContentViewModel.kt
  7. 1
      app/src/main/res/layout/item_chapter_list.xml

@ -5,10 +5,11 @@ object IntentData {
private val bigData: MutableMap<String, Any> = mutableMapOf()
@Synchronized
fun put(key: String, data: Any?) {
fun put(key: String, data: Any?): String {
data?.let {
bigData[key] = data
}
return key
}
@Synchronized

@ -99,11 +99,14 @@ class ReadBookActivity : BaseReadBookActivity(),
private val searchContentActivity = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
it ?: return@registerForActivityResult
it.data?.let { data ->
data.getIntExtra("chapterIndex", ReadBook.durChapterIndex).let { _ ->
viewModel.searchContentQuery = data.getStringExtra("query") ?: ""
val searchResultIndex = data.getIntExtra("searchResultIndex", 0)
val key = data.getLongExtra("key", System.currentTimeMillis())
val searchResult = IntentData.get<SearchResult>("searchResult$key")
val searchResultList = IntentData.get<List<SearchResult>>("searchResultList$key")
if (searchResult != null && searchResultList != null) {
viewModel.searchContentQuery = searchResult.query
binding.searchMenu.upSearchResultList(searchResultList)
isShowingSearchResult = true
binding.searchMenu.updateSearchResultIndex(searchResultIndex)
binding.searchMenu.updateSearchResultIndex(searchResultList.indexOf(searchResult))
binding.searchMenu.selectedSearchResult?.let { currentResult ->
skipToSearch(currentResult)
showActionMenu()
@ -935,7 +938,7 @@ class ReadBookActivity : BaseReadBookActivity(),
}
}
if (previousResult.chapterIndex != searchResult.chapterIndex) {
if (searchResult.chapterIndex != previousResult?.chapterIndex) {
viewModel.openChapter(searchResult.chapterIndex) {
jumpToPosition()
}

@ -10,7 +10,6 @@ import android.view.animation.Animation
import android.widget.FrameLayout
import androidx.core.view.isVisible
import io.legado.app.R
import io.legado.app.constant.EventBus
import io.legado.app.databinding.ViewSearchMenuBinding
import io.legado.app.help.*
import io.legado.app.lib.theme.*
@ -29,12 +28,15 @@ class SearchMenu @JvmOverloads constructor(
private val callBack: CallBack get() = activity as CallBack
private val binding = ViewSearchMenuBinding.inflate(LayoutInflater.from(context), this, true)
private val menuBottomIn: Animation = AnimationUtilsSupport.loadAnimation(context, R.anim.anim_readbook_bottom_in)
private val menuBottomOut: Animation = AnimationUtilsSupport.loadAnimation(context, R.anim.anim_readbook_bottom_out)
private val menuBottomIn: Animation =
AnimationUtilsSupport.loadAnimation(context, R.anim.anim_readbook_bottom_in)
private val menuBottomOut: Animation =
AnimationUtilsSupport.loadAnimation(context, R.anim.anim_readbook_bottom_out)
private val bgColor: Int = context.bottomBackground
private val textColor: Int = context.getPrimaryTextColor(ColorUtils.isColorLight(bgColor))
private val bottomBackgroundList: ColorStateList =
Selector.colorBuild().setDefaultColor(bgColor).setPressedColor(ColorUtils.darkenColor(bgColor)).create()
Selector.colorBuild().setDefaultColor(bgColor)
.setPressedColor(ColorUtils.darkenColor(bgColor)).create()
private var onMenuOutEnd: (() -> Unit)? = null
private val searchResultList: MutableList<SearchResult> = mutableListOf()
@ -43,26 +45,21 @@ class SearchMenu @JvmOverloads constructor(
private val hasSearchResult: Boolean
get() = searchResultList.isNotEmpty()
val selectedSearchResult: SearchResult?
get() = if (searchResultList.isNotEmpty()) searchResultList[currentSearchResultIndex] else null
val previousSearchResult: SearchResult
get() = searchResultList[lastSearchResultIndex]
get() = searchResultList.getOrNull(currentSearchResultIndex)
val previousSearchResult: SearchResult?
get() = searchResultList.getOrNull(lastSearchResultIndex)
init {
initAnimation()
initView()
bindEvent()
updateSearchInfo()
observeSearchResultList()
}
private fun observeSearchResultList() {
activity?.let { owner ->
eventObservable<List<SearchResult>>(EventBus.SEARCH_RESULT).observe(owner, {
fun upSearchResultList(resultList: List<SearchResult>) {
searchResultList.clear()
searchResultList.addAll(it)
searchResultList.addAll(resultList)
updateSearchInfo()
})
}
}
private fun initView() = binding.run {
@ -104,9 +101,11 @@ class SearchMenu @JvmOverloads constructor(
}
}
@SuppressLint("SetTextI18n")
fun updateSearchInfo() {
ReadBook.curTextChapter?.let {
binding.tvCurrentSearchInfo.text = context.getString(R.string.search_content_size) + ": ${searchResultList.size} / 当前章节: ${it.title}"
binding.tvCurrentSearchInfo.text =
"""${context.getString(R.string.search_content_size)}: ${searchResultList.size} / 当前章节: ${it.title}"""
}
}
@ -143,13 +142,6 @@ class SearchMenu @JvmOverloads constructor(
}
}
//设置
// llSetting.setOnClickListener {
// runMenuOut {
// callBack.showSearchSetting()
// }
// }
fabLeft.setOnClickListener {
updateSearchResultIndex(currentSearchResultIndex - 1)
callBack.navigateToSearch(searchResultList[currentSearchResultIndex])

@ -13,6 +13,7 @@ import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookChapter
import io.legado.app.databinding.ActivitySearchContentBinding
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.getPrimaryTextColor
import io.legado.app.lib.theme.primaryTextColor
@ -165,11 +166,10 @@ class SearchContentActivity :
override fun openSearchResult(searchResult: SearchResult) {
postEvent(EventBus.SEARCH_RESULT, viewModel.searchResultList as List<SearchResult>)
val searchData = Intent()
searchData.putExtra("searchResultIndex", viewModel.searchResultList.indexOf(searchResult))
searchData.putExtra("chapterIndex", searchResult.chapterIndex)
searchData.putExtra("contentPosition", searchResult.queryIndexInChapter)
searchData.putExtra("query", searchResult.query)
searchData.putExtra("resultCountWithinChapter", searchResult.resultCountWithinChapter)
val key = System.currentTimeMillis()
IntentData.put("searchResult$key", searchResult)
IntentData.put("searchResultList$key", viewModel.searchResultList)
searchData.putExtra("key", key)
setResult(RESULT_OK, searchData)
finish()
}

@ -14,7 +14,6 @@ import io.legado.app.utils.hexString
class SearchContentAdapter(context: Context, val callback: Callback) :
RecyclerAdapter<SearchResult, ItemSearchListBinding>(context) {
val cacheFileNames = hashSetOf<String>()
val textColor = context.getCompatColor(R.color.primaryText).hexString.substring(2)
val accentColor = context.accentColor.hexString.substring(2)

@ -21,7 +21,6 @@ class SearchContentViewModel(application: Application) : BaseViewModel(applicati
var searchResultCounts = 0
val cacheChapterNames = hashSetOf<String>()
val searchResultList: MutableList<SearchResult> = mutableListOf()
var selectedIndex = 0
fun initBook(bookUrl: String, success: () -> Unit) {
this.bookUrl = bookUrl

@ -12,6 +12,7 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:singleLine="true"
android:ellipsize="marquee"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@+id/iv_checked"

Loading…
Cancel
Save