优化
This commit is contained in:
@@ -47,9 +47,9 @@ object ReadManga : CoroutineScope by MainScope() {
|
||||
var chapterChanged = false
|
||||
var book: Book? = null
|
||||
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 bookSource: BookSource? = null
|
||||
var chapterTitle: String = ""
|
||||
@@ -65,7 +65,6 @@ object ReadManga : CoroutineScope by MainScope() {
|
||||
val downloadedChapters = hashSetOf<Int>()
|
||||
val downloadFailChapters = hashMapOf<Int, Int>()
|
||||
private val downloadLoadingChapters = arrayListOf<Int>()
|
||||
var isMangaMode = false
|
||||
val downloadScope = CoroutineScope(SupervisorJob() + IO)
|
||||
var rateLimiter = ConcurrentRateLimiter(null)
|
||||
|
||||
@@ -74,11 +73,11 @@ object ReadManga : CoroutineScope by MainScope() {
|
||||
val book = book ?: return@execute
|
||||
book.lastCheckCount = 0
|
||||
book.durChapterTime = System.currentTimeMillis()
|
||||
val changed = book.durChapterIndex != durChapterPagePos
|
||||
book.durChapterIndex = durChapterPagePos
|
||||
val changed = book.durChapterIndex != durChapterIndex
|
||||
book.durChapterIndex = durChapterIndex
|
||||
book.durChapterPos = durChapterPos
|
||||
if (!pageChanged || changed) {
|
||||
appDb.bookChapterDao.getChapter(book.bookUrl, durChapterPagePos)?.let {
|
||||
appDb.bookChapterDao.getChapter(book.bookUrl, durChapterIndex)?.let {
|
||||
book.durChapterTitle = it.getDisplayTitle(
|
||||
ContentProcessor.get(book.name, book.origin).getTitleReplaceRules(),
|
||||
book.getUseReplaceRule()
|
||||
@@ -91,16 +90,15 @@ object ReadManga : CoroutineScope by MainScope() {
|
||||
|
||||
fun upData(book: Book) {
|
||||
ReadManga.book = book
|
||||
isMangaMode = true
|
||||
durChapterPageCount = appDb.bookChapterDao.getChapterCount(book.bookUrl)
|
||||
chapterSize = appDb.bookChapterDao.getChapterCount(book.bookUrl)
|
||||
simulatedChapterSize = if (book.readSimulating()) {
|
||||
book.simulatedTotalChapterNum()
|
||||
} else {
|
||||
durChapterPageCount
|
||||
chapterSize
|
||||
}
|
||||
|
||||
if (durChapterPagePos != book.durChapterIndex || tocChanged) {
|
||||
durChapterPagePos = book.durChapterIndex
|
||||
if (durChapterIndex != book.durChapterIndex || tocChanged) {
|
||||
durChapterIndex = book.durChapterIndex
|
||||
durChapterPos = book.durChapterPos
|
||||
}
|
||||
upWebBook(book)
|
||||
@@ -111,16 +109,15 @@ object ReadManga : CoroutineScope by MainScope() {
|
||||
|
||||
fun resetData(book: Book) {
|
||||
ReadManga.book = book
|
||||
isMangaMode = true
|
||||
readRecord.bookName = book.name
|
||||
readRecord.readTime = appDb.readRecordDao.getReadTime(book.name) ?: 0
|
||||
durChapterPageCount = appDb.bookChapterDao.getChapterCount(book.bookUrl)
|
||||
chapterSize = appDb.bookChapterDao.getChapterCount(book.bookUrl)
|
||||
simulatedChapterSize = if (book.readSimulating()) {
|
||||
book.simulatedTotalChapterNum()
|
||||
} else {
|
||||
durChapterPageCount
|
||||
chapterSize
|
||||
}
|
||||
durChapterPagePos = book.durChapterIndex
|
||||
durChapterIndex = book.durChapterIndex
|
||||
durChapterPos = book.durChapterPos
|
||||
upWebBook(book)
|
||||
synchronized(this) {
|
||||
@@ -203,7 +200,7 @@ object ReadManga : CoroutineScope by MainScope() {
|
||||
|
||||
|
||||
fun loadContent() {
|
||||
loadContent(durChapterPagePos)
|
||||
loadContent(durChapterIndex)
|
||||
}
|
||||
|
||||
fun loadContent(
|
||||
@@ -245,11 +242,10 @@ object ReadManga : CoroutineScope by MainScope() {
|
||||
tocChanged = false
|
||||
chapterChanged = false
|
||||
book = null
|
||||
durChapterPagePos = 0
|
||||
isMangaMode = false
|
||||
durChapterPageCount = 0
|
||||
durChapterIndex = 0
|
||||
chapterSize = 0
|
||||
durChapterPos = 0
|
||||
durChapterCount = 0
|
||||
durChapterImageCount = 0
|
||||
bookSource = null
|
||||
chapterTitle = ""
|
||||
loadingChapters.clear()
|
||||
@@ -282,7 +278,7 @@ object ReadManga : CoroutineScope by MainScope() {
|
||||
}
|
||||
mTopChapter = chapter
|
||||
chapterTitle = chapter.title
|
||||
if (chapter.index !in durChapterPagePos - 1..durChapterPagePos + 1) {
|
||||
if (chapter.index !in durChapterIndex - 1..durChapterIndex + 1) {
|
||||
return
|
||||
}
|
||||
if (content.isNotEmpty()) {
|
||||
@@ -295,9 +291,9 @@ object ReadManga : CoroutineScope by MainScope() {
|
||||
}
|
||||
}.distinctUntilChanged().mapIndexed { index, src ->
|
||||
MangaContent(
|
||||
mChapterPageCount = durChapterPageCount,
|
||||
mChapterPagePos = durChapterPagePos.plus(1),
|
||||
mChapterNextPagePos = durChapterPagePos.plus(1),
|
||||
chapterSize = chapterSize,
|
||||
mChapterIndex = durChapterIndex.plus(1),
|
||||
nextChapterIndex = durChapterIndex.plus(1),
|
||||
mImageUrl = src,
|
||||
mDurChapterPos = index.plus(1),
|
||||
mChapterName = chapterTitle
|
||||
@@ -306,22 +302,22 @@ object ReadManga : CoroutineScope by MainScope() {
|
||||
this.forEach {
|
||||
it.mDurChapterCount = this.size
|
||||
}
|
||||
durChapterCount = this.size
|
||||
durChapterImageCount = this.size
|
||||
}
|
||||
val contentList = mutableListOf<Any>()
|
||||
contentList.add(
|
||||
ReaderLoading(
|
||||
durChapterPagePos,
|
||||
durChapterIndex,
|
||||
"阅读 ${chapter.title}",
|
||||
mNextChapterIndex = durChapterPagePos.plus(1)
|
||||
mNextChapterIndex = durChapterIndex.plus(1)
|
||||
)
|
||||
)
|
||||
contentList.addAll(list)
|
||||
contentList.add(
|
||||
ReaderLoading(
|
||||
durChapterPagePos,
|
||||
durChapterIndex,
|
||||
"已读完 ${chapter.title}",
|
||||
mNextChapterIndex = durChapterPagePos.plus(1)
|
||||
mNextChapterIndex = durChapterIndex.plus(1)
|
||||
)
|
||||
)
|
||||
runOnUI {
|
||||
@@ -339,15 +335,15 @@ object ReadManga : CoroutineScope by MainScope() {
|
||||
return
|
||||
}
|
||||
|
||||
if (index > durChapterPageCount - 1) {
|
||||
if (index > chapterSize - 1) {
|
||||
upToc(index)
|
||||
return
|
||||
}
|
||||
if (durChapterPagePos < simulatedChapterSize - 1) {
|
||||
if (durChapterIndex < simulatedChapterSize - 1) {
|
||||
durChapterPos = 0
|
||||
durChapterPagePos = index
|
||||
durChapterIndex = index
|
||||
saveRead()
|
||||
loadContent(durChapterPagePos)
|
||||
loadContent(durChapterIndex)
|
||||
AppLog.putDebug("moveToNextChapter-curPageChanged()")
|
||||
curPageChanged()
|
||||
} else {
|
||||
@@ -374,18 +370,18 @@ object ReadManga : CoroutineScope by MainScope() {
|
||||
book.lastCheckTime = System.currentTimeMillis()
|
||||
WebBook.getChapterList(this, bookSource, book).onSuccess(IO) { cList ->
|
||||
if (book.bookUrl == ReadManga.book?.bookUrl
|
||||
&& cList.size > durChapterPageCount
|
||||
&& cList.size > chapterSize
|
||||
) {
|
||||
appDb.bookChapterDao.delByBook(book.bookUrl)
|
||||
appDb.bookChapterDao.insert(*cList.toTypedArray())
|
||||
saveRead()
|
||||
durChapterPos = 0
|
||||
durChapterPagePos = index
|
||||
durChapterPageCount = cList.size
|
||||
durChapterIndex = index
|
||||
chapterSize = cList.size
|
||||
simulatedChapterSize = book.simulatedTotalChapterNum()
|
||||
loadContent(durChapterPagePos)
|
||||
loadContent(durChapterIndex)
|
||||
} else {
|
||||
durChapterPagePos = durChapterPagePos.minus(1)
|
||||
durChapterIndex = durChapterIndex.minus(1)
|
||||
saveRead()
|
||||
gameOver = true
|
||||
runOnUI {
|
||||
@@ -409,7 +405,7 @@ object ReadManga : CoroutineScope by MainScope() {
|
||||
runOnUI {
|
||||
mCallback?.loadComplete()
|
||||
}
|
||||
if (durChapterPagePos >= durChapterPageCount.minus(1)) {
|
||||
if (durChapterIndex >= chapterSize.minus(1)) {
|
||||
gameOver = true
|
||||
runOnUI {
|
||||
mCallback?.noData()
|
||||
@@ -475,16 +471,16 @@ object ReadManga : CoroutineScope by MainScope() {
|
||||
//预下载
|
||||
launch {
|
||||
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 ((downloadFailChapters[i] ?: 0) >= 3) continue
|
||||
downloadIndex(i)
|
||||
}
|
||||
}
|
||||
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 ((downloadFailChapters[i] ?: 0) >= 3) continue
|
||||
downloadIndex(i)
|
||||
@@ -496,7 +492,7 @@ object ReadManga : CoroutineScope by MainScope() {
|
||||
|
||||
private suspend fun downloadIndex(index: Int) {
|
||||
if (index < 0) return
|
||||
if (index > durChapterPageCount - 1) {
|
||||
if (index > chapterSize - 1) {
|
||||
upToc()
|
||||
return
|
||||
}
|
||||
@@ -540,12 +536,12 @@ object ReadManga : CoroutineScope by MainScope() {
|
||||
book.lastCheckTime = System.currentTimeMillis()
|
||||
WebBook.getChapterList(this, bookSource, book).onSuccess(IO) { cList ->
|
||||
if (book.bookUrl == ReadManga.book?.bookUrl
|
||||
&& cList.size > durChapterPageCount
|
||||
&& cList.size > chapterSize
|
||||
) {
|
||||
appDb.bookChapterDao.delByBook(book.bookUrl)
|
||||
appDb.bookChapterDao.insert(*cList.toTypedArray())
|
||||
saveRead()
|
||||
durChapterPageCount = cList.size
|
||||
chapterSize = cList.size
|
||||
simulatedChapterSize = book.simulatedTotalChapterNum()
|
||||
}
|
||||
}
|
||||
@@ -601,23 +597,23 @@ object ReadManga : CoroutineScope by MainScope() {
|
||||
}
|
||||
|
||||
fun setProgress(progress: BookProgress) {
|
||||
if (progress.durChapterIndex < durChapterPageCount &&
|
||||
(durChapterPagePos != progress.durChapterIndex
|
||||
if (progress.durChapterIndex < chapterSize &&
|
||||
(durChapterIndex != progress.durChapterIndex
|
||||
|| durChapterPos != progress.durChapterPos)
|
||||
) {
|
||||
chapterChanged = true
|
||||
if (progress.durChapterIndex == durChapterPagePos) {
|
||||
if (progress.durChapterIndex == durChapterIndex) {
|
||||
durChapterPos = progress.durChapterPos
|
||||
mCallback?.adjustmentProgress()
|
||||
} else {
|
||||
durChapterPagePos = progress.durChapterIndex
|
||||
durChapterIndex = progress.durChapterIndex
|
||||
durChapterPos = progress.durChapterPos
|
||||
if (addLoading(durChapterPagePos)) {
|
||||
loadContent(durChapterPagePos)
|
||||
if (addLoading(durChapterIndex)) {
|
||||
loadContent(durChapterIndex)
|
||||
} else {
|
||||
Coroutine.async {
|
||||
val book = book!!
|
||||
appDb.bookChapterDao.getChapter(book.bookUrl, durChapterPagePos)
|
||||
appDb.bookChapterDao.getChapter(book.bookUrl, durChapterIndex)
|
||||
?.let { chapter ->
|
||||
getContent(
|
||||
downloadScope,
|
||||
|
||||
@@ -2,9 +2,9 @@ package io.legado.app.model.recyclerView
|
||||
|
||||
|
||||
data class MangaContent(
|
||||
var mChapterPagePos: Int = 0,//总章节位置
|
||||
var mChapterPageCount: Int,//总章节数量
|
||||
var mChapterNextPagePos: Int = 0,//下一章
|
||||
var mChapterIndex: Int = 0,//总章节位置
|
||||
var chapterSize: Int,//总章节数量
|
||||
var nextChapterIndex: Int = 0,//下一章
|
||||
val mImageUrl: String = "",//当前URL
|
||||
var mDurChapterPos: Int = 0,//当前章节位置
|
||||
var mDurChapterCount: Int = 0,//当前章节内容总数
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package io.legado.app.model.recyclerView
|
||||
|
||||
data class ReaderLoading(
|
||||
val mChapterPagePos: Int = 0,
|
||||
val mChapterIndex: Int = 0,
|
||||
val mMessage: String? = null,
|
||||
val mNextChapterIndex: Int = 0,
|
||||
var mLoading: Boolean = false,
|
||||
|
||||
@@ -50,7 +50,7 @@ class MangaViewModel(application: Application) : BaseViewModel(application) {
|
||||
else -> appDb.bookDao.getBook(bookUrl)
|
||||
} ?: ReadManga.book
|
||||
when {
|
||||
book != null -> initMange(book)
|
||||
book != null -> initManga(book)
|
||||
else -> context.getString(R.string.no_book)//没有找到书
|
||||
}
|
||||
}.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
|
||||
if (isSameBook) {
|
||||
ReadManga.upData(book)
|
||||
@@ -78,10 +78,7 @@ class MangaViewModel(application: Application) : BaseViewModel(application) {
|
||||
return
|
||||
}
|
||||
|
||||
if ((ReadManga.durChapterPageCount == 0 || book.isLocalModified()) && !loadChapterListAwait(
|
||||
book
|
||||
)
|
||||
) {
|
||||
if ((ReadManga.chapterSize == 0 || book.isLocalModified()) && !loadChapterListAwait(book)) {
|
||||
return
|
||||
}
|
||||
ensureChapterExist()
|
||||
@@ -108,7 +105,7 @@ class MangaViewModel(application: Application) : BaseViewModel(application) {
|
||||
}
|
||||
appDb.bookChapterDao.delByBook(oldBook.bookUrl)
|
||||
appDb.bookChapterDao.insert(*cList.toTypedArray())
|
||||
ReadManga.durChapterPageCount = cList.size
|
||||
ReadManga.chapterSize = cList.size
|
||||
ReadManga.simulatedChapterSize = book.simulatedTotalChapterNum()
|
||||
return true
|
||||
}.onFailure {
|
||||
@@ -138,8 +135,8 @@ class MangaViewModel(application: Application) : BaseViewModel(application) {
|
||||
}
|
||||
|
||||
private fun ensureChapterExist() {
|
||||
if (ReadManga.simulatedChapterSize > 0 && ReadManga.durChapterPagePos > ReadManga.simulatedChapterSize - 1) {
|
||||
ReadManga.durChapterPagePos = ReadManga.simulatedChapterSize - 1
|
||||
if (ReadManga.simulatedChapterSize > 0 && ReadManga.durChapterIndex > 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) {
|
||||
if (index < ReadManga.durChapterPageCount) {
|
||||
if (index < ReadManga.chapterSize) {
|
||||
ReadManga.chapterChanged = true
|
||||
ReadManga.durChapterPagePos = index
|
||||
ReadManga.durChapterIndex = index
|
||||
ReadManga.durChapterPos = durChapterPos
|
||||
ReadManga.saveRead()
|
||||
ReadManga.loadContent(index)
|
||||
@@ -249,10 +246,10 @@ class MangaViewModel(application: Application) : BaseViewModel(application) {
|
||||
|
||||
fun refreshContentDur(book: Book) {
|
||||
execute {
|
||||
appDb.bookChapterDao.getChapter(book.bookUrl, ReadManga.durChapterPagePos)
|
||||
appDb.bookChapterDao.getChapter(book.bookUrl, ReadManga.durChapterIndex)
|
||||
?.let { 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
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.Activity
|
||||
import android.content.Intent
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
@@ -164,20 +163,23 @@ class ReadMangaActivity : VMBaseActivity<ActivityMangaBinding, MangaViewModel>()
|
||||
}
|
||||
loadMoreView.setOnClickListener {
|
||||
if (!loadMoreView.isLoading && !ReadManga.gameOver) {
|
||||
scrollToBottom(true, ReadManga.durChapterPagePos)
|
||||
scrollToBottom(true, ReadManga.durChapterIndex)
|
||||
}
|
||||
}
|
||||
loadMoreView.gone()
|
||||
mMangaFooterConfig =
|
||||
GSON.fromJsonObject<MangaFooterConfig>(AppConfig.mangaFooterConfig).getOrNull()
|
||||
?: MangaFooterConfig()
|
||||
}
|
||||
|
||||
override fun observeLiveBus() {
|
||||
observeEvent<MangaFooterConfig>(EventBus.UP_MANGA_CONFIG) {
|
||||
mMangaFooterConfig = it
|
||||
upInfoBar(
|
||||
ReadManga.durChapterPagePos.plus(1),
|
||||
ReadManga.durChapterPageCount,
|
||||
ReadManga.durChapterIndex.plus(1),
|
||||
ReadManga.chapterSize,
|
||||
ReadManga.durChapterPos.plus(1),
|
||||
ReadManga.durChapterCount,
|
||||
ReadManga.durChapterImageCount,
|
||||
ReadManga.chapterTitle
|
||||
)
|
||||
}
|
||||
@@ -185,7 +187,7 @@ class ReadMangaActivity : VMBaseActivity<ActivityMangaBinding, MangaViewModel>()
|
||||
|
||||
private fun initRecyclerView() {
|
||||
mAdapter.isHorizontal = AppConfig.enableMangaHorizontalScroll
|
||||
binding.mRecyclerMange.run {
|
||||
binding.mRecyclerManga.run {
|
||||
adapter = mAdapter
|
||||
itemAnimator = null
|
||||
layoutManager = mLayoutManager
|
||||
@@ -193,9 +195,7 @@ class ReadMangaActivity : VMBaseActivity<ActivityMangaBinding, MangaViewModel>()
|
||||
mLayoutManager.initialPrefetchItemCount = 4
|
||||
mLayoutManager.isItemPrefetchEnabled = true
|
||||
setItemViewCacheSize(AppConfig.preDownloadNum)
|
||||
singlePagerScroller(
|
||||
AppConfig.enableMangaHorizontalScroll
|
||||
)
|
||||
singlePagerScroller(AppConfig.enableMangaHorizontalScroll)
|
||||
disabledClickScroller(AppConfig.disableClickScroll)
|
||||
disableMangaScaling(AppConfig.disableMangaScale)
|
||||
setPreScrollListener { _, dx, dy, position ->
|
||||
@@ -218,8 +218,8 @@ class ReadMangaActivity : VMBaseActivity<ActivityMangaBinding, MangaViewModel>()
|
||||
if (content is MangaContent) {
|
||||
ReadManga.durChapterPos = content.mDurChapterPos.minus(1)
|
||||
upInfoBar(
|
||||
content.mChapterPagePos,
|
||||
content.mChapterPageCount,
|
||||
content.mChapterIndex,
|
||||
content.chapterSize,
|
||||
content.mDurChapterPos,
|
||||
content.mDurChapterCount,
|
||||
content.mChapterName
|
||||
@@ -275,10 +275,10 @@ class ReadMangaActivity : VMBaseActivity<ActivityMangaBinding, MangaViewModel>()
|
||||
if (list.size > 1) {
|
||||
binding.infobar.isVisible = true
|
||||
upInfoBar(
|
||||
ReadManga.durChapterPagePos.plus(1),
|
||||
ReadManga.durChapterPageCount,
|
||||
ReadManga.durChapterIndex.plus(1),
|
||||
ReadManga.chapterSize,
|
||||
ReadManga.durChapterPos.plus(1),
|
||||
ReadManga.durChapterCount,
|
||||
ReadManga.durChapterImageCount,
|
||||
ReadManga.chapterTitle
|
||||
)
|
||||
}
|
||||
@@ -288,12 +288,12 @@ class ReadMangaActivity : VMBaseActivity<ActivityMangaBinding, MangaViewModel>()
|
||||
(mAdapter.getCurrentList().last() as ReaderLoading).mNextChapterIndex
|
||||
scrollToBottom(index = nextIndex)
|
||||
} else {
|
||||
binding.mRecyclerMange.scrollToPosition(ReadManga.durChapterPos)
|
||||
binding.mRecyclerManga.scrollToPosition(ReadManga.durChapterPos)
|
||||
}
|
||||
}
|
||||
|
||||
if (ReadManga.chapterChanged) {
|
||||
binding.mRecyclerMange.scrollToPosition(ReadManga.durChapterPos)
|
||||
binding.mRecyclerManga.scrollToPosition(ReadManga.durChapterPos)
|
||||
}
|
||||
|
||||
ReadManga.chapterChanged = false
|
||||
@@ -305,10 +305,10 @@ class ReadMangaActivity : VMBaseActivity<ActivityMangaBinding, MangaViewModel>()
|
||||
}
|
||||
|
||||
private fun upInfoBar(
|
||||
chapterPagePos: Int,
|
||||
chapterPageCount: Int,
|
||||
chapterIndex: Int,
|
||||
chapterSize: Int,
|
||||
chapterPos: Int,
|
||||
chapterCount: Int,
|
||||
chapterImageCount: Int,
|
||||
chapterName: String,
|
||||
) {
|
||||
mMangaFooterConfig.run {
|
||||
@@ -324,21 +324,21 @@ class ReadMangaActivity : VMBaseActivity<ActivityMangaBinding, MangaViewModel>()
|
||||
if (!hidePageNumberLabel) {
|
||||
mLabelBuilder.append(getString(R.string.manga_check_page_number))
|
||||
}
|
||||
mLabelBuilder.append("${chapterPos}/${chapterCount}").append(" ")
|
||||
mLabelBuilder.append("${chapterPos}/${chapterImageCount}").append(" ")
|
||||
}
|
||||
|
||||
if (!hideChapter) {
|
||||
if (!hideChapterLabel) {
|
||||
mLabelBuilder.append(getString(R.string.manga_check_chapter))
|
||||
}
|
||||
mLabelBuilder.append("${chapterPagePos}/${chapterPageCount}").append(" ")
|
||||
mLabelBuilder.append("${chapterIndex}/${chapterSize}").append(" ")
|
||||
}
|
||||
|
||||
if (!hideProgressRatio) {
|
||||
if (!hideProgressRatioLabel) {
|
||||
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(
|
||||
@@ -395,7 +395,7 @@ class ReadMangaActivity : VMBaseActivity<ActivityMangaBinding, MangaViewModel>()
|
||||
|
||||
override fun adjustmentProgress() {
|
||||
if (ReadManga.chapterChanged) {
|
||||
binding.mRecyclerMange.scrollToPosition(ReadManga.durChapterPos)
|
||||
binding.mRecyclerManga.scrollToPosition(ReadManga.durChapterPos)
|
||||
binding.flLoading.isGone = true
|
||||
}
|
||||
}
|
||||
@@ -572,17 +572,17 @@ class ReadMangaActivity : VMBaseActivity<ActivityMangaBinding, MangaViewModel>()
|
||||
|
||||
private fun addRecyclerViewPreloader(maxPreload: Int) {
|
||||
if (mRecyclerViewPreloader != null) {
|
||||
binding.mRecyclerMange.removeOnScrollListener(mRecyclerViewPreloader!!)
|
||||
binding.mRecyclerManga.removeOnScrollListener(mRecyclerViewPreloader!!)
|
||||
}
|
||||
mRecyclerViewPreloader = RecyclerViewPreloader(
|
||||
Glide.with(this), mAdapter, mSizeProvider, maxPreload
|
||||
)
|
||||
binding.mRecyclerMange.addOnScrollListener(mRecyclerViewPreloader!!)
|
||||
binding.mRecyclerManga.addOnScrollListener(mRecyclerViewPreloader!!)
|
||||
}
|
||||
|
||||
private fun singlePagerScroller(enableHorizontalScroll: Boolean) {
|
||||
if (enableHorizontalScroll) {
|
||||
mPagerSnapHelper.attachToRecyclerView(binding.mRecyclerMange)
|
||||
mPagerSnapHelper.attachToRecyclerView(binding.mRecyclerManga)
|
||||
} else {
|
||||
mPagerSnapHelper.attachToRecyclerView(null)
|
||||
}
|
||||
@@ -603,14 +603,14 @@ class ReadMangaActivity : VMBaseActivity<ActivityMangaBinding, MangaViewModel>()
|
||||
|
||||
private fun disableMangaScaling(disable: Boolean) {
|
||||
binding.webtoonFrame.disableMangaScale = disable
|
||||
binding.mRecyclerMange.disableMangaScaling = disable
|
||||
binding.mRecyclerManga.disableMangaScaling = disable
|
||||
if (disable) {
|
||||
binding.mRecyclerMange.resetZoom()
|
||||
binding.mRecyclerManga.resetZoom()
|
||||
}
|
||||
}
|
||||
|
||||
private fun disabledClickScroller(disable: Boolean) {
|
||||
binding.mRecyclerMange.disabledClickScroller = disable
|
||||
binding.mRecyclerManga.disabledClickScroller = disable
|
||||
}
|
||||
|
||||
private fun upLayoutInDisplayCutoutMode() {
|
||||
@@ -623,35 +623,47 @@ class ReadMangaActivity : VMBaseActivity<ActivityMangaBinding, MangaViewModel>()
|
||||
}
|
||||
|
||||
private fun scrollToNext() {
|
||||
if (binding.mRecyclerMange.isAtBottom()) {
|
||||
if (binding.mRecyclerManga.isAtBottom()) {
|
||||
return
|
||||
}
|
||||
val (dx, dy) = if (AppConfig.enableMangaHorizontalScroll) {
|
||||
val width =
|
||||
binding.mRecyclerMange.width - binding.mRecyclerMange.paddingStart - binding.mRecyclerMange.paddingEnd
|
||||
Pair(width, 0)
|
||||
val dx: Int
|
||||
val dy: Int
|
||||
if (AppConfig.enableMangaHorizontalScroll) {
|
||||
val width = binding.mRecyclerManga.run {
|
||||
width - paddingStart - paddingEnd
|
||||
}
|
||||
dx = width
|
||||
dy = 0
|
||||
} else {
|
||||
val height =
|
||||
binding.mRecyclerMange.height - binding.mRecyclerMange.paddingTop - binding.mRecyclerMange.paddingBottom
|
||||
Pair(0, height)
|
||||
val height = binding.mRecyclerManga.run {
|
||||
height - paddingTop - paddingBottom
|
||||
}
|
||||
dx = 0
|
||||
dy = height
|
||||
}
|
||||
binding.mRecyclerMange.smoothScrollBy(dx, dy, null)
|
||||
binding.mRecyclerManga.smoothScrollBy(dx, dy, null)
|
||||
}
|
||||
|
||||
private fun scrollToPrev() {
|
||||
if (binding.mRecyclerMange.isAtTop()) {
|
||||
if (binding.mRecyclerManga.isAtTop()) {
|
||||
return
|
||||
}
|
||||
val (dx, dy) = if (AppConfig.enableMangaHorizontalScroll) {
|
||||
val width =
|
||||
binding.mRecyclerMange.width - binding.mRecyclerMange.paddingStart - binding.mRecyclerMange.paddingEnd
|
||||
Pair(width, 0)
|
||||
val dx: Int
|
||||
val dy: Int
|
||||
if (AppConfig.enableMangaHorizontalScroll) {
|
||||
val width = binding.mRecyclerManga.run {
|
||||
width - paddingStart - paddingEnd
|
||||
}
|
||||
dx = width
|
||||
dy = 0
|
||||
} else {
|
||||
val height =
|
||||
binding.mRecyclerMange.height - binding.mRecyclerMange.paddingTop - binding.mRecyclerMange.paddingBottom
|
||||
Pair(0, height)
|
||||
val height = binding.mRecyclerManga.run {
|
||||
height - paddingTop - paddingBottom
|
||||
}
|
||||
dx = 0
|
||||
dy = height
|
||||
}
|
||||
binding.mRecyclerMange.smoothScrollBy(-dx, -dy, null)
|
||||
binding.mRecyclerManga.smoothScrollBy(-dx, -dy, null)
|
||||
}
|
||||
|
||||
private fun startAutoPage() {
|
||||
@@ -696,7 +708,7 @@ class ReadMangaActivity : VMBaseActivity<ActivityMangaBinding, MangaViewModel>()
|
||||
ReadManga.book?.removeType(BookType.notShelf)
|
||||
ReadManga.book?.save()
|
||||
ReadManga.inBookshelf = true
|
||||
setResult(Activity.RESULT_OK)
|
||||
setResult(RESULT_OK)
|
||||
}
|
||||
noButton { viewModel.removeFromBookshelf { super.finish() } }
|
||||
}
|
||||
@@ -704,9 +716,8 @@ class ReadMangaActivity : VMBaseActivity<ActivityMangaBinding, MangaViewModel>()
|
||||
}
|
||||
|
||||
private fun RecyclerView.isAtTop(): Boolean {
|
||||
return (mLayoutManager.findFirstCompletelyVisibleItemPosition() == 0) && !canScrollVertically(
|
||||
-1
|
||||
)
|
||||
return (mLayoutManager.findFirstCompletelyVisibleItemPosition() == 0)
|
||||
&& !canScrollVertically(-1)
|
||||
}
|
||||
|
||||
private fun RecyclerView.isAtBottom(): Boolean {
|
||||
|
||||
Reference in New Issue
Block a user