Fix reader
This commit is contained in:
@@ -69,7 +69,6 @@ abstract class BaseReaderFragment(@LayoutRes contentLayoutId: Int) : BaseFragmen
|
||||
}
|
||||
|
||||
fun findCurrentPageIndex(chapterId: Long): Int {
|
||||
val pages = this.pages
|
||||
var offset = 0
|
||||
for ((id, count) in chaptersMap) {
|
||||
if (id == chapterId) {
|
||||
@@ -80,6 +79,17 @@ abstract class BaseReaderFragment(@LayoutRes contentLayoutId: Int) : BaseFragmen
|
||||
return -1
|
||||
}
|
||||
|
||||
fun findChapterOffset(chapterId: Long): Int {
|
||||
var offset = 0
|
||||
for ((id, count) in chaptersMap) {
|
||||
if (id == chapterId) {
|
||||
return offset
|
||||
}
|
||||
offset += count
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
fun getPages(chapterId: Long): List<MangaPage>? {
|
||||
var offset = 0
|
||||
for ((id, count) in chaptersMap) {
|
||||
@@ -113,13 +123,12 @@ abstract class BaseReaderFragment(@LayoutRes contentLayoutId: Int) : BaseFragmen
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected fun notifyPageChanged(page: Int) {
|
||||
var i = page
|
||||
val chapters = lastState?.manga?.chapters ?: return
|
||||
val chapter = chaptersMap.firstOrNull { x ->
|
||||
i -= x.second
|
||||
i <= 0
|
||||
i < 0
|
||||
} ?: return
|
||||
(activity as? ReaderListener)?.onPageChanged(
|
||||
chapter = chapters.find { x -> x.id == chapter.first } ?: return,
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
package org.koitharu.kotatsu.ui.reader
|
||||
|
||||
import android.content.ContentResolver
|
||||
import android.util.Log
|
||||
import android.webkit.URLUtil
|
||||
import kotlinx.coroutines.CancellationException
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import kotlinx.coroutines.*
|
||||
import moxy.InjectViewState
|
||||
import moxy.presenterScope
|
||||
import okhttp3.OkHttpClient
|
||||
@@ -27,10 +25,12 @@ import org.koitharu.kotatsu.utils.ext.mimeType
|
||||
@InjectViewState
|
||||
class ReaderPresenter : BasePresenter<ReaderView>() {
|
||||
|
||||
private var loaderJob: Job? = null
|
||||
private var isInitialized = false
|
||||
|
||||
fun loadChapter(manga: Manga, chapterId: Long, action: ReaderAction) {
|
||||
presenterScope.launch {
|
||||
loaderJob?.cancel()
|
||||
loaderJob = presenterScope.launch {
|
||||
viewState.onLoadingStateChanged(isLoading = true)
|
||||
try {
|
||||
withContext(Dispatchers.IO) {
|
||||
@@ -63,6 +63,8 @@ class ReaderPresenter : BasePresenter<ReaderView>() {
|
||||
viewState.onPagesLoaded(chapterId, pages, action)
|
||||
}
|
||||
}
|
||||
} catch (e: CancellationException){
|
||||
Log.w(null, "Loader job cancelled", e)
|
||||
} catch (e: Exception) {
|
||||
if (BuildConfig.DEBUG) {
|
||||
e.printStackTrace()
|
||||
|
||||
@@ -44,7 +44,7 @@ class StandardReaderFragment : BaseReaderFragment(R.layout.fragment_reader_stand
|
||||
it.replaceData(pages)
|
||||
lastState?.let { state ->
|
||||
if (chapterId == state.chapterId) {
|
||||
pager.setCurrentItem(state.page, false)
|
||||
pager.setCurrentItem(findChapterOffset(chapterId) + state.page, false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user