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. 48
      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() 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()
@ -935,7 +938,7 @@ class ReadBookActivity : BaseReadBookActivity(),
} }
} }
if (previousResult.chapterIndex != searchResult.chapterIndex) { if (searchResult.chapterIndex != previousResult?.chapterIndex) {
viewModel.openChapter(searchResult.chapterIndex) { viewModel.openChapter(searchResult.chapterIndex) {
jumpToPosition() jumpToPosition()
} }

@ -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.*
@ -29,12 +28,15 @@ class SearchMenu @JvmOverloads constructor(
private val callBack: CallBack get() = activity as CallBack private val callBack: CallBack get() = activity as CallBack
private val binding = ViewSearchMenuBinding.inflate(LayoutInflater.from(context), this, true) 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 menuBottomIn: Animation =
private val menuBottomOut: Animation = AnimationUtilsSupport.loadAnimation(context, R.anim.anim_readbook_bottom_out) 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 bgColor: Int = context.bottomBackground
private val textColor: Int = context.getPrimaryTextColor(ColorUtils.isColorLight(bgColor)) private val textColor: Int = context.getPrimaryTextColor(ColorUtils.isColorLight(bgColor))
private val bottomBackgroundList: ColorStateList = 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 var onMenuOutEnd: (() -> Unit)? = null
private val searchResultList: MutableList<SearchResult> = mutableListOf() private val searchResultList: MutableList<SearchResult> = mutableListOf()
@ -43,26 +45,21 @@ 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.getOrNull(lastSearchResultIndex)
init { init {
initAnimation() initAnimation()
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 {
@ -104,18 +101,20 @@ class SearchMenu @JvmOverloads constructor(
} }
} }
@SuppressLint("SetTextI18n")
fun updateSearchInfo() { fun updateSearchInfo() {
ReadBook.curTextChapter?.let { 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}"""
} }
} }
fun updateSearchResultIndex(updateIndex: Int) { fun updateSearchResultIndex(updateIndex: Int) {
lastSearchResultIndex = currentSearchResultIndex lastSearchResultIndex = currentSearchResultIndex
currentSearchResultIndex = when { currentSearchResultIndex = when {
updateIndex < 0 -> 0 updateIndex < 0 -> 0
updateIndex >= searchResultList.size -> searchResultList.size - 1 updateIndex >= searchResultList.size -> searchResultList.size - 1
else -> updateIndex else -> updateIndex
} }
} }
@ -143,13 +142,6 @@ class SearchMenu @JvmOverloads constructor(
} }
} }
//设置
// llSetting.setOnClickListener {
// runMenuOut {
// callBack.showSearchSetting()
// }
// }
fabLeft.setOnClickListener { fabLeft.setOnClickListener {
updateSearchResultIndex(currentSearchResultIndex - 1) updateSearchResultIndex(currentSearchResultIndex - 1)
callBack.navigateToSearch(searchResultList[currentSearchResultIndex]) callBack.navigateToSearch(searchResultList[currentSearchResultIndex])
@ -192,8 +184,8 @@ class SearchMenu @JvmOverloads constructor(
root.padding = 0 root.padding = 0
when (activity?.navigationBarGravity) { when (activity?.navigationBarGravity) {
Gravity.BOTTOM -> root.bottomPadding = navigationBarHeight Gravity.BOTTOM -> root.bottomPadding = navigationBarHeight
Gravity.LEFT -> root.leftPadding = navigationBarHeight Gravity.LEFT -> root.leftPadding = navigationBarHeight
Gravity.RIGHT -> root.rightPadding = navigationBarHeight Gravity.RIGHT -> root.rightPadding = navigationBarHeight
} }
} }
callBack.upSystemUiVisibility() callBack.upSystemUiVisibility()

@ -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,11 +166,10 @@ 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()
searchData.putExtra("searchResultIndex", viewModel.searchResultList.indexOf(searchResult)) val key = System.currentTimeMillis()
searchData.putExtra("chapterIndex", searchResult.chapterIndex) IntentData.put("searchResult$key", searchResult)
searchData.putExtra("contentPosition", searchResult.queryIndexInChapter) IntentData.put("searchResultList$key", viewModel.searchResultList)
searchData.putExtra("query", searchResult.query) searchData.putExtra("key", key)
searchData.putExtra("resultCountWithinChapter", searchResult.resultCountWithinChapter)
setResult(RESULT_OK, searchData) setResult(RESULT_OK, searchData)
finish() finish()
} }

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

@ -21,7 +21,6 @@ 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 selectedIndex = 0
fun initBook(bookUrl: String, success: () -> Unit) { fun initBook(bookUrl: String, success: () -> Unit) {
this.bookUrl = bookUrl this.bookUrl = bookUrl

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

Loading…
Cancel
Save