From b5670d83390dba4e46c4032513e49ce4c573f574 Mon Sep 17 00:00:00 2001 From: gedoor Date: Thu, 6 Jan 2022 22:16:32 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/book/read/ReadBookActivity.kt | 2 +- .../io/legado/app/ui/book/read/SearchMenu.kt | 28 +++++++++---------- .../searchContent/SearchContentAdapter.kt | 1 - .../searchContent/SearchContentViewModel.kt | 1 - 4 files changed, 14 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt index 519388b52..cdfabc26a 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt @@ -99,7 +99,7 @@ class ReadBookActivity : BaseReadBookActivity(), private val searchContentActivity = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { it ?: return@registerForActivityResult it.data?.let { data -> - data.getIntExtra("chapterIndex", ReadBook.durChapterIndex).let { _ -> + data.getIntExtra("chapterIndex", ReadBook.durChapterIndex).let { viewModel.searchContentQuery = data.getStringExtra("query") ?: "" val searchResultIndex = data.getIntExtra("searchResultIndex", 0) isShowingSearchResult = true diff --git a/app/src/main/java/io/legado/app/ui/book/read/SearchMenu.kt b/app/src/main/java/io/legado/app/ui/book/read/SearchMenu.kt index 6e176c437..fd89dc2e6 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/SearchMenu.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/SearchMenu.kt @@ -29,12 +29,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 = mutableListOf() @@ -104,18 +107,20 @@ 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}""" } } fun updateSearchResultIndex(updateIndex: Int) { lastSearchResultIndex = currentSearchResultIndex currentSearchResultIndex = when { - updateIndex < 0 -> 0 + updateIndex < 0 -> 0 updateIndex >= searchResultList.size -> searchResultList.size - 1 - else -> updateIndex + else -> updateIndex } } @@ -143,13 +148,6 @@ class SearchMenu @JvmOverloads constructor( } } - //设置 -// llSetting.setOnClickListener { -// runMenuOut { -// callBack.showSearchSetting() -// } -// } - fabLeft.setOnClickListener { updateSearchResultIndex(currentSearchResultIndex - 1) callBack.navigateToSearch(searchResultList[currentSearchResultIndex]) @@ -192,8 +190,8 @@ class SearchMenu @JvmOverloads constructor( root.padding = 0 when (activity?.navigationBarGravity) { Gravity.BOTTOM -> root.bottomPadding = navigationBarHeight - Gravity.LEFT -> root.leftPadding = navigationBarHeight - Gravity.RIGHT -> root.rightPadding = navigationBarHeight + Gravity.LEFT -> root.leftPadding = navigationBarHeight + Gravity.RIGHT -> root.rightPadding = navigationBarHeight } } callBack.upSystemUiVisibility() diff --git a/app/src/main/java/io/legado/app/ui/book/searchContent/SearchContentAdapter.kt b/app/src/main/java/io/legado/app/ui/book/searchContent/SearchContentAdapter.kt index 364e7daaf..426f50864 100644 --- a/app/src/main/java/io/legado/app/ui/book/searchContent/SearchContentAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/searchContent/SearchContentAdapter.kt @@ -14,7 +14,6 @@ import io.legado.app.utils.hexString class SearchContentAdapter(context: Context, val callback: Callback) : RecyclerAdapter(context) { - val cacheFileNames = hashSetOf() val textColor = context.getCompatColor(R.color.primaryText).hexString.substring(2) val accentColor = context.accentColor.hexString.substring(2) diff --git a/app/src/main/java/io/legado/app/ui/book/searchContent/SearchContentViewModel.kt b/app/src/main/java/io/legado/app/ui/book/searchContent/SearchContentViewModel.kt index 6489e2852..f745dae5a 100644 --- a/app/src/main/java/io/legado/app/ui/book/searchContent/SearchContentViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/searchContent/SearchContentViewModel.kt @@ -21,7 +21,6 @@ class SearchContentViewModel(application: Application) : BaseViewModel(applicati var searchResultCounts = 0 val cacheChapterNames = hashSetOf() val searchResultList: MutableList = mutableListOf() - var selectedIndex = 0 fun initBook(bookUrl: String, success: () -> Unit) { this.bookUrl = bookUrl