|
@@ -47,9 +47,9 @@ object ReadManga : CoroutineScope by MainScope() {
|
|
|
var chapterChanged = false
|
|
var chapterChanged = false
|
|
|
var book: Book? = null
|
|
var book: Book? = null
|
|
|
val executor = globalExecutor
|
|
val executor = globalExecutor
|
|
|
- var durChapterPagePos = 0 //章节位置
|
|
|
|
|
- var durChapterPageCount = 0//总章节
|
|
|
|
|
- var durChapterCount = 0
|
|
|
|
|
|
|
+ var durChapterIndex = 0 //章节位置
|
|
|
|
|
+ var chapterSize = 0//总章节
|
|
|
|
|
+ var durChapterImageCount = 0
|
|
|
var durChapterPos = 0
|
|
var durChapterPos = 0
|
|
|
var bookSource: BookSource? = null
|
|
var bookSource: BookSource? = null
|
|
|
var chapterTitle: String = ""
|
|
var chapterTitle: String = ""
|
|
@@ -65,7 +65,6 @@ object ReadManga : CoroutineScope by MainScope() {
|
|
|
val downloadedChapters = hashSetOf<Int>()
|
|
val downloadedChapters = hashSetOf<Int>()
|
|
|
val downloadFailChapters = hashMapOf<Int, Int>()
|
|
val downloadFailChapters = hashMapOf<Int, Int>()
|
|
|
private val downloadLoadingChapters = arrayListOf<Int>()
|
|
private val downloadLoadingChapters = arrayListOf<Int>()
|
|
|
- var isMangaMode = false
|
|
|
|
|
val downloadScope = CoroutineScope(SupervisorJob() + IO)
|
|
val downloadScope = CoroutineScope(SupervisorJob() + IO)
|
|
|
var rateLimiter = ConcurrentRateLimiter(null)
|
|
var rateLimiter = ConcurrentRateLimiter(null)
|
|
|
|
|
|
|
@@ -74,11 +73,11 @@ object ReadManga : CoroutineScope by MainScope() {
|
|
|
val book = book ?: return@execute
|
|
val book = book ?: return@execute
|
|
|
book.lastCheckCount = 0
|
|
book.lastCheckCount = 0
|
|
|
book.durChapterTime = System.currentTimeMillis()
|
|
book.durChapterTime = System.currentTimeMillis()
|
|
|
- val changed = book.durChapterIndex != durChapterPagePos
|
|
|
|
|
- book.durChapterIndex = durChapterPagePos
|
|
|
|
|
|
|
+ val changed = book.durChapterIndex != durChapterIndex
|
|
|
|
|
+ book.durChapterIndex = durChapterIndex
|
|
|
book.durChapterPos = durChapterPos
|
|
book.durChapterPos = durChapterPos
|
|
|
if (!pageChanged || changed) {
|
|
if (!pageChanged || changed) {
|
|
|
- appDb.bookChapterDao.getChapter(book.bookUrl, durChapterPagePos)?.let {
|
|
|
|
|
|
|
+ appDb.bookChapterDao.getChapter(book.bookUrl, durChapterIndex)?.let {
|
|
|
book.durChapterTitle = it.getDisplayTitle(
|
|
book.durChapterTitle = it.getDisplayTitle(
|
|
|
ContentProcessor.get(book.name, book.origin).getTitleReplaceRules(),
|
|
ContentProcessor.get(book.name, book.origin).getTitleReplaceRules(),
|
|
|
book.getUseReplaceRule()
|
|
book.getUseReplaceRule()
|
|
@@ -91,16 +90,15 @@ object ReadManga : CoroutineScope by MainScope() {
|
|
|
|
|
|
|
|
fun upData(book: Book) {
|
|
fun upData(book: Book) {
|
|
|
ReadManga.book = book
|
|
ReadManga.book = book
|
|
|
- isMangaMode = true
|
|
|
|
|
- durChapterPageCount = appDb.bookChapterDao.getChapterCount(book.bookUrl)
|
|
|
|
|
|
|
+ chapterSize = appDb.bookChapterDao.getChapterCount(book.bookUrl)
|
|
|
simulatedChapterSize = if (book.readSimulating()) {
|
|
simulatedChapterSize = if (book.readSimulating()) {
|
|
|
book.simulatedTotalChapterNum()
|
|
book.simulatedTotalChapterNum()
|
|
|
} else {
|
|
} else {
|
|
|
- durChapterPageCount
|
|
|
|
|
|
|
+ chapterSize
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (durChapterPagePos != book.durChapterIndex || tocChanged) {
|
|
|
|
|
- durChapterPagePos = book.durChapterIndex
|
|
|
|
|
|
|
+ if (durChapterIndex != book.durChapterIndex || tocChanged) {
|
|
|
|
|
+ durChapterIndex = book.durChapterIndex
|
|
|
durChapterPos = book.durChapterPos
|
|
durChapterPos = book.durChapterPos
|
|
|
}
|
|
}
|
|
|
upWebBook(book)
|
|
upWebBook(book)
|
|
@@ -111,16 +109,15 @@ object ReadManga : CoroutineScope by MainScope() {
|
|
|
|
|
|
|
|
fun resetData(book: Book) {
|
|
fun resetData(book: Book) {
|
|
|
ReadManga.book = book
|
|
ReadManga.book = book
|
|
|
- isMangaMode = true
|
|
|
|
|
readRecord.bookName = book.name
|
|
readRecord.bookName = book.name
|
|
|
readRecord.readTime = appDb.readRecordDao.getReadTime(book.name) ?: 0
|
|
readRecord.readTime = appDb.readRecordDao.getReadTime(book.name) ?: 0
|
|
|
- durChapterPageCount = appDb.bookChapterDao.getChapterCount(book.bookUrl)
|
|
|
|
|
|
|
+ chapterSize = appDb.bookChapterDao.getChapterCount(book.bookUrl)
|
|
|
simulatedChapterSize = if (book.readSimulating()) {
|
|
simulatedChapterSize = if (book.readSimulating()) {
|
|
|
book.simulatedTotalChapterNum()
|
|
book.simulatedTotalChapterNum()
|
|
|
} else {
|
|
} else {
|
|
|
- durChapterPageCount
|
|
|
|
|
|
|
+ chapterSize
|
|
|
}
|
|
}
|
|
|
- durChapterPagePos = book.durChapterIndex
|
|
|
|
|
|
|
+ durChapterIndex = book.durChapterIndex
|
|
|
durChapterPos = book.durChapterPos
|
|
durChapterPos = book.durChapterPos
|
|
|
upWebBook(book)
|
|
upWebBook(book)
|
|
|
synchronized(this) {
|
|
synchronized(this) {
|
|
@@ -203,7 +200,7 @@ object ReadManga : CoroutineScope by MainScope() {
|
|
|
|
|
|
|
|
|
|
|
|
|
fun loadContent() {
|
|
fun loadContent() {
|
|
|
- loadContent(durChapterPagePos)
|
|
|
|
|
|
|
+ loadContent(durChapterIndex)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
fun loadContent(
|
|
fun loadContent(
|
|
@@ -245,11 +242,10 @@ object ReadManga : CoroutineScope by MainScope() {
|
|
|
tocChanged = false
|
|
tocChanged = false
|
|
|
chapterChanged = false
|
|
chapterChanged = false
|
|
|
book = null
|
|
book = null
|
|
|
- durChapterPagePos = 0
|
|
|
|
|
- isMangaMode = false
|
|
|
|
|
- durChapterPageCount = 0
|
|
|
|
|
|
|
+ durChapterIndex = 0
|
|
|
|
|
+ chapterSize = 0
|
|
|
durChapterPos = 0
|
|
durChapterPos = 0
|
|
|
- durChapterCount = 0
|
|
|
|
|
|
|
+ durChapterImageCount = 0
|
|
|
bookSource = null
|
|
bookSource = null
|
|
|
chapterTitle = ""
|
|
chapterTitle = ""
|
|
|
loadingChapters.clear()
|
|
loadingChapters.clear()
|
|
@@ -282,7 +278,7 @@ object ReadManga : CoroutineScope by MainScope() {
|
|
|
}
|
|
}
|
|
|
mTopChapter = chapter
|
|
mTopChapter = chapter
|
|
|
chapterTitle = chapter.title
|
|
chapterTitle = chapter.title
|
|
|
- if (chapter.index !in durChapterPagePos - 1..durChapterPagePos + 1) {
|
|
|
|
|
|
|
+ if (chapter.index !in durChapterIndex - 1..durChapterIndex + 1) {
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
if (content.isNotEmpty()) {
|
|
if (content.isNotEmpty()) {
|
|
@@ -295,9 +291,9 @@ object ReadManga : CoroutineScope by MainScope() {
|
|
|
}
|
|
}
|
|
|
}.distinctUntilChanged().mapIndexed { index, src ->
|
|
}.distinctUntilChanged().mapIndexed { index, src ->
|
|
|
MangaContent(
|
|
MangaContent(
|
|
|
- mChapterPageCount = durChapterPageCount,
|
|
|
|
|
- mChapterPagePos = durChapterPagePos.plus(1),
|
|
|
|
|
- mChapterNextPagePos = durChapterPagePos.plus(1),
|
|
|
|
|
|
|
+ chapterSize = chapterSize,
|
|
|
|
|
+ mChapterIndex = durChapterIndex.plus(1),
|
|
|
|
|
+ nextChapterIndex = durChapterIndex.plus(1),
|
|
|
mImageUrl = src,
|
|
mImageUrl = src,
|
|
|
mDurChapterPos = index.plus(1),
|
|
mDurChapterPos = index.plus(1),
|
|
|
mChapterName = chapterTitle
|
|
mChapterName = chapterTitle
|
|
@@ -306,22 +302,22 @@ object ReadManga : CoroutineScope by MainScope() {
|
|
|
this.forEach {
|
|
this.forEach {
|
|
|
it.mDurChapterCount = this.size
|
|
it.mDurChapterCount = this.size
|
|
|
}
|
|
}
|
|
|
- durChapterCount = this.size
|
|
|
|
|
|
|
+ durChapterImageCount = this.size
|
|
|
}
|
|
}
|
|
|
val contentList = mutableListOf<Any>()
|
|
val contentList = mutableListOf<Any>()
|
|
|
contentList.add(
|
|
contentList.add(
|
|
|
ReaderLoading(
|
|
ReaderLoading(
|
|
|
- durChapterPagePos,
|
|
|
|
|
|
|
+ durChapterIndex,
|
|
|
"阅读 ${chapter.title}",
|
|
"阅读 ${chapter.title}",
|
|
|
- mNextChapterIndex = durChapterPagePos.plus(1)
|
|
|
|
|
|
|
+ mNextChapterIndex = durChapterIndex.plus(1)
|
|
|
)
|
|
)
|
|
|
)
|
|
)
|
|
|
contentList.addAll(list)
|
|
contentList.addAll(list)
|
|
|
contentList.add(
|
|
contentList.add(
|
|
|
ReaderLoading(
|
|
ReaderLoading(
|
|
|
- durChapterPagePos,
|
|
|
|
|
|
|
+ durChapterIndex,
|
|
|
"已读完 ${chapter.title}",
|
|
"已读完 ${chapter.title}",
|
|
|
- mNextChapterIndex = durChapterPagePos.plus(1)
|
|
|
|
|
|
|
+ mNextChapterIndex = durChapterIndex.plus(1)
|
|
|
)
|
|
)
|
|
|
)
|
|
)
|
|
|
runOnUI {
|
|
runOnUI {
|
|
@@ -339,15 +335,15 @@ object ReadManga : CoroutineScope by MainScope() {
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (index > durChapterPageCount - 1) {
|
|
|
|
|
|
|
+ if (index > chapterSize - 1) {
|
|
|
upToc(index)
|
|
upToc(index)
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
- if (durChapterPagePos < simulatedChapterSize - 1) {
|
|
|
|
|
|
|
+ if (durChapterIndex < simulatedChapterSize - 1) {
|
|
|
durChapterPos = 0
|
|
durChapterPos = 0
|
|
|
- durChapterPagePos = index
|
|
|
|
|
|
|
+ durChapterIndex = index
|
|
|
saveRead()
|
|
saveRead()
|
|
|
- loadContent(durChapterPagePos)
|
|
|
|
|
|
|
+ loadContent(durChapterIndex)
|
|
|
AppLog.putDebug("moveToNextChapter-curPageChanged()")
|
|
AppLog.putDebug("moveToNextChapter-curPageChanged()")
|
|
|
curPageChanged()
|
|
curPageChanged()
|
|
|
} else {
|
|
} else {
|
|
@@ -374,18 +370,18 @@ object ReadManga : CoroutineScope by MainScope() {
|
|
|
book.lastCheckTime = System.currentTimeMillis()
|
|
book.lastCheckTime = System.currentTimeMillis()
|
|
|
WebBook.getChapterList(this, bookSource, book).onSuccess(IO) { cList ->
|
|
WebBook.getChapterList(this, bookSource, book).onSuccess(IO) { cList ->
|
|
|
if (book.bookUrl == ReadManga.book?.bookUrl
|
|
if (book.bookUrl == ReadManga.book?.bookUrl
|
|
|
- && cList.size > durChapterPageCount
|
|
|
|
|
|
|
+ && cList.size > chapterSize
|
|
|
) {
|
|
) {
|
|
|
appDb.bookChapterDao.delByBook(book.bookUrl)
|
|
appDb.bookChapterDao.delByBook(book.bookUrl)
|
|
|
appDb.bookChapterDao.insert(*cList.toTypedArray())
|
|
appDb.bookChapterDao.insert(*cList.toTypedArray())
|
|
|
saveRead()
|
|
saveRead()
|
|
|
durChapterPos = 0
|
|
durChapterPos = 0
|
|
|
- durChapterPagePos = index
|
|
|
|
|
- durChapterPageCount = cList.size
|
|
|
|
|
|
|
+ durChapterIndex = index
|
|
|
|
|
+ chapterSize = cList.size
|
|
|
simulatedChapterSize = book.simulatedTotalChapterNum()
|
|
simulatedChapterSize = book.simulatedTotalChapterNum()
|
|
|
- loadContent(durChapterPagePos)
|
|
|
|
|
|
|
+ loadContent(durChapterIndex)
|
|
|
} else {
|
|
} else {
|
|
|
- durChapterPagePos = durChapterPagePos.minus(1)
|
|
|
|
|
|
|
+ durChapterIndex = durChapterIndex.minus(1)
|
|
|
saveRead()
|
|
saveRead()
|
|
|
gameOver = true
|
|
gameOver = true
|
|
|
runOnUI {
|
|
runOnUI {
|
|
@@ -409,7 +405,7 @@ object ReadManga : CoroutineScope by MainScope() {
|
|
|
runOnUI {
|
|
runOnUI {
|
|
|
mCallback?.loadComplete()
|
|
mCallback?.loadComplete()
|
|
|
}
|
|
}
|
|
|
- if (durChapterPagePos >= durChapterPageCount.minus(1)) {
|
|
|
|
|
|
|
+ if (durChapterIndex >= chapterSize.minus(1)) {
|
|
|
gameOver = true
|
|
gameOver = true
|
|
|
runOnUI {
|
|
runOnUI {
|
|
|
mCallback?.noData()
|
|
mCallback?.noData()
|
|
@@ -475,16 +471,16 @@ object ReadManga : CoroutineScope by MainScope() {
|
|
|
//预下载
|
|
//预下载
|
|
|
launch {
|
|
launch {
|
|
|
val maxChapterIndex =
|
|
val maxChapterIndex =
|
|
|
- min(durChapterPagePos + AppConfig.preDownloadNum, durChapterPageCount)
|
|
|
|
|
- for (i in durChapterPagePos.plus(2)..maxChapterIndex) {
|
|
|
|
|
|
|
+ min(durChapterIndex + AppConfig.preDownloadNum, chapterSize)
|
|
|
|
|
+ for (i in durChapterIndex.plus(2)..maxChapterIndex) {
|
|
|
if (downloadedChapters.contains(i)) continue
|
|
if (downloadedChapters.contains(i)) continue
|
|
|
if ((downloadFailChapters[i] ?: 0) >= 3) continue
|
|
if ((downloadFailChapters[i] ?: 0) >= 3) continue
|
|
|
downloadIndex(i)
|
|
downloadIndex(i)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
launch {
|
|
launch {
|
|
|
- val minChapterIndex = durChapterPagePos - min(5, AppConfig.preDownloadNum)
|
|
|
|
|
- for (i in durChapterPagePos.minus(2) downTo minChapterIndex) {
|
|
|
|
|
|
|
+ val minChapterIndex = durChapterIndex - min(5, AppConfig.preDownloadNum)
|
|
|
|
|
+ for (i in durChapterIndex.minus(2) downTo minChapterIndex) {
|
|
|
if (downloadedChapters.contains(i)) continue
|
|
if (downloadedChapters.contains(i)) continue
|
|
|
if ((downloadFailChapters[i] ?: 0) >= 3) continue
|
|
if ((downloadFailChapters[i] ?: 0) >= 3) continue
|
|
|
downloadIndex(i)
|
|
downloadIndex(i)
|
|
@@ -496,7 +492,7 @@ object ReadManga : CoroutineScope by MainScope() {
|
|
|
|
|
|
|
|
private suspend fun downloadIndex(index: Int) {
|
|
private suspend fun downloadIndex(index: Int) {
|
|
|
if (index < 0) return
|
|
if (index < 0) return
|
|
|
- if (index > durChapterPageCount - 1) {
|
|
|
|
|
|
|
+ if (index > chapterSize - 1) {
|
|
|
upToc()
|
|
upToc()
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
@@ -540,12 +536,12 @@ object ReadManga : CoroutineScope by MainScope() {
|
|
|
book.lastCheckTime = System.currentTimeMillis()
|
|
book.lastCheckTime = System.currentTimeMillis()
|
|
|
WebBook.getChapterList(this, bookSource, book).onSuccess(IO) { cList ->
|
|
WebBook.getChapterList(this, bookSource, book).onSuccess(IO) { cList ->
|
|
|
if (book.bookUrl == ReadManga.book?.bookUrl
|
|
if (book.bookUrl == ReadManga.book?.bookUrl
|
|
|
- && cList.size > durChapterPageCount
|
|
|
|
|
|
|
+ && cList.size > chapterSize
|
|
|
) {
|
|
) {
|
|
|
appDb.bookChapterDao.delByBook(book.bookUrl)
|
|
appDb.bookChapterDao.delByBook(book.bookUrl)
|
|
|
appDb.bookChapterDao.insert(*cList.toTypedArray())
|
|
appDb.bookChapterDao.insert(*cList.toTypedArray())
|
|
|
saveRead()
|
|
saveRead()
|
|
|
- durChapterPageCount = cList.size
|
|
|
|
|
|
|
+ chapterSize = cList.size
|
|
|
simulatedChapterSize = book.simulatedTotalChapterNum()
|
|
simulatedChapterSize = book.simulatedTotalChapterNum()
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -601,23 +597,23 @@ object ReadManga : CoroutineScope by MainScope() {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
fun setProgress(progress: BookProgress) {
|
|
fun setProgress(progress: BookProgress) {
|
|
|
- if (progress.durChapterIndex < durChapterPageCount &&
|
|
|
|
|
- (durChapterPagePos != progress.durChapterIndex
|
|
|
|
|
|
|
+ if (progress.durChapterIndex < chapterSize &&
|
|
|
|
|
+ (durChapterIndex != progress.durChapterIndex
|
|
|
|| durChapterPos != progress.durChapterPos)
|
|
|| durChapterPos != progress.durChapterPos)
|
|
|
) {
|
|
) {
|
|
|
chapterChanged = true
|
|
chapterChanged = true
|
|
|
- if (progress.durChapterIndex == durChapterPagePos) {
|
|
|
|
|
|
|
+ if (progress.durChapterIndex == durChapterIndex) {
|
|
|
durChapterPos = progress.durChapterPos
|
|
durChapterPos = progress.durChapterPos
|
|
|
mCallback?.adjustmentProgress()
|
|
mCallback?.adjustmentProgress()
|
|
|
} else {
|
|
} else {
|
|
|
- durChapterPagePos = progress.durChapterIndex
|
|
|
|
|
|
|
+ durChapterIndex = progress.durChapterIndex
|
|
|
durChapterPos = progress.durChapterPos
|
|
durChapterPos = progress.durChapterPos
|
|
|
- if (addLoading(durChapterPagePos)) {
|
|
|
|
|
- loadContent(durChapterPagePos)
|
|
|
|
|
|
|
+ if (addLoading(durChapterIndex)) {
|
|
|
|
|
+ loadContent(durChapterIndex)
|
|
|
} else {
|
|
} else {
|
|
|
Coroutine.async {
|
|
Coroutine.async {
|
|
|
val book = book!!
|
|
val book = book!!
|
|
|
- appDb.bookChapterDao.getChapter(book.bookUrl, durChapterPagePos)
|
|
|
|
|
|
|
+ appDb.bookChapterDao.getChapter(book.bookUrl, durChapterIndex)
|
|
|
?.let { chapter ->
|
|
?.let { chapter ->
|
|
|
getContent(
|
|
getContent(
|
|
|
downloadScope,
|
|
downloadScope,
|