Skip to content

Commit

Permalink
Properly handle EHentai browse duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
jobobby04 committed Jan 16, 2022
1 parent 18a119e commit e8100fc
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import eu.kanade.tachiyomi.util.system.logcat
import exh.log.xLogE
import exh.savedsearches.EXHSavedSearch
import exh.savedsearches.JsonSavedSearch
import exh.source.isEhBasedSource
import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.asFlow
import kotlinx.coroutines.flow.catch
Expand Down Expand Up @@ -342,7 +343,13 @@ open class BrowseSourcePresenter(
}

open fun createPager(query: String, filters: FilterList): Pager {
return SourcePager(source, query, filters)
// SY -->
return if (source.isEhBasedSource()) {
EHentaiPager(source, query, filters)
} else {
SourcePager(source, query, filters)
}
// SY <--
}

// SY -->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package eu.kanade.tachiyomi.ui.browse.source.browse

import eu.kanade.tachiyomi.source.CatalogueSource
import eu.kanade.tachiyomi.source.model.FilterList
import eu.kanade.tachiyomi.source.model.MetadataMangasPage
import eu.kanade.tachiyomi.util.lang.awaitSingle

open class EHentaiPager(source: CatalogueSource, query: String, filters: FilterList) : SourcePager(source, query, filters) {

private var lastMangaLink: String? = null

override suspend fun requestNextPage() {
val page = currentPage
val lastMangaLink = lastMangaLink

val observable = if (query.isBlank() && filters.isEmpty()) {
source.fetchPopularManga(page)
} else {
source.fetchSearchManga(page, query, filters)
}

val mangasPage = observable.awaitSingle()

mangasPage.mangas.lastOrNull()?.let {
this.lastMangaLink = it.url
}
if (lastMangaLink != null) {
val index = mangasPage.mangas.indexOfFirst { it.url == lastMangaLink }
if (index != -1) {
val lastIndex = mangasPage.mangas.size
val startIndex = (index + 1).coerceAtMost(mangasPage.mangas.lastIndex)
onPageReceived(
if (mangasPage is MetadataMangasPage) {
mangasPage.copy(
mangas = mangasPage.mangas.subList(startIndex, lastIndex),
mangasMetadata = mangasPage.mangasMetadata.subList(startIndex, lastIndex)
)
} else {
mangasPage.copy(
mangas = mangasPage.mangas.subList(startIndex, lastIndex)
)
}
)
} else {
onPageReceived(mangasPage)
}
} else {
onPageReceived(mangasPage)
}
}
}

0 comments on commit e8100fc

Please sign in to comment.