From a78ad090346e123e027bba21e14780f926a605ec Mon Sep 17 00:00:00 2001 From: gedoor Date: Thu, 6 Jan 2022 21:12:40 +0800 Subject: [PATCH 1/5] =?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/src/main/res/layout/item_chapter_list.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/res/layout/item_chapter_list.xml b/app/src/main/res/layout/item_chapter_list.xml index 0ff88dbdd..f51671428 100644 --- a/app/src/main/res/layout/item_chapter_list.xml +++ b/app/src/main/res/layout/item_chapter_list.xml @@ -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" From b5670d83390dba4e46c4032513e49ce4c573f574 Mon Sep 17 00:00:00 2001 From: gedoor Date: Thu, 6 Jan 2022 22:16:32 +0800 Subject: [PATCH 2/5] =?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 From c702df43c1459f0011f39458a3353b89bbc8e9ac Mon Sep 17 00:00:00 2001 From: gedoor Date: Thu, 6 Jan 2022 23:17:59 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/io/legado/app/help/IntentData.kt | 3 ++- .../legado/app/ui/book/read/ReadBookActivity.kt | 11 +++++++---- .../io/legado/app/ui/book/read/SearchMenu.kt | 16 +++++----------- .../book/searchContent/SearchContentActivity.kt | 6 ++++++ 4 files changed, 20 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/IntentData.kt b/app/src/main/java/io/legado/app/help/IntentData.kt index 2ce48bde3..474a88bc8 100644 --- a/app/src/main/java/io/legado/app/help/IntentData.kt +++ b/app/src/main/java/io/legado/app/help/IntentData.kt @@ -5,10 +5,11 @@ object IntentData { private val bigData: MutableMap = mutableMapOf() @Synchronized - fun put(key: String, data: Any?) { + fun put(key: String, data: Any?): String { data?.let { bigData[key] = data } + return key } @Synchronized 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 cdfabc26a..b8df716c3 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,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$key") + val searchResultList = IntentData.get>("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() 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 fd89dc2e6..7a9519109 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 @@ -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.* @@ -46,7 +45,7 @@ class SearchMenu @JvmOverloads constructor( private val hasSearchResult: Boolean get() = searchResultList.isNotEmpty() val selectedSearchResult: SearchResult? - get() = if (searchResultList.isNotEmpty()) searchResultList[currentSearchResultIndex] else null + get() = searchResultList.getOrNull(currentSearchResultIndex) val previousSearchResult: SearchResult get() = searchResultList[lastSearchResultIndex] @@ -55,17 +54,12 @@ class SearchMenu @JvmOverloads constructor( initView() bindEvent() updateSearchInfo() - observeSearchResultList() } - private fun observeSearchResultList() { - activity?.let { owner -> - eventObservable>(EventBus.SEARCH_RESULT).observe(owner, { - searchResultList.clear() - searchResultList.addAll(it) - updateSearchInfo() - }) - } + fun upSearchResultList(resultList: List) { + searchResultList.clear() + searchResultList.addAll(resultList) + updateSearchInfo() } private fun initView() = binding.run { diff --git a/app/src/main/java/io/legado/app/ui/book/searchContent/SearchContentActivity.kt b/app/src/main/java/io/legado/app/ui/book/searchContent/SearchContentActivity.kt index 274cc4fd3..d91dc2719 100644 --- a/app/src/main/java/io/legado/app/ui/book/searchContent/SearchContentActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/searchContent/SearchContentActivity.kt @@ -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,6 +166,11 @@ class SearchContentActivity : override fun openSearchResult(searchResult: SearchResult) { postEvent(EventBus.SEARCH_RESULT, viewModel.searchResultList as List) 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("chapterIndex", searchResult.chapterIndex) searchData.putExtra("contentPosition", searchResult.queryIndexInChapter) From 69979321bcbc4959d5551794b50758d6d1f86d07 Mon Sep 17 00:00:00 2001 From: gedoor Date: Thu, 6 Jan 2022 23:18:19 +0800 Subject: [PATCH 4/5] =?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/searchContent/SearchContentActivity.kt | 6 ------ 1 file changed, 6 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/searchContent/SearchContentActivity.kt b/app/src/main/java/io/legado/app/ui/book/searchContent/SearchContentActivity.kt index d91dc2719..a4bbfbbd2 100644 --- a/app/src/main/java/io/legado/app/ui/book/searchContent/SearchContentActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/searchContent/SearchContentActivity.kt @@ -170,12 +170,6 @@ class SearchContentActivity : IntentData.put("searchResult$key", searchResult) IntentData.put("searchResultList$key", viewModel.searchResultList) searchData.putExtra("key", key) - - 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) setResult(RESULT_OK, searchData) finish() } From c20b2b3cc941b3f990a7caf44ac18fe257f18bee Mon Sep 17 00:00:00 2001 From: gedoor Date: Thu, 6 Jan 2022 23:43:52 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/io/legado/app/ui/book/read/ReadBookActivity.kt | 2 +- app/src/main/java/io/legado/app/ui/book/read/SearchMenu.kt | 4 ++-- 2 files changed, 3 insertions(+), 3 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 b8df716c3..f32b9a991 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 @@ -938,7 +938,7 @@ class ReadBookActivity : BaseReadBookActivity(), } } - if (previousResult.chapterIndex != searchResult.chapterIndex) { + if (searchResult.chapterIndex != previousResult?.chapterIndex) { viewModel.openChapter(searchResult.chapterIndex) { jumpToPosition() } 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 7a9519109..3e6a444d0 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 @@ -46,8 +46,8 @@ class SearchMenu @JvmOverloads constructor( get() = searchResultList.isNotEmpty() val selectedSearchResult: SearchResult? get() = searchResultList.getOrNull(currentSearchResultIndex) - val previousSearchResult: SearchResult - get() = searchResultList[lastSearchResultIndex] + val previousSearchResult: SearchResult? + get() = searchResultList.getOrNull(lastSearchResultIndex) init { initAnimation()