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

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

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

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

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

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

@ -10,8 +10,8 @@ import io.legado.app.data.appDb
import io.legado.app.help.AppConfig
import io.legado.app.help.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)) {
BookRead.moveToPrevChapter(true)
ReadBook.moveToPrevChapter(true)
} else {
ReadAloud.prevParagraph(context)
}
}
KeyEvent.KEYCODE_MEDIA_NEXT -> {
if (context.getPrefBoolean("mediaButtonPerNext", false)) {
BookRead.moveToNextChapter(true)
ReadBook.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.put("readAloud start Service")
if (BookRead.book != null) {
BookRead.readAloud()
if (ReadBook.book != null) {
ReadBook.readAloud()
} else {
appDb.bookDao.lastReadBook?.let {
BookRead.resetData(it)
BookRead.curTextChapter ?: BookRead.loadContent(false)
BookRead.readAloud()
ReadBook.resetData(it)
ReadBook.curTextChapter ?: ReadBook.loadContent(false)
ReadBook.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()
BookRead.uploadProgress()
ReadBook.uploadProgress()
}
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
intent?.action?.let { action ->
when (action) {
IntentAction.play -> {
textChapter = BookRead.curTextChapter
pageIndex = BookRead.durPageIndex()
textChapter = ReadBook.curTextChapter
pageIndex = ReadBook.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)
BookRead.uploadProgress()
ReadBook.uploadProgress()
doDs()
}
@ -160,7 +160,7 @@ abstract class BaseReadAloudService : BaseService(),
readAloudNumber -= contentList[nowSpeak].length.minus(1)
play()
} else {
BookRead.moveToPrevChapter(true)
ReadBook.moveToPrevChapter(true)
}
}
@ -303,8 +303,8 @@ abstract class BaseReadAloudService : BaseService(),
)
else -> getString(R.string.read_aloud_t)
}
nTitle += ": ${BookRead.book?.name}"
var nSubtitle = BookRead.curTextChapter?.title
nTitle += ": ${ReadBook.book?.name}"
var nSubtitle = ReadBook.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() {
BookRead.upReadStartTime()
if (!BookRead.moveToNextChapter(true)) {
ReadBook.upReadStartTime()
if (!ReadBook.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++
BookRead.moveToNextPage()
ReadBook.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.BookRead
import io.legado.app.model.ReadBook
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++
BookRead.moveToNextPage()
ReadBook.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++
BookRead.moveToNextPage()
ReadBook.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.BookRead
import io.legado.app.model.ReadBook
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 (BookRead.book?.name == book.name && BookRead.book?.author == book.author) {
BookRead.book = book
if (ReadBook.book?.name == book.name && ReadBook.book?.author == book.author) {
ReadBook.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.BookRead
import io.legado.app.model.ReadBook
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 (BookRead.book?.bookUrl == book.bookUrl) {
BookRead.book = book
if (ReadBook.book?.bookUrl == book.bookUrl) {
ReadBook.book = book
}
appDb.bookDao.update(book)
}.onSuccess {

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

@ -22,6 +22,7 @@ import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookChapter
import io.legado.app.data.entities.BookProgress
import io.legado.app.data.entities.BookSource
import io.legado.app.help.IntentData
import io.legado.app.help.ReadBookConfig
import io.legado.app.help.ReadTipConfig
import io.legado.app.help.coroutine.Coroutine
@ -30,9 +31,9 @@ import io.legado.app.help.storage.Backup
import io.legado.app.lib.dialogs.alert
import io.legado.app.lib.dialogs.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
@ -49,6 +50,7 @@ import io.legado.app.ui.book.searchContent.SearchContentActivity
import io.legado.app.ui.book.source.edit.BookSourceEditActivity
import io.legado.app.ui.book.toc.BookmarkDialog
import io.legado.app.ui.book.toc.TocActivityResult
import io.legado.app.ui.browser.WebViewActivity
import io.legado.app.ui.dict.DictDialog
import io.legado.app.ui.login.SourceLoginActivity
import io.legado.app.ui.replace.ReplaceRuleActivity
@ -66,7 +68,7 @@ class ReadBookActivity : ReadBookBaseActivity(),
ReadMenu.CallBack,
ReadAloudDialog.CallBack,
ChangeSourceDialog.CallBack,
BookRead.CallBack,
ReadBook.CallBack,
AutoReadDialog.CallBack,
TocRegexDialog.CallBack,
ColorPickerDialogListener {
@ -97,7 +99,7 @@ class ReadBookActivity : ReadBookBaseActivity(),
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
it ?: return@registerForActivityResult
it.data?.let { data ->
data.getIntExtra("index", BookRead.durChapterIndex).let { index ->
data.getIntExtra("index", ReadBook.durChapterIndex).let { index ->
viewModel.searchContentQuery = data.getStringExtra("query") ?: ""
val indexWithinChapter = data.getIntExtra("indexWithinChapter", 0)
skipToSearch(index, indexWithinChapter)
@ -131,7 +133,7 @@ class ReadBookActivity : ReadBookBaseActivity(),
binding.cursorLeft.setOnTouchListener(this)
binding.cursorRight.setOnTouchListener(this)
upScreenTimeOut()
BookRead.callBack = this
ReadBook.callBack = this
}
override fun onPostCreate(savedInstanceState: Bundle?) {
@ -151,7 +153,7 @@ class ReadBookActivity : ReadBookBaseActivity(),
override fun onResume() {
super.onResume()
BookRead.readStartTime = System.currentTimeMillis()
ReadBook.readStartTime = System.currentTimeMillis()
upSystemUiVisibility()
timeBatteryReceiver = TimeBatteryReceiver.register(this)
binding.readView.upTime()
@ -161,14 +163,14 @@ class ReadBookActivity : ReadBookBaseActivity(),
super.onPause()
autoPageStop()
backupJob?.cancel()
BookRead.saveRead()
ReadBook.saveRead()
timeBatteryReceiver?.let {
unregisterReceiver(it)
timeBatteryReceiver = null
}
upSystemUiVisibility()
if (!BuildConfig.DEBUG) {
BookRead.uploadProgress()
ReadBook.uploadProgress()
Backup.autoBack(this)
}
}
@ -189,13 +191,13 @@ class ReadBookActivity : ReadBookBaseActivity(),
*/
private fun upMenu() {
val menu = menu
val book = BookRead.book
val book = ReadBook.book
if (menu != null && book != null) {
val onLine = !book.isLocalBook()
for (i in 0 until menu.size) {
val item = menu[i]
when (item.groupId) {
R.id.menu_group_on_line -> item.isVisible == onLine
R.id.menu_group_on_line -> item.isVisible = onLine
R.id.menu_group_local -> item.isVisible = !onLine
R.id.menu_group_text -> item.isVisible = book.isLocalTxt()
else -> when (item.itemId) {
@ -222,16 +224,16 @@ class ReadBookActivity : ReadBookBaseActivity(),
when (item.itemId) {
R.id.menu_change_source -> {
binding.readMenu.runMenuOut()
BookRead.book?.let {
ReadBook.book?.let {
showDialogFragment(ChangeSourceDialog(it.name, it.author))
}
}
R.id.menu_refresh -> {
if (BookRead.bookSource == null) {
if (ReadBook.bookSource == null) {
upContent()
} else {
BookRead.book?.let {
BookRead.curTextChapter = null
ReadBook.book?.let {
ReadBook.curTextChapter = null
binding.readView.upContent()
viewModel.refreshContent(it)
}
@ -239,12 +241,12 @@ class ReadBookActivity : ReadBookBaseActivity(),
}
R.id.menu_download -> showDownloadDialog()
R.id.menu_add_bookmark -> {
val book = BookRead.book
val page = BookRead.curTextChapter?.page(BookRead.durPageIndex())
val book = ReadBook.book
val page = ReadBook.curTextChapter?.page(ReadBook.durPageIndex())
if (book != null && page != null) {
val bookmark = book.createBookMark().apply {
chapterIndex = BookRead.durChapterIndex
chapterPos = BookRead.durChapterPos
chapterIndex = ReadBook.durChapterIndex
chapterPos = ReadBook.durChapterPos
chapterName = page.title
bookText = page.text.trim()
}
@ -252,35 +254,35 @@ class ReadBookActivity : ReadBookBaseActivity(),
}
}
R.id.menu_copy_text -> showDialogFragment(
TextDialog(BookRead.curTextChapter?.getContent())
TextDialog(ReadBook.curTextChapter?.getContent())
)
R.id.menu_update_toc -> BookRead.book?.let {
R.id.menu_update_toc -> ReadBook.book?.let {
loadChapterList(it)
}
R.id.menu_enable_replace -> BookRead.book?.let {
R.id.menu_enable_replace -> ReadBook.book?.let {
it.setUseReplaceRule(!it.getUseReplaceRule())
menu?.findItem(R.id.menu_enable_replace)?.isChecked = it.getUseReplaceRule()
viewModel.replaceRuleChanged()
}
R.id.menu_re_segment -> BookRead.book?.let {
R.id.menu_re_segment -> ReadBook.book?.let {
it.setReSegment(!it.getReSegment())
menu?.findItem(R.id.menu_re_segment)?.isChecked = it.getReSegment()
BookRead.loadContent(false)
ReadBook.loadContent(false)
}
R.id.menu_page_anim -> showPageAnimConfig {
binding.readView.upPageAnim()
BookRead.loadContent(false)
ReadBook.loadContent(false)
}
R.id.menu_book_info -> BookRead.book?.let {
R.id.menu_book_info -> ReadBook.book?.let {
startActivity<BookInfoActivity> {
putExtra("name", it.name)
putExtra("author", it.author)
}
}
R.id.menu_toc_regex -> showDialogFragment(
TocRegexDialog(BookRead.book?.tocUrl)
TocRegexDialog(ReadBook.book?.tocUrl)
)
R.id.menu_reverse_content -> BookRead.book?.let {
R.id.menu_reverse_content -> ReadBook.book?.let {
viewModel.reverseContent(it)
}
R.id.menu_set_charset -> showCharsetConfig()
@ -291,11 +293,11 @@ class ReadBookActivity : ReadBookBaseActivity(),
R.string.image_style,
imgStyles
) { _, index ->
BookRead.book?.setImageStyle(imgStyles[index])
BookRead.loadContent(false)
ReadBook.book?.setImageStyle(imgStyles[index])
ReadBook.loadContent(false)
}
}
R.id.menu_get_progress -> BookRead.book?.let {
R.id.menu_get_progress -> ReadBook.book?.let {
viewModel.syncBookProgress(it) { progress ->
sureSyncProgress(progress)
}
@ -517,10 +519,10 @@ class ReadBookActivity : ReadBookBaseActivity(),
}
R.id.menu_replace -> {
val scopes = arrayListOf<String>()
BookRead.book?.name?.let {
ReadBook.book?.name?.let {
scopes.add(it)
}
BookRead.bookSource?.bookSourceUrl?.let {
ReadBook.bookSource?.bookSourceUrl?.let {
scopes.add(it)
}
replaceActivity.launch(
@ -580,7 +582,7 @@ class ReadBookActivity : ReadBookBaseActivity(),
}
override fun loadChapterList(book: Book) {
BookRead.upMsg(getString(R.string.toc_updateing))
ReadBook.upMsg(getString(R.string.toc_updateing))
viewModel.loadChapterList(book)
}
@ -590,7 +592,7 @@ class ReadBookActivity : ReadBookBaseActivity(),
override fun contentLoadFinish() {
if (intent.getBooleanExtra("readAloud", false)) {
intent.removeExtra("readAloud")
BookRead.readAloud()
ReadBook.readAloud()
}
loadStates = true
}
@ -606,7 +608,7 @@ class ReadBookActivity : ReadBookBaseActivity(),
launch {
autoPageProgress = 0
binding.readView.upContent(relativePosition, resetPageOffset)
binding.readMenu.setSeekPage(BookRead.durPageIndex())
binding.readMenu.setSeekPage(ReadBook.durPageIndex())
loadStates = false
success?.invoke()
}
@ -624,7 +626,7 @@ class ReadBookActivity : ReadBookBaseActivity(),
override fun pageChanged() {
launch {
autoPageProgress = 0
binding.readMenu.setSeekPage(BookRead.durPageIndex())
binding.readMenu.setSeekPage(ReadBook.durPageIndex())
startBackupJob()
}
}
@ -637,7 +639,7 @@ class ReadBookActivity : ReadBookBaseActivity(),
}
override val oldBook: Book?
get() = BookRead.book
get() = ReadBook.book
override fun changeTo(source: BookSource, book: Book) {
viewModel.changeTo(source, book)
@ -722,7 +724,7 @@ class ReadBookActivity : ReadBookBaseActivity(),
}
override fun openSourceEditActivity() {
BookRead.bookSource?.let {
ReadBook.bookSource?.let {
sourceEditActivity.launch {
putExtra("sourceUrl", it.bookSourceUrl)
}
@ -740,7 +742,7 @@ class ReadBookActivity : ReadBookBaseActivity(),
* 打开目录
*/
override fun openChapterList() {
BookRead.book?.let {
ReadBook.book?.let {
tocActivity.launch(it.bookUrl)
}
}
@ -749,7 +751,7 @@ class ReadBookActivity : ReadBookBaseActivity(),
* 打开搜索界面
*/
override fun openSearchActivity(searchWord: String?) {
BookRead.book?.let {
ReadBook.book?.let {
searchContentActivity.launch(Intent(this, SearchContentActivity::class.java).apply {
putExtra("bookUrl", it.bookUrl)
putExtra("searchWord", searchWord ?: viewModel.searchContentQuery)
@ -787,7 +789,7 @@ class ReadBookActivity : ReadBookBaseActivity(),
}
override fun showLogin() {
BookRead.bookSource?.let {
ReadBook.bookSource?.let {
startActivity<SourceLoginActivity> {
putExtra("sourceUrl", it.bookSourceUrl)
}
@ -796,16 +798,30 @@ class ReadBookActivity : ReadBookBaseActivity(),
override fun payAction() {
Coroutine.async(this) {
val book = BookRead.book ?: throw NoStackTraceException("no book")
val chapter = appDb.bookChapterDao.getChapter(book.bookUrl, BookRead.durChapterIndex)
val book = ReadBook.book ?: throw NoStackTraceException("no book")
val chapter = appDb.bookChapterDao.getChapter(book.bookUrl, ReadBook.durChapterIndex)
?: throw NoStackTraceException("no chapter")
val source = BookRead.bookSource ?: throw NoStackTraceException("no book source")
val source = ReadBook.bookSource ?: throw NoStackTraceException("no book source")
val payAction = source.getContentRule().payAction
if (payAction.isNullOrEmpty()) {
throw NoStackTraceException("no pay action")
}
if (payAction.isAbsUrl()) {
payAction
} else {
source.evalJS(payAction) {
put("book", book)
put("chapter", chapter)
}?.toString()
}
}.onSuccess {
it?.let {
startActivity<WebViewActivity> {
putExtra("title", "购买")
putExtra("url", it)
IntentData.put(it, ReadBook.bookSource)
}
}
}.onError {
toastOnUi(it.localizedMessage)
}
@ -817,7 +833,7 @@ class ReadBookActivity : ReadBookBaseActivity(),
override fun onClickReadAloud() {
autoPageStop()
when {
!BaseReadAloudService.isRun -> BookRead.readAloud()
!BaseReadAloudService.isRun -> ReadBook.readAloud()
BaseReadAloudService.pause -> ReadAloud.resume(this)
else -> ReadAloud.pause(this)
}
@ -851,7 +867,7 @@ class ReadBookActivity : ReadBookBaseActivity(),
override fun onDialogDismissed(dialogId: Int) = Unit
override fun onTocRegexDialogResult(tocRegex: String) {
BookRead.book?.let {
ReadBook.book?.let {
it.tocUrl = tocRegex
viewModel.loadChapterList(it)
}
@ -861,7 +877,7 @@ class ReadBookActivity : ReadBookBaseActivity(),
alert(R.string.get_book_progress) {
setMessage(R.string.current_progress_exceeds_cloud)
okButton {
BookRead.setProgress(progress)
ReadBook.setProgress(progress)
}
noButton()
}
@ -869,9 +885,9 @@ class ReadBookActivity : ReadBookBaseActivity(),
private fun skipToSearch(index: Int, indexWithinChapter: Int) {
viewModel.openChapter(index) {
val pages = BookRead.curTextChapter?.pages ?: return@openChapter
val pages = ReadBook.curTextChapter?.pages ?: return@openChapter
val positions = viewModel.searchResultPositions(pages, indexWithinChapter)
BookRead.skipToPage(positions[0]) {
ReadBook.skipToPage(positions[0]) {
launch {
binding.readView.curPage.selectStartMoveIndex(0, positions[1], positions[2])
delay(20L)
@ -901,7 +917,7 @@ class ReadBookActivity : ReadBookBaseActivity(),
backupJob?.cancel()
backupJob = launch {
delay(120000)
BookRead.book?.let {
ReadBook.book?.let {
AppWebDav.uploadBookProgress(it)
Backup.autoBack(this@ReadBookActivity)
}
@ -909,12 +925,12 @@ class ReadBookActivity : ReadBookBaseActivity(),
}
override fun finish() {
BookRead.book?.let {
if (!BookRead.inBookshelf) {
ReadBook.book?.let {
if (!ReadBook.inBookshelf) {
alert(title = getString(R.string.add_to_shelf)) {
setMessage(getString(R.string.check_add_bookshelf, it.name))
okButton {
BookRead.inBookshelf = true
ReadBook.inBookshelf = true
setResult(Activity.RESULT_OK)
}
noButton { viewModel.removeFromBookshelf { super.finish() } }
@ -929,7 +945,7 @@ class ReadBookActivity : ReadBookBaseActivity(),
super.onDestroy()
textActionMenu.dismiss()
binding.readView.onDestroy()
BookRead.msg = null
ReadBook.msg = null
if (!BuildConfig.DEBUG) {
Backup.autoBack(this)
}
@ -940,14 +956,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, BookRead.durChapterPos)
viewModel.openChapter(it.index, ReadBook.durChapterPos)
readView.upContent()
}
observeEvent<Boolean>(EventBus.MEDIA_BUTTON) {
if (it) {
onClickReadAloud()
} else {
BookRead.readAloud(!BaseReadAloudService.pause)
ReadBook.readAloud(!BaseReadAloudService.pause)
}
}
observeEvent<Boolean>(EventBus.UP_CONFIG) {
@ -955,15 +971,15 @@ class ReadBookActivity : ReadBookBaseActivity(),
readView.upBg()
readView.upStyle()
if (it) {
BookRead.loadContent(resetPageOffset = false)
ReadBook.loadContent(resetPageOffset = false)
} else {
readView.upContent(resetPageOffset = false)
}
}
observeEvent<Int>(EventBus.ALOUD_STATE) {
if (it == Status.STOP || it == Status.PAUSE) {
BookRead.curTextChapter?.let { textChapter ->
val page = textChapter.getPageByReadPos(BookRead.durChapterPos)
ReadBook.curTextChapter?.let { textChapter ->
val page = textChapter.getPageByReadPos(ReadBook.durChapterPos)
if (page != null) {
page.removePageAloudSpan()
readView.upContent(resetPageOffset = false)
@ -974,9 +990,9 @@ class ReadBookActivity : ReadBookBaseActivity(),
observeEventSticky<Int>(EventBus.TTS_PROGRESS) { chapterStart ->
launch(IO) {
if (BaseReadAloudService.isPlay()) {
BookRead.curTextChapter?.let { textChapter ->
val aloudSpanStart = chapterStart - BookRead.durChapterPos
textChapter.getPageByReadPos(BookRead.durChapterPos)
ReadBook.curTextChapter?.let { textChapter ->
val aloudSpanStart = chapterStart - ReadBook.durChapterPos
textChapter.getPageByReadPos(ReadBook.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?) {
BookRead.msg = null
ReadBook.msg = null
setOrientation()
upLayoutInDisplayCutoutMode()
super.onCreate(savedInstanceState)
@ -186,7 +186,7 @@ abstract class ReadBookBaseActivity :
@SuppressLint("InflateParams")
fun showDownloadDialog() {
BookRead.book?.let { book ->
ReadBook.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(BookRead.book?.charset)
editView.setText(ReadBook.book?.charset)
}
customView { alertBinding.root }
okButton {
alertBinding.editView.text?.toString()?.let {
BookRead.setCharset(it)
ReadBook.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 ->
BookRead.book?.setPageAnim(i - 1)
ReadBook.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 {
BookRead.inBookshelf = intent.getBooleanExtra("inBookshelf", true)
ReadBook.inBookshelf = intent.getBooleanExtra("inBookshelf", true)
val bookUrl = intent.getStringExtra("bookUrl")
val book = when {
bookUrl.isNullOrEmpty() -> appDb.bookDao.lastReadBook
else -> appDb.bookDao.getBook(bookUrl)
} ?: BookRead.book
} ?: ReadBook.book
when {
book != null -> initBook(book)
else -> BookRead.upMsg(context.getString(R.string.no_book))
else -> ReadBook.upMsg(context.getString(R.string.no_book))
}
}.onFinally {
BookRead.saveRead()
ReadBook.saveRead()
}
}
private fun initBook(book: Book) {
if (BookRead.book?.bookUrl != book.bookUrl) {
BookRead.resetData(book)
if (ReadBook.book?.bookUrl != book.bookUrl) {
ReadBook.resetData(book)
isInitFinish = true
if (BookRead.chapterSize == 0) {
if (ReadBook.chapterSize == 0) {
if (book.tocUrl.isEmpty()) {
loadBookInfo(book)
} else {
loadChapterList(book)
}
} else {
if (BookRead.durChapterIndex > BookRead.chapterSize - 1) {
BookRead.durChapterIndex = BookRead.chapterSize - 1
if (ReadBook.durChapterIndex > ReadBook.chapterSize - 1) {
ReadBook.durChapterIndex = ReadBook.chapterSize - 1
}
BookRead.loadContent(resetPageOffset = true)
ReadBook.loadContent(resetPageOffset = true)
}
syncBookProgress(book)
} else {
BookRead.book = book
if (BookRead.durChapterIndex != book.durChapterIndex) {
BookRead.durChapterIndex = book.durChapterIndex
BookRead.durChapterPos = book.durChapterPos
BookRead.clearTextChapter()
}
BookRead.callBack?.upMenuView()
BookRead.upWebBook(book)
ReadBook.book = book
if (ReadBook.durChapterIndex != book.durChapterIndex) {
ReadBook.durChapterIndex = book.durChapterIndex
ReadBook.durChapterPos = book.durChapterPos
ReadBook.clearTextChapter()
}
ReadBook.callBack?.upMenuView()
ReadBook.upWebBook(book)
isInitFinish = true
BookRead.chapterSize = appDb.bookChapterDao.getChapterCount(book.bookUrl)
if (BookRead.chapterSize == 0) {
ReadBook.chapterSize = appDb.bookChapterDao.getChapterCount(book.bookUrl)
if (ReadBook.chapterSize == 0) {
if (book.tocUrl.isEmpty()) {
loadBookInfo(book)
} else {
loadChapterList(book)
}
} else {
if (BookRead.curTextChapter != null) {
BookRead.callBack?.upContent(resetPageOffset = false)
if (ReadBook.curTextChapter != null) {
ReadBook.callBack?.upContent(resetPageOffset = false)
} else {
BookRead.loadContent(resetPageOffset = true)
ReadBook.loadContent(resetPageOffset = true)
}
}
if (!BaseReadAloudService.isRun) {
syncBookProgress(book)
}
}
if (!book.isLocalBook() && BookRead.bookSource == null) {
if (!book.isLocalBook() && ReadBook.bookSource == null) {
autoChangeSource(book.name, book.author)
return
}
@ -102,12 +102,12 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
if (book.isLocalBook()) {
loadChapterList(book)
} else {
BookRead.bookSource?.let { source ->
ReadBook.bookSource?.let { source ->
WebBook.getBookInfo(viewModelScope, source, book, canReName = false)
.onSuccess {
loadChapterList(book)
}.onError {
BookRead.upMsg("详情页出错: ${it.localizedMessage}")
ReadBook.upMsg("详情页出错: ${it.localizedMessage}")
}
}
}
@ -120,24 +120,24 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
appDb.bookChapterDao.delByBook(book.bookUrl)
appDb.bookChapterDao.insert(*it.toTypedArray())
appDb.bookDao.update(book)
BookRead.chapterSize = it.size
BookRead.upMsg(null)
BookRead.loadContent(resetPageOffset = true)
ReadBook.chapterSize = it.size
ReadBook.upMsg(null)
ReadBook.loadContent(resetPageOffset = true)
}
}.onError {
BookRead.upMsg("LoadTocError:${it.localizedMessage}")
ReadBook.upMsg("LoadTocError:${it.localizedMessage}")
}
} else {
BookRead.bookSource?.let {
ReadBook.bookSource?.let {
WebBook.getChapterList(viewModelScope, it, book)
.onSuccess(IO) { cList ->
appDb.bookChapterDao.insert(*cList.toTypedArray())
appDb.bookDao.update(book)
BookRead.chapterSize = cList.size
BookRead.upMsg(null)
BookRead.loadContent(resetPageOffset = true)
ReadBook.chapterSize = cList.size
ReadBook.upMsg(null)
ReadBook.loadContent(resetPageOffset = true)
}.onError {
BookRead.upMsg(context.getString(R.string.error_load_toc))
ReadBook.upMsg(context.getString(R.string.error_load_toc))
}
}
}
@ -158,7 +158,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
) {
alertSync?.invoke(progress)
} else {
BookRead.setProgress(progress)
ReadBook.setProgress(progress)
}
}
}
@ -166,12 +166,12 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
fun changeTo(source: BookSource, book: Book) {
execute {
BookRead.upMsg(context.getString(R.string.loading))
ReadBook.upMsg(context.getString(R.string.loading))
if (book.tocUrl.isEmpty()) {
WebBook.getBookInfoAwait(this, source, book)
}
val chapters = WebBook.getChapterListAwait(this, source, book)
val oldBook = BookRead.book!!
val oldBook = ReadBook.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())
BookRead.resetData(book)
BookRead.upMsg(null)
BookRead.loadContent(resetPageOffset = true)
ReadBook.resetData(book)
ReadBook.upMsg(null)
ReadBook.loadContent(resetPageOffset = true)
}.timeout(60000)
.onError {
context.toastOnUi("换源失败\n${it.localizedMessage}")
BookRead.upMsg(null)
ReadBook.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(BookRead.book)
it.second.upInfoFromOld(ReadBook.book)
changeTo(it.first, it.second)
} ?: throw NoStackTraceException("自动换源失败")
}.onStart {
BookRead.upMsg(context.getString(R.string.source_auto_changing))
ReadBook.upMsg(context.getString(R.string.source_auto_changing))
}.onError {
context.toastOnUi(it.msg)
}.onFinally {
BookRead.upMsg(null)
ReadBook.upMsg(null)
}
}
fun openChapter(index: Int, durChapterPos: Int = 0, success: (() -> Unit)? = null) {
BookRead.clearTextChapter()
BookRead.callBack?.upContent()
if (index != BookRead.durChapterIndex) {
BookRead.durChapterIndex = index
BookRead.durChapterPos = durChapterPos
}
BookRead.saveRead()
BookRead.loadContent(resetPageOffset = true) {
ReadBook.clearTextChapter()
ReadBook.callBack?.upContent()
if (index != ReadBook.durChapterIndex) {
ReadBook.durChapterIndex = index
ReadBook.durChapterPos = durChapterPos
}
ReadBook.saveRead()
ReadBook.loadContent(resetPageOffset = true) {
success?.invoke()
}
}
fun removeFromBookshelf(success: (() -> Unit)?) {
execute {
Book.delete(BookRead.book)
Book.delete(ReadBook.book)
}.onSuccess {
success?.invoke()
}
@ -233,8 +233,8 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
fun upBookSource(success: (() -> Unit)?) {
execute {
BookRead.book?.let { book ->
BookRead.bookSource = appDb.bookSourceDao.getBookSource(book.origin)
ReadBook.book?.let { book ->
ReadBook.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, BookRead.durChapterIndex)
appDb.bookChapterDao.getChapter(book.bookUrl, ReadBook.durChapterIndex)
?.let { chapter ->
BookHelp.delContent(book, chapter)
BookRead.loadContent(BookRead.durChapterIndex, resetPageOffset = false)
ReadBook.loadContent(ReadBook.durChapterIndex, resetPageOffset = false)
}
}
}
fun reverseContent(book: Book) {
execute {
appDb.bookChapterDao.getChapter(book.bookUrl, BookRead.durChapterIndex)
appDb.bookChapterDao.getChapter(book.bookUrl, ReadBook.durChapterIndex)
?.let { chapter ->
BookHelp.reverseContent(book, chapter)
BookRead.loadContent(BookRead.durChapterIndex, resetPageOffset = false)
ReadBook.loadContent(ReadBook.durChapterIndex, resetPageOffset = false)
}
}
}
@ -328,16 +328,16 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
*/
fun replaceRuleChanged() {
execute {
BookRead.book?.let {
ReadBook.book?.let {
ContentProcessor.get(it.name, it.origin).upReplaceRules()
BookRead.loadContent(resetPageOffset = false)
ReadBook.loadContent(resetPageOffset = false)
}
}
}
fun disableSource() {
execute {
BookRead.bookSource?.let {
ReadBook.bookSource?.let {
it.enabled = false
appDb.bookSourceDao.update(it)
}

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

@ -11,8 +11,8 @@ import io.legado.app.databinding.DialogReadAloudBinding
import io.legado.app.help.AppConfig
import io.legado.app.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 { BookRead.moveToPrevChapter(upContent = true, toLast = false) }
tvNext.setOnClickListener { BookRead.moveToNextChapter(true) }
tvPre.setOnClickListener { ReadBook.moveToPrevChapter(upContent = true, toLast = false) }
tvNext.setOnClickListener { ReadBook.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.BookRead
import io.legado.app.model.ReadBook
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 ->
BookRead.book?.setPageAnim(-1)
ReadBook.book?.setPageAnim(-1)
ReadBookConfig.pageAnim = binding.rgPageAnim.getIndexById(checkedId)
callBack?.upPageAnim()
BookRead.loadContent(false)
ReadBook.loadContent(false)
}
cbShareLayout.onCheckedChangeListener = { _, isChecked ->
ReadBookConfig.shareLayout = isChecked
@ -177,7 +177,7 @@ class ReadStyleDialog : BaseDialogFragment(), FontSelectDialog.CallBack {
}
private fun upView() = binding.run {
BookRead.pageAnim().let {
ReadBook.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.BookRead
import io.legado.app.model.ReadBook
import io.legado.app.ui.book.read.PhotoDialog
import io.legado.app.ui.book.read.page.entities.TextChar
import io.legado.app.ui.book.read.page.entities.TextLine
@ -163,12 +163,12 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
lineBottom: Float,
isImageLine: Boolean
) {
val book = BookRead.book ?: return
val book = ReadBook.book ?: return
ImageProvider.getImage(
book,
textPage.chapterIndex,
textChar.charData,
BookRead.bookSource,
ReadBook.bookSource,
true
)?.let {
val rectF = if (isImageLine) {
@ -495,7 +495,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
fun createBookmark(): Bookmark? {
val page = relativePage(selectStart[0])
page.getTextChapter()?.let { chapter ->
BookRead.book?.let { book ->
ReadBook.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.BookRead
import io.legado.app.model.ReadBook
import io.legado.app.ui.book.read.page.entities.TextPage
import io.legado.app.ui.book.read.page.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 = BookRead.book?.name
tvBookName?.text = ReadBook.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 -> BookRead.moveToNextChapter(true)
4 -> BookRead.moveToPrevChapter(upContent = true, toLast = false)
3 -> ReadBook.moveToNextChapter(true)
4 -> ReadBook.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 = BookRead.pageAnim() == 3
isScroll = ReadBook.pageAnim() == 3
ChapterProvider.upLayout()
when (BookRead.pageAnim()) {
when (ReadBook.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) BookRead.textChapter(0) else null
return if (callBack.isInitFinish) ReadBook.textChapter(0) else null
}
override val nextChapter: TextChapter?
get() {
return if (callBack.isInitFinish) BookRead.textChapter(1) else null
return if (callBack.isInitFinish) ReadBook.textChapter(1) else null
}
override val prevChapter: TextChapter?
get() {
return if (callBack.isInitFinish) BookRead.textChapter(-1) else null
return if (callBack.isInitFinish) ReadBook.textChapter(-1) else null
}
override fun hasNextChapter(): Boolean {
return BookRead.durChapterIndex < BookRead.chapterSize - 1
return ReadBook.durChapterIndex < ReadBook.chapterSize - 1
}
override fun hasPrevChapter(): Boolean {
return BookRead.durChapterIndex > 0
return ReadBook.durChapterIndex > 0
}
interface CallBack {

@ -1,11 +1,11 @@
package io.legado.app.ui.book.read.page.api
import io.legado.app.model.BookRead
import io.legado.app.model.ReadBook
import io.legado.app.ui.book.read.page.entities.TextChapter
interface DataSource {
val pageIndex: Int get() = BookRead.durPageIndex()
val pageIndex: Int get() = ReadBook.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.BookRead
import io.legado.app.model.ReadBook
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? {
BookRead.curTextChapter?.let {
ReadBook.curTextChapter?.let {
if (it.position == chapterIndex) {
return it
}
}
BookRead.nextTextChapter?.let {
ReadBook.nextTextChapter?.let {
if (it.position == chapterIndex) {
return it
}
}
BookRead.prevTextChapter?.let {
ReadBook.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.BookRead
import io.legado.app.model.ReadBook
import io.legado.app.ui.book.read.page.entities.TextChapter
import io.legado.app.ui.book.read.page.entities.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, BookRead.bookSource)
ImageProvider.getImage(book, bookChapter.index, src, ReadBook.bookSource)
matcher.appendReplacement(sb, srcReplaceChar)
}
}
@ -208,7 +208,7 @@ object ChapterProvider {
imageStyle: String?,
): Float {
var durY = y
ImageProvider.getImage(book, chapter.index, src, BookRead.bookSource)?.let {
ImageProvider.getImage(book, chapter.index, src, ReadBook.bookSource)?.let {
if (durY > visibleHeight) {
textPages.last().height = durY
textPages.add(TextPage())
@ -586,7 +586,7 @@ object ChapterProvider {
*/
fun upLayout() {
doublePage = viewWidth > viewHeight
&& BookRead.pageAnim() != 3
&& ReadBook.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.BookRead
import io.legado.app.model.ReadBook
import io.legado.app.ui.book.read.page.api.DataSource
import io.legado.app.ui.book.read.page.api.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() {
BookRead.setPageIndex(0)
ReadBook.setPageIndex(0)
}
override fun moveToLast() = with(dataSource) {
currentChapter?.let {
if (it.pageSize == 0) {
BookRead.setPageIndex(0)
ReadBook.setPageIndex(0)
} else {
BookRead.setPageIndex(it.pageSize.minus(1))
ReadBook.setPageIndex(it.pageSize.minus(1))
}
} ?: BookRead.setPageIndex(0)
} ?: ReadBook.setPageIndex(0)
}
override fun moveToNext(upContent: Boolean): Boolean = with(dataSource) {
return if (hasNext()) {
if (currentChapter?.isLastIndex(pageIndex) == true) {
BookRead.moveToNextChapter(upContent)
ReadBook.moveToNextChapter(upContent)
} else {
BookRead.setPageIndex(pageIndex.plus(1))
ReadBook.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) {
BookRead.moveToPrevChapter(upContent)
ReadBook.moveToPrevChapter(upContent)
} else {
BookRead.setPageIndex(pageIndex.minus(1))
ReadBook.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) {
BookRead.msg?.let {
ReadBook.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) {
BookRead.msg?.let {
ReadBook.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) {
BookRead.msg?.let {
ReadBook.msg?.let {
return@with TextPage(text = it).format()
}
if (pageIndex > 0) {

Loading…
Cancel
Save