mirror of
https://github.com/gedoor/legado.git
synced 2025-08-10 00:52:30 +00:00
fix: 使用原来的模拟追读逻辑
This commit is contained in:
@@ -165,16 +165,16 @@ data class Book(
|
||||
if (config.readSimulating) {
|
||||
val currentDate = LocalDate.now()
|
||||
val daysPassed = between(this.config.startDate, currentDate).days + 1
|
||||
|
||||
// 计算当前应该解锁到哪一章
|
||||
val chaptersToUnlock = (config.startChapter ?: 0) + (daysPassed * config.dailyChapters)
|
||||
return chaptersToUnlock
|
||||
val chaptersToUnlock =
|
||||
max(0, (config.startChapter ?: 0) + (daysPassed * config.dailyChapters))
|
||||
return min(this.totalChapterNum, chaptersToUnlock)
|
||||
} else return this.totalChapterNum
|
||||
}
|
||||
|
||||
fun getRealAuthor() = author.replace(AppPattern.authorRegex, "")
|
||||
|
||||
fun getUnreadChapterNum() = max(totalChapterNum - durChapterIndex - 1, 0)
|
||||
fun getUnreadChapterNum() = max(simulatedTotalChapterNum() - durChapterIndex - 1, 0)
|
||||
|
||||
fun getDisplayCover() = if (customCoverUrl.isNullOrEmpty()) coverUrl else customCoverUrl
|
||||
|
||||
|
||||
@@ -165,7 +165,7 @@ object AudioPlay {
|
||||
|
||||
fun next(context: Context) {
|
||||
book?.let { book ->
|
||||
if (book.durChapterIndex + 1 < book.totalChapterNum) {
|
||||
if (book.durChapterIndex + 1 < book.simulatedTotalChapterNum()) {
|
||||
book.durChapterIndex += 1
|
||||
book.durChapterPos = 0
|
||||
durChapterIndex = book.durChapterIndex
|
||||
|
||||
@@ -229,7 +229,7 @@ object ReadBook : CoroutineScope by MainScope() {
|
||||
}
|
||||
|
||||
fun moveToNextChapter(upContent: Boolean, upContentInPlace: Boolean = true): Boolean {
|
||||
if (durChapterIndex < chapterSize - 1) {
|
||||
if (durChapterIndex < (book?.simulatedTotalChapterNum()?: chapterSize) - 1) {
|
||||
durChapterPos = 0
|
||||
durChapterIndex++
|
||||
prevTextChapter?.cancelLayout()
|
||||
|
||||
@@ -119,12 +119,10 @@ object BookChapterList {
|
||||
coroutineContext.ensureActive()
|
||||
//去重
|
||||
val lh = LinkedHashSet(chapterList)
|
||||
val fullList = ArrayList(lh)
|
||||
val list = ArrayList(lh)
|
||||
if (!book.getReverseToc()) {
|
||||
fullList.reverse()
|
||||
list.reverse()
|
||||
}
|
||||
val list =
|
||||
if (book.getReadSimulating()) fullList.take(book.simulatedTotalChapterNum()) else fullList
|
||||
Debug.log(book.origin, "◇目录总数:${list.size}")
|
||||
coroutineContext.ensureActive()
|
||||
val formatJs = tocRule.formatJs
|
||||
@@ -147,7 +145,8 @@ object BookChapterList {
|
||||
}
|
||||
val replaceRules = ContentProcessor.get(book.name, book.origin).getTitleReplaceRules()
|
||||
book.latestChapterTitle =
|
||||
list.last().getDisplayTitle(replaceRules, book.getUseReplaceRule())
|
||||
list.getOrElse(book.simulatedTotalChapterNum() - 1) {
|
||||
list.last() }.getDisplayTitle(replaceRules, book.getUseReplaceRule())
|
||||
book.durChapterTitle = list.getOrElse(book.durChapterIndex) { list.last() }
|
||||
.getDisplayTitle(replaceRules, book.getUseReplaceRule())
|
||||
if (book.totalChapterNum < list.size) {
|
||||
|
||||
@@ -116,12 +116,14 @@ class AudioPlayActivity :
|
||||
R.id.menu_change_source -> AudioPlay.book?.let {
|
||||
showDialogFragment(ChangeBookSourceDialog(it.name, it.author))
|
||||
}
|
||||
|
||||
R.id.menu_login -> AudioPlay.bookSource?.let {
|
||||
startActivity<SourceLoginActivity> {
|
||||
putExtra("type", "bookSource")
|
||||
putExtra("key", it.bookSourceUrl)
|
||||
}
|
||||
}
|
||||
|
||||
R.id.menu_wake_lock -> AppConfig.audioPlayUseWakeLock = !AppConfig.audioPlayUseWakeLock
|
||||
R.id.menu_copy_audio_url -> sendToClip(AudioPlayService.url)
|
||||
R.id.menu_edit_source -> AudioPlay.bookSource?.let {
|
||||
@@ -129,6 +131,7 @@ class AudioPlayActivity :
|
||||
putExtra("sourceUrl", it.bookSourceUrl)
|
||||
}
|
||||
}
|
||||
|
||||
R.id.menu_log -> showDialogFragment<AppLogDialog>()
|
||||
}
|
||||
return super.onCompatOptionsItemSelected(item)
|
||||
@@ -266,7 +269,8 @@ class AudioPlayActivity :
|
||||
binding.tvSubTitle.text = it
|
||||
AudioPlay.book?.let { book ->
|
||||
binding.ivSkipPrevious.isEnabled = book.durChapterIndex > 0
|
||||
binding.ivSkipNext.isEnabled = book.durChapterIndex < book.totalChapterNum - 1
|
||||
binding.ivSkipNext.isEnabled =
|
||||
book.durChapterIndex < book.simulatedTotalChapterNum() - 1
|
||||
}
|
||||
}
|
||||
observeEventSticky<Int>(EventBus.AUDIO_SIZE) {
|
||||
|
||||
@@ -251,7 +251,7 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
|
||||
appDb.bookChapterDao.insert(*it.toTypedArray())
|
||||
if (book.isSameNameAuthor(ReadBook.book)) {
|
||||
ReadBook.book = book
|
||||
ReadBook.chapterSize = book.totalChapterNum
|
||||
ReadBook.chapterSize = book.simulatedTotalChapterNum()
|
||||
}
|
||||
}
|
||||
bookData.postValue(book)
|
||||
|
||||
@@ -409,4 +409,4 @@ abstract class BaseReadBookActivity :
|
||||
val nextKeysStr = getPrefString(PreferKey.nextKeys)
|
||||
return nextKeysStr?.split(",")?.contains(keyCode.toString()) ?: false
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -229,6 +229,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
|
||||
AppLog.put("拉取阅读进度失败《${book.name}》\n${it.localizedMessage}", it)
|
||||
}.onSuccess { progress ->
|
||||
if (progress.durChapterIndex < book.durChapterIndex ||
|
||||
progress.durChapterIndex >= book.simulatedTotalChapterNum() ||
|
||||
(progress.durChapterIndex == book.durChapterIndex
|
||||
&& progress.durChapterPos < book.durChapterPos)
|
||||
) {
|
||||
|
||||
@@ -708,7 +708,8 @@ class ReadView(context: Context, attrs: AttributeSet) :
|
||||
}
|
||||
|
||||
override fun hasNextChapter(): Boolean {
|
||||
return ReadBook.durChapterIndex < ReadBook.chapterSize - 1
|
||||
return ReadBook.durChapterIndex < ((ReadBook.book?.simulatedTotalChapterNum()
|
||||
?: ReadBook.chapterSize) - 1)
|
||||
}
|
||||
|
||||
override fun hasPrevChapter(): Boolean {
|
||||
|
||||
@@ -118,7 +118,10 @@ class ChapterListFragment : VMBaseFragment<TocViewModel>(R.layout.fragment_chapt
|
||||
lifecycleScope.launch {
|
||||
withContext(IO) {
|
||||
when {
|
||||
searchKey.isNullOrBlank() -> appDb.bookChapterDao.getChapterList(viewModel.bookUrl)
|
||||
searchKey.isNullOrBlank() -> appDb.bookChapterDao.getChapterList(
|
||||
viewModel.bookUrl
|
||||
).take(book?.simulatedTotalChapterNum() ?: Int.MAX_VALUE)
|
||||
|
||||
else -> appDb.bookChapterDao.search(viewModel.bookUrl, searchKey)
|
||||
}
|
||||
}.let {
|
||||
@@ -163,9 +166,10 @@ class ChapterListFragment : VMBaseFragment<TocViewModel>(R.layout.fragment_chapt
|
||||
|
||||
override fun openChapter(bookChapter: BookChapter) {
|
||||
activity?.run {
|
||||
setResult(RESULT_OK, Intent()
|
||||
.putExtra("index", bookChapter.index)
|
||||
.putExtra("chapterChanged", bookChapter.index != durChapterIndex)
|
||||
setResult(
|
||||
RESULT_OK, Intent()
|
||||
.putExtra("index", bookChapter.index)
|
||||
.putExtra("chapterChanged", bookChapter.index != durChapterIndex)
|
||||
)
|
||||
finish()
|
||||
}
|
||||
|
||||
@@ -192,7 +192,7 @@ class TocActivity : VMBaseActivity<ActivityChapterListBinding, TocViewModel>(),
|
||||
ReadBook.book?.let { readBook ->
|
||||
if (readBook == book) {
|
||||
ReadBook.book = book
|
||||
ReadBook.chapterSize = book.totalChapterNum
|
||||
ReadBook.chapterSize = book.simulatedTotalChapterNum()
|
||||
ReadBook.upMsg(null)
|
||||
ReadBook.loadContent(resetPageOffset = true)
|
||||
}
|
||||
|
||||
@@ -163,7 +163,7 @@ class MainViewModel(application: Application) : BaseViewModel(application) {
|
||||
appDb.bookChapterDao.insert(*toc.toTypedArray())
|
||||
if (book.isSameNameAuthor(ReadBook.book)) {
|
||||
ReadBook.book = book
|
||||
ReadBook.chapterSize = book.totalChapterNum
|
||||
ReadBook.chapterSize = book.simulatedTotalChapterNum()
|
||||
}
|
||||
addDownload(source, book)
|
||||
}.onFailure {
|
||||
|
||||
Reference in New Issue
Block a user