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