From 60b5b536bf7a0c61b492d2828ba3d276ea92baf2 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sun, 20 Sep 2020 19:29:38 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=AD=A3=E6=96=87=E6=90=9C?= =?UTF-8?q?=E7=B4=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/ui/book/read/ReadBookActivity.kt | 12 +++++++----- .../main/java/io/legado/app/ui/book/read/ReadMenu.kt | 4 ++-- .../app/ui/book/searchContent/SearchListActivity.kt | 11 ++++++----- .../app/ui/book/searchContent/SearchListViewModel.kt | 10 ---------- app/src/main/res/menu/content_select_action.xml | 4 ++++ app/src/main/res/values-zh-rHK/strings.xml | 2 +- app/src/main/res/values-zh-rTW/strings.xml | 3 +-- app/src/main/res/values-zh/strings.xml | 2 +- app/src/main/res/values/strings.xml | 2 +- 9 files changed, 23 insertions(+), 27 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 7120e047a..53a549425 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 @@ -9,7 +9,6 @@ import android.graphics.drawable.ColorDrawable import android.net.Uri import android.os.Bundle import android.os.Handler -import android.util.Log import android.view.* import android.view.ViewGroup.LayoutParams.WRAP_CONTENT import androidx.core.view.get @@ -49,7 +48,6 @@ import io.legado.app.ui.book.read.page.PageView import io.legado.app.ui.book.read.page.TextPageFactory import io.legado.app.ui.book.read.page.delegate.PageDelegate import io.legado.app.ui.book.searchContent.SearchListActivity -import io.legado.app.ui.book.searchContent.SearchResult import io.legado.app.ui.book.source.edit.BookSourceEditActivity import io.legado.app.ui.login.SourceLogin import io.legado.app.ui.replacerule.ReplaceRuleActivity @@ -496,6 +494,10 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo ) return true } + R.id.menu_search_content -> { + openSearchActivity(selectedText) + return true + } } return false } @@ -680,12 +682,12 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo /** * 打开搜索界面 */ - //todo: change request code - override fun openSearchList() { + override fun openSearchActivity(searchWord: String?) { ReadBook.book?.let { startActivityForResult( requestCodeSearchResult, - Pair("bookUrl", it.bookUrl) + Pair("bookUrl", it.bookUrl), + Pair("searchWord", searchWord) ) } } diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt index bef8898ee..a532bac2a 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt @@ -175,7 +175,7 @@ class ReadMenu : FrameLayout { //搜索 fabSearch.onClick { runMenuOut { - callBack?.openSearchList() + callBack?.openSearchActivity(null) } } @@ -300,7 +300,7 @@ class ReadMenu : FrameLayout { fun autoPage() fun openReplaceRule() fun openChapterList() - fun openSearchList() + fun openSearchActivity(searchWord: String?) fun showReadStyle() fun showMoreSetting() fun showReadAloudDialog() diff --git a/app/src/main/java/io/legado/app/ui/book/searchContent/SearchListActivity.kt b/app/src/main/java/io/legado/app/ui/book/searchContent/SearchListActivity.kt index 12079695d..6c01801c3 100644 --- a/app/src/main/java/io/legado/app/ui/book/searchContent/SearchListActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/searchContent/SearchListActivity.kt @@ -29,8 +29,7 @@ import org.jetbrains.anko.sdk27.listeners.onClick class SearchListActivity : VMBaseActivity(R.layout.activity_search_list), - SearchListAdapter.Callback, - SearchListViewModel.SearchListCallBack { + SearchListAdapter.Callback { override val viewModel: SearchListViewModel get() = getViewModel(SearchListViewModel::class.java) @@ -42,7 +41,6 @@ class SearchListActivity : VMBaseActivity(R.layout.activity private var searchResultList: MutableList = mutableListOf() override fun onActivityCreated(savedInstanceState: Bundle?) { - viewModel.searchCallBack = this val bbg = bottomBackground val btc = getPrimaryTextColor(ColorUtils.isColorLight(bbg)) ll_search_base_info.setBackgroundColor(bbg) @@ -68,7 +66,7 @@ class SearchListActivity : VMBaseActivity(R.layout.activity search_view.setOnQueryTextListener(object : SearchView.OnQueryTextListener { override fun onQueryTextSubmit(query: String): Boolean { if (viewModel.lastQuery != query) { - viewModel.startContentSearch(query) + startContentSearch(query) } return false } @@ -103,6 +101,9 @@ class SearchListActivity : VMBaseActivity(R.layout.activity viewModel.book?.let { initCacheFileNames(it) durChapterIndex = it.durChapterIndex + intent.getStringExtra("searchWord")?.let { searchWord -> + search_view.setQuery(searchWord, true) + } } } } @@ -128,7 +129,7 @@ class SearchListActivity : VMBaseActivity(R.layout.activity } @SuppressLint("SetTextI18n") - override fun startContentSearch(newText: String) { + fun startContentSearch(newText: String) { // 按章节搜索内容 if (!newText.isBlank()) { adapter.clearItems() diff --git a/app/src/main/java/io/legado/app/ui/book/searchContent/SearchListViewModel.kt b/app/src/main/java/io/legado/app/ui/book/searchContent/SearchListViewModel.kt index 060d74067..0b8cd1259 100644 --- a/app/src/main/java/io/legado/app/ui/book/searchContent/SearchListViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/searchContent/SearchListViewModel.kt @@ -9,7 +9,6 @@ import io.legado.app.data.entities.Book class SearchListViewModel(application: Application) : BaseViewModel(application) { var bookUrl: String = "" var book: Book? = null - var searchCallBack: SearchListCallBack? = null var lastQuery: String = "" fun initBook(bookUrl: String, success: () -> Unit) { @@ -21,13 +20,4 @@ class SearchListViewModel(application: Application) : BaseViewModel(application) } } - fun startContentSearch(newText: String) { - searchCallBack?.startContentSearch(newText) - } - - - interface SearchListCallBack { - fun startContentSearch(newText: String) - } - } \ No newline at end of file diff --git a/app/src/main/res/menu/content_select_action.xml b/app/src/main/res/menu/content_select_action.xml index ff83efd96..692f1092f 100644 --- a/app/src/main/res/menu/content_select_action.xml +++ b/app/src/main/res/menu/content_select_action.xml @@ -13,6 +13,10 @@ android:id="@+id/menu_aloud" android:title="@string/read_aloud" /> + + diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index eac3f655b..2e7d44236 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -766,6 +766,6 @@ 切換默認主題 分享選中書源 時間排序 - 搜索 + 全文搜索 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 25fe6e740..d7d39b40c 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -766,7 +766,6 @@ 切換默認主題 分享選中書源 時間排序 - 搜索 - + 全文搜索 diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index 3da57c6c5..8e4821f0a 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -769,6 +769,6 @@ 使用保存主题,导入,分享主题 切换默认主题 时间排序 - 搜索 + 全文搜索 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 46e2c5304..77e490b8c 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -771,6 +771,6 @@ Save, Import, Share theme Share selected sources Sort by update time - Search + Search content \ No newline at end of file