|
|
|
@ -16,7 +16,6 @@ import org.koitharu.kotatsu.core.model.parcelable.ParcelableManga
|
|
|
|
import org.koitharu.kotatsu.core.parser.MangaRepository
|
|
|
|
import org.koitharu.kotatsu.core.parser.MangaRepository
|
|
|
|
import org.koitharu.kotatsu.core.ui.BaseViewModel
|
|
|
|
import org.koitharu.kotatsu.core.ui.BaseViewModel
|
|
|
|
import org.koitharu.kotatsu.core.util.ext.firstNotNull
|
|
|
|
import org.koitharu.kotatsu.core.util.ext.firstNotNull
|
|
|
|
import org.koitharu.kotatsu.core.util.ext.firstNotNullOrNull
|
|
|
|
|
|
|
|
import org.koitharu.kotatsu.core.util.ext.require
|
|
|
|
import org.koitharu.kotatsu.core.util.ext.require
|
|
|
|
import org.koitharu.kotatsu.details.domain.DoubleMangaLoadUseCase
|
|
|
|
import org.koitharu.kotatsu.details.domain.DoubleMangaLoadUseCase
|
|
|
|
import org.koitharu.kotatsu.list.ui.model.ListHeader
|
|
|
|
import org.koitharu.kotatsu.list.ui.model.ListHeader
|
|
|
|
@ -29,10 +28,11 @@ class PagesThumbnailsViewModel @Inject constructor(
|
|
|
|
savedStateHandle: SavedStateHandle,
|
|
|
|
savedStateHandle: SavedStateHandle,
|
|
|
|
mangaRepositoryFactory: MangaRepository.Factory,
|
|
|
|
mangaRepositoryFactory: MangaRepository.Factory,
|
|
|
|
private val chaptersLoader: ChaptersLoader,
|
|
|
|
private val chaptersLoader: ChaptersLoader,
|
|
|
|
private val doubleMangaLoadUseCase: DoubleMangaLoadUseCase,
|
|
|
|
doubleMangaLoadUseCase: DoubleMangaLoadUseCase,
|
|
|
|
) : BaseViewModel() {
|
|
|
|
) : BaseViewModel() {
|
|
|
|
|
|
|
|
|
|
|
|
private val currentPageIndex: Int = savedStateHandle[PagesThumbnailsSheet.ARG_CURRENT_PAGE] ?: -1
|
|
|
|
private val currentPageIndex: Int =
|
|
|
|
|
|
|
|
savedStateHandle[PagesThumbnailsSheet.ARG_CURRENT_PAGE] ?: -1
|
|
|
|
private val initialChapterId: Long = savedStateHandle[PagesThumbnailsSheet.ARG_CHAPTER_ID] ?: 0L
|
|
|
|
private val initialChapterId: Long = savedStateHandle[PagesThumbnailsSheet.ARG_CHAPTER_ID] ?: 0L
|
|
|
|
val manga = savedStateHandle.require<ParcelableManga>(PagesThumbnailsSheet.ARG_MANGA).manga
|
|
|
|
val manga = savedStateHandle.require<ParcelableManga>(PagesThumbnailsSheet.ARG_MANGA).manga
|
|
|
|
|
|
|
|
|
|
|
|
@ -46,7 +46,6 @@ class PagesThumbnailsViewModel @Inject constructor(
|
|
|
|
private var loadingJob: Job? = null
|
|
|
|
private var loadingJob: Job? = null
|
|
|
|
private var loadingPrevJob: Job? = null
|
|
|
|
private var loadingPrevJob: Job? = null
|
|
|
|
private var loadingNextJob: Job? = null
|
|
|
|
private var loadingNextJob: Job? = null
|
|
|
|
private var isLoadAboveAllowed = false
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val thumbnails = MutableStateFlow<List<ListModel>>(emptyList())
|
|
|
|
val thumbnails = MutableStateFlow<List<ListModel>>(emptyList())
|
|
|
|
val branch = MutableStateFlow<String?>(null)
|
|
|
|
val branch = MutableStateFlow<String?>(null)
|
|
|
|
@ -60,17 +59,8 @@ class PagesThumbnailsViewModel @Inject constructor(
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fun allowLoadAbove() {
|
|
|
|
|
|
|
|
if (!isLoadAboveAllowed) {
|
|
|
|
|
|
|
|
loadingJob = launchLoadingJob(Dispatchers.Default) {
|
|
|
|
|
|
|
|
isLoadAboveAllowed = true
|
|
|
|
|
|
|
|
updateList()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fun loadPrevChapter() {
|
|
|
|
fun loadPrevChapter() {
|
|
|
|
if (!isLoadAboveAllowed || loadingJob?.isActive == true || loadingPrevJob?.isActive == true) {
|
|
|
|
if (loadingJob?.isActive == true || loadingPrevJob?.isActive == true) {
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
loadingPrevJob = loadPrevNextChapter(isNext = false)
|
|
|
|
loadingPrevJob = loadPrevNextChapter(isNext = false)
|
|
|
|
@ -91,7 +81,6 @@ class PagesThumbnailsViewModel @Inject constructor(
|
|
|
|
|
|
|
|
|
|
|
|
private suspend fun updateList() {
|
|
|
|
private suspend fun updateList() {
|
|
|
|
val snapshot = chaptersLoader.snapshot()
|
|
|
|
val snapshot = chaptersLoader.snapshot()
|
|
|
|
val mangaChapters = mangaDetails.firstNotNullOrNull()?.chapters.orEmpty()
|
|
|
|
|
|
|
|
val pages = buildList(snapshot.size + chaptersLoader.size + 2) {
|
|
|
|
val pages = buildList(snapshot.size + chaptersLoader.size + 2) {
|
|
|
|
var previousChapterId = 0L
|
|
|
|
var previousChapterId = 0L
|
|
|
|
for (page in snapshot) {
|
|
|
|
for (page in snapshot) {
|
|
|
|
|