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 098c8fe9f..2445e39b1 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 @@ -57,6 +57,7 @@ import io.legado.app.ui.book.searchContent.SearchContentActivity import io.legado.app.ui.book.searchContent.SearchResult import io.legado.app.ui.book.source.edit.BookSourceEditActivity import io.legado.app.ui.book.toc.TocActivityResult +import io.legado.app.ui.book.toc.TxtTocRegexDialog import io.legado.app.ui.browser.WebViewActivity import io.legado.app.ui.dict.DictDialog import io.legado.app.ui.document.HandleFileContract @@ -86,7 +87,7 @@ class ReadBookActivity : BaseReadBookActivity(), ChangeChapterSourceDialog.CallBack, ReadBook.CallBack, AutoReadDialog.CallBack, - TocRegexDialog.CallBack, + TxtTocRegexDialog.CallBack, ColorPickerDialogListener { private val tocActivity = @@ -383,7 +384,7 @@ class ReadBookActivity : BaseReadBookActivity(), } R.id.menu_log -> showDialogFragment() R.id.menu_toc_regex -> showDialogFragment( - TocRegexDialog(ReadBook.book?.tocUrl) + TxtTocRegexDialog(ReadBook.book?.tocUrl) ) R.id.menu_reverse_content -> ReadBook.book?.let { viewModel.reverseContent(it) diff --git a/app/src/main/java/io/legado/app/ui/book/toc/TocActivity.kt b/app/src/main/java/io/legado/app/ui/book/toc/TocActivity.kt index 8cb93e35f..75d83f343 100644 --- a/app/src/main/java/io/legado/app/ui/book/toc/TocActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/toc/TocActivity.kt @@ -15,6 +15,7 @@ import com.google.android.material.tabs.TabLayout import io.legado.app.R import io.legado.app.base.VMBaseActivity import io.legado.app.databinding.ActivityChapterListBinding +import io.legado.app.help.book.isLocalTxt import io.legado.app.help.config.AppConfig import io.legado.app.lib.theme.accentColor import io.legado.app.lib.theme.primaryTextColor @@ -25,13 +26,16 @@ import io.legado.app.utils.showDialogFragment import io.legado.app.utils.viewbindingdelegate.viewBinding import io.legado.app.utils.visible - +/** + * 目录 + */ class TocActivity : VMBaseActivity() { override val binding by viewBinding(ActivityChapterListBinding::inflate) override val viewModel by viewModels() private lateinit var tabLayout: TabLayout + private var menu: Menu? = null private var searchView: SearchView? = null override fun onActivityCreated(savedInstanceState: Bundle?) { @@ -40,6 +44,9 @@ class TocActivity : VMBaseActivity() { tabLayout.setSelectedTabIndicatorColor(accentColor) binding.viewPager.adapter = TabFragmentPageAdapter() tabLayout.setupWithViewPager(binding.viewPager) + viewModel.bookData.observe(this) { + menu?.setGroupVisible(R.id.menu_group_text, it.isLocalTxt) + } intent.getStringExtra("bookUrl")?.let { viewModel.initBook(it) } @@ -47,6 +54,10 @@ class TocActivity : VMBaseActivity() { override fun onCompatCreateOptionsMenu(menu: Menu): Boolean { menuInflater.inflate(R.menu.book_toc, menu) + this.menu = menu + viewModel.bookData.value?.let { + menu.setGroupVisible(R.id.menu_group_text, it.isLocalTxt) + } val search = menu.findItem(R.id.menu_search) searchView = (search.actionView as SearchView).apply { applyTint(primaryTextColor) @@ -84,6 +95,9 @@ class TocActivity : VMBaseActivity() { override fun onCompatOptionsItemSelected(item: MenuItem): Boolean { when (item.itemId) { + R.id.menu_toc_regex -> showDialogFragment( + TxtTocRegexDialog(viewModel.bookData.value?.tocUrl) + ) R.id.menu_reverse_toc -> viewModel.reverseToc { viewModel.chapterListCallBack?.upChapterList(searchView?.query?.toString()) setResult(RESULT_OK, Intent().apply { @@ -101,12 +115,12 @@ class TocActivity : VMBaseActivity() { return super.onCompatOptionsItemSelected(item) } - override fun onBackPressed() { + override fun finish() { if (tabLayout.isGone) { searchView?.onActionViewCollapsed() tabLayout.visible() } else { - super.onBackPressed() + super.finish() } } diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/TocRegexDialog.kt b/app/src/main/java/io/legado/app/ui/book/toc/TxtTocRegexDialog.kt similarity index 98% rename from app/src/main/java/io/legado/app/ui/book/read/config/TocRegexDialog.kt rename to app/src/main/java/io/legado/app/ui/book/toc/TxtTocRegexDialog.kt index 36ae41686..cc5eb1b24 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/TocRegexDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/toc/TxtTocRegexDialog.kt @@ -1,4 +1,4 @@ -package io.legado.app.ui.book.read.config +package io.legado.app.ui.book.toc import android.annotation.SuppressLint import android.content.Context @@ -33,7 +33,10 @@ import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.flow.conflate import kotlinx.coroutines.launch -class TocRegexDialog() : BaseDialogFragment(R.layout.dialog_toc_regex), +/** + * txt目录规则 + */ +class TxtTocRegexDialog() : BaseDialogFragment(R.layout.dialog_toc_regex), Toolbar.OnMenuItemClickListener { constructor(tocRegex: String?) : this() { @@ -43,7 +46,7 @@ class TocRegexDialog() : BaseDialogFragment(R.layout.dialog_toc_regex), } private val importTocRuleKey = "tocRuleUrl" - private val viewModel: TocRegexViewModel by viewModels() + private val viewModel: TxtTocRegexViewModel by viewModels() private val binding by viewBinding(DialogTocRegexBinding::bind) private val adapter by lazy { TocRegexAdapter(requireContext()) } var selectedName: String? = null diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/TocRegexViewModel.kt b/app/src/main/java/io/legado/app/ui/book/toc/TxtTocRegexViewModel.kt similarity index 78% rename from app/src/main/java/io/legado/app/ui/book/read/config/TocRegexViewModel.kt rename to app/src/main/java/io/legado/app/ui/book/toc/TxtTocRegexViewModel.kt index aabb38983..bfc17111f 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/TocRegexViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/toc/TxtTocRegexViewModel.kt @@ -1,4 +1,4 @@ -package io.legado.app.ui.book.read.config +package io.legado.app.ui.book.toc import android.app.Application import io.legado.app.base.BaseViewModel @@ -6,7 +6,10 @@ import io.legado.app.data.appDb import io.legado.app.data.entities.TxtTocRule import io.legado.app.help.DefaultData -class TocRegexViewModel(application: Application) : BaseViewModel(application) { +/** + * txt目录规则 + */ +class TxtTocRegexViewModel(application: Application) : BaseViewModel(application) { fun saveRule(rule: TxtTocRule) { execute { diff --git a/app/src/main/res/menu/book_toc.xml b/app/src/main/res/menu/book_toc.xml index 7bb1c39a6..fce5759fc 100644 --- a/app/src/main/res/menu/book_toc.xml +++ b/app/src/main/res/menu/book_toc.xml @@ -10,6 +10,17 @@ app:actionViewClass="androidx.appcompat.widget.SearchView" app:showAsAction="always" /> + + + + + +