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

View file

@ -262,7 +262,7 @@ class PagerPageHolder(
context
)) {
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
else {
@ -280,15 +280,15 @@ class PagerPageHolder(
} else {
val imageView = initSubsamplingImageView()
imageView.setImage(ImageSource.inputStream(openStream!!))
imageView.background = ColorDrawable(ThemeUtil.readerBackgroundColor(viewer.config.readerTheme))
background = ColorDrawable(ThemeUtil.readerBackgroundColor(viewer.config.readerTheme))
}
} else {
val imageView = initImageView()
imageView.setImage(openStream!!)
if (viewer.config.readerTheme >= 2 && page.bg != null) {
imageView.background = page.bg
background = page.bg
} else if (viewer.config.readerTheme < 2) {
imageView.background =
background =
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.ViewerChapters
import eu.kanade.tachiyomi.ui.reader.viewer.BaseViewer
import eu.kanade.tachiyomi.util.view.visible
import rx.subscriptions.CompositeSubscription
import timber.log.Timber
import kotlin.math.max
@ -126,10 +127,10 @@ class WebtoonViewer(val activity: ReaderActivity, val isContinuous: Boolean = tr
private fun checkAllowPreload(page: ReaderPage?): Boolean {
// Page is transition page - preload allowed
page == null ?: return true
page ?: return true
// Initial opening - preload allowed
currentPage == null ?: return true
currentPage ?: return true
val nextItem = adapter.items.getOrNull(adapter.items.count() - 1)
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
// 1. Going between pages of same chapter
// 2. Next chapter page
return when (page!!.chapter) {
return when (page.chapter) {
(currentPage as? ReaderPage)?.chapter -> true
nextChapter -> true
else -> false
@ -156,7 +157,6 @@ class WebtoonViewer(val activity: ReaderActivity, val isContinuous: Boolean = tr
*/
override fun destroy() {
super.destroy()
config.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.
*/
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)
// Preload next chapter once we're within the last 3 pages of the current chapter
val inPreloadRange = pages.size - page.number < 3
val pages = page.chapter.pages ?: return
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) {
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)
@ -210,7 +210,7 @@ class WebtoonViewer(val activity: ReaderActivity, val isContinuous: Boolean = tr
Timber.d("Recycler first layout")
val pages = chapters.currChapter.pages ?: return
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:tools="http://schemas.android.com/tools"
android:id="@+id/reader_layout"
@ -7,6 +7,7 @@
android:gravity="center">
<FrameLayout
android:id="@+id/reader_container"
android:layout_width="match_parent"
android:layout_height="match_parent">
@ -34,13 +35,11 @@
</FrameLayout>
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:id="@+id/reader_menu"
<eu.kanade.tachiyomi.ui.reader.ReaderColorFilterView
android:id="@+id/color_overlay"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent"
android:visibility="invisible"
tools:visibility="visible">
android:visibility="gone" />
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appbar"
@ -61,9 +60,7 @@
</com.google.android.material.appbar.AppBarLayout>
<include layout="@layout/reader_chapters_sheet" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
<include layout="@layout/reader_chapters_sheet"/>
<View
android:id="@+id/brightness_overlay"
@ -71,10 +68,4 @@
android:layout_height="match_parent"
android:visibility="gone" />
<eu.kanade.tachiyomi.ui.reader.ReaderColorFilterView
android:id="@+id/color_overlay"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone" />
</FrameLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>