mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-13 08:47:32 +01:00
Load next/prev chapter depending on the sorting method
This commit is contained in:
parent
e885469504
commit
af0cf9e52d
2 changed files with 37 additions and 6 deletions
|
@ -53,6 +53,18 @@ interface ChapterQueries : DbProvider {
|
||||||
.prepare()
|
.prepare()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getNextChapterBySource(chapter: Chapter) = db.get()
|
||||||
|
.`object`(Chapter::class.java)
|
||||||
|
.withQuery(Query.builder()
|
||||||
|
.table(ChapterTable.TABLE)
|
||||||
|
.where("""${ChapterTable.COL_MANGA_ID} = ? AND
|
||||||
|
${ChapterTable.COL_SOURCE_ORDER} < ?""")
|
||||||
|
.whereArgs(chapter.manga_id, chapter.source_order)
|
||||||
|
.orderBy("${ChapterTable.COL_SOURCE_ORDER} DESC")
|
||||||
|
.limit(1)
|
||||||
|
.build())
|
||||||
|
.prepare()
|
||||||
|
|
||||||
fun getPreviousChapter(chapter: Chapter): PreparedGetObject<Chapter> {
|
fun getPreviousChapter(chapter: Chapter): PreparedGetObject<Chapter> {
|
||||||
// Add a delta to the chapter number, because binary decimal representation
|
// Add a delta to the chapter number, because binary decimal representation
|
||||||
// can retrieve the same chapter again
|
// can retrieve the same chapter again
|
||||||
|
@ -65,12 +77,24 @@ interface ChapterQueries : DbProvider {
|
||||||
"${ChapterTable.COL_CHAPTER_NUMBER} < ? AND " +
|
"${ChapterTable.COL_CHAPTER_NUMBER} < ? AND " +
|
||||||
"${ChapterTable.COL_CHAPTER_NUMBER} >= ?")
|
"${ChapterTable.COL_CHAPTER_NUMBER} >= ?")
|
||||||
.whereArgs(chapter.manga_id, chapterNumber, chapterNumber - 1)
|
.whereArgs(chapter.manga_id, chapterNumber, chapterNumber - 1)
|
||||||
.orderBy(ChapterTable.COL_CHAPTER_NUMBER + " DESC")
|
.orderBy("${ChapterTable.COL_CHAPTER_NUMBER} DESC")
|
||||||
.limit(1)
|
.limit(1)
|
||||||
.build())
|
.build())
|
||||||
.prepare()
|
.prepare()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getPreviousChapterBySource(chapter: Chapter) = db.get()
|
||||||
|
.`object`(Chapter::class.java)
|
||||||
|
.withQuery(Query.builder()
|
||||||
|
.table(ChapterTable.TABLE)
|
||||||
|
.where("""${ChapterTable.COL_MANGA_ID} = ? AND
|
||||||
|
${ChapterTable.COL_SOURCE_ORDER} > ?""")
|
||||||
|
.whereArgs(chapter.manga_id, chapter.source_order)
|
||||||
|
.orderBy(ChapterTable.COL_SOURCE_ORDER)
|
||||||
|
.limit(1)
|
||||||
|
.build())
|
||||||
|
.prepare()
|
||||||
|
|
||||||
fun getNextUnreadChapter(manga: Manga) = db.get()
|
fun getNextUnreadChapter(manga: Manga) = db.get()
|
||||||
.`object`(Chapter::class.java)
|
.`object`(Chapter::class.java)
|
||||||
.withQuery(Query.builder()
|
.withQuery(Query.builder()
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package eu.kanade.tachiyomi.ui.reader
|
package eu.kanade.tachiyomi.ui.reader
|
||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.util.Pair
|
|
||||||
import eu.kanade.tachiyomi.data.cache.ChapterCache
|
import eu.kanade.tachiyomi.data.cache.ChapterCache
|
||||||
import eu.kanade.tachiyomi.data.database.DatabaseHelper
|
import eu.kanade.tachiyomi.data.database.DatabaseHelper
|
||||||
import eu.kanade.tachiyomi.data.database.models.Chapter
|
import eu.kanade.tachiyomi.data.database.models.Chapter
|
||||||
|
@ -180,10 +179,8 @@ class ReaderPresenter : BasePresenter<ReaderActivity>() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getAdjacentChaptersObservable(): Observable<Pair<Chapter, Chapter>> {
|
private fun getAdjacentChaptersObservable(): Observable<Pair<Chapter, Chapter>> {
|
||||||
return Observable.zip(
|
val strategy = getAdjacentChaptersStrategy()
|
||||||
db.getPreviousChapter(chapter).asRxObservable().take(1),
|
return Observable.zip(strategy.first, strategy.second) { prev, next -> Pair(prev, next) }
|
||||||
db.getNextChapter(chapter).asRxObservable().take(1),
|
|
||||||
{ a, b -> Pair.create(a, b) })
|
|
||||||
.doOnNext { pair ->
|
.doOnNext { pair ->
|
||||||
previousChapter = pair.first
|
previousChapter = pair.first
|
||||||
nextChapter = pair.second
|
nextChapter = pair.second
|
||||||
|
@ -191,6 +188,16 @@ class ReaderPresenter : BasePresenter<ReaderActivity>() {
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun getAdjacentChaptersStrategy() = when (manga.sorting) {
|
||||||
|
Manga.SORTING_NUMBER -> Pair(
|
||||||
|
db.getPreviousChapter(chapter).asRxObservable().take(1),
|
||||||
|
db.getNextChapter(chapter).asRxObservable().take(1))
|
||||||
|
Manga.SORTING_SOURCE -> Pair(
|
||||||
|
db.getPreviousChapterBySource(chapter).asRxObservable().take(1),
|
||||||
|
db.getNextChapterBySource(chapter).asRxObservable().take(1))
|
||||||
|
else -> throw AssertionError("Unknown sorting method")
|
||||||
|
}
|
||||||
|
|
||||||
// Preload the first pages of the next chapter. Only for non seamless mode
|
// Preload the first pages of the next chapter. Only for non seamless mode
|
||||||
private fun getPreloadNextChapterObservable(): Observable<Page> {
|
private fun getPreloadNextChapterObservable(): Observable<Page> {
|
||||||
return source.getCachedPageListOrPullFromNetwork(nextChapter!!.url)
|
return source.getCachedPageListOrPullFromNetwork(nextChapter!!.url)
|
||||||
|
|
Loading…
Reference in a new issue