|
|
@ -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 -> |
|
|
|
|
|
|
|
eventObservable<List<SearchResult>>(EventBus.SEARCH_RESULT).observe(owner, { |
|
|
|
|
|
|
|
searchResultList.clear() |
|
|
|
searchResultList.clear() |
|
|
|
searchResultList.addAll(it) |
|
|
|
searchResultList.addAll(resultList) |
|
|
|
updateSearchInfo() |
|
|
|
updateSearchInfo() |
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun initView() = binding.run { |
|
|
|
private fun initView() = binding.run { |
|
|
@ -104,9 +101,11 @@ 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}""" |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -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]) |
|
|
|