优化
This commit is contained in:
@@ -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 durChapterIndex = 0 //章节位置
|
||||||
var durChapterPageCount = 0//总章节
|
var chapterSize = 0//总章节
|
||||||
var durChapterCount = 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
|
val changed = book.durChapterIndex != durChapterIndex
|
||||||
book.durChapterIndex = durChapterPagePos
|
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
|
chapterSize = appDb.bookChapterDao.getChapterCount(book.bookUrl)
|
||||||
durChapterPageCount = 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) {
|
if (durChapterIndex != book.durChapterIndex || tocChanged) {
|
||||||
durChapterPagePos = book.durChapterIndex
|
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
|
durChapterIndex = 0
|
||||||
isMangaMode = false
|
chapterSize = 0
|
||||||
durChapterPageCount = 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,
|
chapterSize = chapterSize,
|
||||||
mChapterPagePos = durChapterPagePos.plus(1),
|
mChapterIndex = durChapterIndex.plus(1),
|
||||||
mChapterNextPagePos = durChapterPagePos.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
|
durChapterIndex = index
|
||||||
durChapterPageCount = cList.size
|
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)
|
min(durChapterIndex + AppConfig.preDownloadNum, chapterSize)
|
||||||
for (i in durChapterPagePos.plus(2)..maxChapterIndex) {
|
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)
|
val minChapterIndex = durChapterIndex - min(5, AppConfig.preDownloadNum)
|
||||||
for (i in durChapterPagePos.minus(2) downTo minChapterIndex) {
|
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 &&
|
if (progress.durChapterIndex < chapterSize &&
|
||||||
(durChapterPagePos != progress.durChapterIndex
|
(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)) {
|
if (addLoading(durChapterIndex)) {
|
||||||
loadContent(durChapterPagePos)
|
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,
|
||||||
|
|||||||
@@ -2,9 +2,9 @@ package io.legado.app.model.recyclerView
|
|||||||
|
|
||||||
|
|
||||||
data class MangaContent(
|
data class MangaContent(
|
||||||
var mChapterPagePos: Int = 0,//总章节位置
|
var mChapterIndex: Int = 0,//总章节位置
|
||||||
var mChapterPageCount: Int,//总章节数量
|
var chapterSize: Int,//总章节数量
|
||||||
var mChapterNextPagePos: Int = 0,//下一章
|
var nextChapterIndex: Int = 0,//下一章
|
||||||
val mImageUrl: String = "",//当前URL
|
val mImageUrl: String = "",//当前URL
|
||||||
var mDurChapterPos: Int = 0,//当前章节位置
|
var mDurChapterPos: Int = 0,//当前章节位置
|
||||||
var mDurChapterCount: Int = 0,//当前章节内容总数
|
var mDurChapterCount: Int = 0,//当前章节内容总数
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package io.legado.app.model.recyclerView
|
package io.legado.app.model.recyclerView
|
||||||
|
|
||||||
data class ReaderLoading(
|
data class ReaderLoading(
|
||||||
val mChapterPagePos: Int = 0,
|
val mChapterIndex: Int = 0,
|
||||||
val mMessage: String? = null,
|
val mMessage: String? = null,
|
||||||
val mNextChapterIndex: Int = 0,
|
val mNextChapterIndex: Int = 0,
|
||||||
var mLoading: Boolean = false,
|
var mLoading: Boolean = false,
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ class MangaViewModel(application: Application) : BaseViewModel(application) {
|
|||||||
else -> appDb.bookDao.getBook(bookUrl)
|
else -> appDb.bookDao.getBook(bookUrl)
|
||||||
} ?: ReadManga.book
|
} ?: ReadManga.book
|
||||||
when {
|
when {
|
||||||
book != null -> initMange(book)
|
book != null -> initManga(book)
|
||||||
else -> context.getString(R.string.no_book)//没有找到书
|
else -> context.getString(R.string.no_book)//没有找到书
|
||||||
}
|
}
|
||||||
}.onSuccess {
|
}.onSuccess {
|
||||||
@@ -63,7 +63,7 @@ class MangaViewModel(application: Application) : BaseViewModel(application) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun initMange(book: Book) {
|
private suspend fun initManga(book: Book) {
|
||||||
val isSameBook = ReadManga.book?.bookUrl == book.bookUrl
|
val isSameBook = ReadManga.book?.bookUrl == book.bookUrl
|
||||||
if (isSameBook) {
|
if (isSameBook) {
|
||||||
ReadManga.upData(book)
|
ReadManga.upData(book)
|
||||||
@@ -78,10 +78,7 @@ class MangaViewModel(application: Application) : BaseViewModel(application) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((ReadManga.durChapterPageCount == 0 || book.isLocalModified()) && !loadChapterListAwait(
|
if ((ReadManga.chapterSize == 0 || book.isLocalModified()) && !loadChapterListAwait(book)) {
|
||||||
book
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ensureChapterExist()
|
ensureChapterExist()
|
||||||
@@ -108,7 +105,7 @@ class MangaViewModel(application: Application) : BaseViewModel(application) {
|
|||||||
}
|
}
|
||||||
appDb.bookChapterDao.delByBook(oldBook.bookUrl)
|
appDb.bookChapterDao.delByBook(oldBook.bookUrl)
|
||||||
appDb.bookChapterDao.insert(*cList.toTypedArray())
|
appDb.bookChapterDao.insert(*cList.toTypedArray())
|
||||||
ReadManga.durChapterPageCount = cList.size
|
ReadManga.chapterSize = cList.size
|
||||||
ReadManga.simulatedChapterSize = book.simulatedTotalChapterNum()
|
ReadManga.simulatedChapterSize = book.simulatedTotalChapterNum()
|
||||||
return true
|
return true
|
||||||
}.onFailure {
|
}.onFailure {
|
||||||
@@ -138,8 +135,8 @@ class MangaViewModel(application: Application) : BaseViewModel(application) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun ensureChapterExist() {
|
private fun ensureChapterExist() {
|
||||||
if (ReadManga.simulatedChapterSize > 0 && ReadManga.durChapterPagePos > ReadManga.simulatedChapterSize - 1) {
|
if (ReadManga.simulatedChapterSize > 0 && ReadManga.durChapterIndex > ReadManga.simulatedChapterSize - 1) {
|
||||||
ReadManga.durChapterPagePos = ReadManga.simulatedChapterSize - 1
|
ReadManga.durChapterIndex = ReadManga.simulatedChapterSize - 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -224,9 +221,9 @@ class MangaViewModel(application: Application) : BaseViewModel(application) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun openChapter(index: Int, durChapterPos: Int = 0) {
|
fun openChapter(index: Int, durChapterPos: Int = 0) {
|
||||||
if (index < ReadManga.durChapterPageCount) {
|
if (index < ReadManga.chapterSize) {
|
||||||
ReadManga.chapterChanged = true
|
ReadManga.chapterChanged = true
|
||||||
ReadManga.durChapterPagePos = index
|
ReadManga.durChapterIndex = index
|
||||||
ReadManga.durChapterPos = durChapterPos
|
ReadManga.durChapterPos = durChapterPos
|
||||||
ReadManga.saveRead()
|
ReadManga.saveRead()
|
||||||
ReadManga.loadContent(index)
|
ReadManga.loadContent(index)
|
||||||
@@ -249,10 +246,10 @@ class MangaViewModel(application: Application) : BaseViewModel(application) {
|
|||||||
|
|
||||||
fun refreshContentDur(book: Book) {
|
fun refreshContentDur(book: Book) {
|
||||||
execute {
|
execute {
|
||||||
appDb.bookChapterDao.getChapter(book.bookUrl, ReadManga.durChapterPagePos)
|
appDb.bookChapterDao.getChapter(book.bookUrl, ReadManga.durChapterIndex)
|
||||||
?.let { chapter ->
|
?.let { chapter ->
|
||||||
BookHelp.delContent(book, chapter)
|
BookHelp.delContent(book, chapter)
|
||||||
openChapter(ReadManga.durChapterPagePos, ReadManga.durChapterPos)
|
openChapter(ReadManga.durChapterIndex, ReadManga.durChapterPos)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package io.legado.app.ui.book.manga
|
package io.legado.app.ui.book.manga
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
import android.app.Activity
|
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
@@ -164,20 +163,23 @@ class ReadMangaActivity : VMBaseActivity<ActivityMangaBinding, MangaViewModel>()
|
|||||||
}
|
}
|
||||||
loadMoreView.setOnClickListener {
|
loadMoreView.setOnClickListener {
|
||||||
if (!loadMoreView.isLoading && !ReadManga.gameOver) {
|
if (!loadMoreView.isLoading && !ReadManga.gameOver) {
|
||||||
scrollToBottom(true, ReadManga.durChapterPagePos)
|
scrollToBottom(true, ReadManga.durChapterIndex)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
loadMoreView.gone()
|
loadMoreView.gone()
|
||||||
mMangaFooterConfig =
|
mMangaFooterConfig =
|
||||||
GSON.fromJsonObject<MangaFooterConfig>(AppConfig.mangaFooterConfig).getOrNull()
|
GSON.fromJsonObject<MangaFooterConfig>(AppConfig.mangaFooterConfig).getOrNull()
|
||||||
?: MangaFooterConfig()
|
?: MangaFooterConfig()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun observeLiveBus() {
|
||||||
observeEvent<MangaFooterConfig>(EventBus.UP_MANGA_CONFIG) {
|
observeEvent<MangaFooterConfig>(EventBus.UP_MANGA_CONFIG) {
|
||||||
mMangaFooterConfig = it
|
mMangaFooterConfig = it
|
||||||
upInfoBar(
|
upInfoBar(
|
||||||
ReadManga.durChapterPagePos.plus(1),
|
ReadManga.durChapterIndex.plus(1),
|
||||||
ReadManga.durChapterPageCount,
|
ReadManga.chapterSize,
|
||||||
ReadManga.durChapterPos.plus(1),
|
ReadManga.durChapterPos.plus(1),
|
||||||
ReadManga.durChapterCount,
|
ReadManga.durChapterImageCount,
|
||||||
ReadManga.chapterTitle
|
ReadManga.chapterTitle
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -185,7 +187,7 @@ class ReadMangaActivity : VMBaseActivity<ActivityMangaBinding, MangaViewModel>()
|
|||||||
|
|
||||||
private fun initRecyclerView() {
|
private fun initRecyclerView() {
|
||||||
mAdapter.isHorizontal = AppConfig.enableMangaHorizontalScroll
|
mAdapter.isHorizontal = AppConfig.enableMangaHorizontalScroll
|
||||||
binding.mRecyclerMange.run {
|
binding.mRecyclerManga.run {
|
||||||
adapter = mAdapter
|
adapter = mAdapter
|
||||||
itemAnimator = null
|
itemAnimator = null
|
||||||
layoutManager = mLayoutManager
|
layoutManager = mLayoutManager
|
||||||
@@ -193,9 +195,7 @@ class ReadMangaActivity : VMBaseActivity<ActivityMangaBinding, MangaViewModel>()
|
|||||||
mLayoutManager.initialPrefetchItemCount = 4
|
mLayoutManager.initialPrefetchItemCount = 4
|
||||||
mLayoutManager.isItemPrefetchEnabled = true
|
mLayoutManager.isItemPrefetchEnabled = true
|
||||||
setItemViewCacheSize(AppConfig.preDownloadNum)
|
setItemViewCacheSize(AppConfig.preDownloadNum)
|
||||||
singlePagerScroller(
|
singlePagerScroller(AppConfig.enableMangaHorizontalScroll)
|
||||||
AppConfig.enableMangaHorizontalScroll
|
|
||||||
)
|
|
||||||
disabledClickScroller(AppConfig.disableClickScroll)
|
disabledClickScroller(AppConfig.disableClickScroll)
|
||||||
disableMangaScaling(AppConfig.disableMangaScale)
|
disableMangaScaling(AppConfig.disableMangaScale)
|
||||||
setPreScrollListener { _, dx, dy, position ->
|
setPreScrollListener { _, dx, dy, position ->
|
||||||
@@ -218,8 +218,8 @@ class ReadMangaActivity : VMBaseActivity<ActivityMangaBinding, MangaViewModel>()
|
|||||||
if (content is MangaContent) {
|
if (content is MangaContent) {
|
||||||
ReadManga.durChapterPos = content.mDurChapterPos.minus(1)
|
ReadManga.durChapterPos = content.mDurChapterPos.minus(1)
|
||||||
upInfoBar(
|
upInfoBar(
|
||||||
content.mChapterPagePos,
|
content.mChapterIndex,
|
||||||
content.mChapterPageCount,
|
content.chapterSize,
|
||||||
content.mDurChapterPos,
|
content.mDurChapterPos,
|
||||||
content.mDurChapterCount,
|
content.mDurChapterCount,
|
||||||
content.mChapterName
|
content.mChapterName
|
||||||
@@ -275,10 +275,10 @@ class ReadMangaActivity : VMBaseActivity<ActivityMangaBinding, MangaViewModel>()
|
|||||||
if (list.size > 1) {
|
if (list.size > 1) {
|
||||||
binding.infobar.isVisible = true
|
binding.infobar.isVisible = true
|
||||||
upInfoBar(
|
upInfoBar(
|
||||||
ReadManga.durChapterPagePos.plus(1),
|
ReadManga.durChapterIndex.plus(1),
|
||||||
ReadManga.durChapterPageCount,
|
ReadManga.chapterSize,
|
||||||
ReadManga.durChapterPos.plus(1),
|
ReadManga.durChapterPos.plus(1),
|
||||||
ReadManga.durChapterCount,
|
ReadManga.durChapterImageCount,
|
||||||
ReadManga.chapterTitle
|
ReadManga.chapterTitle
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -288,12 +288,12 @@ class ReadMangaActivity : VMBaseActivity<ActivityMangaBinding, MangaViewModel>()
|
|||||||
(mAdapter.getCurrentList().last() as ReaderLoading).mNextChapterIndex
|
(mAdapter.getCurrentList().last() as ReaderLoading).mNextChapterIndex
|
||||||
scrollToBottom(index = nextIndex)
|
scrollToBottom(index = nextIndex)
|
||||||
} else {
|
} else {
|
||||||
binding.mRecyclerMange.scrollToPosition(ReadManga.durChapterPos)
|
binding.mRecyclerManga.scrollToPosition(ReadManga.durChapterPos)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ReadManga.chapterChanged) {
|
if (ReadManga.chapterChanged) {
|
||||||
binding.mRecyclerMange.scrollToPosition(ReadManga.durChapterPos)
|
binding.mRecyclerManga.scrollToPosition(ReadManga.durChapterPos)
|
||||||
}
|
}
|
||||||
|
|
||||||
ReadManga.chapterChanged = false
|
ReadManga.chapterChanged = false
|
||||||
@@ -305,10 +305,10 @@ class ReadMangaActivity : VMBaseActivity<ActivityMangaBinding, MangaViewModel>()
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun upInfoBar(
|
private fun upInfoBar(
|
||||||
chapterPagePos: Int,
|
chapterIndex: Int,
|
||||||
chapterPageCount: Int,
|
chapterSize: Int,
|
||||||
chapterPos: Int,
|
chapterPos: Int,
|
||||||
chapterCount: Int,
|
chapterImageCount: Int,
|
||||||
chapterName: String,
|
chapterName: String,
|
||||||
) {
|
) {
|
||||||
mMangaFooterConfig.run {
|
mMangaFooterConfig.run {
|
||||||
@@ -324,21 +324,21 @@ class ReadMangaActivity : VMBaseActivity<ActivityMangaBinding, MangaViewModel>()
|
|||||||
if (!hidePageNumberLabel) {
|
if (!hidePageNumberLabel) {
|
||||||
mLabelBuilder.append(getString(R.string.manga_check_page_number))
|
mLabelBuilder.append(getString(R.string.manga_check_page_number))
|
||||||
}
|
}
|
||||||
mLabelBuilder.append("${chapterPos}/${chapterCount}").append(" ")
|
mLabelBuilder.append("${chapterPos}/${chapterImageCount}").append(" ")
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!hideChapter) {
|
if (!hideChapter) {
|
||||||
if (!hideChapterLabel) {
|
if (!hideChapterLabel) {
|
||||||
mLabelBuilder.append(getString(R.string.manga_check_chapter))
|
mLabelBuilder.append(getString(R.string.manga_check_chapter))
|
||||||
}
|
}
|
||||||
mLabelBuilder.append("${chapterPagePos}/${chapterPageCount}").append(" ")
|
mLabelBuilder.append("${chapterIndex}/${chapterSize}").append(" ")
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!hideProgressRatio) {
|
if (!hideProgressRatio) {
|
||||||
if (!hideProgressRatioLabel) {
|
if (!hideProgressRatioLabel) {
|
||||||
mLabelBuilder.append(getString(R.string.manga_check_progress))
|
mLabelBuilder.append(getString(R.string.manga_check_progress))
|
||||||
}
|
}
|
||||||
mLabelBuilder.append("${chapterPagePos.div(chapterPageCount).times(100)}%")
|
mLabelBuilder.append("${chapterIndex.div(chapterSize).times(100)}%")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
binding.infobar.update(
|
binding.infobar.update(
|
||||||
@@ -395,7 +395,7 @@ class ReadMangaActivity : VMBaseActivity<ActivityMangaBinding, MangaViewModel>()
|
|||||||
|
|
||||||
override fun adjustmentProgress() {
|
override fun adjustmentProgress() {
|
||||||
if (ReadManga.chapterChanged) {
|
if (ReadManga.chapterChanged) {
|
||||||
binding.mRecyclerMange.scrollToPosition(ReadManga.durChapterPos)
|
binding.mRecyclerManga.scrollToPosition(ReadManga.durChapterPos)
|
||||||
binding.flLoading.isGone = true
|
binding.flLoading.isGone = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -572,17 +572,17 @@ class ReadMangaActivity : VMBaseActivity<ActivityMangaBinding, MangaViewModel>()
|
|||||||
|
|
||||||
private fun addRecyclerViewPreloader(maxPreload: Int) {
|
private fun addRecyclerViewPreloader(maxPreload: Int) {
|
||||||
if (mRecyclerViewPreloader != null) {
|
if (mRecyclerViewPreloader != null) {
|
||||||
binding.mRecyclerMange.removeOnScrollListener(mRecyclerViewPreloader!!)
|
binding.mRecyclerManga.removeOnScrollListener(mRecyclerViewPreloader!!)
|
||||||
}
|
}
|
||||||
mRecyclerViewPreloader = RecyclerViewPreloader(
|
mRecyclerViewPreloader = RecyclerViewPreloader(
|
||||||
Glide.with(this), mAdapter, mSizeProvider, maxPreload
|
Glide.with(this), mAdapter, mSizeProvider, maxPreload
|
||||||
)
|
)
|
||||||
binding.mRecyclerMange.addOnScrollListener(mRecyclerViewPreloader!!)
|
binding.mRecyclerManga.addOnScrollListener(mRecyclerViewPreloader!!)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun singlePagerScroller(enableHorizontalScroll: Boolean) {
|
private fun singlePagerScroller(enableHorizontalScroll: Boolean) {
|
||||||
if (enableHorizontalScroll) {
|
if (enableHorizontalScroll) {
|
||||||
mPagerSnapHelper.attachToRecyclerView(binding.mRecyclerMange)
|
mPagerSnapHelper.attachToRecyclerView(binding.mRecyclerManga)
|
||||||
} else {
|
} else {
|
||||||
mPagerSnapHelper.attachToRecyclerView(null)
|
mPagerSnapHelper.attachToRecyclerView(null)
|
||||||
}
|
}
|
||||||
@@ -603,14 +603,14 @@ class ReadMangaActivity : VMBaseActivity<ActivityMangaBinding, MangaViewModel>()
|
|||||||
|
|
||||||
private fun disableMangaScaling(disable: Boolean) {
|
private fun disableMangaScaling(disable: Boolean) {
|
||||||
binding.webtoonFrame.disableMangaScale = disable
|
binding.webtoonFrame.disableMangaScale = disable
|
||||||
binding.mRecyclerMange.disableMangaScaling = disable
|
binding.mRecyclerManga.disableMangaScaling = disable
|
||||||
if (disable) {
|
if (disable) {
|
||||||
binding.mRecyclerMange.resetZoom()
|
binding.mRecyclerManga.resetZoom()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun disabledClickScroller(disable: Boolean) {
|
private fun disabledClickScroller(disable: Boolean) {
|
||||||
binding.mRecyclerMange.disabledClickScroller = disable
|
binding.mRecyclerManga.disabledClickScroller = disable
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun upLayoutInDisplayCutoutMode() {
|
private fun upLayoutInDisplayCutoutMode() {
|
||||||
@@ -623,35 +623,47 @@ class ReadMangaActivity : VMBaseActivity<ActivityMangaBinding, MangaViewModel>()
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun scrollToNext() {
|
private fun scrollToNext() {
|
||||||
if (binding.mRecyclerMange.isAtBottom()) {
|
if (binding.mRecyclerManga.isAtBottom()) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
val (dx, dy) = if (AppConfig.enableMangaHorizontalScroll) {
|
val dx: Int
|
||||||
val width =
|
val dy: Int
|
||||||
binding.mRecyclerMange.width - binding.mRecyclerMange.paddingStart - binding.mRecyclerMange.paddingEnd
|
if (AppConfig.enableMangaHorizontalScroll) {
|
||||||
Pair(width, 0)
|
val width = binding.mRecyclerManga.run {
|
||||||
|
width - paddingStart - paddingEnd
|
||||||
|
}
|
||||||
|
dx = width
|
||||||
|
dy = 0
|
||||||
} else {
|
} else {
|
||||||
val height =
|
val height = binding.mRecyclerManga.run {
|
||||||
binding.mRecyclerMange.height - binding.mRecyclerMange.paddingTop - binding.mRecyclerMange.paddingBottom
|
height - paddingTop - paddingBottom
|
||||||
Pair(0, height)
|
}
|
||||||
|
dx = 0
|
||||||
|
dy = height
|
||||||
}
|
}
|
||||||
binding.mRecyclerMange.smoothScrollBy(dx, dy, null)
|
binding.mRecyclerManga.smoothScrollBy(dx, dy, null)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun scrollToPrev() {
|
private fun scrollToPrev() {
|
||||||
if (binding.mRecyclerMange.isAtTop()) {
|
if (binding.mRecyclerManga.isAtTop()) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
val (dx, dy) = if (AppConfig.enableMangaHorizontalScroll) {
|
val dx: Int
|
||||||
val width =
|
val dy: Int
|
||||||
binding.mRecyclerMange.width - binding.mRecyclerMange.paddingStart - binding.mRecyclerMange.paddingEnd
|
if (AppConfig.enableMangaHorizontalScroll) {
|
||||||
Pair(width, 0)
|
val width = binding.mRecyclerManga.run {
|
||||||
|
width - paddingStart - paddingEnd
|
||||||
|
}
|
||||||
|
dx = width
|
||||||
|
dy = 0
|
||||||
} else {
|
} else {
|
||||||
val height =
|
val height = binding.mRecyclerManga.run {
|
||||||
binding.mRecyclerMange.height - binding.mRecyclerMange.paddingTop - binding.mRecyclerMange.paddingBottom
|
height - paddingTop - paddingBottom
|
||||||
Pair(0, height)
|
}
|
||||||
|
dx = 0
|
||||||
|
dy = height
|
||||||
}
|
}
|
||||||
binding.mRecyclerMange.smoothScrollBy(-dx, -dy, null)
|
binding.mRecyclerManga.smoothScrollBy(-dx, -dy, null)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun startAutoPage() {
|
private fun startAutoPage() {
|
||||||
@@ -696,7 +708,7 @@ class ReadMangaActivity : VMBaseActivity<ActivityMangaBinding, MangaViewModel>()
|
|||||||
ReadManga.book?.removeType(BookType.notShelf)
|
ReadManga.book?.removeType(BookType.notShelf)
|
||||||
ReadManga.book?.save()
|
ReadManga.book?.save()
|
||||||
ReadManga.inBookshelf = true
|
ReadManga.inBookshelf = true
|
||||||
setResult(Activity.RESULT_OK)
|
setResult(RESULT_OK)
|
||||||
}
|
}
|
||||||
noButton { viewModel.removeFromBookshelf { super.finish() } }
|
noButton { viewModel.removeFromBookshelf { super.finish() } }
|
||||||
}
|
}
|
||||||
@@ -704,9 +716,8 @@ class ReadMangaActivity : VMBaseActivity<ActivityMangaBinding, MangaViewModel>()
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun RecyclerView.isAtTop(): Boolean {
|
private fun RecyclerView.isAtTop(): Boolean {
|
||||||
return (mLayoutManager.findFirstCompletelyVisibleItemPosition() == 0) && !canScrollVertically(
|
return (mLayoutManager.findFirstCompletelyVisibleItemPosition() == 0)
|
||||||
-1
|
&& !canScrollVertically(-1)
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun RecyclerView.isAtBottom(): Boolean {
|
private fun RecyclerView.isAtBottom(): Boolean {
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
<io.legado.app.ui.book.manga.rv.WebtoonRecyclerView
|
<io.legado.app.ui.book.manga.rv.WebtoonRecyclerView
|
||||||
android:id="@+id/mRecyclerMange"
|
android:id="@+id/mRecyclerManga"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent" />
|
android:layout_height="match_parent" />
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user