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 d20afbfec..eedf933fc 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 @@ -6,7 +6,6 @@ import android.content.Intent import android.content.res.Configuration import android.graphics.Color import android.graphics.drawable.ColorDrawable -import android.net.Uri import android.os.Bundle import android.os.Handler import android.os.Looper @@ -23,9 +22,7 @@ import io.legado.app.constant.PreferKey import io.legado.app.constant.Status import io.legado.app.data.entities.Book import io.legado.app.data.entities.BookChapter -import io.legado.app.help.BookHelp import io.legado.app.help.ReadBookConfig -import io.legado.app.help.coroutine.Coroutine import io.legado.app.help.storage.Backup import io.legado.app.help.storage.SyncBookProgress import io.legado.app.lib.dialogs.alert @@ -47,7 +44,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.SearchContentActivity -import io.legado.app.ui.book.source.edit.BookSourceEditActivity import io.legado.app.ui.book.toc.ChapterListActivity import io.legado.app.ui.login.SourceLogin import io.legado.app.ui.replace.ReplaceRuleActivity @@ -62,7 +58,6 @@ import kotlinx.coroutines.Dispatchers.Main import kotlinx.coroutines.delay import kotlinx.coroutines.launch import kotlinx.coroutines.withContext -import org.jetbrains.anko.sdk27.listeners.onClick import org.jetbrains.anko.startActivity import org.jetbrains.anko.startActivityForResult import org.jetbrains.anko.toast @@ -80,7 +75,6 @@ class ReadBookActivity : ReadBookBaseActivity(), TocRegexDialog.CallBack, ColorPickerDialogListener { private val requestCodeChapterList = 568 - private val requestCodeEditSource = 111 private val requestCodeReplace = 312 private val requestCodeSearchResult = 123 private var menu: Menu? = null @@ -102,7 +96,11 @@ class ReadBookActivity : ReadBookBaseActivity(), override val headerHeight: Int get() = page_view.curPage.headerHeight override fun onActivityCreated(savedInstanceState: Bundle?) { - initView() + super.onActivityCreated(savedInstanceState) + cursor_left.setColorFilter(accentColor) + cursor_right.setColorFilter(accentColor) + cursor_left.setOnTouchListener(this) + cursor_right.setOnTouchListener(this) upScreenTimeOut() ReadBook.callBack = this ReadBook.titleDate.observe(this) { @@ -161,32 +159,6 @@ class ReadBookActivity : ReadBookBaseActivity(), } } - /** - * 初始化View - */ - private fun initView() { - cursor_left.setColorFilter(accentColor) - cursor_right.setColorFilter(accentColor) - cursor_left.setOnTouchListener(this) - cursor_right.setOnTouchListener(this) - tv_chapter_name.onClick { - ReadBook.webBook?.let { - startActivityForResult( - requestCodeEditSource, - Pair("data", it.bookSource.bookSourceUrl) - ) - } - } - tv_chapter_url.onClick { - runCatching { - val url = tv_chapter_url.text.toString() - val intent = Intent(Intent.ACTION_VIEW) - intent.data = Uri.parse(url) - startActivity(intent) - } - } - } - override fun onCompatCreateOptionsMenu(menu: Menu): Boolean { menuInflater.inflate(R.menu.read_book, menu) return super.onCompatCreateOptionsMenu(menu) @@ -248,7 +220,7 @@ class ReadBookActivity : ReadBookBaseActivity(), R.id.menu_enable_replace -> ReadBook.book?.let { it.setUseReplaceRule(!it.getUseReplaceRule()) menu?.findItem(R.id.menu_enable_replace)?.isChecked = it.getUseReplaceRule() - onReplaceRuleSave() + viewModel.replaceRuleChanged() } R.id.menu_re_segment -> ReadBook.book?.let { it.setReSegment(!it.getReSegment()) @@ -689,16 +661,6 @@ class ReadBookActivity : ReadBookBaseActivity(), } } - /** - * 替换规则变化 - */ - private fun onReplaceRuleSave() { - Coroutine.async { - BookHelp.upReplaceRules() - ReadBook.loadContent(resetPageOffset = false) - } - } - /** * 显示阅读样式配置 */ @@ -765,7 +727,6 @@ class ReadBookActivity : ReadBookBaseActivity(), super.onActivityResult(requestCode, resultCode, data) if (resultCode == Activity.RESULT_OK) { when (requestCode) { - requestCodeEditSource -> viewModel.upBookSource() requestCodeChapterList -> data?.getIntExtra("index", ReadBook.durChapterIndex)?.let { index -> if (index != ReadBook.durChapterIndex) { @@ -821,9 +782,8 @@ class ReadBookActivity : ReadBookBaseActivity(), } } } - requestCodeReplace -> onReplaceRuleSave() + requestCodeReplace -> viewModel.replaceRuleChanged() } - } } @@ -915,7 +875,7 @@ class ReadBookActivity : ReadBookBaseActivity(), read_menu.upBrightnessState() } observeEvent(EventBus.REPLACE_RULE_SAVE) { - onReplaceRuleSave() + viewModel.replaceRuleChanged() } } diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookBaseActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookBaseActivity.kt index 878af076b..598668e8b 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookBaseActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookBaseActivity.kt @@ -1,7 +1,10 @@ package io.legado.app.ui.book.read import android.annotation.SuppressLint +import android.app.Activity +import android.content.Intent import android.content.pm.ActivityInfo +import android.net.Uri import android.os.Build import android.os.Bundle import android.view.* @@ -22,6 +25,7 @@ import io.legado.app.service.help.CacheBook import io.legado.app.service.help.ReadBook import io.legado.app.ui.book.read.config.BgTextConfigDialog import io.legado.app.ui.book.read.config.PaddingConfigDialog +import io.legado.app.ui.book.source.edit.BookSourceEditActivity import io.legado.app.ui.widget.text.AutoCompleteTextView import io.legado.app.utils.applyTint import io.legado.app.utils.getPrefString @@ -29,13 +33,16 @@ import io.legado.app.utils.getViewModel import io.legado.app.utils.requestInputMethod import kotlinx.android.synthetic.main.dialog_download_choice.view.* import kotlinx.android.synthetic.main.dialog_edit_text.view.* +import kotlinx.android.synthetic.main.view_read_menu.* +import org.jetbrains.anko.sdk27.listeners.onClick +import org.jetbrains.anko.startActivityForResult abstract class ReadBookBaseActivity : VMBaseActivity(R.layout.activity_book_read) { override val viewModel: ReadBookViewModel get() = getViewModel(ReadBookViewModel::class.java) - + private val requestCodeEditSource = 111 override fun onCreate(savedInstanceState: Bundle?) { ReadBook.msg = null @@ -44,6 +51,41 @@ abstract class ReadBookBaseActivity : super.onCreate(savedInstanceState) } + override fun onActivityCreated(savedInstanceState: Bundle?) { + initView() + } + + /** + * 初始化View + */ + private fun initView() { + tv_chapter_name.onClick { + ReadBook.webBook?.let { + startActivityForResult( + requestCodeEditSource, + Pair("data", it.bookSource.bookSourceUrl) + ) + } + } + tv_chapter_url.onClick { + runCatching { + val url = tv_chapter_url.text.toString() + val intent = Intent(Intent.ACTION_VIEW) + intent.data = Uri.parse(url) + startActivity(intent) + } + } + } + + override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { + super.onActivityResult(requestCode, resultCode, data) + if (resultCode == Activity.RESULT_OK) { + when (requestCode) { + requestCodeEditSource -> viewModel.upBookSource() + } + } + } + fun showPaddingConfig() { PaddingConfigDialog().show(supportFragmentManager, "paddingConfig") } @@ -65,7 +107,6 @@ abstract class ReadBookBaseActivity : } } - /** * 更新状态栏,导航栏 */ @@ -139,7 +180,7 @@ abstract class ReadBookBaseActivity : /** * 适配刘海 */ - fun upLayoutInDisplayCutoutMode() { + private fun upLayoutInDisplayCutoutMode() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P && AppConfig.readBodyToLh) { window.attributes = window.attributes.apply { layoutInDisplayCutoutMode = diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt index 648e9d483..64087032b 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt @@ -271,6 +271,16 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { } } + /** + * 替换规则变化 + */ + fun replaceRuleChanged() { + execute { + BookHelp.upReplaceRules() + ReadBook.loadContent(resetPageOffset = false) + } + } + override fun onCleared() { super.onCleared() if (BaseReadAloudService.pause) { diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt index 46fbbb215..fbb8fa226 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt @@ -14,7 +14,7 @@ import io.legado.app.constant.PreferKey import io.legado.app.help.ReadBookConfig import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.bottomBackground -import io.legado.app.ui.book.read.ReadBookActivityHelp +import io.legado.app.ui.book.read.ReadBookActivity import io.legado.app.utils.dp import io.legado.app.utils.getPrefBoolean import io.legado.app.utils.postEvent @@ -101,9 +101,7 @@ class MoreConfigDialog : DialogFragment() { PreferKey.keepLight -> postEvent(key, true) PreferKey.textSelectAble -> postEvent(key, getPrefBoolean(key)) getString(R.string.pk_requested_direction) -> { - activity?.let { - ReadBookActivityHelp.setOrientation(it) - } + (activity as? ReadBookActivity)?.setOrientation() } PreferKey.textFullJustify, PreferKey.textBottomJustify -> {