From c1daabd898c356f07604cfbf915315d6cd6037a5 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 17 Mar 2022 11:17:06 +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 --- .../changesource/ChangeBookSourceDialog.kt | 12 ++++++++-- .../changesource/ChangeChapterSourceDialog.kt | 22 ++++++++++++++----- .../res/layout/dialog_book_change_source.xml | 13 ++++++----- app/src/main/res/menu/change_source.xml | 5 +++++ app/src/main/res/values-es-rES/strings.xml | 1 + app/src/main/res/values-ja-rJP/strings.xml | 1 + app/src/main/res/values-pt-rBR/strings.xml | 1 + app/src/main/res/values-zh-rHK/strings.xml | 1 + app/src/main/res/values-zh-rTW/strings.xml | 1 + app/src/main/res/values-zh/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + 11 files changed, 45 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeBookSourceDialog.kt b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeBookSourceDialog.kt index 996786d68..c671a7355 100644 --- a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeBookSourceDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeBookSourceDialog.kt @@ -10,7 +10,6 @@ import androidx.appcompat.widget.Toolbar import androidx.core.os.bundleOf import androidx.fragment.app.viewModels import androidx.lifecycle.lifecycleScope -import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import io.legado.app.R import io.legado.app.base.BaseDialogFragment @@ -88,7 +87,6 @@ class ChangeBookSourceDialog() : BaseDialogFragment(R.layout.dialog_book_change_ } private fun initRecyclerView() { - binding.recyclerView.layoutManager = LinearLayoutManager(context) binding.recyclerView.addItemDecoration(VerticalDivider(requireContext())) binding.recyclerView.adapter = adapter adapter.registerAdapterDataObserver(object : RecyclerView.AdapterDataObserver() { @@ -167,6 +165,7 @@ class ChangeBookSourceDialog() : BaseDialogFragment(R.layout.dialog_book_change_ override fun onMenuItemClick(item: MenuItem?): Boolean { when (item?.itemId) { + R.id.menu_scroll_to_dur -> scrollToDurSource() R.id.menu_check_author -> { AppConfig.changeSourceCheckAuthor = !item.isChecked item.isChecked = !item.isChecked @@ -198,6 +197,15 @@ class ChangeBookSourceDialog() : BaseDialogFragment(R.layout.dialog_book_change_ return false } + private fun scrollToDurSource() { + adapter.getItems().forEachIndexed { index, searchBook -> + if (searchBook.bookUrl == bookUrl) { + binding.recyclerView.scrollToPosition(index) + return + } + } + } + override fun changeTo(searchBook: SearchBook) { changeSource(searchBook) dismissAllowingStateLoss() diff --git a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeChapterSourceDialog.kt b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeChapterSourceDialog.kt index 8e433127e..d32fb8e9f 100644 --- a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeChapterSourceDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeChapterSourceDialog.kt @@ -59,6 +59,12 @@ class ChangeChapterSourceDialog() : BaseDialogFragment(R.layout.dialog_chapter_c registerForActivityResult(StartActivityContract(BookSourceEditActivity::class.java)) { viewModel.startSearch() } + private val searchBookAdapter by lazy { + ChangeChapterSourceAdapter(requireContext(), viewModel, this) + } + private val tocAdapter by lazy { + ChangeChapterTocAdapter(requireContext(), this) + } private val tocSuccess: (toc: List) -> Unit = { tocAdapter.durChapterIndex = BookHelp.getDurChapter(viewModel.chapterIndex, viewModel.chapterTitle, it) @@ -71,12 +77,6 @@ class ChangeChapterSourceDialog() : BaseDialogFragment(R.layout.dialog_chapter_c callBack?.replaceContent(it) dismissAllowingStateLoss() } - private val searchBookAdapter by lazy { - ChangeChapterSourceAdapter(requireContext(), viewModel, this) - } - private val tocAdapter by lazy { - ChangeChapterTocAdapter(requireContext(), this) - } private var searchBook: SearchBook? = null override fun onStart() { @@ -199,6 +199,7 @@ class ChangeChapterSourceDialog() : BaseDialogFragment(R.layout.dialog_chapter_c override fun onMenuItemClick(item: MenuItem?): Boolean { when (item?.itemId) { + R.id.menu_scroll_to_dur -> scrollToDurSource() R.id.menu_check_author -> { AppConfig.changeSourceCheckAuthor = !item.isChecked item.isChecked = !item.isChecked @@ -230,6 +231,15 @@ class ChangeChapterSourceDialog() : BaseDialogFragment(R.layout.dialog_chapter_c return false } + private fun scrollToDurSource() { + searchBookAdapter.getItems().forEachIndexed { index, searchBook -> + if (searchBook.bookUrl == bookUrl) { + binding.recyclerView.scrollToPosition(index) + return + } + } + } + override fun openToc(searchBook: SearchBook) { this.searchBook = searchBook tocAdapter.setItems(null) diff --git a/app/src/main/res/layout/dialog_book_change_source.xml b/app/src/main/res/layout/dialog_book_change_source.xml index d72fab249..b1c1b4592 100644 --- a/app/src/main/res/layout/dialog_book_change_source.xml +++ b/app/src/main/res/layout/dialog_book_change_source.xml @@ -1,10 +1,10 @@ + android:background="@color/background" + android:orientation="vertical"> + app:fitStatusBar="false" + app:popupTheme="@style/AppTheme.PopupOverlay" + app:titleTextAppearance="@style/ToolbarTitle" /> + android:layout_height="match_parent" + app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" /> \ No newline at end of file diff --git a/app/src/main/res/menu/change_source.xml b/app/src/main/res/menu/change_source.xml index 5e42ff079..50946c57f 100644 --- a/app/src/main/res/menu/change_source.xml +++ b/app/src/main/res/menu/change_source.xml @@ -18,6 +18,11 @@ app:showAsAction="always" tools:ignore="AlwaysShowAction" /> + + 仅在wifi下加载网络封面 封面规则 进入详情页时使用封面规则重新获取封面 + 定位到当前书源 diff --git a/app/src/main/res/values-ja-rJP/strings.xml b/app/src/main/res/values-ja-rJP/strings.xml index b7dc408c8..322024473 100644 --- a/app/src/main/res/values-ja-rJP/strings.xml +++ b/app/src/main/res/values-ja-rJP/strings.xml @@ -964,5 +964,6 @@ 仅在wifi下加载网络封面 封面规则 进入详情页时使用封面规则重新获取封面 + 定位到当前书源 diff --git a/app/src/main/res/values-pt-rBR/strings.xml b/app/src/main/res/values-pt-rBR/strings.xml index 09b72966e..ef4cec0bc 100644 --- a/app/src/main/res/values-pt-rBR/strings.xml +++ b/app/src/main/res/values-pt-rBR/strings.xml @@ -964,5 +964,6 @@ 仅在wifi下加载网络封面 封面规则 进入详情页时使用封面规则重新获取封面 + 定位到当前书源 diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index 02661958d..118aeec95 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -961,5 +961,6 @@ 仅在wifi下加载网络封面 封面规则 进入详情页时使用封面规则重新获取封面 + 定位到当前书源 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index a4740207b..867c16e00 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -963,5 +963,6 @@ 仅在wifi下加载网络封面 封面规则 进入详情页时使用封面规则重新获取封面 + 定位到当前书源 diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index 26718d53e..d74f0580b 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -963,5 +963,6 @@ 仅在wifi下加载网络封面 封面规则 进入详情页时使用封面规则重新获取封面 + 定位到当前书源 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 3c783ff95..aaf699e7c 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -964,5 +964,6 @@ 仅在wifi下加载网络封面 封面规则 进入详情页时使用封面规则重新获取封面 + 定位到当前书源