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.storage.AppWebDav
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.LocalBook
import io.legado.app.model.localBook.UmdFile
@ -159,9 +159,9 @@ object BookController {
if (book != null) {
book.save()
AppWebDav.uploadBookProgress(book)
if (ReadBook.book?.bookUrl == book.bookUrl) {
ReadBook.book = book
ReadBook.durChapterIndex = book.durChapterIndex
if (BookRead.book?.bookUrl == book.bookUrl) {
BookRead.book = book
BookRead.durChapterIndex = book.durChapterIndex
}
return returnData.setData("")
}
@ -176,9 +176,9 @@ object BookController {
}
appDb.bookDao.update(book)
AppWebDav.uploadBookProgress(book)
if (ReadBook.book?.bookUrl == book.bookUrl) {
ReadBook.book = book
ReadBook.durChapterIndex = index
if (BookRead.book?.bookUrl == book.bookUrl) {
BookRead.book = book
BookRead.durChapterIndex = index
}
}

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

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

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

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

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

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

@ -9,7 +9,7 @@ import io.legado.app.constant.EventBus
import io.legado.app.help.AppConfig
import io.legado.app.help.MediaHelp
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 java.util.*
@ -122,7 +122,7 @@ class TTSReadAloudService : BaseReadAloudService(), TextToSpeech.OnInitListener
textChapter?.let {
if (readAloudNumber + 1 > it.getReadLength(pageIndex + 1)) {
pageIndex++
ReadBook.moveToNextPage()
BookRead.moveToNextPage()
}
postEvent(EventBus.TTS_PROGRESS, readAloudNumber + 1)
}
@ -141,7 +141,7 @@ class TTSReadAloudService : BaseReadAloudService(), TextToSpeech.OnInitListener
textChapter?.let {
if (readAloudNumber + start > it.getReadLength(pageIndex + 1)) {
pageIndex++
ReadBook.moveToNextPage()
BookRead.moveToNextPage()
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.BookSource
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.webBook.WebBook
import io.legado.app.utils.postEvent
@ -210,8 +210,8 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
book.durChapterTitle = it.durChapterTitle
}
book.save()
if (ReadBook.book?.name == book.name && ReadBook.book?.author == book.author) {
ReadBook.book = book
if (BookRead.book?.name == book.name && BookRead.book?.author == book.author) {
BookRead.book = book
}
}
}.onSuccess {

@ -5,7 +5,7 @@ import androidx.lifecycle.MutableLiveData
import io.legado.app.base.BaseViewModel
import io.legado.app.data.appDb
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) {
var book: Book? = null
@ -22,8 +22,8 @@ class BookInfoEditViewModel(application: Application) : BaseViewModel(applicatio
fun saveBook(book: Book, success: (() -> Unit)?) {
execute {
if (ReadBook.book?.bookUrl == book.bookUrl) {
ReadBook.book = book
if (BookRead.book?.bookUrl == book.bookUrl) {
BookRead.book = book
}
appDb.bookDao.update(book)
}.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.selector
import io.legado.app.lib.theme.accentColor
import io.legado.app.model.BookRead
import io.legado.app.model.NoStackTraceException
import io.legado.app.model.ReadAloud
import io.legado.app.model.ReadBook
import io.legado.app.receiver.TimeBatteryReceiver
import io.legado.app.service.BaseReadAloudService
import io.legado.app.ui.book.changesource.ChangeSourceDialog
@ -66,7 +66,7 @@ class ReadBookActivity : ReadBookBaseActivity(),
ReadMenu.CallBack,
ReadAloudDialog.CallBack,
ChangeSourceDialog.CallBack,
ReadBook.CallBack,
BookRead.CallBack,
AutoReadDialog.CallBack,
TocRegexDialog.CallBack,
ColorPickerDialogListener {
@ -97,7 +97,7 @@ class ReadBookActivity : ReadBookBaseActivity(),
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
it ?: return@registerForActivityResult
it.data?.let { data ->
data.getIntExtra("index", ReadBook.durChapterIndex).let { index ->
data.getIntExtra("index", BookRead.durChapterIndex).let { index ->
viewModel.searchContentQuery = data.getStringExtra("query") ?: ""
val indexWithinChapter = data.getIntExtra("indexWithinChapter", 0)
skipToSearch(index, indexWithinChapter)
@ -131,7 +131,7 @@ class ReadBookActivity : ReadBookBaseActivity(),
binding.cursorLeft.setOnTouchListener(this)
binding.cursorRight.setOnTouchListener(this)
upScreenTimeOut()
ReadBook.callBack = this
BookRead.callBack = this
}
override fun onPostCreate(savedInstanceState: Bundle?) {
@ -151,7 +151,7 @@ class ReadBookActivity : ReadBookBaseActivity(),
override fun onResume() {
super.onResume()
ReadBook.readStartTime = System.currentTimeMillis()
BookRead.readStartTime = System.currentTimeMillis()
upSystemUiVisibility()
timeBatteryReceiver = TimeBatteryReceiver.register(this)
binding.readView.upTime()
@ -161,14 +161,14 @@ class ReadBookActivity : ReadBookBaseActivity(),
super.onPause()
autoPageStop()
backupJob?.cancel()
ReadBook.saveRead()
BookRead.saveRead()
timeBatteryReceiver?.let {
unregisterReceiver(it)
timeBatteryReceiver = null
}
upSystemUiVisibility()
if (!BuildConfig.DEBUG) {
ReadBook.uploadProgress()
BookRead.uploadProgress()
Backup.autoBack(this)
}
}
@ -189,7 +189,7 @@ class ReadBookActivity : ReadBookBaseActivity(),
*/
private fun upMenu() {
val menu = menu
val book = ReadBook.book
val book = BookRead.book
if (menu != null && book != null) {
val onLine = !book.isLocalBook()
for (i in 0 until menu.size) {
@ -223,16 +223,16 @@ class ReadBookActivity : ReadBookBaseActivity(),
when (item.itemId) {
R.id.menu_change_source -> {
binding.readMenu.runMenuOut()
ReadBook.book?.let {
BookRead.book?.let {
supportFragmentManager.showDialog(ChangeSourceDialog(it.name, it.author))
}
}
R.id.menu_refresh -> {
if (ReadBook.bookSource == null) {
if (BookRead.bookSource == null) {
upContent()
} else {
ReadBook.book?.let {
ReadBook.curTextChapter = null
BookRead.book?.let {
BookRead.curTextChapter = null
binding.readView.upContent()
viewModel.refreshContent(it)
}
@ -240,12 +240,12 @@ class ReadBookActivity : ReadBookBaseActivity(),
}
R.id.menu_download -> showDownloadDialog()
R.id.menu_add_bookmark -> {
val book = ReadBook.book
val page = ReadBook.curTextChapter?.page(ReadBook.durPageIndex())
val book = BookRead.book
val page = BookRead.curTextChapter?.page(BookRead.durPageIndex())
if (book != null && page != null) {
val bookmark = book.createBookMark().apply {
chapterIndex = ReadBook.durChapterIndex
chapterPos = ReadBook.durChapterPos
chapterIndex = BookRead.durChapterIndex
chapterPos = BookRead.durChapterPos
chapterName = page.title
bookText = page.text.trim()
}
@ -253,34 +253,34 @@ class ReadBookActivity : ReadBookBaseActivity(),
}
}
R.id.menu_copy_text ->
TextDialog.show(supportFragmentManager, ReadBook.curTextChapter?.getContent())
R.id.menu_update_toc -> ReadBook.book?.let {
TextDialog.show(supportFragmentManager, BookRead.curTextChapter?.getContent())
R.id.menu_update_toc -> BookRead.book?.let {
loadChapterList(it)
}
R.id.menu_enable_replace -> ReadBook.book?.let {
R.id.menu_enable_replace -> BookRead.book?.let {
it.setUseReplaceRule(!it.getUseReplaceRule())
menu?.findItem(R.id.menu_enable_replace)?.isChecked = it.getUseReplaceRule()
viewModel.replaceRuleChanged()
}
R.id.menu_re_segment -> ReadBook.book?.let {
R.id.menu_re_segment -> BookRead.book?.let {
it.setReSegment(!it.getReSegment())
menu?.findItem(R.id.menu_re_segment)?.isChecked = it.getReSegment()
ReadBook.loadContent(false)
BookRead.loadContent(false)
}
R.id.menu_page_anim -> showPageAnimConfig {
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> {
putExtra("name", it.name)
putExtra("author", it.author)
}
}
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)
}
R.id.menu_set_charset -> showCharsetConfig()
@ -291,11 +291,11 @@ class ReadBookActivity : ReadBookBaseActivity(),
R.string.image_style,
imgStyles
) { _, index ->
ReadBook.book?.setImageStyle(imgStyles[index])
ReadBook.loadContent(false)
BookRead.book?.setImageStyle(imgStyles[index])
BookRead.loadContent(false)
}
}
R.id.menu_get_progress -> ReadBook.book?.let {
R.id.menu_get_progress -> BookRead.book?.let {
viewModel.syncBookProgress(it) { progress ->
sureSyncProgress(progress)
}
@ -517,10 +517,10 @@ class ReadBookActivity : ReadBookBaseActivity(),
}
R.id.menu_replace -> {
val scopes = arrayListOf<String>()
ReadBook.book?.name?.let {
BookRead.book?.name?.let {
scopes.add(it)
}
ReadBook.bookSource?.bookSourceUrl?.let {
BookRead.bookSource?.bookSourceUrl?.let {
scopes.add(it)
}
replaceActivity.launch(
@ -580,7 +580,7 @@ class ReadBookActivity : ReadBookBaseActivity(),
}
override fun loadChapterList(book: Book) {
ReadBook.upMsg(getString(R.string.toc_updateing))
BookRead.upMsg(getString(R.string.toc_updateing))
viewModel.loadChapterList(book)
}
@ -590,7 +590,7 @@ class ReadBookActivity : ReadBookBaseActivity(),
override fun contentLoadFinish() {
if (intent.getBooleanExtra("readAloud", false)) {
intent.removeExtra("readAloud")
ReadBook.readAloud()
BookRead.readAloud()
}
loadStates = true
}
@ -606,7 +606,7 @@ class ReadBookActivity : ReadBookBaseActivity(),
launch {
autoPageProgress = 0
binding.readView.upContent(relativePosition, resetPageOffset)
binding.readMenu.setSeekPage(ReadBook.durPageIndex())
binding.readMenu.setSeekPage(BookRead.durPageIndex())
loadStates = false
success?.invoke()
}
@ -624,7 +624,7 @@ class ReadBookActivity : ReadBookBaseActivity(),
override fun pageChanged() {
launch {
autoPageProgress = 0
binding.readMenu.setSeekPage(ReadBook.durPageIndex())
binding.readMenu.setSeekPage(BookRead.durPageIndex())
startBackupJob()
}
}
@ -637,7 +637,7 @@ class ReadBookActivity : ReadBookBaseActivity(),
}
override val oldBook: Book?
get() = ReadBook.book
get() = BookRead.book
override fun changeTo(source: BookSource, book: Book) {
viewModel.changeTo(source, book)
@ -722,7 +722,7 @@ class ReadBookActivity : ReadBookBaseActivity(),
}
override fun openSourceEditActivity() {
ReadBook.bookSource?.let {
BookRead.bookSource?.let {
sourceEditActivity.launch {
putExtra("sourceUrl", it.bookSourceUrl)
}
@ -740,7 +740,7 @@ class ReadBookActivity : ReadBookBaseActivity(),
* 打开目录
*/
override fun openChapterList() {
ReadBook.book?.let {
BookRead.book?.let {
tocActivity.launch(it.bookUrl)
}
}
@ -749,7 +749,7 @@ class ReadBookActivity : ReadBookBaseActivity(),
* 打开搜索界面
*/
override fun openSearchActivity(searchWord: String?) {
ReadBook.book?.let {
BookRead.book?.let {
searchContentActivity.launch(Intent(this, SearchContentActivity::class.java).apply {
putExtra("bookUrl", it.bookUrl)
putExtra("searchWord", searchWord ?: viewModel.searchContentQuery)
@ -780,7 +780,7 @@ class ReadBookActivity : ReadBookBaseActivity(),
}
override fun showLogin() {
ReadBook.bookSource?.let {
BookRead.bookSource?.let {
startActivity<SourceLoginActivity> {
putExtra("sourceUrl", it.bookSourceUrl)
}
@ -789,10 +789,10 @@ class ReadBookActivity : ReadBookBaseActivity(),
override fun payAction() {
Coroutine.async(this) {
val book = ReadBook.book ?: throw NoStackTraceException("no book")
val chapter = appDb.bookChapterDao.getChapter(book.bookUrl, ReadBook.durChapterIndex)
val book = BookRead.book ?: throw NoStackTraceException("no book")
val chapter = appDb.bookChapterDao.getChapter(book.bookUrl, BookRead.durChapterIndex)
?: 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
if (payAction.isNullOrEmpty()) {
throw NoStackTraceException("no pay action")
@ -810,7 +810,7 @@ class ReadBookActivity : ReadBookBaseActivity(),
override fun onClickReadAloud() {
autoPageStop()
when {
!BaseReadAloudService.isRun -> ReadBook.readAloud()
!BaseReadAloudService.isRun -> BookRead.readAloud()
BaseReadAloudService.pause -> ReadAloud.resume(this)
else -> ReadAloud.pause(this)
}
@ -844,7 +844,7 @@ class ReadBookActivity : ReadBookBaseActivity(),
override fun onDialogDismissed(dialogId: Int) = Unit
override fun onTocRegexDialogResult(tocRegex: String) {
ReadBook.book?.let {
BookRead.book?.let {
it.tocUrl = tocRegex
viewModel.loadChapterList(it)
}
@ -854,7 +854,7 @@ class ReadBookActivity : ReadBookBaseActivity(),
alert(R.string.get_book_progress) {
setMessage(R.string.current_progress_exceeds_cloud)
okButton {
ReadBook.setProgress(progress)
BookRead.setProgress(progress)
}
noButton()
}.show()
@ -862,9 +862,9 @@ class ReadBookActivity : ReadBookBaseActivity(),
private fun skipToSearch(index: Int, indexWithinChapter: Int) {
viewModel.openChapter(index) {
val pages = ReadBook.curTextChapter?.pages ?: return@openChapter
val pages = BookRead.curTextChapter?.pages ?: return@openChapter
val positions = viewModel.searchResultPositions(pages, indexWithinChapter)
ReadBook.skipToPage(positions[0]) {
BookRead.skipToPage(positions[0]) {
launch {
binding.readView.curPage.selectStartMoveIndex(0, positions[1], positions[2])
delay(20L)
@ -894,7 +894,7 @@ class ReadBookActivity : ReadBookBaseActivity(),
backupJob?.cancel()
backupJob = launch {
delay(120000)
ReadBook.book?.let {
BookRead.book?.let {
AppWebDav.uploadBookProgress(it)
Backup.autoBack(this@ReadBookActivity)
}
@ -902,12 +902,12 @@ class ReadBookActivity : ReadBookBaseActivity(),
}
override fun finish() {
ReadBook.book?.let {
if (!ReadBook.inBookshelf) {
BookRead.book?.let {
if (!BookRead.inBookshelf) {
alert(title = getString(R.string.add_to_shelf)) {
setMessage(getString(R.string.check_add_bookshelf, it.name))
okButton {
ReadBook.inBookshelf = true
BookRead.inBookshelf = true
setResult(Activity.RESULT_OK)
}
noButton { viewModel.removeFromBookshelf { super.finish() } }
@ -922,7 +922,7 @@ class ReadBookActivity : ReadBookBaseActivity(),
super.onDestroy()
textActionMenu.dismiss()
binding.readView.onDestroy()
ReadBook.msg = null
BookRead.msg = null
if (!BuildConfig.DEBUG) {
Backup.autoBack(this)
}
@ -933,14 +933,14 @@ class ReadBookActivity : ReadBookBaseActivity(),
observeEvent<String>(EventBus.TIME_CHANGED) { readView.upTime() }
observeEvent<Int>(EventBus.BATTERY_CHANGED) { readView.upBattery(it) }
observeEvent<BookChapter>(EventBus.OPEN_CHAPTER) {
viewModel.openChapter(it.index, ReadBook.durChapterPos)
viewModel.openChapter(it.index, BookRead.durChapterPos)
readView.upContent()
}
observeEvent<Boolean>(EventBus.MEDIA_BUTTON) {
if (it) {
onClickReadAloud()
} else {
ReadBook.readAloud(!BaseReadAloudService.pause)
BookRead.readAloud(!BaseReadAloudService.pause)
}
}
observeEvent<Boolean>(EventBus.UP_CONFIG) {
@ -948,15 +948,15 @@ class ReadBookActivity : ReadBookBaseActivity(),
readView.upBg()
readView.upStyle()
if (it) {
ReadBook.loadContent(resetPageOffset = false)
BookRead.loadContent(resetPageOffset = false)
} else {
readView.upContent(resetPageOffset = false)
}
}
observeEvent<Int>(EventBus.ALOUD_STATE) {
if (it == Status.STOP || it == Status.PAUSE) {
ReadBook.curTextChapter?.let { textChapter ->
val page = textChapter.getPageByReadPos(ReadBook.durChapterPos)
BookRead.curTextChapter?.let { textChapter ->
val page = textChapter.getPageByReadPos(BookRead.durChapterPos)
if (page != null) {
page.removePageAloudSpan()
readView.upContent(resetPageOffset = false)
@ -967,9 +967,9 @@ class ReadBookActivity : ReadBookBaseActivity(),
observeEventSticky<Int>(EventBus.TTS_PROGRESS) { chapterStart ->
launch(IO) {
if (BaseReadAloudService.isPlay()) {
ReadBook.curTextChapter?.let { textChapter ->
val aloudSpanStart = chapterStart - ReadBook.durChapterPos
textChapter.getPageByReadPos(ReadBook.durChapterPos)
BookRead.curTextChapter?.let { textChapter ->
val aloudSpanStart = chapterStart - BookRead.durChapterPos
textChapter.getPageByReadPos(BookRead.durChapterPos)
?.upPageAloudSpan(aloudSpanStart)
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.backgroundColor
import io.legado.app.lib.theme.bottomBackground
import io.legado.app.model.BookRead
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.ClickActionConfigDialog
import io.legado.app.ui.book.read.config.PaddingConfigDialog
@ -42,7 +42,7 @@ abstract class ReadBookBaseActivity :
var bottomDialog = 0
override fun onCreate(savedInstanceState: Bundle?) {
ReadBook.msg = null
BookRead.msg = null
setOrientation()
upLayoutInDisplayCutoutMode()
super.onCreate(savedInstanceState)
@ -186,7 +186,7 @@ abstract class ReadBookBaseActivity :
@SuppressLint("InflateParams")
fun showDownloadDialog() {
ReadBook.book?.let { book ->
BookRead.book?.let { book ->
alert(titleResource = R.string.offline_cache) {
val alertBinding = DialogDownloadChoiceBinding.inflate(layoutInflater).apply {
root.setBackgroundColor(root.context.backgroundColor)
@ -211,12 +211,12 @@ abstract class ReadBookBaseActivity :
val alertBinding = DialogEditTextBinding.inflate(layoutInflater).apply {
editView.hint = "charset"
editView.setFilterValues(charsets)
editView.setText(ReadBook.book?.charset)
editView.setText(BookRead.book?.charset)
}
customView { alertBinding.root }
okButton {
alertBinding.editView.text?.toString()?.let {
ReadBook.setCharset(it)
BookRead.setCharset(it)
}
}
cancelButton()
@ -232,7 +232,7 @@ abstract class ReadBookBaseActivity :
items.add(getString(R.string.page_anim_scroll))
items.add(getString(R.string.page_anim_none))
selector(R.string.page_anim, items) { _, i ->
ReadBook.book?.setPageAnim(i - 1)
BookRead.book?.setPageAnim(i - 1)
success()
}
}

@ -14,9 +14,9 @@ import io.legado.app.help.AppConfig
import io.legado.app.help.BookHelp
import io.legado.app.help.ContentProcessor
import io.legado.app.help.storage.AppWebDav
import io.legado.app.model.BookRead
import io.legado.app.model.NoStackTraceException
import io.legado.app.model.ReadAloud
import io.legado.app.model.ReadBook
import io.legado.app.model.localBook.LocalBook
import io.legado.app.model.webBook.WebBook
import io.legado.app.service.BaseReadAloudService
@ -32,67 +32,67 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
fun initData(intent: Intent) {
execute {
ReadBook.inBookshelf = intent.getBooleanExtra("inBookshelf", true)
BookRead.inBookshelf = intent.getBooleanExtra("inBookshelf", true)
val bookUrl = intent.getStringExtra("bookUrl")
val book = when {
bookUrl.isNullOrEmpty() -> appDb.bookDao.lastReadBook
else -> appDb.bookDao.getBook(bookUrl)
} ?: ReadBook.book
} ?: BookRead.book
when {
book != null -> initBook(book)
else -> ReadBook.upMsg(context.getString(R.string.no_book))
else -> BookRead.upMsg(context.getString(R.string.no_book))
}
}.onFinally {
ReadBook.saveRead()
BookRead.saveRead()
}
}
private fun initBook(book: Book) {
if (ReadBook.book?.bookUrl != book.bookUrl) {
ReadBook.resetData(book)
if (BookRead.book?.bookUrl != book.bookUrl) {
BookRead.resetData(book)
isInitFinish = true
if (ReadBook.chapterSize == 0) {
if (BookRead.chapterSize == 0) {
if (book.tocUrl.isEmpty()) {
loadBookInfo(book)
} else {
loadChapterList(book)
}
} else {
if (ReadBook.durChapterIndex > ReadBook.chapterSize - 1) {
ReadBook.durChapterIndex = ReadBook.chapterSize - 1
if (BookRead.durChapterIndex > BookRead.chapterSize - 1) {
BookRead.durChapterIndex = BookRead.chapterSize - 1
}
ReadBook.loadContent(resetPageOffset = true)
BookRead.loadContent(resetPageOffset = true)
}
syncBookProgress(book)
} else {
ReadBook.book = book
if (ReadBook.durChapterIndex != book.durChapterIndex) {
ReadBook.durChapterIndex = book.durChapterIndex
ReadBook.durChapterPos = book.durChapterPos
ReadBook.clearTextChapter()
}
ReadBook.callBack?.upMenuView()
ReadBook.upWebBook(book)
BookRead.book = book
if (BookRead.durChapterIndex != book.durChapterIndex) {
BookRead.durChapterIndex = book.durChapterIndex
BookRead.durChapterPos = book.durChapterPos
BookRead.clearTextChapter()
}
BookRead.callBack?.upMenuView()
BookRead.upWebBook(book)
isInitFinish = true
ReadBook.chapterSize = appDb.bookChapterDao.getChapterCount(book.bookUrl)
if (ReadBook.chapterSize == 0) {
BookRead.chapterSize = appDb.bookChapterDao.getChapterCount(book.bookUrl)
if (BookRead.chapterSize == 0) {
if (book.tocUrl.isEmpty()) {
loadBookInfo(book)
} else {
loadChapterList(book)
}
} else {
if (ReadBook.curTextChapter != null) {
ReadBook.callBack?.upContent(resetPageOffset = false)
if (BookRead.curTextChapter != null) {
BookRead.callBack?.upContent(resetPageOffset = false)
} else {
ReadBook.loadContent(resetPageOffset = true)
BookRead.loadContent(resetPageOffset = true)
}
}
if (!BaseReadAloudService.isRun) {
syncBookProgress(book)
}
}
if (!book.isLocalBook() && ReadBook.bookSource == null) {
if (!book.isLocalBook() && BookRead.bookSource == null) {
autoChangeSource(book.name, book.author)
return
}
@ -102,12 +102,12 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
if (book.isLocalBook()) {
loadChapterList(book)
} else {
ReadBook.bookSource?.let { source ->
BookRead.bookSource?.let { source ->
WebBook.getBookInfo(viewModelScope, source, book, canReName = false)
.onSuccess {
loadChapterList(book)
}.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.insert(*it.toTypedArray())
appDb.bookDao.update(book)
ReadBook.chapterSize = it.size
ReadBook.upMsg(null)
ReadBook.loadContent(resetPageOffset = true)
BookRead.chapterSize = it.size
BookRead.upMsg(null)
BookRead.loadContent(resetPageOffset = true)
}
}.onError {
ReadBook.upMsg("LoadTocError:${it.localizedMessage}")
BookRead.upMsg("LoadTocError:${it.localizedMessage}")
}
} else {
ReadBook.bookSource?.let {
BookRead.bookSource?.let {
WebBook.getChapterList(viewModelScope, it, book)
.onSuccess(IO) { cList ->
appDb.bookChapterDao.insert(*cList.toTypedArray())
appDb.bookDao.update(book)
ReadBook.chapterSize = cList.size
ReadBook.upMsg(null)
ReadBook.loadContent(resetPageOffset = true)
BookRead.chapterSize = cList.size
BookRead.upMsg(null)
BookRead.loadContent(resetPageOffset = true)
}.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)
} else {
ReadBook.setProgress(progress)
BookRead.setProgress(progress)
}
}
}
@ -166,12 +166,12 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
fun changeTo(source: BookSource, book: Book) {
execute {
ReadBook.upMsg(context.getString(R.string.loading))
BookRead.upMsg(context.getString(R.string.loading))
if (book.tocUrl.isEmpty()) {
WebBook.getBookInfoAwait(this, source, book)
}
val chapters = WebBook.getChapterListAwait(this, source, book)
val oldBook = ReadBook.book!!
val oldBook = BookRead.book!!
book.durChapterIndex = BookHelp.getDurChapter(
oldBook.durChapterIndex,
oldBook.totalChapterNum,
@ -181,13 +181,13 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
book.durChapterTitle = chapters[book.durChapterIndex].title
oldBook.changeTo(book)
appDb.bookChapterDao.insert(*chapters.toTypedArray())
ReadBook.resetData(book)
ReadBook.upMsg(null)
ReadBook.loadContent(resetPageOffset = true)
BookRead.resetData(book)
BookRead.upMsg(null)
BookRead.loadContent(resetPageOffset = true)
}.timeout(60000)
.onError {
context.toastOnUi("换源失败\n${it.localizedMessage}")
ReadBook.upMsg(null)
BookRead.upMsg(null)
}.onFinally {
postEvent(EventBus.SOURCE_CHANGED, book.bookUrl)
}
@ -198,34 +198,34 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
execute {
val sources = appDb.bookSourceDao.allTextEnabled
WebBook.preciseSearch(this, sources, name, author)?.let {
it.second.upInfoFromOld(ReadBook.book)
it.second.upInfoFromOld(BookRead.book)
changeTo(it.first, it.second)
} ?: throw NoStackTraceException("自动换源失败")
}.onStart {
ReadBook.upMsg(context.getString(R.string.source_auto_changing))
BookRead.upMsg(context.getString(R.string.source_auto_changing))
}.onError {
context.toastOnUi(it.msg)
}.onFinally {
ReadBook.upMsg(null)
BookRead.upMsg(null)
}
}
fun openChapter(index: Int, durChapterPos: Int = 0, success: (() -> Unit)? = null) {
ReadBook.clearTextChapter()
ReadBook.callBack?.upContent()
if (index != ReadBook.durChapterIndex) {
ReadBook.durChapterIndex = index
ReadBook.durChapterPos = durChapterPos
}
ReadBook.saveRead()
ReadBook.loadContent(resetPageOffset = true) {
BookRead.clearTextChapter()
BookRead.callBack?.upContent()
if (index != BookRead.durChapterIndex) {
BookRead.durChapterIndex = index
BookRead.durChapterPos = durChapterPos
}
BookRead.saveRead()
BookRead.loadContent(resetPageOffset = true) {
success?.invoke()
}
}
fun removeFromBookshelf(success: (() -> Unit)?) {
execute {
Book.delete(ReadBook.book)
Book.delete(BookRead.book)
}.onSuccess {
success?.invoke()
}
@ -233,8 +233,8 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
fun upBookSource(success: (() -> Unit)?) {
execute {
ReadBook.book?.let { book ->
ReadBook.bookSource = appDb.bookSourceDao.getBookSource(book.origin)
BookRead.book?.let { book ->
BookRead.bookSource = appDb.bookSourceDao.getBookSource(book.origin)
}
}.onSuccess {
success?.invoke()
@ -243,20 +243,20 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
fun refreshContent(book: Book) {
execute {
appDb.bookChapterDao.getChapter(book.bookUrl, ReadBook.durChapterIndex)
appDb.bookChapterDao.getChapter(book.bookUrl, BookRead.durChapterIndex)
?.let { chapter ->
BookHelp.delContent(book, chapter)
ReadBook.loadContent(ReadBook.durChapterIndex, resetPageOffset = false)
BookRead.loadContent(BookRead.durChapterIndex, resetPageOffset = false)
}
}
}
fun reverseContent(book: Book) {
execute {
appDb.bookChapterDao.getChapter(book.bookUrl, ReadBook.durChapterIndex)
appDb.bookChapterDao.getChapter(book.bookUrl, BookRead.durChapterIndex)
?.let { 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() {
execute {
ReadBook.book?.let {
BookRead.book?.let {
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.help.*
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.widget.seekbar.SeekBarChangeListener
import io.legado.app.utils.*
@ -145,7 +145,7 @@ class ReadMenu @JvmOverloads constructor(
val url = tvChapterUrl.text.toString()
putExtra("title", tvChapterName.text)
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 {
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 {
@ -250,10 +250,10 @@ class ReadMenu @JvmOverloads constructor(
menuBottomIn = AnimationUtilsSupport.loadAnimation(context, R.anim.anim_readbook_bottom_in)
menuTopIn.setAnimationListener(object : Animation.AnimationListener {
override fun onAnimationStart(animation: Animation) {
binding.tvLogin.isGone = ReadBook.bookSource?.loginUrl.isNullOrEmpty()
binding.tvPay.isGone = ReadBook.bookSource?.loginUrl.isNullOrEmpty()
|| ReadBook.curTextChapter?.isVip != true
|| ReadBook.curTextChapter?.isPay == true
binding.tvLogin.isGone = BookRead.bookSource?.loginUrl.isNullOrEmpty()
binding.tvPay.isGone = BookRead.bookSource?.loginUrl.isNullOrEmpty()
|| BookRead.curTextChapter?.isVip != true
|| BookRead.curTextChapter?.isPay == true
callBack.upSystemUiVisibility()
binding.llBrightness.visible(showBrightnessView)
}
@ -300,20 +300,20 @@ class ReadMenu @JvmOverloads constructor(
}
fun upBookView() {
binding.titleBar.title = ReadBook.book?.name
ReadBook.curTextChapter?.let {
binding.titleBar.title = BookRead.book?.name
BookRead.curTextChapter?.let {
binding.tvChapterName.text = it.title
binding.tvChapterName.visible()
if (!ReadBook.isLocalBook) {
if (!BookRead.isLocalBook) {
binding.tvChapterUrl.text = it.url
binding.tvChapterUrl.visible()
} else {
binding.tvChapterUrl.gone()
}
binding.seekReadPage.max = it.pageSize.minus(1)
binding.seekReadPage.progress = ReadBook.durPageIndex()
binding.tvPre.isEnabled = ReadBook.durChapterIndex != 0
binding.tvNext.isEnabled = ReadBook.durChapterIndex != ReadBook.chapterSize - 1
binding.seekReadPage.progress = BookRead.durPageIndex()
binding.tvPre.isEnabled = BookRead.durChapterIndex != 0
binding.tvNext.isEnabled = BookRead.durChapterIndex != BookRead.chapterSize - 1
} ?: let {
binding.tvChapterName.gone()
binding.tvChapterUrl.gone()

@ -10,8 +10,8 @@ import io.legado.app.databinding.DialogAutoReadBinding
import io.legado.app.help.ReadBookConfig
import io.legado.app.lib.theme.bottomBackground
import io.legado.app.lib.theme.getPrimaryTextColor
import io.legado.app.model.BookRead
import io.legado.app.model.ReadAloud
import io.legado.app.model.ReadBook
import io.legado.app.service.BaseReadAloudService
import io.legado.app.ui.book.read.ReadBookActivity
import io.legado.app.ui.book.read.ReadBookBaseActivity
@ -103,7 +103,7 @@ class AutoReadDialog : BaseDialogFragment() {
binding.llSetting.setOnClickListener {
(activity as ReadBookBaseActivity).showPageAnimConfig {
(activity as ReadBookActivity).upPageAnim()
ReadBook.loadContent(false)
BookRead.loadContent(false)
}
}
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.lib.theme.ATH
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.page.ReadView
import io.legado.app.ui.book.read.page.provider.ChapterProvider
@ -126,7 +126,7 @@ class MoreConfigDialog : DialogFragment() {
}
PreferKey.doublePageHorizontal -> {
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.lib.theme.bottomBackground
import io.legado.app.lib.theme.getPrimaryTextColor
import io.legado.app.model.BookRead
import io.legado.app.model.ReadAloud
import io.legado.app.model.ReadBook
import io.legado.app.service.BaseReadAloudService
import io.legado.app.ui.book.read.ReadBookActivity
import io.legado.app.ui.widget.seekbar.SeekBarChangeListener
@ -102,8 +102,8 @@ class ReadAloudDialog : BaseDialogFragment() {
llSetting.setOnClickListener {
ReadAloudConfigDialog().show(childFragmentManager, "readAloudConfigDialog")
}
tvPre.setOnClickListener { ReadBook.moveToPrevChapter(upContent = true, toLast = false) }
tvNext.setOnClickListener { ReadBook.moveToNextChapter(true) }
tvPre.setOnClickListener { BookRead.moveToPrevChapter(upContent = true, toLast = false) }
tvNext.setOnClickListener { BookRead.moveToNextChapter(true) }
ivStop.setOnClickListener {
ReadAloud.stop(requireContext())
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.bottomBackground
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.widget.font.FontSelectDialog
import io.legado.app.utils.*
@ -129,10 +129,10 @@ class ReadStyleDialog : BaseDialogFragment(), FontSelectDialog.CallBack {
TipConfigDialog().show(childFragmentManager, "tipConfigDialog")
}
rgPageAnim.setOnCheckedChangeListener { _, checkedId ->
ReadBook.book?.setPageAnim(-1)
BookRead.book?.setPageAnim(-1)
ReadBookConfig.pageAnim = binding.rgPageAnim.getIndexById(checkedId)
callBack?.upPageAnim()
ReadBook.loadContent(false)
BookRead.loadContent(false)
}
cbShareLayout.onCheckedChangeListener = { _, isChecked ->
ReadBookConfig.shareLayout = isChecked
@ -177,7 +177,7 @@ class ReadStyleDialog : BaseDialogFragment(), FontSelectDialog.CallBack {
}
private fun upView() = binding.run {
ReadBook.pageAnim().let {
BookRead.pageAnim().let {
if (it >= 0 && it < rgPageAnim.childCount) {
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.help.ReadBookConfig
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.TextLine
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,
isImageLine: Boolean
) {
val book = ReadBook.book ?: return
val book = BookRead.book ?: return
ImageProvider.getImage(
book,
textPage.chapterIndex,
textChar.charData,
ReadBook.bookSource,
BookRead.bookSource,
true
)?.let {
val rectF = if (isImageLine) {
@ -500,7 +500,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
fun createBookmark(): Bookmark? {
val page = relativePage(selectStart[0])
page.getTextChapter()?.let { chapter ->
ReadBook.book?.let { book ->
BookRead.book?.let { book ->
return book.createBookMark().apply {
chapterIndex = page.chapterIndex
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.help.ReadBookConfig
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.provider.ChapterProvider
import io.legado.app.ui.widget.BatteryView
@ -224,7 +224,7 @@ class PageView(context: Context) : FrameLayout(context) {
@SuppressLint("SetTextI18n")
fun setProgress(textPage: TextPage) = textPage.apply {
tvBookName?.text = ReadBook.book?.name
tvBookName?.text = BookRead.book?.name
tvTitle?.text = textPage.title
tvPage?.text = "${index.plus(1)}/$pageSize"
tvTotalProgress?.text = readProgress

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

@ -1,11 +1,11 @@
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
interface DataSource {
val pageIndex: Int get() = ReadBook.durPageIndex()
val pageIndex: Int get() = BookRead.durPageIndex()
val currentChapter: TextChapter?

@ -4,7 +4,7 @@ import android.text.Layout
import android.text.StaticLayout
import io.legado.app.R
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 splitties.init.appCtx
import java.text.DecimalFormat
@ -171,17 +171,17 @@ data class TextPage(
}
fun getTextChapter(): TextChapter? {
ReadBook.curTextChapter?.let {
BookRead.curTextChapter?.let {
if (it.position == chapterIndex) {
return it
}
}
ReadBook.nextTextChapter?.let {
BookRead.nextTextChapter?.let {
if (it.position == chapterIndex) {
return it
}
}
ReadBook.prevTextChapter?.let {
BookRead.prevTextChapter?.let {
if (it.position == chapterIndex) {
return it
}

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

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

@ -8,7 +8,7 @@ import androidx.fragment.app.FragmentManager
import io.legado.app.R
import io.legado.app.base.BaseDialogFragment
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.utils.viewbindingdelegate.viewBinding
@ -54,10 +54,10 @@ class PhotoDialog : BaseDialogFragment() {
arguments?.let {
val chapterIndex = it.getInt("chapterIndex")
val src = it.getString("src")
ReadBook.book?.let { book ->
BookRead.book?.let { book ->
src?.let {
execute {
ImageProvider.getImage(book, chapterIndex, src, ReadBook.bookSource)
ImageProvider.getImage(book, chapterIndex, src, BookRead.bookSource)
}.onSuccess { bitmap ->
if (bitmap != null) {
binding.photoView.setImageBitmap(bitmap)

Loading…
Cancel
Save