pull/1395/head
gedoor 3 years ago
parent 65291016db
commit 38c3e746a9
  1. 14
      app/src/main/java/io/legado/app/api/controller/BookController.kt
  2. 3
      app/src/main/java/io/legado/app/data/entities/BaseSource.kt
  3. 6
      app/src/main/java/io/legado/app/data/entities/Book.kt
  4. 4
      app/src/main/java/io/legado/app/model/CacheBook.kt
  5. 10
      app/src/main/java/io/legado/app/model/ReadBook.kt
  6. 16
      app/src/main/java/io/legado/app/receiver/MediaButtonReceiver.kt
  7. 20
      app/src/main/java/io/legado/app/service/BaseReadAloudService.kt
  8. 4
      app/src/main/java/io/legado/app/service/HttpReadAloudService.kt
  9. 6
      app/src/main/java/io/legado/app/service/TTSReadAloudService.kt
  10. 6
      app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt
  11. 6
      app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditViewModel.kt
  12. 6
      app/src/main/java/io/legado/app/ui/book/read/PhotoDialog.kt
  13. 140
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
  14. 12
      app/src/main/java/io/legado/app/ui/book/read/ReadBookBaseActivity.kt
  15. 124
      app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt
  16. 36
      app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt
  17. 4
      app/src/main/java/io/legado/app/ui/book/read/config/AutoReadDialog.kt
  18. 4
      app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt
  19. 6
      app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudDialog.kt
  20. 8
      app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt
  21. 8
      app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt
  22. 4
      app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt
  23. 20
      app/src/main/java/io/legado/app/ui/book/read/page/ReadView.kt
  24. 4
      app/src/main/java/io/legado/app/ui/book/read/page/api/DataSource.kt
  25. 8
      app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPage.kt
  26. 8
      app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt
  27. 24
      app/src/main/java/io/legado/app/ui/book/read/page/provider/TextPageFactory.kt

@ -12,7 +12,7 @@ import io.legado.app.help.ContentProcessor
import io.legado.app.help.glide.ImageLoader import io.legado.app.help.glide.ImageLoader
import io.legado.app.help.storage.AppWebDav import io.legado.app.help.storage.AppWebDav
import io.legado.app.model.BookCover import io.legado.app.model.BookCover
import io.legado.app.model.BookRead import io.legado.app.model.ReadBook
import io.legado.app.model.localBook.EpubFile import io.legado.app.model.localBook.EpubFile
import io.legado.app.model.localBook.LocalBook import io.legado.app.model.localBook.LocalBook
import io.legado.app.model.localBook.UmdFile import io.legado.app.model.localBook.UmdFile
@ -159,9 +159,9 @@ object BookController {
if (book != null) { if (book != null) {
book.save() book.save()
AppWebDav.uploadBookProgress(book) AppWebDav.uploadBookProgress(book)
if (BookRead.book?.bookUrl == book.bookUrl) { if (ReadBook.book?.bookUrl == book.bookUrl) {
BookRead.book = book ReadBook.book = book
BookRead.durChapterIndex = book.durChapterIndex ReadBook.durChapterIndex = book.durChapterIndex
} }
return returnData.setData("") return returnData.setData("")
} }
@ -176,9 +176,9 @@ object BookController {
} }
appDb.bookDao.update(book) appDb.bookDao.update(book)
AppWebDav.uploadBookProgress(book) AppWebDav.uploadBookProgress(book)
if (BookRead.book?.bookUrl == book.bookUrl) { if (ReadBook.book?.bookUrl == book.bookUrl) {
BookRead.book = book ReadBook.book = book
BookRead.durChapterIndex = index ReadBook.durChapterIndex = index
} }
} }

@ -145,8 +145,9 @@ interface BaseSource : JsExtensions {
* 执行JS * 执行JS
*/ */
@Throws(Exception::class) @Throws(Exception::class)
fun evalJS(jsStr: String): Any? { fun evalJS(jsStr: String, bindingsConfig: SimpleBindings.() -> Unit = {}): Any? {
val bindings = SimpleBindings() val bindings = SimpleBindings()
bindings.apply(bindingsConfig)
bindings["java"] = this bindings["java"] = this
bindings["source"] = this bindings["source"] = this
bindings["baseUrl"] = getKey() bindings["baseUrl"] = getKey()

@ -6,7 +6,7 @@ import io.legado.app.constant.AppPattern
import io.legado.app.constant.BookType import io.legado.app.constant.BookType
import io.legado.app.data.appDb import io.legado.app.data.appDb
import io.legado.app.help.AppConfig import io.legado.app.help.AppConfig
import io.legado.app.model.BookRead import io.legado.app.model.ReadBook
import io.legado.app.utils.GSON import io.legado.app.utils.GSON
import io.legado.app.utils.MD5Utils import io.legado.app.utils.MD5Utils
import io.legado.app.utils.fromJsonObject import io.legado.app.utils.fromJsonObject
@ -266,8 +266,8 @@ data class Book(
fun delete(book: Book?) { fun delete(book: Book?) {
book ?: return book ?: return
if (BookRead.book?.bookUrl == book.bookUrl) { if (ReadBook.book?.bookUrl == book.bookUrl) {
BookRead.book = null ReadBook.book = null
} }
appDb.bookDao.delete(book) appDb.bookDao.delete(book)
} }

@ -275,8 +275,8 @@ object CacheBook {
content: String, content: String,
resetPageOffset: Boolean = false resetPageOffset: Boolean = false
) { ) {
if (BookRead.book?.bookUrl == book.bookUrl) { if (ReadBook.book?.bookUrl == book.bookUrl) {
BookRead.contentLoadFinish( ReadBook.contentLoadFinish(
book, chapter, content, book, chapter, content,
resetPageOffset = resetPageOffset resetPageOffset = resetPageOffset
) )

@ -26,7 +26,7 @@ import splitties.init.appCtx
@Suppress("MemberVisibilityCanBePrivate") @Suppress("MemberVisibilityCanBePrivate")
object BookRead : CoroutineScope by MainScope() { object ReadBook : CoroutineScope by MainScope() {
var book: Book? = null var book: Book? = null
var callBack: CallBack? = null var callBack: CallBack? = null
var inBookshelf = false var inBookshelf = false
@ -44,7 +44,7 @@ object BookRead : CoroutineScope by MainScope() {
var readStartTime: Long = System.currentTimeMillis() var readStartTime: Long = System.currentTimeMillis()
fun resetData(book: Book) { fun resetData(book: Book) {
BookRead.book = book ReadBook.book = book
readRecord.bookName = book.name readRecord.bookName = book.name
readRecord.readTime = appDb.readRecordDao.getReadTime(book.name) ?: 0 readRecord.readTime = appDb.readRecordDao.getReadTime(book.name) ?: 0
chapterSize = appDb.bookChapterDao.getChapterCount(book.bookUrl) chapterSize = appDb.bookChapterDao.getChapterCount(book.bookUrl)
@ -111,8 +111,8 @@ object BookRead : CoroutineScope by MainScope() {
} }
fun upMsg(msg: String?) { fun upMsg(msg: String?) {
if (BookRead.msg != msg) { if (ReadBook.msg != msg) {
BookRead.msg = msg ReadBook.msg = msg
callBack?.upContent() callBack?.upContent()
} }
} }
@ -379,7 +379,7 @@ object BookRead : CoroutineScope by MainScope() {
if (System.currentTimeMillis() - book.lastCheckTime < 600000) return if (System.currentTimeMillis() - book.lastCheckTime < 600000) return
book.lastCheckTime = System.currentTimeMillis() book.lastCheckTime = System.currentTimeMillis()
WebBook.getChapterList(this, bookSource, book).onSuccess(IO) { cList -> WebBook.getChapterList(this, bookSource, book).onSuccess(IO) { cList ->
if (book.bookUrl == BookRead.book?.bookUrl if (book.bookUrl == ReadBook.book?.bookUrl
&& cList.size > chapterSize && cList.size > chapterSize
) { ) {
appDb.bookChapterDao.insert(*cList.toTypedArray()) appDb.bookChapterDao.insert(*cList.toTypedArray())

@ -10,8 +10,8 @@ import io.legado.app.data.appDb
import io.legado.app.help.AppConfig import io.legado.app.help.AppConfig
import io.legado.app.help.LifecycleHelp import io.legado.app.help.LifecycleHelp
import io.legado.app.model.AudioPlay import io.legado.app.model.AudioPlay
import io.legado.app.model.BookRead
import io.legado.app.model.ReadAloud import io.legado.app.model.ReadAloud
import io.legado.app.model.ReadBook
import io.legado.app.service.AudioPlayService import io.legado.app.service.AudioPlayService
import io.legado.app.service.BaseReadAloudService import io.legado.app.service.BaseReadAloudService
import io.legado.app.ui.book.audio.AudioPlayActivity import io.legado.app.ui.book.audio.AudioPlayActivity
@ -46,14 +46,14 @@ class MediaButtonReceiver : BroadcastReceiver() {
when (keycode) { when (keycode) {
KeyEvent.KEYCODE_MEDIA_PREVIOUS -> { KeyEvent.KEYCODE_MEDIA_PREVIOUS -> {
if (context.getPrefBoolean("mediaButtonPerNext", false)) { if (context.getPrefBoolean("mediaButtonPerNext", false)) {
BookRead.moveToPrevChapter(true) ReadBook.moveToPrevChapter(true)
} else { } else {
ReadAloud.prevParagraph(context) ReadAloud.prevParagraph(context)
} }
} }
KeyEvent.KEYCODE_MEDIA_NEXT -> { KeyEvent.KEYCODE_MEDIA_NEXT -> {
if (context.getPrefBoolean("mediaButtonPerNext", false)) { if (context.getPrefBoolean("mediaButtonPerNext", false)) {
BookRead.moveToNextChapter(true) ReadBook.moveToNextChapter(true)
} else { } else {
ReadAloud.nextParagraph(context) ReadAloud.nextParagraph(context)
} }
@ -89,13 +89,13 @@ class MediaButtonReceiver : BroadcastReceiver() {
postEvent(EventBus.MEDIA_BUTTON, true) postEvent(EventBus.MEDIA_BUTTON, true)
else -> if (AppConfig.mediaButtonOnExit || LifecycleHelp.activitySize() > 0 || !isMediaKey) { else -> if (AppConfig.mediaButtonOnExit || LifecycleHelp.activitySize() > 0 || !isMediaKey) {
AppLog.put("readAloud start Service") AppLog.put("readAloud start Service")
if (BookRead.book != null) { if (ReadBook.book != null) {
BookRead.readAloud() ReadBook.readAloud()
} else { } else {
appDb.bookDao.lastReadBook?.let { appDb.bookDao.lastReadBook?.let {
BookRead.resetData(it) ReadBook.resetData(it)
BookRead.curTextChapter ?: BookRead.loadContent(false) ReadBook.curTextChapter ?: ReadBook.loadContent(false)
BookRead.readAloud() ReadBook.readAloud()
} }
} }
} }

@ -17,8 +17,8 @@ import io.legado.app.R
import io.legado.app.base.BaseService import io.legado.app.base.BaseService
import io.legado.app.constant.* import io.legado.app.constant.*
import io.legado.app.help.MediaHelp import io.legado.app.help.MediaHelp
import io.legado.app.model.BookRead
import io.legado.app.model.ReadAloud import io.legado.app.model.ReadAloud
import io.legado.app.model.ReadBook
import io.legado.app.receiver.MediaButtonReceiver import io.legado.app.receiver.MediaButtonReceiver
import io.legado.app.ui.book.read.ReadBookActivity import io.legado.app.ui.book.read.ReadBookActivity
import io.legado.app.ui.book.read.page.entities.TextChapter import io.legado.app.ui.book.read.page.entities.TextChapter
@ -77,15 +77,15 @@ abstract class BaseReadAloudService : BaseService(),
postEvent(EventBus.ALOUD_STATE, Status.STOP) postEvent(EventBus.ALOUD_STATE, Status.STOP)
upMediaSessionPlaybackState(PlaybackStateCompat.STATE_STOPPED) upMediaSessionPlaybackState(PlaybackStateCompat.STATE_STOPPED)
mediaSessionCompat.release() mediaSessionCompat.release()
BookRead.uploadProgress() ReadBook.uploadProgress()
} }
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
intent?.action?.let { action -> intent?.action?.let { action ->
when (action) { when (action) {
IntentAction.play -> { IntentAction.play -> {
textChapter = BookRead.curTextChapter textChapter = ReadBook.curTextChapter
pageIndex = BookRead.durPageIndex() pageIndex = ReadBook.durPageIndex()
newReadAloud( newReadAloud(
intent.getBooleanExtra("play", true) intent.getBooleanExtra("play", true)
) )
@ -140,7 +140,7 @@ abstract class BaseReadAloudService : BaseService(),
upNotification() upNotification()
upMediaSessionPlaybackState(PlaybackStateCompat.STATE_PAUSED) upMediaSessionPlaybackState(PlaybackStateCompat.STATE_PAUSED)
postEvent(EventBus.ALOUD_STATE, Status.PAUSE) postEvent(EventBus.ALOUD_STATE, Status.PAUSE)
BookRead.uploadProgress() ReadBook.uploadProgress()
doDs() doDs()
} }
@ -160,7 +160,7 @@ abstract class BaseReadAloudService : BaseService(),
readAloudNumber -= contentList[nowSpeak].length.minus(1) readAloudNumber -= contentList[nowSpeak].length.minus(1)
play() play()
} else { } else {
BookRead.moveToPrevChapter(true) ReadBook.moveToPrevChapter(true)
} }
} }
@ -303,8 +303,8 @@ abstract class BaseReadAloudService : BaseService(),
) )
else -> getString(R.string.read_aloud_t) else -> getString(R.string.read_aloud_t)
} }
nTitle += ": ${BookRead.book?.name}" nTitle += ": ${ReadBook.book?.name}"
var nSubtitle = BookRead.curTextChapter?.title var nSubtitle = ReadBook.curTextChapter?.title
if (nSubtitle.isNullOrBlank()) if (nSubtitle.isNullOrBlank())
nSubtitle = getString(R.string.read_aloud_s) nSubtitle = getString(R.string.read_aloud_s)
val builder = NotificationCompat.Builder(this, AppConst.channelIdReadAloud) val builder = NotificationCompat.Builder(this, AppConst.channelIdReadAloud)
@ -351,8 +351,8 @@ abstract class BaseReadAloudService : BaseService(),
abstract fun aloudServicePendingIntent(actionStr: String): PendingIntent? abstract fun aloudServicePendingIntent(actionStr: String): PendingIntent?
open fun nextChapter() { open fun nextChapter() {
BookRead.upReadStartTime() ReadBook.upReadStartTime()
if (!BookRead.moveToNextChapter(true)) { if (!ReadBook.moveToNextChapter(true)) {
stopSelf() stopSelf()
} }
} }

@ -6,8 +6,8 @@ import io.legado.app.constant.AppLog
import io.legado.app.constant.EventBus import io.legado.app.constant.EventBus
import io.legado.app.help.AppConfig import io.legado.app.help.AppConfig
import io.legado.app.help.coroutine.Coroutine import io.legado.app.help.coroutine.Coroutine
import io.legado.app.model.BookRead
import io.legado.app.model.ReadAloud import io.legado.app.model.ReadAloud
import io.legado.app.model.ReadBook
import io.legado.app.model.analyzeRule.AnalyzeUrl import io.legado.app.model.analyzeRule.AnalyzeUrl
import io.legado.app.utils.* import io.legado.app.utils.*
import kotlinx.coroutines.* import kotlinx.coroutines.*
@ -232,7 +232,7 @@ class HttpReadAloudService : BaseReadAloudService(),
for (i in start..contentList[nowSpeak].length) { for (i in start..contentList[nowSpeak].length) {
if (readAloudNumber + i > textChapter.getReadLength(pageIndex + 1)) { if (readAloudNumber + i > textChapter.getReadLength(pageIndex + 1)) {
pageIndex++ pageIndex++
BookRead.moveToNextPage() ReadBook.moveToNextPage()
postEvent(EventBus.TTS_PROGRESS, readAloudNumber + i) postEvent(EventBus.TTS_PROGRESS, readAloudNumber + i)
} }
delay(sleep.toLong()) delay(sleep.toLong())

@ -9,7 +9,7 @@ import io.legado.app.constant.EventBus
import io.legado.app.help.AppConfig import io.legado.app.help.AppConfig
import io.legado.app.help.MediaHelp import io.legado.app.help.MediaHelp
import io.legado.app.lib.dialogs.SelectItem import io.legado.app.lib.dialogs.SelectItem
import io.legado.app.model.BookRead import io.legado.app.model.ReadBook
import io.legado.app.utils.* import io.legado.app.utils.*
import java.util.* import java.util.*
@ -122,7 +122,7 @@ class TTSReadAloudService : BaseReadAloudService(), TextToSpeech.OnInitListener
textChapter?.let { textChapter?.let {
if (readAloudNumber + 1 > it.getReadLength(pageIndex + 1)) { if (readAloudNumber + 1 > it.getReadLength(pageIndex + 1)) {
pageIndex++ pageIndex++
BookRead.moveToNextPage() ReadBook.moveToNextPage()
} }
postEvent(EventBus.TTS_PROGRESS, readAloudNumber + 1) postEvent(EventBus.TTS_PROGRESS, readAloudNumber + 1)
} }
@ -141,7 +141,7 @@ class TTSReadAloudService : BaseReadAloudService(), TextToSpeech.OnInitListener
textChapter?.let { textChapter?.let {
if (readAloudNumber + start > it.getReadLength(pageIndex + 1)) { if (readAloudNumber + start > it.getReadLength(pageIndex + 1)) {
pageIndex++ pageIndex++
BookRead.moveToNextPage() ReadBook.moveToNextPage()
postEvent(EventBus.TTS_PROGRESS, readAloudNumber + start) postEvent(EventBus.TTS_PROGRESS, readAloudNumber + start)
} }
} }

@ -11,7 +11,7 @@ import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookChapter import io.legado.app.data.entities.BookChapter
import io.legado.app.data.entities.BookSource import io.legado.app.data.entities.BookSource
import io.legado.app.help.BookHelp import io.legado.app.help.BookHelp
import io.legado.app.model.BookRead import io.legado.app.model.ReadBook
import io.legado.app.model.localBook.LocalBook import io.legado.app.model.localBook.LocalBook
import io.legado.app.model.webBook.WebBook import io.legado.app.model.webBook.WebBook
import io.legado.app.utils.postEvent import io.legado.app.utils.postEvent
@ -210,8 +210,8 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
book.durChapterTitle = it.durChapterTitle book.durChapterTitle = it.durChapterTitle
} }
book.save() book.save()
if (BookRead.book?.name == book.name && BookRead.book?.author == book.author) { if (ReadBook.book?.name == book.name && ReadBook.book?.author == book.author) {
BookRead.book = book ReadBook.book = book
} }
} }
}.onSuccess { }.onSuccess {

@ -5,7 +5,7 @@ import androidx.lifecycle.MutableLiveData
import io.legado.app.base.BaseViewModel import io.legado.app.base.BaseViewModel
import io.legado.app.data.appDb import io.legado.app.data.appDb
import io.legado.app.data.entities.Book import io.legado.app.data.entities.Book
import io.legado.app.model.BookRead import io.legado.app.model.ReadBook
class BookInfoEditViewModel(application: Application) : BaseViewModel(application) { class BookInfoEditViewModel(application: Application) : BaseViewModel(application) {
var book: Book? = null var book: Book? = null
@ -22,8 +22,8 @@ class BookInfoEditViewModel(application: Application) : BaseViewModel(applicatio
fun saveBook(book: Book, success: (() -> Unit)?) { fun saveBook(book: Book, success: (() -> Unit)?) {
execute { execute {
if (BookRead.book?.bookUrl == book.bookUrl) { if (ReadBook.book?.bookUrl == book.bookUrl) {
BookRead.book = book ReadBook.book = book
} }
appDb.bookDao.update(book) appDb.bookDao.update(book)
}.onSuccess { }.onSuccess {

@ -7,7 +7,7 @@ import android.view.ViewGroup
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.BaseDialogFragment import io.legado.app.base.BaseDialogFragment
import io.legado.app.databinding.DialogPhotoViewBinding import io.legado.app.databinding.DialogPhotoViewBinding
import io.legado.app.model.BookRead import io.legado.app.model.ReadBook
import io.legado.app.ui.book.read.page.provider.ImageProvider import io.legado.app.ui.book.read.page.provider.ImageProvider
import io.legado.app.utils.viewbindingdelegate.viewBinding import io.legado.app.utils.viewbindingdelegate.viewBinding
@ -43,10 +43,10 @@ class PhotoDialog() : BaseDialogFragment() {
arguments?.let { arguments?.let {
val chapterIndex = it.getInt("chapterIndex") val chapterIndex = it.getInt("chapterIndex")
val src = it.getString("src") val src = it.getString("src")
BookRead.book?.let { book -> ReadBook.book?.let { book ->
src?.let { src?.let {
execute { execute {
ImageProvider.getImage(book, chapterIndex, src, BookRead.bookSource) ImageProvider.getImage(book, chapterIndex, src, ReadBook.bookSource)
}.onSuccess { bitmap -> }.onSuccess { bitmap ->
if (bitmap != null) { if (bitmap != null) {
binding.photoView.setImageBitmap(bitmap) binding.photoView.setImageBitmap(bitmap)

@ -22,6 +22,7 @@ import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookChapter import io.legado.app.data.entities.BookChapter
import io.legado.app.data.entities.BookProgress import io.legado.app.data.entities.BookProgress
import io.legado.app.data.entities.BookSource import io.legado.app.data.entities.BookSource
import io.legado.app.help.IntentData
import io.legado.app.help.ReadBookConfig import io.legado.app.help.ReadBookConfig
import io.legado.app.help.ReadTipConfig import io.legado.app.help.ReadTipConfig
import io.legado.app.help.coroutine.Coroutine import io.legado.app.help.coroutine.Coroutine
@ -30,9 +31,9 @@ import io.legado.app.help.storage.Backup
import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.alert
import io.legado.app.lib.dialogs.selector import io.legado.app.lib.dialogs.selector
import io.legado.app.lib.theme.accentColor import io.legado.app.lib.theme.accentColor
import io.legado.app.model.BookRead
import io.legado.app.model.NoStackTraceException import io.legado.app.model.NoStackTraceException
import io.legado.app.model.ReadAloud import io.legado.app.model.ReadAloud
import io.legado.app.model.ReadBook
import io.legado.app.receiver.TimeBatteryReceiver import io.legado.app.receiver.TimeBatteryReceiver
import io.legado.app.service.BaseReadAloudService import io.legado.app.service.BaseReadAloudService
import io.legado.app.ui.book.changesource.ChangeSourceDialog import io.legado.app.ui.book.changesource.ChangeSourceDialog
@ -49,6 +50,7 @@ import io.legado.app.ui.book.searchContent.SearchContentActivity
import io.legado.app.ui.book.source.edit.BookSourceEditActivity import io.legado.app.ui.book.source.edit.BookSourceEditActivity
import io.legado.app.ui.book.toc.BookmarkDialog import io.legado.app.ui.book.toc.BookmarkDialog
import io.legado.app.ui.book.toc.TocActivityResult import io.legado.app.ui.book.toc.TocActivityResult
import io.legado.app.ui.browser.WebViewActivity
import io.legado.app.ui.dict.DictDialog import io.legado.app.ui.dict.DictDialog
import io.legado.app.ui.login.SourceLoginActivity import io.legado.app.ui.login.SourceLoginActivity
import io.legado.app.ui.replace.ReplaceRuleActivity import io.legado.app.ui.replace.ReplaceRuleActivity
@ -66,7 +68,7 @@ class ReadBookActivity : ReadBookBaseActivity(),
ReadMenu.CallBack, ReadMenu.CallBack,
ReadAloudDialog.CallBack, ReadAloudDialog.CallBack,
ChangeSourceDialog.CallBack, ChangeSourceDialog.CallBack,
BookRead.CallBack, ReadBook.CallBack,
AutoReadDialog.CallBack, AutoReadDialog.CallBack,
TocRegexDialog.CallBack, TocRegexDialog.CallBack,
ColorPickerDialogListener { ColorPickerDialogListener {
@ -97,7 +99,7 @@ class ReadBookActivity : ReadBookBaseActivity(),
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
it ?: return@registerForActivityResult it ?: return@registerForActivityResult
it.data?.let { data -> it.data?.let { data ->
data.getIntExtra("index", BookRead.durChapterIndex).let { index -> data.getIntExtra("index", ReadBook.durChapterIndex).let { index ->
viewModel.searchContentQuery = data.getStringExtra("query") ?: "" viewModel.searchContentQuery = data.getStringExtra("query") ?: ""
val indexWithinChapter = data.getIntExtra("indexWithinChapter", 0) val indexWithinChapter = data.getIntExtra("indexWithinChapter", 0)
skipToSearch(index, indexWithinChapter) skipToSearch(index, indexWithinChapter)
@ -131,7 +133,7 @@ class ReadBookActivity : ReadBookBaseActivity(),
binding.cursorLeft.setOnTouchListener(this) binding.cursorLeft.setOnTouchListener(this)
binding.cursorRight.setOnTouchListener(this) binding.cursorRight.setOnTouchListener(this)
upScreenTimeOut() upScreenTimeOut()
BookRead.callBack = this ReadBook.callBack = this
} }
override fun onPostCreate(savedInstanceState: Bundle?) { override fun onPostCreate(savedInstanceState: Bundle?) {
@ -151,7 +153,7 @@ class ReadBookActivity : ReadBookBaseActivity(),
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
BookRead.readStartTime = System.currentTimeMillis() ReadBook.readStartTime = System.currentTimeMillis()
upSystemUiVisibility() upSystemUiVisibility()
timeBatteryReceiver = TimeBatteryReceiver.register(this) timeBatteryReceiver = TimeBatteryReceiver.register(this)
binding.readView.upTime() binding.readView.upTime()
@ -161,14 +163,14 @@ class ReadBookActivity : ReadBookBaseActivity(),
super.onPause() super.onPause()
autoPageStop() autoPageStop()
backupJob?.cancel() backupJob?.cancel()
BookRead.saveRead() ReadBook.saveRead()
timeBatteryReceiver?.let { timeBatteryReceiver?.let {
unregisterReceiver(it) unregisterReceiver(it)
timeBatteryReceiver = null timeBatteryReceiver = null
} }
upSystemUiVisibility() upSystemUiVisibility()
if (!BuildConfig.DEBUG) { if (!BuildConfig.DEBUG) {
BookRead.uploadProgress() ReadBook.uploadProgress()
Backup.autoBack(this) Backup.autoBack(this)
} }
} }
@ -189,13 +191,13 @@ class ReadBookActivity : ReadBookBaseActivity(),
*/ */
private fun upMenu() { private fun upMenu() {
val menu = menu val menu = menu
val book = BookRead.book val book = ReadBook.book
if (menu != null && book != null) { if (menu != null && book != null) {
val onLine = !book.isLocalBook() val onLine = !book.isLocalBook()
for (i in 0 until menu.size) { for (i in 0 until menu.size) {
val item = menu[i] val item = menu[i]
when (item.groupId) { when (item.groupId) {
R.id.menu_group_on_line -> item.isVisible == onLine R.id.menu_group_on_line -> item.isVisible = onLine
R.id.menu_group_local -> item.isVisible = !onLine R.id.menu_group_local -> item.isVisible = !onLine
R.id.menu_group_text -> item.isVisible = book.isLocalTxt() R.id.menu_group_text -> item.isVisible = book.isLocalTxt()
else -> when (item.itemId) { else -> when (item.itemId) {
@ -222,16 +224,16 @@ class ReadBookActivity : ReadBookBaseActivity(),
when (item.itemId) { when (item.itemId) {
R.id.menu_change_source -> { R.id.menu_change_source -> {
binding.readMenu.runMenuOut() binding.readMenu.runMenuOut()
BookRead.book?.let { ReadBook.book?.let {
showDialogFragment(ChangeSourceDialog(it.name, it.author)) showDialogFragment(ChangeSourceDialog(it.name, it.author))
} }
} }
R.id.menu_refresh -> { R.id.menu_refresh -> {
if (BookRead.bookSource == null) { if (ReadBook.bookSource == null) {
upContent() upContent()
} else { } else {
BookRead.book?.let { ReadBook.book?.let {
BookRead.curTextChapter = null ReadBook.curTextChapter = null
binding.readView.upContent() binding.readView.upContent()
viewModel.refreshContent(it) viewModel.refreshContent(it)
} }
@ -239,12 +241,12 @@ class ReadBookActivity : ReadBookBaseActivity(),
} }
R.id.menu_download -> showDownloadDialog() R.id.menu_download -> showDownloadDialog()
R.id.menu_add_bookmark -> { R.id.menu_add_bookmark -> {
val book = BookRead.book val book = ReadBook.book
val page = BookRead.curTextChapter?.page(BookRead.durPageIndex()) val page = ReadBook.curTextChapter?.page(ReadBook.durPageIndex())
if (book != null && page != null) { if (book != null && page != null) {
val bookmark = book.createBookMark().apply { val bookmark = book.createBookMark().apply {
chapterIndex = BookRead.durChapterIndex chapterIndex = ReadBook.durChapterIndex
chapterPos = BookRead.durChapterPos chapterPos = ReadBook.durChapterPos
chapterName = page.title chapterName = page.title
bookText = page.text.trim() bookText = page.text.trim()
} }
@ -252,35 +254,35 @@ class ReadBookActivity : ReadBookBaseActivity(),
} }
} }
R.id.menu_copy_text -> showDialogFragment( R.id.menu_copy_text -> showDialogFragment(
TextDialog(BookRead.curTextChapter?.getContent()) TextDialog(ReadBook.curTextChapter?.getContent())
) )
R.id.menu_update_toc -> BookRead.book?.let { R.id.menu_update_toc -> ReadBook.book?.let {
loadChapterList(it) loadChapterList(it)
} }
R.id.menu_enable_replace -> BookRead.book?.let { R.id.menu_enable_replace -> ReadBook.book?.let {
it.setUseReplaceRule(!it.getUseReplaceRule()) it.setUseReplaceRule(!it.getUseReplaceRule())
menu?.findItem(R.id.menu_enable_replace)?.isChecked = it.getUseReplaceRule() menu?.findItem(R.id.menu_enable_replace)?.isChecked = it.getUseReplaceRule()
viewModel.replaceRuleChanged() viewModel.replaceRuleChanged()
} }
R.id.menu_re_segment -> BookRead.book?.let { R.id.menu_re_segment -> ReadBook.book?.let {
it.setReSegment(!it.getReSegment()) it.setReSegment(!it.getReSegment())
menu?.findItem(R.id.menu_re_segment)?.isChecked = it.getReSegment() menu?.findItem(R.id.menu_re_segment)?.isChecked = it.getReSegment()
BookRead.loadContent(false) ReadBook.loadContent(false)
} }
R.id.menu_page_anim -> showPageAnimConfig { R.id.menu_page_anim -> showPageAnimConfig {
binding.readView.upPageAnim() binding.readView.upPageAnim()
BookRead.loadContent(false) ReadBook.loadContent(false)
} }
R.id.menu_book_info -> BookRead.book?.let { R.id.menu_book_info -> ReadBook.book?.let {
startActivity<BookInfoActivity> { startActivity<BookInfoActivity> {
putExtra("name", it.name) putExtra("name", it.name)
putExtra("author", it.author) putExtra("author", it.author)
} }
} }
R.id.menu_toc_regex -> showDialogFragment( R.id.menu_toc_regex -> showDialogFragment(
TocRegexDialog(BookRead.book?.tocUrl) TocRegexDialog(ReadBook.book?.tocUrl)
) )
R.id.menu_reverse_content -> BookRead.book?.let { R.id.menu_reverse_content -> ReadBook.book?.let {
viewModel.reverseContent(it) viewModel.reverseContent(it)
} }
R.id.menu_set_charset -> showCharsetConfig() R.id.menu_set_charset -> showCharsetConfig()
@ -291,11 +293,11 @@ class ReadBookActivity : ReadBookBaseActivity(),
R.string.image_style, R.string.image_style,
imgStyles imgStyles
) { _, index -> ) { _, index ->
BookRead.book?.setImageStyle(imgStyles[index]) ReadBook.book?.setImageStyle(imgStyles[index])
BookRead.loadContent(false) ReadBook.loadContent(false)
} }
} }
R.id.menu_get_progress -> BookRead.book?.let { R.id.menu_get_progress -> ReadBook.book?.let {
viewModel.syncBookProgress(it) { progress -> viewModel.syncBookProgress(it) { progress ->
sureSyncProgress(progress) sureSyncProgress(progress)
} }
@ -517,10 +519,10 @@ class ReadBookActivity : ReadBookBaseActivity(),
} }
R.id.menu_replace -> { R.id.menu_replace -> {
val scopes = arrayListOf<String>() val scopes = arrayListOf<String>()
BookRead.book?.name?.let { ReadBook.book?.name?.let {
scopes.add(it) scopes.add(it)
} }
BookRead.bookSource?.bookSourceUrl?.let { ReadBook.bookSource?.bookSourceUrl?.let {
scopes.add(it) scopes.add(it)
} }
replaceActivity.launch( replaceActivity.launch(
@ -580,7 +582,7 @@ class ReadBookActivity : ReadBookBaseActivity(),
} }
override fun loadChapterList(book: Book) { override fun loadChapterList(book: Book) {
BookRead.upMsg(getString(R.string.toc_updateing)) ReadBook.upMsg(getString(R.string.toc_updateing))
viewModel.loadChapterList(book) viewModel.loadChapterList(book)
} }
@ -590,7 +592,7 @@ class ReadBookActivity : ReadBookBaseActivity(),
override fun contentLoadFinish() { override fun contentLoadFinish() {
if (intent.getBooleanExtra("readAloud", false)) { if (intent.getBooleanExtra("readAloud", false)) {
intent.removeExtra("readAloud") intent.removeExtra("readAloud")
BookRead.readAloud() ReadBook.readAloud()
} }
loadStates = true loadStates = true
} }
@ -606,7 +608,7 @@ class ReadBookActivity : ReadBookBaseActivity(),
launch { launch {
autoPageProgress = 0 autoPageProgress = 0
binding.readView.upContent(relativePosition, resetPageOffset) binding.readView.upContent(relativePosition, resetPageOffset)
binding.readMenu.setSeekPage(BookRead.durPageIndex()) binding.readMenu.setSeekPage(ReadBook.durPageIndex())
loadStates = false loadStates = false
success?.invoke() success?.invoke()
} }
@ -624,7 +626,7 @@ class ReadBookActivity : ReadBookBaseActivity(),
override fun pageChanged() { override fun pageChanged() {
launch { launch {
autoPageProgress = 0 autoPageProgress = 0
binding.readMenu.setSeekPage(BookRead.durPageIndex()) binding.readMenu.setSeekPage(ReadBook.durPageIndex())
startBackupJob() startBackupJob()
} }
} }
@ -637,7 +639,7 @@ class ReadBookActivity : ReadBookBaseActivity(),
} }
override val oldBook: Book? override val oldBook: Book?
get() = BookRead.book get() = ReadBook.book
override fun changeTo(source: BookSource, book: Book) { override fun changeTo(source: BookSource, book: Book) {
viewModel.changeTo(source, book) viewModel.changeTo(source, book)
@ -722,7 +724,7 @@ class ReadBookActivity : ReadBookBaseActivity(),
} }
override fun openSourceEditActivity() { override fun openSourceEditActivity() {
BookRead.bookSource?.let { ReadBook.bookSource?.let {
sourceEditActivity.launch { sourceEditActivity.launch {
putExtra("sourceUrl", it.bookSourceUrl) putExtra("sourceUrl", it.bookSourceUrl)
} }
@ -740,7 +742,7 @@ class ReadBookActivity : ReadBookBaseActivity(),
* 打开目录 * 打开目录
*/ */
override fun openChapterList() { override fun openChapterList() {
BookRead.book?.let { ReadBook.book?.let {
tocActivity.launch(it.bookUrl) tocActivity.launch(it.bookUrl)
} }
} }
@ -749,7 +751,7 @@ class ReadBookActivity : ReadBookBaseActivity(),
* 打开搜索界面 * 打开搜索界面
*/ */
override fun openSearchActivity(searchWord: String?) { override fun openSearchActivity(searchWord: String?) {
BookRead.book?.let { ReadBook.book?.let {
searchContentActivity.launch(Intent(this, SearchContentActivity::class.java).apply { searchContentActivity.launch(Intent(this, SearchContentActivity::class.java).apply {
putExtra("bookUrl", it.bookUrl) putExtra("bookUrl", it.bookUrl)
putExtra("searchWord", searchWord ?: viewModel.searchContentQuery) putExtra("searchWord", searchWord ?: viewModel.searchContentQuery)
@ -787,7 +789,7 @@ class ReadBookActivity : ReadBookBaseActivity(),
} }
override fun showLogin() { override fun showLogin() {
BookRead.bookSource?.let { ReadBook.bookSource?.let {
startActivity<SourceLoginActivity> { startActivity<SourceLoginActivity> {
putExtra("sourceUrl", it.bookSourceUrl) putExtra("sourceUrl", it.bookSourceUrl)
} }
@ -796,16 +798,30 @@ class ReadBookActivity : ReadBookBaseActivity(),
override fun payAction() { override fun payAction() {
Coroutine.async(this) { Coroutine.async(this) {
val book = BookRead.book ?: throw NoStackTraceException("no book") val book = ReadBook.book ?: throw NoStackTraceException("no book")
val chapter = appDb.bookChapterDao.getChapter(book.bookUrl, BookRead.durChapterIndex) val chapter = appDb.bookChapterDao.getChapter(book.bookUrl, ReadBook.durChapterIndex)
?: throw NoStackTraceException("no chapter") ?: throw NoStackTraceException("no chapter")
val source = BookRead.bookSource ?: throw NoStackTraceException("no book source") val source = ReadBook.bookSource ?: throw NoStackTraceException("no book source")
val payAction = source.getContentRule().payAction val payAction = source.getContentRule().payAction
if (payAction.isNullOrEmpty()) { if (payAction.isNullOrEmpty()) {
throw NoStackTraceException("no pay action") throw NoStackTraceException("no pay action")
} }
if (payAction.isAbsUrl()) {
payAction
} else {
source.evalJS(payAction) {
put("book", book)
put("chapter", chapter)
}?.toString()
}
}.onSuccess { }.onSuccess {
it?.let {
startActivity<WebViewActivity> {
putExtra("title", "购买")
putExtra("url", it)
IntentData.put(it, ReadBook.bookSource)
}
}
}.onError { }.onError {
toastOnUi(it.localizedMessage) toastOnUi(it.localizedMessage)
} }
@ -817,7 +833,7 @@ class ReadBookActivity : ReadBookBaseActivity(),
override fun onClickReadAloud() { override fun onClickReadAloud() {
autoPageStop() autoPageStop()
when { when {
!BaseReadAloudService.isRun -> BookRead.readAloud() !BaseReadAloudService.isRun -> ReadBook.readAloud()
BaseReadAloudService.pause -> ReadAloud.resume(this) BaseReadAloudService.pause -> ReadAloud.resume(this)
else -> ReadAloud.pause(this) else -> ReadAloud.pause(this)
} }
@ -851,7 +867,7 @@ class ReadBookActivity : ReadBookBaseActivity(),
override fun onDialogDismissed(dialogId: Int) = Unit override fun onDialogDismissed(dialogId: Int) = Unit
override fun onTocRegexDialogResult(tocRegex: String) { override fun onTocRegexDialogResult(tocRegex: String) {
BookRead.book?.let { ReadBook.book?.let {
it.tocUrl = tocRegex it.tocUrl = tocRegex
viewModel.loadChapterList(it) viewModel.loadChapterList(it)
} }
@ -861,7 +877,7 @@ class ReadBookActivity : ReadBookBaseActivity(),
alert(R.string.get_book_progress) { alert(R.string.get_book_progress) {
setMessage(R.string.current_progress_exceeds_cloud) setMessage(R.string.current_progress_exceeds_cloud)
okButton { okButton {
BookRead.setProgress(progress) ReadBook.setProgress(progress)
} }
noButton() noButton()
} }
@ -869,9 +885,9 @@ class ReadBookActivity : ReadBookBaseActivity(),
private fun skipToSearch(index: Int, indexWithinChapter: Int) { private fun skipToSearch(index: Int, indexWithinChapter: Int) {
viewModel.openChapter(index) { viewModel.openChapter(index) {
val pages = BookRead.curTextChapter?.pages ?: return@openChapter val pages = ReadBook.curTextChapter?.pages ?: return@openChapter
val positions = viewModel.searchResultPositions(pages, indexWithinChapter) val positions = viewModel.searchResultPositions(pages, indexWithinChapter)
BookRead.skipToPage(positions[0]) { ReadBook.skipToPage(positions[0]) {
launch { launch {
binding.readView.curPage.selectStartMoveIndex(0, positions[1], positions[2]) binding.readView.curPage.selectStartMoveIndex(0, positions[1], positions[2])
delay(20L) delay(20L)
@ -901,7 +917,7 @@ class ReadBookActivity : ReadBookBaseActivity(),
backupJob?.cancel() backupJob?.cancel()
backupJob = launch { backupJob = launch {
delay(120000) delay(120000)
BookRead.book?.let { ReadBook.book?.let {
AppWebDav.uploadBookProgress(it) AppWebDav.uploadBookProgress(it)
Backup.autoBack(this@ReadBookActivity) Backup.autoBack(this@ReadBookActivity)
} }
@ -909,12 +925,12 @@ class ReadBookActivity : ReadBookBaseActivity(),
} }
override fun finish() { override fun finish() {
BookRead.book?.let { ReadBook.book?.let {
if (!BookRead.inBookshelf) { if (!ReadBook.inBookshelf) {
alert(title = getString(R.string.add_to_shelf)) { alert(title = getString(R.string.add_to_shelf)) {
setMessage(getString(R.string.check_add_bookshelf, it.name)) setMessage(getString(R.string.check_add_bookshelf, it.name))
okButton { okButton {
BookRead.inBookshelf = true ReadBook.inBookshelf = true
setResult(Activity.RESULT_OK) setResult(Activity.RESULT_OK)
} }
noButton { viewModel.removeFromBookshelf { super.finish() } } noButton { viewModel.removeFromBookshelf { super.finish() } }
@ -929,7 +945,7 @@ class ReadBookActivity : ReadBookBaseActivity(),
super.onDestroy() super.onDestroy()
textActionMenu.dismiss() textActionMenu.dismiss()
binding.readView.onDestroy() binding.readView.onDestroy()
BookRead.msg = null ReadBook.msg = null
if (!BuildConfig.DEBUG) { if (!BuildConfig.DEBUG) {
Backup.autoBack(this) Backup.autoBack(this)
} }
@ -940,14 +956,14 @@ class ReadBookActivity : ReadBookBaseActivity(),
observeEvent<String>(EventBus.TIME_CHANGED) { readView.upTime() } observeEvent<String>(EventBus.TIME_CHANGED) { readView.upTime() }
observeEvent<Int>(EventBus.BATTERY_CHANGED) { readView.upBattery(it) } observeEvent<Int>(EventBus.BATTERY_CHANGED) { readView.upBattery(it) }
observeEvent<BookChapter>(EventBus.OPEN_CHAPTER) { observeEvent<BookChapter>(EventBus.OPEN_CHAPTER) {
viewModel.openChapter(it.index, BookRead.durChapterPos) viewModel.openChapter(it.index, ReadBook.durChapterPos)
readView.upContent() readView.upContent()
} }
observeEvent<Boolean>(EventBus.MEDIA_BUTTON) { observeEvent<Boolean>(EventBus.MEDIA_BUTTON) {
if (it) { if (it) {
onClickReadAloud() onClickReadAloud()
} else { } else {
BookRead.readAloud(!BaseReadAloudService.pause) ReadBook.readAloud(!BaseReadAloudService.pause)
} }
} }
observeEvent<Boolean>(EventBus.UP_CONFIG) { observeEvent<Boolean>(EventBus.UP_CONFIG) {
@ -955,15 +971,15 @@ class ReadBookActivity : ReadBookBaseActivity(),
readView.upBg() readView.upBg()
readView.upStyle() readView.upStyle()
if (it) { if (it) {
BookRead.loadContent(resetPageOffset = false) ReadBook.loadContent(resetPageOffset = false)
} else { } else {
readView.upContent(resetPageOffset = false) readView.upContent(resetPageOffset = false)
} }
} }
observeEvent<Int>(EventBus.ALOUD_STATE) { observeEvent<Int>(EventBus.ALOUD_STATE) {
if (it == Status.STOP || it == Status.PAUSE) { if (it == Status.STOP || it == Status.PAUSE) {
BookRead.curTextChapter?.let { textChapter -> ReadBook.curTextChapter?.let { textChapter ->
val page = textChapter.getPageByReadPos(BookRead.durChapterPos) val page = textChapter.getPageByReadPos(ReadBook.durChapterPos)
if (page != null) { if (page != null) {
page.removePageAloudSpan() page.removePageAloudSpan()
readView.upContent(resetPageOffset = false) readView.upContent(resetPageOffset = false)
@ -974,9 +990,9 @@ class ReadBookActivity : ReadBookBaseActivity(),
observeEventSticky<Int>(EventBus.TTS_PROGRESS) { chapterStart -> observeEventSticky<Int>(EventBus.TTS_PROGRESS) { chapterStart ->
launch(IO) { launch(IO) {
if (BaseReadAloudService.isPlay()) { if (BaseReadAloudService.isPlay()) {
BookRead.curTextChapter?.let { textChapter -> ReadBook.curTextChapter?.let { textChapter ->
val aloudSpanStart = chapterStart - BookRead.durChapterPos val aloudSpanStart = chapterStart - ReadBook.durChapterPos
textChapter.getPageByReadPos(BookRead.durChapterPos) textChapter.getPageByReadPos(ReadBook.durChapterPos)
?.upPageAloudSpan(aloudSpanStart) ?.upPageAloudSpan(aloudSpanStart)
upContent() upContent()
} }

@ -23,8 +23,8 @@ import io.legado.app.lib.theme.ATH
import io.legado.app.lib.theme.ThemeStore import io.legado.app.lib.theme.ThemeStore
import io.legado.app.lib.theme.backgroundColor import io.legado.app.lib.theme.backgroundColor
import io.legado.app.lib.theme.bottomBackground import io.legado.app.lib.theme.bottomBackground
import io.legado.app.model.BookRead
import io.legado.app.model.CacheBook import io.legado.app.model.CacheBook
import io.legado.app.model.ReadBook
import io.legado.app.ui.book.read.config.BgTextConfigDialog import io.legado.app.ui.book.read.config.BgTextConfigDialog
import io.legado.app.ui.book.read.config.ClickActionConfigDialog import io.legado.app.ui.book.read.config.ClickActionConfigDialog
import io.legado.app.ui.book.read.config.PaddingConfigDialog import io.legado.app.ui.book.read.config.PaddingConfigDialog
@ -42,7 +42,7 @@ abstract class ReadBookBaseActivity :
var bottomDialog = 0 var bottomDialog = 0
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
BookRead.msg = null ReadBook.msg = null
setOrientation() setOrientation()
upLayoutInDisplayCutoutMode() upLayoutInDisplayCutoutMode()
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
@ -186,7 +186,7 @@ abstract class ReadBookBaseActivity :
@SuppressLint("InflateParams") @SuppressLint("InflateParams")
fun showDownloadDialog() { fun showDownloadDialog() {
BookRead.book?.let { book -> ReadBook.book?.let { book ->
alert(titleResource = R.string.offline_cache) { alert(titleResource = R.string.offline_cache) {
val alertBinding = DialogDownloadChoiceBinding.inflate(layoutInflater).apply { val alertBinding = DialogDownloadChoiceBinding.inflate(layoutInflater).apply {
root.setBackgroundColor(root.context.backgroundColor) root.setBackgroundColor(root.context.backgroundColor)
@ -211,12 +211,12 @@ abstract class ReadBookBaseActivity :
val alertBinding = DialogEditTextBinding.inflate(layoutInflater).apply { val alertBinding = DialogEditTextBinding.inflate(layoutInflater).apply {
editView.hint = "charset" editView.hint = "charset"
editView.setFilterValues(charsets) editView.setFilterValues(charsets)
editView.setText(BookRead.book?.charset) editView.setText(ReadBook.book?.charset)
} }
customView { alertBinding.root } customView { alertBinding.root }
okButton { okButton {
alertBinding.editView.text?.toString()?.let { alertBinding.editView.text?.toString()?.let {
BookRead.setCharset(it) ReadBook.setCharset(it)
} }
} }
cancelButton() cancelButton()
@ -232,7 +232,7 @@ abstract class ReadBookBaseActivity :
items.add(getString(R.string.page_anim_scroll)) items.add(getString(R.string.page_anim_scroll))
items.add(getString(R.string.page_anim_none)) items.add(getString(R.string.page_anim_none))
selector(R.string.page_anim, items) { _, i -> selector(R.string.page_anim, items) { _, i ->
BookRead.book?.setPageAnim(i - 1) ReadBook.book?.setPageAnim(i - 1)
success() success()
} }
} }

@ -14,9 +14,9 @@ import io.legado.app.help.AppConfig
import io.legado.app.help.BookHelp import io.legado.app.help.BookHelp
import io.legado.app.help.ContentProcessor import io.legado.app.help.ContentProcessor
import io.legado.app.help.storage.AppWebDav import io.legado.app.help.storage.AppWebDav
import io.legado.app.model.BookRead
import io.legado.app.model.NoStackTraceException import io.legado.app.model.NoStackTraceException
import io.legado.app.model.ReadAloud import io.legado.app.model.ReadAloud
import io.legado.app.model.ReadBook
import io.legado.app.model.localBook.LocalBook import io.legado.app.model.localBook.LocalBook
import io.legado.app.model.webBook.WebBook import io.legado.app.model.webBook.WebBook
import io.legado.app.service.BaseReadAloudService import io.legado.app.service.BaseReadAloudService
@ -32,67 +32,67 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
fun initData(intent: Intent) { fun initData(intent: Intent) {
execute { execute {
BookRead.inBookshelf = intent.getBooleanExtra("inBookshelf", true) ReadBook.inBookshelf = intent.getBooleanExtra("inBookshelf", true)
val bookUrl = intent.getStringExtra("bookUrl") val bookUrl = intent.getStringExtra("bookUrl")
val book = when { val book = when {
bookUrl.isNullOrEmpty() -> appDb.bookDao.lastReadBook bookUrl.isNullOrEmpty() -> appDb.bookDao.lastReadBook
else -> appDb.bookDao.getBook(bookUrl) else -> appDb.bookDao.getBook(bookUrl)
} ?: BookRead.book } ?: ReadBook.book
when { when {
book != null -> initBook(book) book != null -> initBook(book)
else -> BookRead.upMsg(context.getString(R.string.no_book)) else -> ReadBook.upMsg(context.getString(R.string.no_book))
} }
}.onFinally { }.onFinally {
BookRead.saveRead() ReadBook.saveRead()
} }
} }
private fun initBook(book: Book) { private fun initBook(book: Book) {
if (BookRead.book?.bookUrl != book.bookUrl) { if (ReadBook.book?.bookUrl != book.bookUrl) {
BookRead.resetData(book) ReadBook.resetData(book)
isInitFinish = true isInitFinish = true
if (BookRead.chapterSize == 0) { if (ReadBook.chapterSize == 0) {
if (book.tocUrl.isEmpty()) { if (book.tocUrl.isEmpty()) {
loadBookInfo(book) loadBookInfo(book)
} else { } else {
loadChapterList(book) loadChapterList(book)
} }
} else { } else {
if (BookRead.durChapterIndex > BookRead.chapterSize - 1) { if (ReadBook.durChapterIndex > ReadBook.chapterSize - 1) {
BookRead.durChapterIndex = BookRead.chapterSize - 1 ReadBook.durChapterIndex = ReadBook.chapterSize - 1
} }
BookRead.loadContent(resetPageOffset = true) ReadBook.loadContent(resetPageOffset = true)
} }
syncBookProgress(book) syncBookProgress(book)
} else { } else {
BookRead.book = book ReadBook.book = book
if (BookRead.durChapterIndex != book.durChapterIndex) { if (ReadBook.durChapterIndex != book.durChapterIndex) {
BookRead.durChapterIndex = book.durChapterIndex ReadBook.durChapterIndex = book.durChapterIndex
BookRead.durChapterPos = book.durChapterPos ReadBook.durChapterPos = book.durChapterPos
BookRead.clearTextChapter() ReadBook.clearTextChapter()
} }
BookRead.callBack?.upMenuView() ReadBook.callBack?.upMenuView()
BookRead.upWebBook(book) ReadBook.upWebBook(book)
isInitFinish = true isInitFinish = true
BookRead.chapterSize = appDb.bookChapterDao.getChapterCount(book.bookUrl) ReadBook.chapterSize = appDb.bookChapterDao.getChapterCount(book.bookUrl)
if (BookRead.chapterSize == 0) { if (ReadBook.chapterSize == 0) {
if (book.tocUrl.isEmpty()) { if (book.tocUrl.isEmpty()) {
loadBookInfo(book) loadBookInfo(book)
} else { } else {
loadChapterList(book) loadChapterList(book)
} }
} else { } else {
if (BookRead.curTextChapter != null) { if (ReadBook.curTextChapter != null) {
BookRead.callBack?.upContent(resetPageOffset = false) ReadBook.callBack?.upContent(resetPageOffset = false)
} else { } else {
BookRead.loadContent(resetPageOffset = true) ReadBook.loadContent(resetPageOffset = true)
} }
} }
if (!BaseReadAloudService.isRun) { if (!BaseReadAloudService.isRun) {
syncBookProgress(book) syncBookProgress(book)
} }
} }
if (!book.isLocalBook() && BookRead.bookSource == null) { if (!book.isLocalBook() && ReadBook.bookSource == null) {
autoChangeSource(book.name, book.author) autoChangeSource(book.name, book.author)
return return
} }
@ -102,12 +102,12 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
if (book.isLocalBook()) { if (book.isLocalBook()) {
loadChapterList(book) loadChapterList(book)
} else { } else {
BookRead.bookSource?.let { source -> ReadBook.bookSource?.let { source ->
WebBook.getBookInfo(viewModelScope, source, book, canReName = false) WebBook.getBookInfo(viewModelScope, source, book, canReName = false)
.onSuccess { .onSuccess {
loadChapterList(book) loadChapterList(book)
}.onError { }.onError {
BookRead.upMsg("详情页出错: ${it.localizedMessage}") ReadBook.upMsg("详情页出错: ${it.localizedMessage}")
} }
} }
} }
@ -120,24 +120,24 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
appDb.bookChapterDao.delByBook(book.bookUrl) appDb.bookChapterDao.delByBook(book.bookUrl)
appDb.bookChapterDao.insert(*it.toTypedArray()) appDb.bookChapterDao.insert(*it.toTypedArray())
appDb.bookDao.update(book) appDb.bookDao.update(book)
BookRead.chapterSize = it.size ReadBook.chapterSize = it.size
BookRead.upMsg(null) ReadBook.upMsg(null)
BookRead.loadContent(resetPageOffset = true) ReadBook.loadContent(resetPageOffset = true)
} }
}.onError { }.onError {
BookRead.upMsg("LoadTocError:${it.localizedMessage}") ReadBook.upMsg("LoadTocError:${it.localizedMessage}")
} }
} else { } else {
BookRead.bookSource?.let { ReadBook.bookSource?.let {
WebBook.getChapterList(viewModelScope, it, book) WebBook.getChapterList(viewModelScope, it, book)
.onSuccess(IO) { cList -> .onSuccess(IO) { cList ->
appDb.bookChapterDao.insert(*cList.toTypedArray()) appDb.bookChapterDao.insert(*cList.toTypedArray())
appDb.bookDao.update(book) appDb.bookDao.update(book)
BookRead.chapterSize = cList.size ReadBook.chapterSize = cList.size
BookRead.upMsg(null) ReadBook.upMsg(null)
BookRead.loadContent(resetPageOffset = true) ReadBook.loadContent(resetPageOffset = true)
}.onError { }.onError {
BookRead.upMsg(context.getString(R.string.error_load_toc)) ReadBook.upMsg(context.getString(R.string.error_load_toc))
} }
} }
} }
@ -158,7 +158,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
) { ) {
alertSync?.invoke(progress) alertSync?.invoke(progress)
} else { } else {
BookRead.setProgress(progress) ReadBook.setProgress(progress)
} }
} }
} }
@ -166,12 +166,12 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
fun changeTo(source: BookSource, book: Book) { fun changeTo(source: BookSource, book: Book) {
execute { execute {
BookRead.upMsg(context.getString(R.string.loading)) ReadBook.upMsg(context.getString(R.string.loading))
if (book.tocUrl.isEmpty()) { if (book.tocUrl.isEmpty()) {
WebBook.getBookInfoAwait(this, source, book) WebBook.getBookInfoAwait(this, source, book)
} }
val chapters = WebBook.getChapterListAwait(this, source, book) val chapters = WebBook.getChapterListAwait(this, source, book)
val oldBook = BookRead.book!! val oldBook = ReadBook.book!!
book.durChapterIndex = BookHelp.getDurChapter( book.durChapterIndex = BookHelp.getDurChapter(
oldBook.durChapterIndex, oldBook.durChapterIndex,
oldBook.totalChapterNum, oldBook.totalChapterNum,
@ -181,13 +181,13 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
book.durChapterTitle = chapters[book.durChapterIndex].title book.durChapterTitle = chapters[book.durChapterIndex].title
oldBook.changeTo(book) oldBook.changeTo(book)
appDb.bookChapterDao.insert(*chapters.toTypedArray()) appDb.bookChapterDao.insert(*chapters.toTypedArray())
BookRead.resetData(book) ReadBook.resetData(book)
BookRead.upMsg(null) ReadBook.upMsg(null)
BookRead.loadContent(resetPageOffset = true) ReadBook.loadContent(resetPageOffset = true)
}.timeout(60000) }.timeout(60000)
.onError { .onError {
context.toastOnUi("换源失败\n${it.localizedMessage}") context.toastOnUi("换源失败\n${it.localizedMessage}")
BookRead.upMsg(null) ReadBook.upMsg(null)
}.onFinally { }.onFinally {
postEvent(EventBus.SOURCE_CHANGED, book.bookUrl) postEvent(EventBus.SOURCE_CHANGED, book.bookUrl)
} }
@ -198,34 +198,34 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
execute { execute {
val sources = appDb.bookSourceDao.allTextEnabled val sources = appDb.bookSourceDao.allTextEnabled
WebBook.preciseSearch(this, sources, name, author)?.let { WebBook.preciseSearch(this, sources, name, author)?.let {
it.second.upInfoFromOld(BookRead.book) it.second.upInfoFromOld(ReadBook.book)
changeTo(it.first, it.second) changeTo(it.first, it.second)
} ?: throw NoStackTraceException("自动换源失败") } ?: throw NoStackTraceException("自动换源失败")
}.onStart { }.onStart {
BookRead.upMsg(context.getString(R.string.source_auto_changing)) ReadBook.upMsg(context.getString(R.string.source_auto_changing))
}.onError { }.onError {
context.toastOnUi(it.msg) context.toastOnUi(it.msg)
}.onFinally { }.onFinally {
BookRead.upMsg(null) ReadBook.upMsg(null)
} }
} }
fun openChapter(index: Int, durChapterPos: Int = 0, success: (() -> Unit)? = null) { fun openChapter(index: Int, durChapterPos: Int = 0, success: (() -> Unit)? = null) {
BookRead.clearTextChapter() ReadBook.clearTextChapter()
BookRead.callBack?.upContent() ReadBook.callBack?.upContent()
if (index != BookRead.durChapterIndex) { if (index != ReadBook.durChapterIndex) {
BookRead.durChapterIndex = index ReadBook.durChapterIndex = index
BookRead.durChapterPos = durChapterPos ReadBook.durChapterPos = durChapterPos
} }
BookRead.saveRead() ReadBook.saveRead()
BookRead.loadContent(resetPageOffset = true) { ReadBook.loadContent(resetPageOffset = true) {
success?.invoke() success?.invoke()
} }
} }
fun removeFromBookshelf(success: (() -> Unit)?) { fun removeFromBookshelf(success: (() -> Unit)?) {
execute { execute {
Book.delete(BookRead.book) Book.delete(ReadBook.book)
}.onSuccess { }.onSuccess {
success?.invoke() success?.invoke()
} }
@ -233,8 +233,8 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
fun upBookSource(success: (() -> Unit)?) { fun upBookSource(success: (() -> Unit)?) {
execute { execute {
BookRead.book?.let { book -> ReadBook.book?.let { book ->
BookRead.bookSource = appDb.bookSourceDao.getBookSource(book.origin) ReadBook.bookSource = appDb.bookSourceDao.getBookSource(book.origin)
} }
}.onSuccess { }.onSuccess {
success?.invoke() success?.invoke()
@ -243,20 +243,20 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
fun refreshContent(book: Book) { fun refreshContent(book: Book) {
execute { execute {
appDb.bookChapterDao.getChapter(book.bookUrl, BookRead.durChapterIndex) appDb.bookChapterDao.getChapter(book.bookUrl, ReadBook.durChapterIndex)
?.let { chapter -> ?.let { chapter ->
BookHelp.delContent(book, chapter) BookHelp.delContent(book, chapter)
BookRead.loadContent(BookRead.durChapterIndex, resetPageOffset = false) ReadBook.loadContent(ReadBook.durChapterIndex, resetPageOffset = false)
} }
} }
} }
fun reverseContent(book: Book) { fun reverseContent(book: Book) {
execute { execute {
appDb.bookChapterDao.getChapter(book.bookUrl, BookRead.durChapterIndex) appDb.bookChapterDao.getChapter(book.bookUrl, ReadBook.durChapterIndex)
?.let { chapter -> ?.let { chapter ->
BookHelp.reverseContent(book, chapter) BookHelp.reverseContent(book, chapter)
BookRead.loadContent(BookRead.durChapterIndex, resetPageOffset = false) ReadBook.loadContent(ReadBook.durChapterIndex, resetPageOffset = false)
} }
} }
} }
@ -328,16 +328,16 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
*/ */
fun replaceRuleChanged() { fun replaceRuleChanged() {
execute { execute {
BookRead.book?.let { ReadBook.book?.let {
ContentProcessor.get(it.name, it.origin).upReplaceRules() ContentProcessor.get(it.name, it.origin).upReplaceRules()
BookRead.loadContent(resetPageOffset = false) ReadBook.loadContent(resetPageOffset = false)
} }
} }
} }
fun disableSource() { fun disableSource() {
execute { execute {
BookRead.bookSource?.let { ReadBook.bookSource?.let {
it.enabled = false it.enabled = false
appDb.bookSourceDao.update(it) appDb.bookSourceDao.update(it)
} }

@ -20,7 +20,7 @@ import io.legado.app.databinding.ViewReadMenuBinding
import io.legado.app.help.* import io.legado.app.help.*
import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.alert
import io.legado.app.lib.theme.* import io.legado.app.lib.theme.*
import io.legado.app.model.BookRead import io.legado.app.model.ReadBook
import io.legado.app.ui.browser.WebViewActivity import io.legado.app.ui.browser.WebViewActivity
import io.legado.app.ui.widget.seekbar.SeekBarChangeListener import io.legado.app.ui.widget.seekbar.SeekBarChangeListener
import io.legado.app.utils.* import io.legado.app.utils.*
@ -159,7 +159,7 @@ class ReadMenu @JvmOverloads constructor(
private fun bindEvent() = binding.run { private fun bindEvent() = binding.run {
val chapterViewClickListener = OnClickListener { val chapterViewClickListener = OnClickListener {
if (BookRead.isLocalBook) { if (ReadBook.isLocalBook) {
return@OnClickListener return@OnClickListener
} }
if (AppConfig.readUrlInBrowser) { if (AppConfig.readUrlInBrowser) {
@ -169,12 +169,12 @@ class ReadMenu @JvmOverloads constructor(
val url = tvChapterUrl.text.toString() val url = tvChapterUrl.text.toString()
putExtra("title", tvChapterName.text) putExtra("title", tvChapterName.text)
putExtra("url", url) putExtra("url", url)
IntentData.put(url, BookRead.bookSource?.getHeaderMap(true)) IntentData.put(url, ReadBook.bookSource?.getHeaderMap(true))
} }
} }
} }
val chapterViewLongClickListener = OnLongClickListener { val chapterViewLongClickListener = OnLongClickListener {
if (BookRead.isLocalBook) { if (ReadBook.isLocalBook) {
return@OnLongClickListener true return@OnLongClickListener true
} }
context.alert(R.string.Open_fan) { context.alert(R.string.Open_fan) {
@ -228,7 +228,7 @@ class ReadMenu @JvmOverloads constructor(
seekReadPage.setOnSeekBarChangeListener(object : SeekBarChangeListener { seekReadPage.setOnSeekBarChangeListener(object : SeekBarChangeListener {
override fun onStopTrackingTouch(seekBar: SeekBar) { override fun onStopTrackingTouch(seekBar: SeekBar) {
BookRead.skipToPage(seekBar.progress) ReadBook.skipToPage(seekBar.progress)
} }
}) })
@ -257,10 +257,10 @@ class ReadMenu @JvmOverloads constructor(
} }
//上一章 //上一章
tvPre.setOnClickListener { BookRead.moveToPrevChapter(upContent = true, toLast = false) } tvPre.setOnClickListener { ReadBook.moveToPrevChapter(upContent = true, toLast = false) }
//下一章 //下一章
tvNext.setOnClickListener { BookRead.moveToNextChapter(true) } tvNext.setOnClickListener { ReadBook.moveToNextChapter(true) }
//目录 //目录
llCatalog.setOnClickListener { llCatalog.setOnClickListener {
@ -299,11 +299,11 @@ class ReadMenu @JvmOverloads constructor(
menuBottomIn = AnimationUtilsSupport.loadAnimation(context, R.anim.anim_readbook_bottom_in) menuBottomIn = AnimationUtilsSupport.loadAnimation(context, R.anim.anim_readbook_bottom_in)
menuTopIn.setAnimationListener(object : Animation.AnimationListener { menuTopIn.setAnimationListener(object : Animation.AnimationListener {
override fun onAnimationStart(animation: Animation) { override fun onAnimationStart(animation: Animation) {
binding.tvSourceAction.isGone = BookRead.isLocalBook binding.tvSourceAction.isGone = ReadBook.isLocalBook
binding.tvLogin.isGone = BookRead.bookSource?.loginUrl.isNullOrEmpty() binding.tvLogin.isGone = ReadBook.bookSource?.loginUrl.isNullOrEmpty()
binding.tvPay.isGone = BookRead.bookSource?.loginUrl.isNullOrEmpty() binding.tvPay.isGone = ReadBook.bookSource?.loginUrl.isNullOrEmpty()
|| BookRead.curTextChapter?.isVip != true || ReadBook.curTextChapter?.isVip != true
|| BookRead.curTextChapter?.isPay == true || ReadBook.curTextChapter?.isPay == true
callBack.upSystemUiVisibility() callBack.upSystemUiVisibility()
binding.llBrightness.visible(showBrightnessView) binding.llBrightness.visible(showBrightnessView)
} }
@ -350,20 +350,20 @@ class ReadMenu @JvmOverloads constructor(
} }
fun upBookView() { fun upBookView() {
binding.titleBar.title = BookRead.book?.name binding.titleBar.title = ReadBook.book?.name
BookRead.curTextChapter?.let { ReadBook.curTextChapter?.let {
binding.tvChapterName.text = it.title binding.tvChapterName.text = it.title
binding.tvChapterName.visible() binding.tvChapterName.visible()
if (!BookRead.isLocalBook) { if (!ReadBook.isLocalBook) {
binding.tvChapterUrl.text = it.url binding.tvChapterUrl.text = it.url
binding.tvChapterUrl.visible() binding.tvChapterUrl.visible()
} else { } else {
binding.tvChapterUrl.gone() binding.tvChapterUrl.gone()
} }
binding.seekReadPage.max = it.pageSize.minus(1) binding.seekReadPage.max = it.pageSize.minus(1)
binding.seekReadPage.progress = BookRead.durPageIndex() binding.seekReadPage.progress = ReadBook.durPageIndex()
binding.tvPre.isEnabled = BookRead.durChapterIndex != 0 binding.tvPre.isEnabled = ReadBook.durChapterIndex != 0
binding.tvNext.isEnabled = BookRead.durChapterIndex != BookRead.chapterSize - 1 binding.tvNext.isEnabled = ReadBook.durChapterIndex != ReadBook.chapterSize - 1
} ?: let { } ?: let {
binding.tvChapterName.gone() binding.tvChapterName.gone()
binding.tvChapterUrl.gone() binding.tvChapterUrl.gone()

@ -10,8 +10,8 @@ import io.legado.app.databinding.DialogAutoReadBinding
import io.legado.app.help.ReadBookConfig import io.legado.app.help.ReadBookConfig
import io.legado.app.lib.theme.bottomBackground import io.legado.app.lib.theme.bottomBackground
import io.legado.app.lib.theme.getPrimaryTextColor import io.legado.app.lib.theme.getPrimaryTextColor
import io.legado.app.model.BookRead
import io.legado.app.model.ReadAloud import io.legado.app.model.ReadAloud
import io.legado.app.model.ReadBook
import io.legado.app.service.BaseReadAloudService import io.legado.app.service.BaseReadAloudService
import io.legado.app.ui.book.read.ReadBookActivity import io.legado.app.ui.book.read.ReadBookActivity
import io.legado.app.ui.book.read.ReadBookBaseActivity import io.legado.app.ui.book.read.ReadBookBaseActivity
@ -103,7 +103,7 @@ class AutoReadDialog : BaseDialogFragment() {
binding.llSetting.setOnClickListener { binding.llSetting.setOnClickListener {
(activity as ReadBookBaseActivity).showPageAnimConfig { (activity as ReadBookBaseActivity).showPageAnimConfig {
(activity as ReadBookActivity).upPageAnim() (activity as ReadBookActivity).upPageAnim()
BookRead.loadContent(false) ReadBook.loadContent(false)
} }
} }
binding.llCatalog.setOnClickListener { callBack?.openChapterList() } binding.llCatalog.setOnClickListener { callBack?.openChapterList() }

@ -15,7 +15,7 @@ import io.legado.app.constant.PreferKey
import io.legado.app.help.ReadBookConfig import io.legado.app.help.ReadBookConfig
import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.ATH
import io.legado.app.lib.theme.bottomBackground import io.legado.app.lib.theme.bottomBackground
import io.legado.app.model.BookRead import io.legado.app.model.ReadBook
import io.legado.app.ui.book.read.ReadBookActivity import io.legado.app.ui.book.read.ReadBookActivity
import io.legado.app.ui.book.read.page.ReadView import io.legado.app.ui.book.read.page.ReadView
import io.legado.app.ui.book.read.page.provider.ChapterProvider import io.legado.app.ui.book.read.page.provider.ChapterProvider
@ -126,7 +126,7 @@ class MoreConfigDialog : DialogFragment() {
} }
PreferKey.doublePageHorizontal -> { PreferKey.doublePageHorizontal -> {
ChapterProvider.upLayout() ChapterProvider.upLayout()
BookRead.loadContent(false) ReadBook.loadContent(false)
} }
} }
} }

@ -11,8 +11,8 @@ import io.legado.app.databinding.DialogReadAloudBinding
import io.legado.app.help.AppConfig import io.legado.app.help.AppConfig
import io.legado.app.lib.theme.bottomBackground import io.legado.app.lib.theme.bottomBackground
import io.legado.app.lib.theme.getPrimaryTextColor import io.legado.app.lib.theme.getPrimaryTextColor
import io.legado.app.model.BookRead
import io.legado.app.model.ReadAloud import io.legado.app.model.ReadAloud
import io.legado.app.model.ReadBook
import io.legado.app.service.BaseReadAloudService import io.legado.app.service.BaseReadAloudService
import io.legado.app.ui.book.read.ReadBookActivity import io.legado.app.ui.book.read.ReadBookActivity
import io.legado.app.ui.widget.seekbar.SeekBarChangeListener import io.legado.app.ui.widget.seekbar.SeekBarChangeListener
@ -102,8 +102,8 @@ class ReadAloudDialog : BaseDialogFragment() {
llSetting.setOnClickListener { llSetting.setOnClickListener {
ReadAloudConfigDialog().show(childFragmentManager, "readAloudConfigDialog") ReadAloudConfigDialog().show(childFragmentManager, "readAloudConfigDialog")
} }
tvPre.setOnClickListener { BookRead.moveToPrevChapter(upContent = true, toLast = false) } tvPre.setOnClickListener { ReadBook.moveToPrevChapter(upContent = true, toLast = false) }
tvNext.setOnClickListener { BookRead.moveToNextChapter(true) } tvNext.setOnClickListener { ReadBook.moveToNextChapter(true) }
ivStop.setOnClickListener { ivStop.setOnClickListener {
ReadAloud.stop(requireContext()) ReadAloud.stop(requireContext())
dismissAllowingStateLoss() dismissAllowingStateLoss()

@ -16,7 +16,7 @@ import io.legado.app.lib.dialogs.selector
import io.legado.app.lib.theme.accentColor import io.legado.app.lib.theme.accentColor
import io.legado.app.lib.theme.bottomBackground import io.legado.app.lib.theme.bottomBackground
import io.legado.app.lib.theme.getPrimaryTextColor import io.legado.app.lib.theme.getPrimaryTextColor
import io.legado.app.model.BookRead import io.legado.app.model.ReadBook
import io.legado.app.ui.book.read.ReadBookActivity import io.legado.app.ui.book.read.ReadBookActivity
import io.legado.app.ui.widget.font.FontSelectDialog import io.legado.app.ui.widget.font.FontSelectDialog
import io.legado.app.utils.* import io.legado.app.utils.*
@ -129,10 +129,10 @@ class ReadStyleDialog : BaseDialogFragment(), FontSelectDialog.CallBack {
TipConfigDialog().show(childFragmentManager, "tipConfigDialog") TipConfigDialog().show(childFragmentManager, "tipConfigDialog")
} }
rgPageAnim.setOnCheckedChangeListener { _, checkedId -> rgPageAnim.setOnCheckedChangeListener { _, checkedId ->
BookRead.book?.setPageAnim(-1) ReadBook.book?.setPageAnim(-1)
ReadBookConfig.pageAnim = binding.rgPageAnim.getIndexById(checkedId) ReadBookConfig.pageAnim = binding.rgPageAnim.getIndexById(checkedId)
callBack?.upPageAnim() callBack?.upPageAnim()
BookRead.loadContent(false) ReadBook.loadContent(false)
} }
cbShareLayout.onCheckedChangeListener = { _, isChecked -> cbShareLayout.onCheckedChangeListener = { _, isChecked ->
ReadBookConfig.shareLayout = isChecked ReadBookConfig.shareLayout = isChecked
@ -177,7 +177,7 @@ class ReadStyleDialog : BaseDialogFragment(), FontSelectDialog.CallBack {
} }
private fun upView() = binding.run { private fun upView() = binding.run {
BookRead.pageAnim().let { ReadBook.pageAnim().let {
if (it >= 0 && it < rgPageAnim.childCount) { if (it >= 0 && it < rgPageAnim.childCount) {
rgPageAnim.check(rgPageAnim[it].id) rgPageAnim.check(rgPageAnim[it].id)
} }

@ -11,7 +11,7 @@ import io.legado.app.constant.PreferKey
import io.legado.app.data.entities.Bookmark import io.legado.app.data.entities.Bookmark
import io.legado.app.help.ReadBookConfig import io.legado.app.help.ReadBookConfig
import io.legado.app.lib.theme.accentColor import io.legado.app.lib.theme.accentColor
import io.legado.app.model.BookRead import io.legado.app.model.ReadBook
import io.legado.app.ui.book.read.PhotoDialog import io.legado.app.ui.book.read.PhotoDialog
import io.legado.app.ui.book.read.page.entities.TextChar import io.legado.app.ui.book.read.page.entities.TextChar
import io.legado.app.ui.book.read.page.entities.TextLine import io.legado.app.ui.book.read.page.entities.TextLine
@ -163,12 +163,12 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
lineBottom: Float, lineBottom: Float,
isImageLine: Boolean isImageLine: Boolean
) { ) {
val book = BookRead.book ?: return val book = ReadBook.book ?: return
ImageProvider.getImage( ImageProvider.getImage(
book, book,
textPage.chapterIndex, textPage.chapterIndex,
textChar.charData, textChar.charData,
BookRead.bookSource, ReadBook.bookSource,
true true
)?.let { )?.let {
val rectF = if (isImageLine) { val rectF = if (isImageLine) {
@ -495,7 +495,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
fun createBookmark(): Bookmark? { fun createBookmark(): Bookmark? {
val page = relativePage(selectStart[0]) val page = relativePage(selectStart[0])
page.getTextChapter()?.let { chapter -> page.getTextChapter()?.let { chapter ->
BookRead.book?.let { book -> ReadBook.book?.let { book ->
return book.createBookMark().apply { return book.createBookMark().apply {
chapterIndex = page.chapterIndex chapterIndex = page.chapterIndex
chapterPos = chapter.getReadLength(page.index) + chapterPos = chapter.getReadLength(page.index) +

@ -14,7 +14,7 @@ import io.legado.app.data.entities.Bookmark
import io.legado.app.databinding.ViewBookPageBinding import io.legado.app.databinding.ViewBookPageBinding
import io.legado.app.help.ReadBookConfig import io.legado.app.help.ReadBookConfig
import io.legado.app.help.ReadTipConfig import io.legado.app.help.ReadTipConfig
import io.legado.app.model.BookRead import io.legado.app.model.ReadBook
import io.legado.app.ui.book.read.page.entities.TextPage import io.legado.app.ui.book.read.page.entities.TextPage
import io.legado.app.ui.book.read.page.provider.ChapterProvider import io.legado.app.ui.book.read.page.provider.ChapterProvider
import io.legado.app.ui.widget.BatteryView import io.legado.app.ui.widget.BatteryView
@ -224,7 +224,7 @@ class PageView(context: Context) : FrameLayout(context) {
@SuppressLint("SetTextI18n") @SuppressLint("SetTextI18n")
fun setProgress(textPage: TextPage) = textPage.apply { fun setProgress(textPage: TextPage) = textPage.apply {
tvBookName?.text = BookRead.book?.name tvBookName?.text = ReadBook.book?.name
tvTitle?.text = textPage.title tvTitle?.text = textPage.title
tvPage?.text = "${index.plus(1)}/$pageSize" tvPage?.text = "${index.plus(1)}/$pageSize"
tvTotalProgress?.text = readProgress tvTotalProgress?.text = readProgress

@ -15,8 +15,8 @@ import android.widget.FrameLayout
import io.legado.app.help.AppConfig import io.legado.app.help.AppConfig
import io.legado.app.help.ReadBookConfig import io.legado.app.help.ReadBookConfig
import io.legado.app.lib.theme.accentColor import io.legado.app.lib.theme.accentColor
import io.legado.app.model.BookRead
import io.legado.app.model.ReadAloud import io.legado.app.model.ReadAloud
import io.legado.app.model.ReadBook
import io.legado.app.ui.book.read.page.api.DataSource import io.legado.app.ui.book.read.page.api.DataSource
import io.legado.app.ui.book.read.page.delegate.* import io.legado.app.ui.book.read.page.delegate.*
import io.legado.app.ui.book.read.page.entities.PageDirection import io.legado.app.ui.book.read.page.entities.PageDirection
@ -409,8 +409,8 @@ class ReadView(context: Context, attrs: AttributeSet) :
0 -> callBack.showActionMenu() 0 -> callBack.showActionMenu()
1 -> pageDelegate?.nextPageByAnim(defaultAnimationSpeed) 1 -> pageDelegate?.nextPageByAnim(defaultAnimationSpeed)
2 -> pageDelegate?.prevPageByAnim(defaultAnimationSpeed) 2 -> pageDelegate?.prevPageByAnim(defaultAnimationSpeed)
3 -> BookRead.moveToNextChapter(true) 3 -> ReadBook.moveToNextChapter(true)
4 -> BookRead.moveToPrevChapter(upContent = true, toLast = false) 4 -> ReadBook.moveToPrevChapter(upContent = true, toLast = false)
5 -> ReadAloud.prevParagraph(context) 5 -> ReadAloud.prevParagraph(context)
6 -> ReadAloud.nextParagraph(context) 6 -> ReadAloud.nextParagraph(context)
} }
@ -468,9 +468,9 @@ class ReadView(context: Context, attrs: AttributeSet) :
} }
fun upPageAnim() { fun upPageAnim() {
isScroll = BookRead.pageAnim() == 3 isScroll = ReadBook.pageAnim() == 3
ChapterProvider.upLayout() ChapterProvider.upLayout()
when (BookRead.pageAnim()) { when (ReadBook.pageAnim()) {
0 -> if (pageDelegate !is CoverPageDelegate) { 0 -> if (pageDelegate !is CoverPageDelegate) {
pageDelegate = CoverPageDelegate(this) pageDelegate = CoverPageDelegate(this)
} }
@ -538,25 +538,25 @@ class ReadView(context: Context, attrs: AttributeSet) :
override val currentChapter: TextChapter? override val currentChapter: TextChapter?
get() { get() {
return if (callBack.isInitFinish) BookRead.textChapter(0) else null return if (callBack.isInitFinish) ReadBook.textChapter(0) else null
} }
override val nextChapter: TextChapter? override val nextChapter: TextChapter?
get() { get() {
return if (callBack.isInitFinish) BookRead.textChapter(1) else null return if (callBack.isInitFinish) ReadBook.textChapter(1) else null
} }
override val prevChapter: TextChapter? override val prevChapter: TextChapter?
get() { get() {
return if (callBack.isInitFinish) BookRead.textChapter(-1) else null return if (callBack.isInitFinish) ReadBook.textChapter(-1) else null
} }
override fun hasNextChapter(): Boolean { override fun hasNextChapter(): Boolean {
return BookRead.durChapterIndex < BookRead.chapterSize - 1 return ReadBook.durChapterIndex < ReadBook.chapterSize - 1
} }
override fun hasPrevChapter(): Boolean { override fun hasPrevChapter(): Boolean {
return BookRead.durChapterIndex > 0 return ReadBook.durChapterIndex > 0
} }
interface CallBack { interface CallBack {

@ -1,11 +1,11 @@
package io.legado.app.ui.book.read.page.api package io.legado.app.ui.book.read.page.api
import io.legado.app.model.BookRead import io.legado.app.model.ReadBook
import io.legado.app.ui.book.read.page.entities.TextChapter import io.legado.app.ui.book.read.page.entities.TextChapter
interface DataSource { interface DataSource {
val pageIndex: Int get() = BookRead.durPageIndex() val pageIndex: Int get() = ReadBook.durPageIndex()
val currentChapter: TextChapter? val currentChapter: TextChapter?

@ -4,7 +4,7 @@ import android.text.Layout
import android.text.StaticLayout import android.text.StaticLayout
import io.legado.app.R import io.legado.app.R
import io.legado.app.help.ReadBookConfig import io.legado.app.help.ReadBookConfig
import io.legado.app.model.BookRead import io.legado.app.model.ReadBook
import io.legado.app.ui.book.read.page.provider.ChapterProvider import io.legado.app.ui.book.read.page.provider.ChapterProvider
import splitties.init.appCtx import splitties.init.appCtx
import java.text.DecimalFormat import java.text.DecimalFormat
@ -171,17 +171,17 @@ data class TextPage(
} }
fun getTextChapter(): TextChapter? { fun getTextChapter(): TextChapter? {
BookRead.curTextChapter?.let { ReadBook.curTextChapter?.let {
if (it.position == chapterIndex) { if (it.position == chapterIndex) {
return it return it
} }
} }
BookRead.nextTextChapter?.let { ReadBook.nextTextChapter?.let {
if (it.position == chapterIndex) { if (it.position == chapterIndex) {
return it return it
} }
} }
BookRead.prevTextChapter?.let { ReadBook.prevTextChapter?.let {
if (it.position == chapterIndex) { if (it.position == chapterIndex) {
return it return it
} }

@ -12,7 +12,7 @@ import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookChapter import io.legado.app.data.entities.BookChapter
import io.legado.app.help.AppConfig import io.legado.app.help.AppConfig
import io.legado.app.help.ReadBookConfig import io.legado.app.help.ReadBookConfig
import io.legado.app.model.BookRead import io.legado.app.model.ReadBook
import io.legado.app.ui.book.read.page.entities.TextChapter import io.legado.app.ui.book.read.page.entities.TextChapter
import io.legado.app.ui.book.read.page.entities.TextChar import io.legado.app.ui.book.read.page.entities.TextChar
import io.legado.app.ui.book.read.page.entities.TextLine import io.legado.app.ui.book.read.page.entities.TextLine
@ -121,7 +121,7 @@ object ChapterProvider {
while (matcher.find()) { while (matcher.find()) {
matcher.group(1)?.let { src -> matcher.group(1)?.let { src ->
srcList.add(src) srcList.add(src)
ImageProvider.getImage(book, bookChapter.index, src, BookRead.bookSource) ImageProvider.getImage(book, bookChapter.index, src, ReadBook.bookSource)
matcher.appendReplacement(sb, srcReplaceChar) matcher.appendReplacement(sb, srcReplaceChar)
} }
} }
@ -208,7 +208,7 @@ object ChapterProvider {
imageStyle: String?, imageStyle: String?,
): Float { ): Float {
var durY = y var durY = y
ImageProvider.getImage(book, chapter.index, src, BookRead.bookSource)?.let { ImageProvider.getImage(book, chapter.index, src, ReadBook.bookSource)?.let {
if (durY > visibleHeight) { if (durY > visibleHeight) {
textPages.last().height = durY textPages.last().height = durY
textPages.add(TextPage()) textPages.add(TextPage())
@ -586,7 +586,7 @@ object ChapterProvider {
*/ */
fun upLayout() { fun upLayout() {
doublePage = viewWidth > viewHeight doublePage = viewWidth > viewHeight
&& BookRead.pageAnim() != 3 && ReadBook.pageAnim() != 3
&& AppConfig.doublePageHorizontal && AppConfig.doublePageHorizontal
if (viewWidth > 0 && viewHeight > 0) { if (viewWidth > 0 && viewHeight > 0) {
paddingLeft = ReadBookConfig.paddingLeft.dp paddingLeft = ReadBookConfig.paddingLeft.dp

@ -1,6 +1,6 @@
package io.legado.app.ui.book.read.page.provider package io.legado.app.ui.book.read.page.provider
import io.legado.app.model.BookRead import io.legado.app.model.ReadBook
import io.legado.app.ui.book.read.page.api.DataSource import io.legado.app.ui.book.read.page.api.DataSource
import io.legado.app.ui.book.read.page.api.PageFactory import io.legado.app.ui.book.read.page.api.PageFactory
import io.legado.app.ui.book.read.page.entities.TextPage import io.legado.app.ui.book.read.page.entities.TextPage
@ -20,25 +20,25 @@ class TextPageFactory(dataSource: DataSource) : PageFactory<TextPage>(dataSource
} }
override fun moveToFirst() { override fun moveToFirst() {
BookRead.setPageIndex(0) ReadBook.setPageIndex(0)
} }
override fun moveToLast() = with(dataSource) { override fun moveToLast() = with(dataSource) {
currentChapter?.let { currentChapter?.let {
if (it.pageSize == 0) { if (it.pageSize == 0) {
BookRead.setPageIndex(0) ReadBook.setPageIndex(0)
} else { } else {
BookRead.setPageIndex(it.pageSize.minus(1)) ReadBook.setPageIndex(it.pageSize.minus(1))
} }
} ?: BookRead.setPageIndex(0) } ?: ReadBook.setPageIndex(0)
} }
override fun moveToNext(upContent: Boolean): Boolean = with(dataSource) { override fun moveToNext(upContent: Boolean): Boolean = with(dataSource) {
return if (hasNext()) { return if (hasNext()) {
if (currentChapter?.isLastIndex(pageIndex) == true) { if (currentChapter?.isLastIndex(pageIndex) == true) {
BookRead.moveToNextChapter(upContent) ReadBook.moveToNextChapter(upContent)
} else { } else {
BookRead.setPageIndex(pageIndex.plus(1)) ReadBook.setPageIndex(pageIndex.plus(1))
} }
if (upContent) upContent(resetPageOffset = false) if (upContent) upContent(resetPageOffset = false)
true true
@ -49,9 +49,9 @@ class TextPageFactory(dataSource: DataSource) : PageFactory<TextPage>(dataSource
override fun moveToPrev(upContent: Boolean): Boolean = with(dataSource) { override fun moveToPrev(upContent: Boolean): Boolean = with(dataSource) {
return if (hasPrev()) { return if (hasPrev()) {
if (pageIndex <= 0) { if (pageIndex <= 0) {
BookRead.moveToPrevChapter(upContent) ReadBook.moveToPrevChapter(upContent)
} else { } else {
BookRead.setPageIndex(pageIndex.minus(1)) ReadBook.setPageIndex(pageIndex.minus(1))
} }
if (upContent) upContent(resetPageOffset = false) if (upContent) upContent(resetPageOffset = false)
true true
@ -61,7 +61,7 @@ class TextPageFactory(dataSource: DataSource) : PageFactory<TextPage>(dataSource
override val curPage: TextPage override val curPage: TextPage
get() = with(dataSource) { get() = with(dataSource) {
BookRead.msg?.let { ReadBook.msg?.let {
return@with TextPage(text = it).format() return@with TextPage(text = it).format()
} }
currentChapter?.let { currentChapter?.let {
@ -72,7 +72,7 @@ class TextPageFactory(dataSource: DataSource) : PageFactory<TextPage>(dataSource
override val nextPage: TextPage override val nextPage: TextPage
get() = with(dataSource) { get() = with(dataSource) {
BookRead.msg?.let { ReadBook.msg?.let {
return@with TextPage(text = it).format() return@with TextPage(text = it).format()
} }
currentChapter?.let { currentChapter?.let {
@ -93,7 +93,7 @@ class TextPageFactory(dataSource: DataSource) : PageFactory<TextPage>(dataSource
override val prevPage: TextPage override val prevPage: TextPage
get() = with(dataSource) { get() = with(dataSource) {
BookRead.msg?.let { ReadBook.msg?.let {
return@with TextPage(text = it).format() return@with TextPage(text = it).format()
} }
if (pageIndex > 0) { if (pageIndex > 0) {

Loading…
Cancel
Save