pull/2473/head
kunfei 2 years ago
parent 2d4f5f574d
commit 4affce176f
  1. 5
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
  2. 20
      app/src/main/java/io/legado/app/ui/book/toc/TocActivity.kt
  3. 9
      app/src/main/java/io/legado/app/ui/book/toc/TxtTocRegexDialog.kt
  4. 7
      app/src/main/java/io/legado/app/ui/book/toc/TxtTocRegexViewModel.kt
  5. 11
      app/src/main/res/menu/book_toc.xml

@ -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<AppLogDialog>()
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)

@ -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<ActivityChapterListBinding, TocViewModel>() {
override val binding by viewBinding(ActivityChapterListBinding::inflate)
override val viewModel by viewModels<TocViewModel>()
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<ActivityChapterListBinding, TocViewModel>() {
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<ActivityChapterListBinding, TocViewModel>() {
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<ActivityChapterListBinding, TocViewModel>() {
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<ActivityChapterListBinding, TocViewModel>() {
return super.onCompatOptionsItemSelected(item)
}
override fun onBackPressed() {
override fun finish() {
if (tabLayout.isGone) {
searchView?.onActionViewCollapsed()
tabLayout.visible()
} else {
super.onBackPressed()
super.finish()
}
}

@ -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

@ -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 {

@ -10,6 +10,17 @@
app:actionViewClass="androidx.appcompat.widget.SearchView"
app:showAsAction="always" />
<group
android:id="@+id/menu_group_text"
android:visible="false">
<item
android:id="@+id/menu_toc_regex"
android:title="@string/txt_toc_regex"
app:showAsAction="never" />
</group>
<item
android:id="@+id/menu_reverse_toc"
android:title="@string/reverse_toc"

Loading…
Cancel
Save