Fixed blank pages in reader

There's a few refactoring changes here, but the actual fix is the reader_activity class and xml
This commit is contained in:
Jay 2020-05-03 12:38:00 -04:00
parent c07ed374e8
commit 379f27b01e
4 changed files with 25 additions and 34 deletions

View File

@ -336,7 +336,7 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>(),
chapters_bottom_sheet.sheetBehavior?.isHideable = !menuVisible chapters_bottom_sheet.sheetBehavior?.isHideable = !menuVisible
if (!menuVisible) if (!menuVisible)
chapters_bottom_sheet.sheetBehavior?.state = BottomSheetBehavior.STATE_HIDDEN chapters_bottom_sheet.sheetBehavior?.state = BottomSheetBehavior.STATE_HIDDEN
reader_menu.doOnApplyWindowInsets { v, insets, _ -> reader_layout.doOnApplyWindowInsets { v, insets, _ ->
sheetManageNavColor = when { sheetManageNavColor = when {
insets.isBottomTappable() -> { insets.isBottomTappable() -> {
window.navigationBarColor = Color.TRANSPARENT window.navigationBarColor = Color.TRANSPARENT
@ -372,7 +372,7 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>(),
if (visible) { if (visible) {
snackbar?.dismiss() snackbar?.dismiss()
systemUi?.show() systemUi?.show()
reader_menu.visibility = View.VISIBLE toolbar.visibility = View.VISIBLE
if (chapters_bottom_sheet.sheetBehavior?.state == BottomSheetBehavior.STATE_EXPANDED) { if (chapters_bottom_sheet.sheetBehavior?.state == BottomSheetBehavior.STATE_EXPANDED) {
chapters_bottom_sheet.sheetBehavior?.isHideable = false chapters_bottom_sheet.sheetBehavior?.isHideable = false
@ -399,14 +399,14 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>(),
val toolbarAnimation = AnimationUtils.loadAnimation(this, R.anim.exit_to_top) val toolbarAnimation = AnimationUtils.loadAnimation(this, R.anim.exit_to_top)
toolbarAnimation.setAnimationListener(object : SimpleAnimationListener() { toolbarAnimation.setAnimationListener(object : SimpleAnimationListener() {
override fun onAnimationEnd(animation: Animation) { override fun onAnimationEnd(animation: Animation) {
reader_menu.visibility = View.GONE toolbar.visibility = View.GONE
} }
}) })
appbar.startAnimation(toolbarAnimation) appbar.startAnimation(toolbarAnimation)
BottomSheetBehavior.from(chapters_bottom_sheet).isHideable = true BottomSheetBehavior.from(chapters_bottom_sheet).isHideable = true
BottomSheetBehavior.from(chapters_bottom_sheet).state = BottomSheetBehavior.STATE_HIDDEN BottomSheetBehavior.from(chapters_bottom_sheet).state = BottomSheetBehavior.STATE_HIDDEN
} else { } else {
reader_menu.visibility = View.GONE toolbar.visibility = View.GONE
} }
} }
menuStickyVisible = false menuStickyVisible = false
@ -661,7 +661,7 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>(),
} }
} }
if (sheetManageNavColor) window.navigationBarColor = getResourceColor(R.attr.colorSecondary) if (sheetManageNavColor) window.navigationBarColor = getResourceColor(R.attr.colorSecondary)
reader_menu.visibility = View.VISIBLE toolbar.visibility = View.VISIBLE
val toolbarAnimation = AnimationUtils.loadAnimation(this, R.anim.enter_from_top) val toolbarAnimation = AnimationUtils.loadAnimation(this, R.anim.enter_from_top)
toolbarAnimation.setAnimationListener(object : SimpleAnimationListener() { toolbarAnimation.setAnimationListener(object : SimpleAnimationListener() {
override fun onAnimationStart(animation: Animation) { override fun onAnimationStart(animation: Animation) {

View File

@ -262,7 +262,7 @@ class PagerPageHolder(
context context
)) { )) {
imageView.setImage(ImageSource.inputStream(openStream!!)) imageView.setImage(ImageSource.inputStream(openStream!!))
imageView.background = page.bg background = page.bg
} }
// if the user switches to automatic when pages are already cached, the bg needs to be loaded // if the user switches to automatic when pages are already cached, the bg needs to be loaded
else { else {
@ -280,15 +280,15 @@ class PagerPageHolder(
} else { } else {
val imageView = initSubsamplingImageView() val imageView = initSubsamplingImageView()
imageView.setImage(ImageSource.inputStream(openStream!!)) imageView.setImage(ImageSource.inputStream(openStream!!))
imageView.background = ColorDrawable(ThemeUtil.readerBackgroundColor(viewer.config.readerTheme)) background = ColorDrawable(ThemeUtil.readerBackgroundColor(viewer.config.readerTheme))
} }
} else { } else {
val imageView = initImageView() val imageView = initImageView()
imageView.setImage(openStream!!) imageView.setImage(openStream!!)
if (viewer.config.readerTheme >= 2 && page.bg != null) { if (viewer.config.readerTheme >= 2 && page.bg != null) {
imageView.background = page.bg background = page.bg
} else if (viewer.config.readerTheme < 2) { } else if (viewer.config.readerTheme < 2) {
imageView.background = background =
ColorDrawable(ThemeUtil.readerBackgroundColor(viewer.config.readerTheme)) ColorDrawable(ThemeUtil.readerBackgroundColor(viewer.config.readerTheme))
} }
} }

View File

@ -12,6 +12,7 @@ import eu.kanade.tachiyomi.ui.reader.model.ChapterTransition
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
import eu.kanade.tachiyomi.util.view.visible
import rx.subscriptions.CompositeSubscription import rx.subscriptions.CompositeSubscription
import timber.log.Timber import timber.log.Timber
import kotlin.math.max import kotlin.math.max
@ -126,10 +127,10 @@ class WebtoonViewer(val activity: ReaderActivity, val isContinuous: Boolean = tr
private fun checkAllowPreload(page: ReaderPage?): Boolean { private fun checkAllowPreload(page: ReaderPage?): Boolean {
// Page is transition page - preload allowed // Page is transition page - preload allowed
page == null ?: return true page ?: return true
// Initial opening - preload allowed // Initial opening - preload allowed
currentPage == null ?: return true currentPage ?: return true
val nextItem = adapter.items.getOrNull(adapter.items.count() - 1) val nextItem = adapter.items.getOrNull(adapter.items.count() - 1)
val nextChapter = (nextItem as? ChapterTransition.Next)?.to ?: (nextItem as? ReaderPage)?.chapter val nextChapter = (nextItem as? ChapterTransition.Next)?.to ?: (nextItem as? ReaderPage)?.chapter
@ -137,7 +138,7 @@ class WebtoonViewer(val activity: ReaderActivity, val isContinuous: Boolean = tr
// Allow preload for // Allow preload for
// 1. Going between pages of same chapter // 1. Going between pages of same chapter
// 2. Next chapter page // 2. Next chapter page
return when (page!!.chapter) { return when (page.chapter) {
(currentPage as? ReaderPage)?.chapter -> true (currentPage as? ReaderPage)?.chapter -> true
nextChapter -> true nextChapter -> true
else -> false else -> false
@ -156,7 +157,6 @@ class WebtoonViewer(val activity: ReaderActivity, val isContinuous: Boolean = tr
*/ */
override fun destroy() { override fun destroy() {
super.destroy() super.destroy()
config.unsubscribe()
subscriptions.unsubscribe() subscriptions.unsubscribe()
} }
@ -165,12 +165,12 @@ class WebtoonViewer(val activity: ReaderActivity, val isContinuous: Boolean = tr
* 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, allowPreload: Boolean) { private fun onPageSelected(page: ReaderPage, allowPreload: Boolean) {
val pages = page.chapter.pages!! // Won't be null because it's the loaded chapter
Timber.d("onPageSelected: ${page.number}/${pages.size}")
activity.onPageSelected(page) activity.onPageSelected(page)
// Preload next chapter once we're within the last 3 pages of the current chapter val pages = page.chapter.pages ?: return
val inPreloadRange = pages.size - page.number < 3 Timber.d("onReaderPageSelected: ${page.number}/${pages.size}")
// Preload next chapter once we're within the last 5 pages of the current chapter
val inPreloadRange = pages.size - page.number < 5
if (inPreloadRange && allowPreload && page.chapter == adapter.currentChapter) { if (inPreloadRange && allowPreload && page.chapter == adapter.currentChapter) {
Timber.d("Request preload next chapter because we're at page ${page.number} of ${pages.size}") Timber.d("Request preload next chapter because we're at page ${page.number} of ${pages.size}")
val nextItem = adapter.items.getOrNull(adapter.items.size - 1) val nextItem = adapter.items.getOrNull(adapter.items.size - 1)
@ -210,7 +210,7 @@ class WebtoonViewer(val activity: ReaderActivity, val isContinuous: Boolean = tr
Timber.d("Recycler first layout") Timber.d("Recycler first layout")
val pages = chapters.currChapter.pages ?: return val pages = chapters.currChapter.pages ?: return
moveToPage(pages[chapters.currChapter.requestedPage]) moveToPage(pages[chapters.currChapter.requestedPage])
recycler.visibility = View.VISIBLE recycler.visible()
} }
} }

View File

@ -1,4 +1,4 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" <androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/reader_layout" android:id="@+id/reader_layout"
@ -7,6 +7,7 @@
android:gravity="center"> android:gravity="center">
<FrameLayout <FrameLayout
android:id="@+id/reader_container"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
@ -34,13 +35,11 @@
</FrameLayout> </FrameLayout>
<androidx.coordinatorlayout.widget.CoordinatorLayout <eu.kanade.tachiyomi.ui.reader.ReaderColorFilterView
android:id="@+id/reader_menu" android:id="@+id/color_overlay"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="@android:color/transparent" android:visibility="gone" />
android:visibility="invisible"
tools:visibility="visible">
<com.google.android.material.appbar.AppBarLayout <com.google.android.material.appbar.AppBarLayout
android:id="@+id/appbar" android:id="@+id/appbar"
@ -63,18 +62,10 @@
<include layout="@layout/reader_chapters_sheet"/> <include layout="@layout/reader_chapters_sheet"/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
<View <View
android:id="@+id/brightness_overlay" android:id="@+id/brightness_overlay"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:visibility="gone" /> android:visibility="gone" />
<eu.kanade.tachiyomi.ui.reader.ReaderColorFilterView </androidx.coordinatorlayout.widget.CoordinatorLayout>
android:id="@+id/color_overlay"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone" />
</FrameLayout>