mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-19 03:39:18 +01:00
Several reader fixes
This commit is contained in:
parent
18f89cc341
commit
116f7d1c4a
@ -22,6 +22,7 @@ import eu.kanade.tachiyomi.ui.base.activity.BaseRxActivity
|
|||||||
import eu.kanade.tachiyomi.ui.reader.ReaderPresenter.SetAsCoverResult.AddToLibraryFirst
|
import eu.kanade.tachiyomi.ui.reader.ReaderPresenter.SetAsCoverResult.AddToLibraryFirst
|
||||||
import eu.kanade.tachiyomi.ui.reader.ReaderPresenter.SetAsCoverResult.Error
|
import eu.kanade.tachiyomi.ui.reader.ReaderPresenter.SetAsCoverResult.Error
|
||||||
import eu.kanade.tachiyomi.ui.reader.ReaderPresenter.SetAsCoverResult.Success
|
import eu.kanade.tachiyomi.ui.reader.ReaderPresenter.SetAsCoverResult.Success
|
||||||
|
import eu.kanade.tachiyomi.ui.reader.model.ReaderChapter
|
||||||
import eu.kanade.tachiyomi.ui.reader.model.ReaderPage
|
import eu.kanade.tachiyomi.ui.reader.model.ReaderPage
|
||||||
import eu.kanade.tachiyomi.ui.reader.model.ViewerChapters
|
import eu.kanade.tachiyomi.ui.reader.model.ViewerChapters
|
||||||
import eu.kanade.tachiyomi.ui.reader.viewer.BaseViewer
|
import eu.kanade.tachiyomi.ui.reader.viewer.BaseViewer
|
||||||
@ -429,20 +430,11 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called from the viewer when the next chapter should be preloaded. It should be called when
|
* Called from the viewer when the given [chapter] should be preloaded. It should be called when
|
||||||
* the viewer is reaching the end of the chapter or the transition page is active.
|
* the viewer is reaching the beginning or end of a chapter or the transition page is active.
|
||||||
*/
|
*/
|
||||||
fun requestPreloadNextChapter() {
|
fun requestPreloadChapter(chapter: ReaderChapter) {
|
||||||
presenter.preloadNextChapter()
|
presenter.preloadChapter(chapter)
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Called from the viewer when the previous chapter should be preloaded. It should be called
|
|
||||||
* when the viewer is going backwards and reaching the beginning of the chapter or the
|
|
||||||
* transition page is active.
|
|
||||||
*/
|
|
||||||
fun requestPreloadPreviousChapter() {
|
|
||||||
presenter.preloadPreviousChapter()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -43,7 +43,7 @@ class ReaderPresenter(
|
|||||||
private val sourceManager: SourceManager = Injekt.get(),
|
private val sourceManager: SourceManager = Injekt.get(),
|
||||||
private val downloadManager: DownloadManager = Injekt.get(),
|
private val downloadManager: DownloadManager = Injekt.get(),
|
||||||
private val coverCache: CoverCache = Injekt.get(),
|
private val coverCache: CoverCache = Injekt.get(),
|
||||||
val preferences: PreferencesHelper = Injekt.get()
|
private val preferences: PreferencesHelper = Injekt.get()
|
||||||
) : BasePresenter<ReaderActivity>() {
|
) : BasePresenter<ReaderActivity>() {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -331,19 +331,10 @@ class ReaderPresenter(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called from the activity to preload the next chapter.
|
* Called from the activity to preload the given [chapter].
|
||||||
*/
|
*/
|
||||||
fun preloadNextChapter() {
|
fun preloadChapter(chapter: ReaderChapter) {
|
||||||
val nextChapter = viewerChaptersRelay.value?.nextChapter ?: return
|
preload(chapter)
|
||||||
preload(nextChapter)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Called from the activity to preload the previous chapter.
|
|
||||||
*/
|
|
||||||
fun preloadPreviousChapter() {
|
|
||||||
val prevChapter = viewerChaptersRelay.value?.prevChapter ?: return
|
|
||||||
preload(prevChapter)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -62,8 +62,12 @@ class HttpPageLoader(
|
|||||||
// Cache current page list progress for online chapters to allow a faster reopen
|
// Cache current page list progress for online chapters to allow a faster reopen
|
||||||
val pages = chapter.pages
|
val pages = chapter.pages
|
||||||
if (pages != null) {
|
if (pages != null) {
|
||||||
// TODO check compatibility with ReaderPage
|
Completable
|
||||||
Completable.fromAction { chapterCache.putPageListToCache(chapter.chapter, pages) }
|
.fromAction {
|
||||||
|
// Convert to pages without reader information
|
||||||
|
val pagesToSave = pages.map { Page(it.index, it.url, it.imageUrl) }
|
||||||
|
chapterCache.putPageListToCache(chapter.chapter, pagesToSave)
|
||||||
|
}
|
||||||
.onErrorComplete()
|
.onErrorComplete()
|
||||||
.subscribeOn(Schedulers.io())
|
.subscribeOn(Schedulers.io())
|
||||||
.subscribe()
|
.subscribe()
|
||||||
|
@ -2,7 +2,6 @@ package eu.kanade.tachiyomi.ui.reader.model
|
|||||||
|
|
||||||
import com.jakewharton.rxrelay.BehaviorRelay
|
import com.jakewharton.rxrelay.BehaviorRelay
|
||||||
import eu.kanade.tachiyomi.data.database.models.Chapter
|
import eu.kanade.tachiyomi.data.database.models.Chapter
|
||||||
import eu.kanade.tachiyomi.ui.reader.loader.DownloadPageLoader
|
|
||||||
import eu.kanade.tachiyomi.ui.reader.loader.PageLoader
|
import eu.kanade.tachiyomi.ui.reader.loader.PageLoader
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
|
||||||
@ -26,10 +25,6 @@ data class ReaderChapter(val chapter: Chapter) {
|
|||||||
|
|
||||||
var requestedPage: Int = 0
|
var requestedPage: Int = 0
|
||||||
|
|
||||||
val isDownloaded
|
|
||||||
get() = pageLoader is DownloadPageLoader
|
|
||||||
|
|
||||||
|
|
||||||
var references = 0
|
var references = 0
|
||||||
private set
|
private set
|
||||||
|
|
||||||
|
@ -168,10 +168,9 @@ class PagerTransitionHolder(
|
|||||||
wrapContent()
|
wrapContent()
|
||||||
setText(R.string.action_retry)
|
setText(R.string.action_retry)
|
||||||
setOnClickListener {
|
setOnClickListener {
|
||||||
if (transition is ChapterTransition.Next) {
|
val toChapter = transition.to
|
||||||
viewer.activity.requestPreloadNextChapter()
|
if (toChapter != null) {
|
||||||
} else {
|
viewer.activity.requestPreloadChapter(toChapter)
|
||||||
viewer.activity.requestPreloadPreviousChapter()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -74,7 +74,7 @@ abstract class PagerViewer(val activity: ReaderActivity) : BaseViewer {
|
|||||||
if (page != null && currentPage != page) {
|
if (page != null && currentPage != page) {
|
||||||
currentPage = page
|
currentPage = page
|
||||||
when (page) {
|
when (page) {
|
||||||
is ReaderPage -> onPageSelected(page)
|
is ReaderPage -> onPageSelected(page, position)
|
||||||
is ChapterTransition -> onTransitionSelected(page)
|
is ChapterTransition -> onTransitionSelected(page)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -128,14 +128,17 @@ abstract class PagerViewer(val activity: ReaderActivity) : BaseViewer {
|
|||||||
* Called from the ViewPager listener when a [page] is marked as active. It notifies the
|
* Called from the ViewPager listener when a [page] is marked as active. It notifies the
|
||||||
* activity of the change and requests the preload of the next chapter if this is the last page.
|
* activity of the change and requests the preload of the next chapter if this is the last page.
|
||||||
*/
|
*/
|
||||||
private fun onPageSelected(page: ReaderPage) {
|
private fun onPageSelected(page: ReaderPage, position: Int) {
|
||||||
val pages = page.chapter.pages!! // Won't be null because it's the loaded chapter
|
val pages = page.chapter.pages!! // Won't be null because it's the loaded chapter
|
||||||
Timber.d("onPageSelected: ${page.number}/${pages.size}")
|
Timber.d("onPageSelected: ${page.number}/${pages.size}")
|
||||||
activity.onPageSelected(page)
|
activity.onPageSelected(page)
|
||||||
|
|
||||||
if (page === pages.last()) {
|
if (page === pages.last()) {
|
||||||
Timber.d("Request preload next chapter because we're at the last page")
|
Timber.d("Request preload next chapter because we're at the last page")
|
||||||
activity.requestPreloadNextChapter()
|
val transition = adapter.items.getOrNull(position + 1) as? ChapterTransition.Next
|
||||||
|
if (transition?.to != null) {
|
||||||
|
activity.requestPreloadChapter(transition.to)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -145,15 +148,10 @@ abstract class PagerViewer(val activity: ReaderActivity) : BaseViewer {
|
|||||||
*/
|
*/
|
||||||
private fun onTransitionSelected(transition: ChapterTransition) {
|
private fun onTransitionSelected(transition: ChapterTransition) {
|
||||||
Timber.d("onTransitionSelected: $transition")
|
Timber.d("onTransitionSelected: $transition")
|
||||||
when (transition) {
|
val toChapter = transition.to
|
||||||
is ChapterTransition.Prev -> {
|
if (toChapter != null) {
|
||||||
Timber.d("Request preload previous chapter because we're on the transition")
|
Timber.d("Request preload destination chapter because we're on the transition")
|
||||||
activity.requestPreloadPreviousChapter()
|
activity.requestPreloadChapter(toChapter)
|
||||||
}
|
|
||||||
is ChapterTransition.Next -> {
|
|
||||||
Timber.d("Request preload next chapter because we're on the transition")
|
|
||||||
activity.requestPreloadNextChapter()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -180,10 +180,9 @@ class WebtoonTransitionHolder(
|
|||||||
wrapContent()
|
wrapContent()
|
||||||
setText(R.string.action_retry)
|
setText(R.string.action_retry)
|
||||||
setOnClickListener {
|
setOnClickListener {
|
||||||
if (transition is ChapterTransition.Next) {
|
val toChapter = transition.to
|
||||||
viewer.activity.requestPreloadNextChapter()
|
if (toChapter != null) {
|
||||||
} else {
|
viewer.activity.requestPreloadChapter(toChapter)
|
||||||
viewer.activity.requestPreloadPreviousChapter()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -68,12 +68,12 @@ class WebtoonViewer(val activity: ReaderActivity) : BaseViewer {
|
|||||||
recycler.adapter = adapter
|
recycler.adapter = adapter
|
||||||
recycler.addOnScrollListener(object : RecyclerView.OnScrollListener() {
|
recycler.addOnScrollListener(object : RecyclerView.OnScrollListener() {
|
||||||
override fun onScrolled(recyclerView: RecyclerView?, dx: Int, dy: Int) {
|
override fun onScrolled(recyclerView: RecyclerView?, dx: Int, dy: Int) {
|
||||||
val index = layoutManager.findLastEndVisibleItemPosition()
|
val position = layoutManager.findLastEndVisibleItemPosition()
|
||||||
val item = adapter.items.getOrNull(index)
|
val item = adapter.items.getOrNull(position)
|
||||||
if (item != null && currentPage != item) {
|
if (item != null && currentPage != item) {
|
||||||
currentPage = item
|
currentPage = item
|
||||||
when (item) {
|
when (item) {
|
||||||
is ReaderPage -> onPageSelected(item)
|
is ReaderPage -> onPageSelected(item, position)
|
||||||
is ChapterTransition -> onTransitionSelected(item)
|
is ChapterTransition -> onTransitionSelected(item)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -81,8 +81,8 @@ class WebtoonViewer(val activity: ReaderActivity) : BaseViewer {
|
|||||||
if (dy < 0) {
|
if (dy < 0) {
|
||||||
val firstIndex = layoutManager.findFirstVisibleItemPosition()
|
val firstIndex = layoutManager.findFirstVisibleItemPosition()
|
||||||
val firstItem = adapter.items.getOrNull(firstIndex)
|
val firstItem = adapter.items.getOrNull(firstIndex)
|
||||||
if (firstItem is ChapterTransition.Prev) {
|
if (firstItem is ChapterTransition.Prev && firstItem.to != null) {
|
||||||
activity.requestPreloadPreviousChapter()
|
activity.requestPreloadChapter(firstItem.to)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -125,29 +125,33 @@ class WebtoonViewer(val activity: ReaderActivity) : BaseViewer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called from the ViewPager listener when a [page] is marked as active. It notifies the
|
* Called from the RecyclerView listener when a [page] is marked as active. It notifies the
|
||||||
* activity of the change and requests the preload of the next chapter if this is the last page.
|
* activity of the change and requests the preload of the next chapter if this is the last page.
|
||||||
*/
|
*/
|
||||||
private fun onPageSelected(page: ReaderPage) {
|
private fun onPageSelected(page: ReaderPage, position: Int) {
|
||||||
val pages = page.chapter.pages!! // Won't be null because it's the loaded chapter
|
val pages = page.chapter.pages!! // Won't be null because it's the loaded chapter
|
||||||
Timber.d("onPageSelected: ${page.number}/${pages.size}")
|
Timber.d("onPageSelected: ${page.number}/${pages.size}")
|
||||||
activity.onPageSelected(page)
|
activity.onPageSelected(page)
|
||||||
|
|
||||||
if (page === pages.last()) {
|
if (page === pages.last()) {
|
||||||
Timber.d("Request preload next chapter because we're at the last page")
|
Timber.d("Request preload next chapter because we're at the last page")
|
||||||
activity.requestPreloadNextChapter()
|
val transition = adapter.items.getOrNull(position + 1) as? ChapterTransition.Next
|
||||||
|
if (transition?.to != null) {
|
||||||
|
activity.requestPreloadChapter(transition.to)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called from the ViewPager listener when a [transition] is marked as active. It request the
|
* Called from the RecyclerView listener when a [transition] is marked as active. It request the
|
||||||
* preload of the destination chapter of the transition.
|
* preload of the destination chapter of the transition.
|
||||||
*/
|
*/
|
||||||
private fun onTransitionSelected(transition: ChapterTransition) {
|
private fun onTransitionSelected(transition: ChapterTransition) {
|
||||||
Timber.d("onTransitionSelected: $transition")
|
Timber.d("onTransitionSelected: $transition")
|
||||||
if (transition is ChapterTransition.Prev) {
|
val toChapter = transition.to
|
||||||
Timber.d("Request preload previous chapter because we're on the transition")
|
if (toChapter != null) {
|
||||||
activity.requestPreloadPreviousChapter()
|
Timber.d("Request preload destination chapter because we're on the transition")
|
||||||
|
activity.requestPreloadChapter(toChapter)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,16 +6,12 @@ import java.net.URLConnection
|
|||||||
object ImageUtil {
|
object ImageUtil {
|
||||||
|
|
||||||
fun isImage(name: String, openStream: (() -> InputStream)? = null): Boolean {
|
fun isImage(name: String, openStream: (() -> InputStream)? = null): Boolean {
|
||||||
try {
|
val contentType = try {
|
||||||
val guessedMime = URLConnection.guessContentTypeFromName(name)
|
URLConnection.guessContentTypeFromName(name)
|
||||||
if (guessedMime.startsWith("image/")) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
/* Ignore error */
|
null
|
||||||
}
|
} ?: openStream?.let { findImageType(it)?.mime }
|
||||||
|
return contentType?.startsWith("image/") ?: false
|
||||||
return openStream?.let { findImageType(it) } != null
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun findImageType(openStream: () -> InputStream): ImageType? {
|
fun findImageType(openStream: () -> InputStream): ImageType? {
|
||||||
|
Loading…
Reference in New Issue
Block a user