pull/2473/head
kunfei 2 years ago
parent 4affce176f
commit f05b057182
  1. 2
      app/src/main/AndroidManifest.xml
  2. 6
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
  3. 2
      app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt
  4. 3
      app/src/main/java/io/legado/app/ui/book/toc/TocActivity.kt
  5. 29
      app/src/main/java/io/legado/app/ui/book/toc/TxtTocRegexViewModel.kt
  6. 2
      app/src/main/java/io/legado/app/ui/book/toc/rule/TxtTocRuleActivity.kt
  7. 2
      app/src/main/java/io/legado/app/ui/book/toc/rule/TxtTocRuleAdapter.kt
  8. 8
      app/src/main/java/io/legado/app/ui/book/toc/rule/TxtTocRuleDialog.kt
  9. 5
      app/src/main/java/io/legado/app/ui/book/toc/rule/TxtTocRuleViewModel.kt

@ -203,7 +203,7 @@
android:screenOrientation="behind" />
<!-- txt目录规则管理 -->
<activity
android:name=".ui.book.import.local.rule.TxtTocRuleActivity"
android:name=".ui.book.toc.rule.TxtTocRuleActivity"
android:launchMode="singleTop"
android:screenOrientation="behind" />
<!-- 替换规则界面 -->

@ -57,7 +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.book.toc.rule.TxtTocRuleDialog
import io.legado.app.ui.browser.WebViewActivity
import io.legado.app.ui.dict.DictDialog
import io.legado.app.ui.document.HandleFileContract
@ -87,7 +87,7 @@ class ReadBookActivity : BaseReadBookActivity(),
ChangeChapterSourceDialog.CallBack,
ReadBook.CallBack,
AutoReadDialog.CallBack,
TxtTocRegexDialog.CallBack,
TxtTocRuleDialog.CallBack,
ColorPickerDialogListener {
private val tocActivity =
@ -384,7 +384,7 @@ class ReadBookActivity : BaseReadBookActivity(),
}
R.id.menu_log -> showDialogFragment<AppLogDialog>()
R.id.menu_toc_regex -> showDialogFragment(
TxtTocRegexDialog(ReadBook.book?.tocUrl)
TxtTocRuleDialog(ReadBook.book?.tocUrl)
)
R.id.menu_reverse_content -> ReadBook.book?.let {
viewModel.reverseContent(it)

@ -28,11 +28,11 @@ import io.legado.app.lib.theme.primaryTextColor
import io.legado.app.model.CheckSource
import io.legado.app.model.Debug
import io.legado.app.ui.association.ImportBookSourceDialog
import io.legado.app.ui.book.import.local.rule.TxtTocRuleActivity
import io.legado.app.ui.book.search.SearchActivity
import io.legado.app.ui.book.search.SearchScope
import io.legado.app.ui.book.source.debug.BookSourceDebugActivity
import io.legado.app.ui.book.source.edit.BookSourceEditActivity
import io.legado.app.ui.book.toc.rule.TxtTocRuleActivity
import io.legado.app.ui.config.CheckSourceConfig
import io.legado.app.ui.document.HandleFileContract
import io.legado.app.ui.qrcode.QrCodeResult

@ -20,6 +20,7 @@ import io.legado.app.help.config.AppConfig
import io.legado.app.lib.theme.accentColor
import io.legado.app.lib.theme.primaryTextColor
import io.legado.app.ui.about.AppLogDialog
import io.legado.app.ui.book.toc.rule.TxtTocRuleDialog
import io.legado.app.utils.applyTint
import io.legado.app.utils.gone
import io.legado.app.utils.showDialogFragment
@ -96,7 +97,7 @@ 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)
TxtTocRuleDialog(viewModel.bookData.value?.tocUrl)
)
R.id.menu_reverse_toc -> viewModel.reverseToc {
viewModel.chapterListCallBack?.upChapterList(searchView?.query?.toString())

@ -1,29 +0,0 @@
package io.legado.app.ui.book.toc
import android.app.Application
import io.legado.app.base.BaseViewModel
import io.legado.app.data.appDb
import io.legado.app.data.entities.TxtTocRule
import io.legado.app.help.DefaultData
/**
* txt目录规则
*/
class TxtTocRegexViewModel(application: Application) : BaseViewModel(application) {
fun saveRule(rule: TxtTocRule) {
execute {
if (rule.serialNumber < 0) {
rule.serialNumber = appDb.txtTocRuleDao.maxOrder + 1
}
appDb.txtTocRuleDao.insert(rule)
}
}
fun importDefault() {
execute {
DefaultData.importDefaultTocRules()
}
}
}

@ -1,4 +1,4 @@
package io.legado.app.ui.book.import.local.rule
package io.legado.app.ui.book.toc.rule
import android.annotation.SuppressLint
import android.os.Bundle

@ -1,4 +1,4 @@
package io.legado.app.ui.book.import.local.rule
package io.legado.app.ui.book.toc.rule
import android.content.Context
import android.os.Bundle

@ -1,4 +1,4 @@
package io.legado.app.ui.book.toc
package io.legado.app.ui.book.toc.rule
import android.annotation.SuppressLint
import android.content.Context
@ -36,7 +36,7 @@ import kotlinx.coroutines.launch
/**
* txt目录规则
*/
class TxtTocRegexDialog() : BaseDialogFragment(R.layout.dialog_toc_regex),
class TxtTocRuleDialog() : BaseDialogFragment(R.layout.dialog_toc_regex),
Toolbar.OnMenuItemClickListener {
constructor(tocRegex: String?) : this() {
@ -46,7 +46,7 @@ class TxtTocRegexDialog() : BaseDialogFragment(R.layout.dialog_toc_regex),
}
private val importTocRuleKey = "tocRuleUrl"
private val viewModel: TxtTocRegexViewModel by viewModels()
private val viewModel: TxtTocRuleViewModel by viewModels()
private val binding by viewBinding(DialogTocRegexBinding::bind)
private val adapter by lazy { TocRegexAdapter(requireContext()) }
var selectedName: String? = null
@ -180,7 +180,7 @@ class TxtTocRegexDialog() : BaseDialogFragment(R.layout.dialog_toc_regex),
tocRule.name = tvRuleName.text.toString()
tocRule.rule = tvRuleRegex.text.toString()
tocRule.example = tvRuleExample.text.toString()
viewModel.saveRule(tocRule)
viewModel.save(tocRule)
}
}
cancelButton()

@ -1,4 +1,4 @@
package io.legado.app.ui.book.import.local.rule
package io.legado.app.ui.book.toc.rule
import android.app.Application
import io.legado.app.base.BaseViewModel
@ -15,6 +15,9 @@ class TxtTocRuleViewModel(app: Application) : BaseViewModel(app) {
fun save(txtTocRule: TxtTocRule) {
execute {
if (txtTocRule.serialNumber < 0) {
txtTocRule.serialNumber = appDb.txtTocRuleDao.maxOrder + 1
}
appDb.txtTocRuleDao.insert(txtTocRule)
}
}
Loading…
Cancel
Save