pull/1352/head
gedoor 3 years ago
parent a5c6e6f7dc
commit e9f5d5f706
  1. 14
      app/src/main/java/io/legado/app/api/controller/BookController.kt
  2. 6
      app/src/main/java/io/legado/app/data/entities/Book.kt
  3. 10
      app/src/main/java/io/legado/app/model/BookRead.kt
  4. 4
      app/src/main/java/io/legado/app/model/CacheBook.kt
  5. 16
      app/src/main/java/io/legado/app/receiver/MediaButtonReceiver.kt
  6. 20
      app/src/main/java/io/legado/app/service/BaseReadAloudService.kt
  7. 4
      app/src/main/java/io/legado/app/service/HttpReadAloudService.kt
  8. 6
      app/src/main/java/io/legado/app/service/TTSReadAloudService.kt
  9. 6
      app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt
  10. 6
      app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditViewModel.kt
  11. 120
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
  12. 12
      app/src/main/java/io/legado/app/ui/book/read/ReadBookBaseActivity.kt
  13. 126
      app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt
  14. 30
      app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt
  15. 4
      app/src/main/java/io/legado/app/ui/book/read/config/AutoReadDialog.kt
  16. 4
      app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt
  17. 6
      app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudDialog.kt
  18. 8
      app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt
  19. 8
      app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt
  20. 4
      app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt
  21. 20
      app/src/main/java/io/legado/app/ui/book/read/page/ReadView.kt
  22. 4
      app/src/main/java/io/legado/app/ui/book/read/page/api/DataSource.kt
  23. 8
      app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPage.kt
  24. 8
      app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt
  25. 24
      app/src/main/java/io/legado/app/ui/book/read/page/provider/TextPageFactory.kt
  26. 6
      app/src/main/java/io/legado/app/ui/widget/dialog/PhotoDialog.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.ReadBook import io.legado.app.model.BookRead
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 (ReadBook.book?.bookUrl == book.bookUrl) { if (BookRead.book?.bookUrl == book.bookUrl) {
ReadBook.book = book BookRead.book = book
ReadBook.durChapterIndex = book.durChapterIndex BookRead.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 (ReadBook.book?.bookUrl == book.bookUrl) { if (BookRead.book?.bookUrl == book.bookUrl) {
ReadBook.book = book BookRead.book = book
ReadBook.durChapterIndex = index BookRead.durChapterIndex = index
} }
} }

@ -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.ReadBook import io.legado.app.model.BookRead
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 (ReadBook.book?.bookUrl == book.bookUrl) { if (BookRead.book?.bookUrl == book.bookUrl) {
ReadBook.book = null BookRead.book = null
} }
appDb.bookDao.delete(book) appDb.bookDao.delete(book)
} }

@ -26,7 +26,7 @@ import splitties.init.appCtx
@Suppress("MemberVisibilityCanBePrivate") @Suppress("MemberVisibilityCanBePrivate")
object ReadBook : CoroutineScope by MainScope() { object BookRead : 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 ReadBook : CoroutineScope by MainScope() {
var readStartTime: Long = System.currentTimeMillis() var readStartTime: Long = System.currentTimeMillis()
fun resetData(book: Book) { fun resetData(book: Book) {
ReadBook.book = book BookRead.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 ReadBook : CoroutineScope by MainScope() {
} }
fun upMsg(msg: String?) { fun upMsg(msg: String?) {
if (ReadBook.msg != msg) { if (BookRead.msg != msg) {
ReadBook.msg = msg BookRead.msg = msg
callBack?.upContent() callBack?.upContent()
} }
} }
@ -379,7 +379,7 @@ object ReadBook : 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 == ReadBook.book?.bookUrl if (book.bookUrl == BookRead.book?.bookUrl
&& cList.size > chapterSize && cList.size > chapterSize
) { ) {
appDb.bookChapterDao.insert(*cList.toTypedArray()) appDb.bookChapterDao.insert(*cList.toTypedArray())

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

@ -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)) {
ReadBook.moveToPrevChapter(true) BookRead.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)) {
ReadBook.moveToNextChapter(true) BookRead.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.addLog("readAloud start Service") AppLog.addLog("readAloud start Service")
if (ReadBook.book != null) { if (BookRead.book != null) {
ReadBook.readAloud() BookRead.readAloud()
} else { } else {
appDb.bookDao.lastReadBook?.let { appDb.bookDao.lastReadBook?.let {
ReadBook.resetData(it) BookRead.resetData(it)
ReadBook.curTextChapter ?: ReadBook.loadContent(false) BookRead.curTextChapter ?: BookRead.loadContent(false)
ReadBook.readAloud() BookRead.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()
ReadBook.uploadProgress() BookRead.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 = ReadBook.curTextChapter textChapter = BookRead.curTextChapter
pageIndex = ReadBook.durPageIndex() pageIndex = BookRead.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)
ReadBook.uploadProgress() BookRead.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 {
ReadBook.moveToPrevChapter(true) BookRead.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 += ": ${ReadBook.book?.name}" nTitle += ": ${BookRead.book?.name}"
var nSubtitle = ReadBook.curTextChapter?.title var nSubtitle = BookRead.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() {
ReadBook.upReadStartTime() BookRead.upReadStartTime()
if (!ReadBook.moveToNextChapter(true)) { if (!BookRead.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++
ReadBook.moveToNextPage() BookRead.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.ReadBook import io.legado.app.model.BookRead
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++
ReadBook.moveToNextPage() BookRead.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++
ReadBook.moveToNextPage() BookRead.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.ReadBook import io.legado.app.model.BookRead
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 (ReadBook.book?.name == book.name && ReadBook.book?.author == book.author) { if (BookRead.book?.name == book.name && BookRead.book?.author == book.author) {
ReadBook.book = book BookRead.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.ReadBook import io.legado.app.model.BookRead
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 (ReadBook.book?.bookUrl == book.bookUrl) { if (BookRead.book?.bookUrl == book.bookUrl) {
ReadBook.book = book BookRead.book = book
} }
appDb.bookDao.update(book) appDb.bookDao.update(book)
}.onSuccess { }.onSuccess {

@ -30,9 +30,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
@ -66,7 +66,7 @@ class ReadBookActivity : ReadBookBaseActivity(),
ReadMenu.CallBack, ReadMenu.CallBack,
ReadAloudDialog.CallBack, ReadAloudDialog.CallBack,
ChangeSourceDialog.CallBack, ChangeSourceDialog.CallBack,
ReadBook.CallBack, BookRead.CallBack,
AutoReadDialog.CallBack, AutoReadDialog.CallBack,
TocRegexDialog.CallBack, TocRegexDialog.CallBack,
ColorPickerDialogListener { ColorPickerDialogListener {
@ -97,7 +97,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", ReadBook.durChapterIndex).let { index -> data.getIntExtra("index", BookRead.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 +131,7 @@ class ReadBookActivity : ReadBookBaseActivity(),
binding.cursorLeft.setOnTouchListener(this) binding.cursorLeft.setOnTouchListener(this)
binding.cursorRight.setOnTouchListener(this) binding.cursorRight.setOnTouchListener(this)
upScreenTimeOut() upScreenTimeOut()
ReadBook.callBack = this BookRead.callBack = this
} }
override fun onPostCreate(savedInstanceState: Bundle?) { override fun onPostCreate(savedInstanceState: Bundle?) {
@ -151,7 +151,7 @@ class ReadBookActivity : ReadBookBaseActivity(),
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
ReadBook.readStartTime = System.currentTimeMillis() BookRead.readStartTime = System.currentTimeMillis()
upSystemUiVisibility() upSystemUiVisibility()
timeBatteryReceiver = TimeBatteryReceiver.register(this) timeBatteryReceiver = TimeBatteryReceiver.register(this)
binding.readView.upTime() binding.readView.upTime()
@ -161,14 +161,14 @@ class ReadBookActivity : ReadBookBaseActivity(),
super.onPause() super.onPause()
autoPageStop() autoPageStop()
backupJob?.cancel() backupJob?.cancel()
ReadBook.saveRead() BookRead.saveRead()
timeBatteryReceiver?.let { timeBatteryReceiver?.let {
unregisterReceiver(it) unregisterReceiver(it)
timeBatteryReceiver = null timeBatteryReceiver = null
} }
upSystemUiVisibility() upSystemUiVisibility()
if (!BuildConfig.DEBUG) { if (!BuildConfig.DEBUG) {
ReadBook.uploadProgress() BookRead.uploadProgress()
Backup.autoBack(this) Backup.autoBack(this)
} }
} }
@ -189,7 +189,7 @@ class ReadBookActivity : ReadBookBaseActivity(),
*/ */
private fun upMenu() { private fun upMenu() {
val menu = menu val menu = menu
val book = ReadBook.book val book = BookRead.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) {
@ -223,16 +223,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()
ReadBook.book?.let { BookRead.book?.let {
supportFragmentManager.showDialog(ChangeSourceDialog(it.name, it.author)) supportFragmentManager.showDialog(ChangeSourceDialog(it.name, it.author))
} }
} }
R.id.menu_refresh -> { R.id.menu_refresh -> {
if (ReadBook.bookSource == null) { if (BookRead.bookSource == null) {
upContent() upContent()
} else { } else {
ReadBook.book?.let { BookRead.book?.let {
ReadBook.curTextChapter = null BookRead.curTextChapter = null
binding.readView.upContent() binding.readView.upContent()
viewModel.refreshContent(it) viewModel.refreshContent(it)
} }
@ -240,12 +240,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 = ReadBook.book val book = BookRead.book
val page = ReadBook.curTextChapter?.page(ReadBook.durPageIndex()) val page = BookRead.curTextChapter?.page(BookRead.durPageIndex())
if (book != null && page != null) { if (book != null && page != null) {
val bookmark = book.createBookMark().apply { val bookmark = book.createBookMark().apply {
chapterIndex = ReadBook.durChapterIndex chapterIndex = BookRead.durChapterIndex
chapterPos = ReadBook.durChapterPos chapterPos = BookRead.durChapterPos
chapterName = page.title chapterName = page.title
bookText = page.text.trim() bookText = page.text.trim()
} }
@ -253,34 +253,34 @@ class ReadBookActivity : ReadBookBaseActivity(),
} }
} }
R.id.menu_copy_text -> R.id.menu_copy_text ->
TextDialog.show(supportFragmentManager, ReadBook.curTextChapter?.getContent()) TextDialog.show(supportFragmentManager, BookRead.curTextChapter?.getContent())
R.id.menu_update_toc -> ReadBook.book?.let { R.id.menu_update_toc -> BookRead.book?.let {
loadChapterList(it) loadChapterList(it)
} }
R.id.menu_enable_replace -> ReadBook.book?.let { R.id.menu_enable_replace -> BookRead.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 -> ReadBook.book?.let { R.id.menu_re_segment -> BookRead.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()
ReadBook.loadContent(false) BookRead.loadContent(false)
} }
R.id.menu_page_anim -> showPageAnimConfig { R.id.menu_page_anim -> showPageAnimConfig {
binding.readView.upPageAnim() binding.readView.upPageAnim()
ReadBook.loadContent(false) BookRead.loadContent(false)
} }
R.id.menu_book_info -> ReadBook.book?.let { R.id.menu_book_info -> BookRead.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 -> supportFragmentManager.showDialog( R.id.menu_toc_regex -> supportFragmentManager.showDialog(
TocRegexDialog(ReadBook.book?.tocUrl) TocRegexDialog(BookRead.book?.tocUrl)
) )
R.id.menu_reverse_content -> ReadBook.book?.let { R.id.menu_reverse_content -> BookRead.book?.let {
viewModel.reverseContent(it) viewModel.reverseContent(it)
} }
R.id.menu_set_charset -> showCharsetConfig() R.id.menu_set_charset -> showCharsetConfig()
@ -291,11 +291,11 @@ class ReadBookActivity : ReadBookBaseActivity(),
R.string.image_style, R.string.image_style,
imgStyles imgStyles
) { _, index -> ) { _, index ->
ReadBook.book?.setImageStyle(imgStyles[index]) BookRead.book?.setImageStyle(imgStyles[index])
ReadBook.loadContent(false) BookRead.loadContent(false)
} }
} }
R.id.menu_get_progress -> ReadBook.book?.let { R.id.menu_get_progress -> BookRead.book?.let {
viewModel.syncBookProgress(it) { progress -> viewModel.syncBookProgress(it) { progress ->
sureSyncProgress(progress) sureSyncProgress(progress)
} }
@ -517,10 +517,10 @@ class ReadBookActivity : ReadBookBaseActivity(),
} }
R.id.menu_replace -> { R.id.menu_replace -> {
val scopes = arrayListOf<String>() val scopes = arrayListOf<String>()
ReadBook.book?.name?.let { BookRead.book?.name?.let {
scopes.add(it) scopes.add(it)
} }
ReadBook.bookSource?.bookSourceUrl?.let { BookRead.bookSource?.bookSourceUrl?.let {
scopes.add(it) scopes.add(it)
} }
replaceActivity.launch( replaceActivity.launch(
@ -580,7 +580,7 @@ class ReadBookActivity : ReadBookBaseActivity(),
} }
override fun loadChapterList(book: Book) { override fun loadChapterList(book: Book) {
ReadBook.upMsg(getString(R.string.toc_updateing)) BookRead.upMsg(getString(R.string.toc_updateing))
viewModel.loadChapterList(book) viewModel.loadChapterList(book)
} }
@ -590,7 +590,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")
ReadBook.readAloud() BookRead.readAloud()
} }
loadStates = true loadStates = true
} }
@ -606,7 +606,7 @@ class ReadBookActivity : ReadBookBaseActivity(),
launch { launch {
autoPageProgress = 0 autoPageProgress = 0
binding.readView.upContent(relativePosition, resetPageOffset) binding.readView.upContent(relativePosition, resetPageOffset)
binding.readMenu.setSeekPage(ReadBook.durPageIndex()) binding.readMenu.setSeekPage(BookRead.durPageIndex())
loadStates = false loadStates = false
success?.invoke() success?.invoke()
} }
@ -624,7 +624,7 @@ class ReadBookActivity : ReadBookBaseActivity(),
override fun pageChanged() { override fun pageChanged() {
launch { launch {
autoPageProgress = 0 autoPageProgress = 0
binding.readMenu.setSeekPage(ReadBook.durPageIndex()) binding.readMenu.setSeekPage(BookRead.durPageIndex())
startBackupJob() startBackupJob()
} }
} }
@ -637,7 +637,7 @@ class ReadBookActivity : ReadBookBaseActivity(),
} }
override val oldBook: Book? override val oldBook: Book?
get() = ReadBook.book get() = BookRead.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 +722,7 @@ class ReadBookActivity : ReadBookBaseActivity(),
} }
override fun openSourceEditActivity() { override fun openSourceEditActivity() {
ReadBook.bookSource?.let { BookRead.bookSource?.let {
sourceEditActivity.launch { sourceEditActivity.launch {
putExtra("sourceUrl", it.bookSourceUrl) putExtra("sourceUrl", it.bookSourceUrl)
} }
@ -740,7 +740,7 @@ class ReadBookActivity : ReadBookBaseActivity(),
* 打开目录 * 打开目录
*/ */
override fun openChapterList() { override fun openChapterList() {
ReadBook.book?.let { BookRead.book?.let {
tocActivity.launch(it.bookUrl) tocActivity.launch(it.bookUrl)
} }
} }
@ -749,7 +749,7 @@ class ReadBookActivity : ReadBookBaseActivity(),
* 打开搜索界面 * 打开搜索界面
*/ */
override fun openSearchActivity(searchWord: String?) { override fun openSearchActivity(searchWord: String?) {
ReadBook.book?.let { BookRead.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)
@ -780,7 +780,7 @@ class ReadBookActivity : ReadBookBaseActivity(),
} }
override fun showLogin() { override fun showLogin() {
ReadBook.bookSource?.let { BookRead.bookSource?.let {
startActivity<SourceLoginActivity> { startActivity<SourceLoginActivity> {
putExtra("sourceUrl", it.bookSourceUrl) putExtra("sourceUrl", it.bookSourceUrl)
} }
@ -789,10 +789,10 @@ class ReadBookActivity : ReadBookBaseActivity(),
override fun payAction() { override fun payAction() {
Coroutine.async(this) { Coroutine.async(this) {
val book = ReadBook.book ?: throw NoStackTraceException("no book") val book = BookRead.book ?: throw NoStackTraceException("no book")
val chapter = appDb.bookChapterDao.getChapter(book.bookUrl, ReadBook.durChapterIndex) val chapter = appDb.bookChapterDao.getChapter(book.bookUrl, BookRead.durChapterIndex)
?: throw NoStackTraceException("no chapter") ?: throw NoStackTraceException("no chapter")
val source = ReadBook.bookSource ?: throw NoStackTraceException("no book source") val source = BookRead.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")
@ -810,7 +810,7 @@ class ReadBookActivity : ReadBookBaseActivity(),
override fun onClickReadAloud() { override fun onClickReadAloud() {
autoPageStop() autoPageStop()
when { when {
!BaseReadAloudService.isRun -> ReadBook.readAloud() !BaseReadAloudService.isRun -> BookRead.readAloud()
BaseReadAloudService.pause -> ReadAloud.resume(this) BaseReadAloudService.pause -> ReadAloud.resume(this)
else -> ReadAloud.pause(this) else -> ReadAloud.pause(this)
} }
@ -844,7 +844,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) {
ReadBook.book?.let { BookRead.book?.let {
it.tocUrl = tocRegex it.tocUrl = tocRegex
viewModel.loadChapterList(it) viewModel.loadChapterList(it)
} }
@ -854,7 +854,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 {
ReadBook.setProgress(progress) BookRead.setProgress(progress)
} }
noButton() noButton()
}.show() }.show()
@ -862,9 +862,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 = ReadBook.curTextChapter?.pages ?: return@openChapter val pages = BookRead.curTextChapter?.pages ?: return@openChapter
val positions = viewModel.searchResultPositions(pages, indexWithinChapter) val positions = viewModel.searchResultPositions(pages, indexWithinChapter)
ReadBook.skipToPage(positions[0]) { BookRead.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)
@ -894,7 +894,7 @@ class ReadBookActivity : ReadBookBaseActivity(),
backupJob?.cancel() backupJob?.cancel()
backupJob = launch { backupJob = launch {
delay(120000) delay(120000)
ReadBook.book?.let { BookRead.book?.let {
AppWebDav.uploadBookProgress(it) AppWebDav.uploadBookProgress(it)
Backup.autoBack(this@ReadBookActivity) Backup.autoBack(this@ReadBookActivity)
} }
@ -902,12 +902,12 @@ class ReadBookActivity : ReadBookBaseActivity(),
} }
override fun finish() { override fun finish() {
ReadBook.book?.let { BookRead.book?.let {
if (!ReadBook.inBookshelf) { if (!BookRead.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 {
ReadBook.inBookshelf = true BookRead.inBookshelf = true
setResult(Activity.RESULT_OK) setResult(Activity.RESULT_OK)
} }
noButton { viewModel.removeFromBookshelf { super.finish() } } noButton { viewModel.removeFromBookshelf { super.finish() } }
@ -922,7 +922,7 @@ class ReadBookActivity : ReadBookBaseActivity(),
super.onDestroy() super.onDestroy()
textActionMenu.dismiss() textActionMenu.dismiss()
binding.readView.onDestroy() binding.readView.onDestroy()
ReadBook.msg = null BookRead.msg = null
if (!BuildConfig.DEBUG) { if (!BuildConfig.DEBUG) {
Backup.autoBack(this) Backup.autoBack(this)
} }
@ -933,14 +933,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, ReadBook.durChapterPos) viewModel.openChapter(it.index, BookRead.durChapterPos)
readView.upContent() readView.upContent()
} }
observeEvent<Boolean>(EventBus.MEDIA_BUTTON) { observeEvent<Boolean>(EventBus.MEDIA_BUTTON) {
if (it) { if (it) {
onClickReadAloud() onClickReadAloud()
} else { } else {
ReadBook.readAloud(!BaseReadAloudService.pause) BookRead.readAloud(!BaseReadAloudService.pause)
} }
} }
observeEvent<Boolean>(EventBus.UP_CONFIG) { observeEvent<Boolean>(EventBus.UP_CONFIG) {
@ -948,15 +948,15 @@ class ReadBookActivity : ReadBookBaseActivity(),
readView.upBg() readView.upBg()
readView.upStyle() readView.upStyle()
if (it) { if (it) {
ReadBook.loadContent(resetPageOffset = false) BookRead.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) {
ReadBook.curTextChapter?.let { textChapter -> BookRead.curTextChapter?.let { textChapter ->
val page = textChapter.getPageByReadPos(ReadBook.durChapterPos) val page = textChapter.getPageByReadPos(BookRead.durChapterPos)
if (page != null) { if (page != null) {
page.removePageAloudSpan() page.removePageAloudSpan()
readView.upContent(resetPageOffset = false) readView.upContent(resetPageOffset = false)
@ -967,9 +967,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()) {
ReadBook.curTextChapter?.let { textChapter -> BookRead.curTextChapter?.let { textChapter ->
val aloudSpanStart = chapterStart - ReadBook.durChapterPos val aloudSpanStart = chapterStart - BookRead.durChapterPos
textChapter.getPageByReadPos(ReadBook.durChapterPos) textChapter.getPageByReadPos(BookRead.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?) {
ReadBook.msg = null BookRead.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() {
ReadBook.book?.let { book -> BookRead.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(ReadBook.book?.charset) editView.setText(BookRead.book?.charset)
} }
customView { alertBinding.root } customView { alertBinding.root }
okButton { okButton {
alertBinding.editView.text?.toString()?.let { alertBinding.editView.text?.toString()?.let {
ReadBook.setCharset(it) BookRead.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 ->
ReadBook.book?.setPageAnim(i - 1) BookRead.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 {
ReadBook.inBookshelf = intent.getBooleanExtra("inBookshelf", true) BookRead.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)
} ?: ReadBook.book } ?: BookRead.book
when { when {
book != null -> initBook(book) book != null -> initBook(book)
else -> ReadBook.upMsg(context.getString(R.string.no_book)) else -> BookRead.upMsg(context.getString(R.string.no_book))
} }
}.onFinally { }.onFinally {
ReadBook.saveRead() BookRead.saveRead()
} }
} }
private fun initBook(book: Book) { private fun initBook(book: Book) {
if (ReadBook.book?.bookUrl != book.bookUrl) { if (BookRead.book?.bookUrl != book.bookUrl) {
ReadBook.resetData(book) BookRead.resetData(book)
isInitFinish = true isInitFinish = true
if (ReadBook.chapterSize == 0) { if (BookRead.chapterSize == 0) {
if (book.tocUrl.isEmpty()) { if (book.tocUrl.isEmpty()) {
loadBookInfo(book) loadBookInfo(book)
} else { } else {
loadChapterList(book) loadChapterList(book)
} }
} else { } else {
if (ReadBook.durChapterIndex > ReadBook.chapterSize - 1) { if (BookRead.durChapterIndex > BookRead.chapterSize - 1) {
ReadBook.durChapterIndex = ReadBook.chapterSize - 1 BookRead.durChapterIndex = BookRead.chapterSize - 1
} }
ReadBook.loadContent(resetPageOffset = true) BookRead.loadContent(resetPageOffset = true)
} }
syncBookProgress(book) syncBookProgress(book)
} else { } else {
ReadBook.book = book BookRead.book = book
if (ReadBook.durChapterIndex != book.durChapterIndex) { if (BookRead.durChapterIndex != book.durChapterIndex) {
ReadBook.durChapterIndex = book.durChapterIndex BookRead.durChapterIndex = book.durChapterIndex
ReadBook.durChapterPos = book.durChapterPos BookRead.durChapterPos = book.durChapterPos
ReadBook.clearTextChapter() BookRead.clearTextChapter()
} }
ReadBook.callBack?.upMenuView() BookRead.callBack?.upMenuView()
ReadBook.upWebBook(book) BookRead.upWebBook(book)
isInitFinish = true isInitFinish = true
ReadBook.chapterSize = appDb.bookChapterDao.getChapterCount(book.bookUrl) BookRead.chapterSize = appDb.bookChapterDao.getChapterCount(book.bookUrl)
if (ReadBook.chapterSize == 0) { if (BookRead.chapterSize == 0) {
if (book.tocUrl.isEmpty()) { if (book.tocUrl.isEmpty()) {
loadBookInfo(book) loadBookInfo(book)
} else { } else {
loadChapterList(book) loadChapterList(book)
} }
} else { } else {
if (ReadBook.curTextChapter != null) { if (BookRead.curTextChapter != null) {
ReadBook.callBack?.upContent(resetPageOffset = false) BookRead.callBack?.upContent(resetPageOffset = false)
} else { } else {
ReadBook.loadContent(resetPageOffset = true) BookRead.loadContent(resetPageOffset = true)
} }
} }
if (!BaseReadAloudService.isRun) { if (!BaseReadAloudService.isRun) {
syncBookProgress(book) syncBookProgress(book)
} }
} }
if (!book.isLocalBook() && ReadBook.bookSource == null) { if (!book.isLocalBook() && BookRead.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 {
ReadBook.bookSource?.let { source -> BookRead.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 {
ReadBook.upMsg("详情页出错: ${it.localizedMessage}") BookRead.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)
ReadBook.chapterSize = it.size BookRead.chapterSize = it.size
ReadBook.upMsg(null) BookRead.upMsg(null)
ReadBook.loadContent(resetPageOffset = true) BookRead.loadContent(resetPageOffset = true)
} }
}.onError { }.onError {
ReadBook.upMsg("LoadTocError:${it.localizedMessage}") BookRead.upMsg("LoadTocError:${it.localizedMessage}")
} }
} else { } else {
ReadBook.bookSource?.let { BookRead.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)
ReadBook.chapterSize = cList.size BookRead.chapterSize = cList.size
ReadBook.upMsg(null) BookRead.upMsg(null)
ReadBook.loadContent(resetPageOffset = true) BookRead.loadContent(resetPageOffset = true)
}.onError { }.onError {
ReadBook.upMsg(context.getString(R.string.error_load_toc)) BookRead.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 {
ReadBook.setProgress(progress) BookRead.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 {
ReadBook.upMsg(context.getString(R.string.loading)) BookRead.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 = ReadBook.book!! val oldBook = BookRead.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())
ReadBook.resetData(book) BookRead.resetData(book)
ReadBook.upMsg(null) BookRead.upMsg(null)
ReadBook.loadContent(resetPageOffset = true) BookRead.loadContent(resetPageOffset = true)
}.timeout(60000) }.timeout(60000)
.onError { .onError {
context.toastOnUi("换源失败\n${it.localizedMessage}") context.toastOnUi("换源失败\n${it.localizedMessage}")
ReadBook.upMsg(null) BookRead.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(ReadBook.book) it.second.upInfoFromOld(BookRead.book)
changeTo(it.first, it.second) changeTo(it.first, it.second)
} ?: throw NoStackTraceException("自动换源失败") } ?: throw NoStackTraceException("自动换源失败")
}.onStart { }.onStart {
ReadBook.upMsg(context.getString(R.string.source_auto_changing)) BookRead.upMsg(context.getString(R.string.source_auto_changing))
}.onError { }.onError {
context.toastOnUi(it.msg) context.toastOnUi(it.msg)
}.onFinally { }.onFinally {
ReadBook.upMsg(null) BookRead.upMsg(null)
} }
} }
fun openChapter(index: Int, durChapterPos: Int = 0, success: (() -> Unit)? = null) { fun openChapter(index: Int, durChapterPos: Int = 0, success: (() -> Unit)? = null) {
ReadBook.clearTextChapter() BookRead.clearTextChapter()
ReadBook.callBack?.upContent() BookRead.callBack?.upContent()
if (index != ReadBook.durChapterIndex) { if (index != BookRead.durChapterIndex) {
ReadBook.durChapterIndex = index BookRead.durChapterIndex = index
ReadBook.durChapterPos = durChapterPos BookRead.durChapterPos = durChapterPos
} }
ReadBook.saveRead() BookRead.saveRead()
ReadBook.loadContent(resetPageOffset = true) { BookRead.loadContent(resetPageOffset = true) {
success?.invoke() success?.invoke()
} }
} }
fun removeFromBookshelf(success: (() -> Unit)?) { fun removeFromBookshelf(success: (() -> Unit)?) {
execute { execute {
Book.delete(ReadBook.book) Book.delete(BookRead.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 {
ReadBook.book?.let { book -> BookRead.book?.let { book ->
ReadBook.bookSource = appDb.bookSourceDao.getBookSource(book.origin) BookRead.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, ReadBook.durChapterIndex) appDb.bookChapterDao.getChapter(book.bookUrl, BookRead.durChapterIndex)
?.let { chapter -> ?.let { chapter ->
BookHelp.delContent(book, chapter) BookHelp.delContent(book, chapter)
ReadBook.loadContent(ReadBook.durChapterIndex, resetPageOffset = false) BookRead.loadContent(BookRead.durChapterIndex, resetPageOffset = false)
} }
} }
} }
fun reverseContent(book: Book) { fun reverseContent(book: Book) {
execute { execute {
appDb.bookChapterDao.getChapter(book.bookUrl, ReadBook.durChapterIndex) appDb.bookChapterDao.getChapter(book.bookUrl, BookRead.durChapterIndex)
?.let { chapter -> ?.let { chapter ->
BookHelp.reverseContent(book, chapter) BookHelp.reverseContent(book, chapter)
ReadBook.loadContent(ReadBook.durChapterIndex, resetPageOffset = false) BookRead.loadContent(BookRead.durChapterIndex, resetPageOffset = false)
} }
} }
} }
@ -328,9 +328,9 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
*/ */
fun replaceRuleChanged() { fun replaceRuleChanged() {
execute { execute {
ReadBook.book?.let { BookRead.book?.let {
ContentProcessor.get(it.name, it.origin).upReplaceRules() ContentProcessor.get(it.name, it.origin).upReplaceRules()
ReadBook.loadContent(resetPageOffset = false) BookRead.loadContent(resetPageOffset = false)
} }
} }
} }

@ -16,7 +16,7 @@ import io.legado.app.constant.PreferKey
import io.legado.app.databinding.ViewReadMenuBinding import io.legado.app.databinding.ViewReadMenuBinding
import io.legado.app.help.* import io.legado.app.help.*
import io.legado.app.lib.theme.* import io.legado.app.lib.theme.*
import io.legado.app.model.ReadBook import io.legado.app.model.BookRead
import io.legado.app.ui.web.WebViewActivity import io.legado.app.ui.web.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.*
@ -145,7 +145,7 @@ 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, ReadBook.bookSource?.getHeaderMap(true)) IntentData.put(url, BookRead.bookSource?.getHeaderMap(true))
} }
} }
//登录 //登录
@ -179,7 +179,7 @@ class ReadMenu @JvmOverloads constructor(
seekReadPage.setOnSeekBarChangeListener(object : SeekBarChangeListener { seekReadPage.setOnSeekBarChangeListener(object : SeekBarChangeListener {
override fun onStopTrackingTouch(seekBar: SeekBar) { override fun onStopTrackingTouch(seekBar: SeekBar) {
ReadBook.skipToPage(seekBar.progress) BookRead.skipToPage(seekBar.progress)
} }
}) })
@ -208,10 +208,10 @@ class ReadMenu @JvmOverloads constructor(
} }
//上一章 //上一章
tvPre.setOnClickListener { ReadBook.moveToPrevChapter(upContent = true, toLast = false) } tvPre.setOnClickListener { BookRead.moveToPrevChapter(upContent = true, toLast = false) }
//下一章 //下一章
tvNext.setOnClickListener { ReadBook.moveToNextChapter(true) } tvNext.setOnClickListener { BookRead.moveToNextChapter(true) }
//目录 //目录
llCatalog.setOnClickListener { llCatalog.setOnClickListener {
@ -250,10 +250,10 @@ 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.tvLogin.isGone = ReadBook.bookSource?.loginUrl.isNullOrEmpty() binding.tvLogin.isGone = BookRead.bookSource?.loginUrl.isNullOrEmpty()
binding.tvPay.isGone = ReadBook.bookSource?.loginUrl.isNullOrEmpty() binding.tvPay.isGone = BookRead.bookSource?.loginUrl.isNullOrEmpty()
|| ReadBook.curTextChapter?.isVip != true || BookRead.curTextChapter?.isVip != true
|| ReadBook.curTextChapter?.isPay == true || BookRead.curTextChapter?.isPay == true
callBack.upSystemUiVisibility() callBack.upSystemUiVisibility()
binding.llBrightness.visible(showBrightnessView) binding.llBrightness.visible(showBrightnessView)
} }
@ -300,20 +300,20 @@ class ReadMenu @JvmOverloads constructor(
} }
fun upBookView() { fun upBookView() {
binding.titleBar.title = ReadBook.book?.name binding.titleBar.title = BookRead.book?.name
ReadBook.curTextChapter?.let { BookRead.curTextChapter?.let {
binding.tvChapterName.text = it.title binding.tvChapterName.text = it.title
binding.tvChapterName.visible() binding.tvChapterName.visible()
if (!ReadBook.isLocalBook) { if (!BookRead.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 = ReadBook.durPageIndex() binding.seekReadPage.progress = BookRead.durPageIndex()
binding.tvPre.isEnabled = ReadBook.durChapterIndex != 0 binding.tvPre.isEnabled = BookRead.durChapterIndex != 0
binding.tvNext.isEnabled = ReadBook.durChapterIndex != ReadBook.chapterSize - 1 binding.tvNext.isEnabled = BookRead.durChapterIndex != BookRead.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()
ReadBook.loadContent(false) BookRead.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.ReadBook import io.legado.app.model.BookRead
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()
ReadBook.loadContent(false) BookRead.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 { ReadBook.moveToPrevChapter(upContent = true, toLast = false) } tvPre.setOnClickListener { BookRead.moveToPrevChapter(upContent = true, toLast = false) }
tvNext.setOnClickListener { ReadBook.moveToNextChapter(true) } tvNext.setOnClickListener { BookRead.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.ReadBook import io.legado.app.model.BookRead
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 ->
ReadBook.book?.setPageAnim(-1) BookRead.book?.setPageAnim(-1)
ReadBookConfig.pageAnim = binding.rgPageAnim.getIndexById(checkedId) ReadBookConfig.pageAnim = binding.rgPageAnim.getIndexById(checkedId)
callBack?.upPageAnim() callBack?.upPageAnim()
ReadBook.loadContent(false) BookRead.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 {
ReadBook.pageAnim().let { BookRead.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.ReadBook import io.legado.app.model.BookRead
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
import io.legado.app.ui.book.read.page.entities.TextPage import io.legado.app.ui.book.read.page.entities.TextPage
@ -166,12 +166,12 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
lineBottom: Float, lineBottom: Float,
isImageLine: Boolean isImageLine: Boolean
) { ) {
val book = ReadBook.book ?: return val book = BookRead.book ?: return
ImageProvider.getImage( ImageProvider.getImage(
book, book,
textPage.chapterIndex, textPage.chapterIndex,
textChar.charData, textChar.charData,
ReadBook.bookSource, BookRead.bookSource,
true true
)?.let { )?.let {
val rectF = if (isImageLine) { val rectF = if (isImageLine) {
@ -500,7 +500,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 ->
ReadBook.book?.let { book -> BookRead.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.ReadBook import io.legado.app.model.BookRead
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 = ReadBook.book?.name tvBookName?.text = BookRead.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 -> ReadBook.moveToNextChapter(true) 3 -> BookRead.moveToNextChapter(true)
4 -> ReadBook.moveToPrevChapter(upContent = true, toLast = false) 4 -> BookRead.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 = ReadBook.pageAnim() == 3 isScroll = BookRead.pageAnim() == 3
ChapterProvider.upLayout() ChapterProvider.upLayout()
when (ReadBook.pageAnim()) { when (BookRead.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) ReadBook.textChapter(0) else null return if (callBack.isInitFinish) BookRead.textChapter(0) else null
} }
override val nextChapter: TextChapter? override val nextChapter: TextChapter?
get() { get() {
return if (callBack.isInitFinish) ReadBook.textChapter(1) else null return if (callBack.isInitFinish) BookRead.textChapter(1) else null
} }
override val prevChapter: TextChapter? override val prevChapter: TextChapter?
get() { get() {
return if (callBack.isInitFinish) ReadBook.textChapter(-1) else null return if (callBack.isInitFinish) BookRead.textChapter(-1) else null
} }
override fun hasNextChapter(): Boolean { override fun hasNextChapter(): Boolean {
return ReadBook.durChapterIndex < ReadBook.chapterSize - 1 return BookRead.durChapterIndex < BookRead.chapterSize - 1
} }
override fun hasPrevChapter(): Boolean { override fun hasPrevChapter(): Boolean {
return ReadBook.durChapterIndex > 0 return BookRead.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.ReadBook import io.legado.app.model.BookRead
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() = ReadBook.durPageIndex() val pageIndex: Int get() = BookRead.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.ReadBook import io.legado.app.model.BookRead
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? {
ReadBook.curTextChapter?.let { BookRead.curTextChapter?.let {
if (it.position == chapterIndex) { if (it.position == chapterIndex) {
return it return it
} }
} }
ReadBook.nextTextChapter?.let { BookRead.nextTextChapter?.let {
if (it.position == chapterIndex) { if (it.position == chapterIndex) {
return it return it
} }
} }
ReadBook.prevTextChapter?.let { BookRead.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.ReadBook import io.legado.app.model.BookRead
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, ReadBook.bookSource) ImageProvider.getImage(book, bookChapter.index, src, BookRead.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, ReadBook.bookSource)?.let { ImageProvider.getImage(book, chapter.index, src, BookRead.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
&& ReadBook.pageAnim() != 3 && BookRead.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.ReadBook import io.legado.app.model.BookRead
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() {
ReadBook.setPageIndex(0) BookRead.setPageIndex(0)
} }
override fun moveToLast() = with(dataSource) { override fun moveToLast() = with(dataSource) {
currentChapter?.let { currentChapter?.let {
if (it.pageSize == 0) { if (it.pageSize == 0) {
ReadBook.setPageIndex(0) BookRead.setPageIndex(0)
} else { } else {
ReadBook.setPageIndex(it.pageSize.minus(1)) BookRead.setPageIndex(it.pageSize.minus(1))
} }
} ?: ReadBook.setPageIndex(0) } ?: BookRead.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) {
ReadBook.moveToNextChapter(upContent) BookRead.moveToNextChapter(upContent)
} else { } else {
ReadBook.setPageIndex(pageIndex.plus(1)) BookRead.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) {
ReadBook.moveToPrevChapter(upContent) BookRead.moveToPrevChapter(upContent)
} else { } else {
ReadBook.setPageIndex(pageIndex.minus(1)) BookRead.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) {
ReadBook.msg?.let { BookRead.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) {
ReadBook.msg?.let { BookRead.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) {
ReadBook.msg?.let { BookRead.msg?.let {
return@with TextPage(text = it).format() return@with TextPage(text = it).format()
} }
if (pageIndex > 0) { if (pageIndex > 0) {

@ -8,7 +8,7 @@ import androidx.fragment.app.FragmentManager
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.ReadBook import io.legado.app.model.BookRead
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
@ -54,10 +54,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")
ReadBook.book?.let { book -> BookRead.book?.let { book ->
src?.let { src?.let {
execute { execute {
ImageProvider.getImage(book, chapterIndex, src, ReadBook.bookSource) ImageProvider.getImage(book, chapterIndex, src, BookRead.bookSource)
}.onSuccess { bitmap -> }.onSuccess { bitmap ->
if (bitmap != null) { if (bitmap != null) {
binding.photoView.setImageBitmap(bitmap) binding.photoView.setImageBitmap(bitmap)

Loading…
Cancel
Save