Reader bottom sheet transparency, as well as a half fix for the fullscreen reader bug

This commit is contained in:
Jobobby04 2020-08-22 22:12:59 -04:00
parent 0abee585fc
commit 1240cc5232
4 changed files with 57 additions and 16 deletions

View File

@ -509,7 +509,7 @@ class ReaderActivity : BaseRxActivity<ReaderActivityBinding, ReaderPresenter>()
} }
val loader = page.chapter.pageLoader val loader = page.chapter.pageLoader
if (page.index == exh_currentPage()?.index && loader is HttpPageLoader) { if (page.index == exhCurrentpage()?.index && loader is HttpPageLoader) {
loader.boostPage(page) loader.boostPage(page)
} else { } else {
loader?.retryPage(page) loader?.retryPage(page)
@ -535,7 +535,7 @@ class ReaderActivity : BaseRxActivity<ReaderActivityBinding, ReaderPresenter>()
binding.ehBoostPage.clicks() binding.ehBoostPage.clicks()
.onEach { .onEach {
viewer?.let { _ -> viewer?.let { _ ->
val curPage = exh_currentPage() ?: run { val curPage = exhCurrentpage() ?: run {
toast("This page cannot be boosted (invalid page)!") toast("This page cannot be boosted (invalid page)!")
return@let return@let
} }
@ -581,13 +581,8 @@ class ReaderActivity : BaseRxActivity<ReaderActivityBinding, ReaderPresenter>()
} }
// EXH --> // EXH -->
private fun exh_currentPage(): ReaderPage? { private fun exhCurrentpage(): ReaderPage? {
val currentPage = ( val currentPage = (((viewer as? PagerViewer)?.currentPage ?: (viewer as? WebtoonViewer)?.currentPage) as? ReaderPage)?.index
(
(viewer as? PagerViewer)?.currentPage
?: (viewer as? WebtoonViewer)?.currentPage
) as? ReaderPage
)?.index
return currentPage?.let { presenter.viewerChaptersRelay.value.currChapter.pages?.getOrNull(it) } return currentPage?.let { presenter.viewerChaptersRelay.value.currChapter.pages?.getOrNull(it) }
} }
// EXH <-- // EXH <--
@ -606,6 +601,10 @@ class ReaderActivity : BaseRxActivity<ReaderActivityBinding, ReaderPresenter>()
} }
binding.readerMenu.isVisible = true binding.readerMenu.isVisible = true
if (readerBottomSheetBinding.chaptersBottomSheet.sheetBehavior.isExpanded()) {
readerBottomSheetBinding.chaptersBottomSheet.sheetBehavior?.isHideable = false
}
if (animate) { if (animate) {
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() {

View File

@ -1,9 +1,12 @@
package eu.kanade.tachiyomi.ui.reader.chapter package eu.kanade.tachiyomi.ui.reader.chapter
import android.content.Context import android.content.Context
import android.content.res.ColorStateList
import android.graphics.Color
import android.util.AttributeSet import android.util.AttributeSet
import android.view.View import android.view.View
import android.widget.LinearLayout import android.widget.LinearLayout
import androidx.core.graphics.ColorUtils
import androidx.core.view.isInvisible import androidx.core.view.isInvisible
import androidx.core.view.isVisible import androidx.core.view.isVisible
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
@ -12,15 +15,20 @@ import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.mikepenz.fastadapter.FastAdapter import com.mikepenz.fastadapter.FastAdapter
import com.mikepenz.fastadapter.adapters.ItemAdapter import com.mikepenz.fastadapter.adapters.ItemAdapter
import com.mikepenz.fastadapter.listeners.ClickEventHook import com.mikepenz.fastadapter.listeners.ClickEventHook
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.databinding.ReaderChaptersSheetBinding import eu.kanade.tachiyomi.databinding.ReaderChaptersSheetBinding
import eu.kanade.tachiyomi.ui.reader.ReaderActivity import eu.kanade.tachiyomi.ui.reader.ReaderActivity
import eu.kanade.tachiyomi.ui.reader.ReaderPresenter import eu.kanade.tachiyomi.ui.reader.ReaderPresenter
import eu.kanade.tachiyomi.util.lang.launchUI import eu.kanade.tachiyomi.util.lang.launchUI
import eu.kanade.tachiyomi.util.system.dpToPx import eu.kanade.tachiyomi.util.system.dpToPx
import eu.kanade.tachiyomi.util.system.getResourceColor
import exh.util.collapse import exh.util.collapse
import exh.util.expand import exh.util.expand
import exh.util.isExpanded import exh.util.isExpanded
import kotlin.math.max import kotlin.math.max
import kotlin.math.min
import kotlin.math.roundToInt
import kotlinx.android.synthetic.main.reader_chapters_sheet.view.pill
class ReaderChapterSheet @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : class ReaderChapterSheet @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) :
LinearLayout(context, attrs) { LinearLayout(context, attrs) {
@ -37,6 +45,8 @@ class ReaderChapterSheet @JvmOverloads constructor(context: Context, attrs: Attr
fun setup(activity: ReaderActivity) { fun setup(activity: ReaderActivity) {
presenter = activity.presenter presenter = activity.presenter
binding = activity.readerBottomSheetBinding binding = activity.readerBottomSheetBinding
val fullPrimary = context.getResourceColor(R.attr.colorSurface)
val primary = ColorUtils.setAlphaComponent(fullPrimary, 200)
sheetBehavior = BottomSheetBehavior.from(this) sheetBehavior = BottomSheetBehavior.from(this)
binding.chaptersButton.setOnClickListener { binding.chaptersButton.setOnClickListener {
@ -52,6 +62,7 @@ class ReaderChapterSheet @JvmOverloads constructor(context: Context, attrs: Attr
} }
post { post {
binding.chapterRecycler.alpha = if (sheetBehavior.isExpanded()) 1f else 0f
binding.chapterRecycler.isClickable = sheetBehavior.isExpanded() binding.chapterRecycler.isClickable = sheetBehavior.isExpanded()
binding.chapterRecycler.isFocusable = sheetBehavior.isExpanded() binding.chapterRecycler.isFocusable = sheetBehavior.isExpanded()
} }
@ -59,10 +70,14 @@ class ReaderChapterSheet @JvmOverloads constructor(context: Context, attrs: Attr
sheetBehavior?.addBottomSheetCallback(object : BottomSheetBehavior.BottomSheetCallback() { sheetBehavior?.addBottomSheetCallback(object : BottomSheetBehavior.BottomSheetCallback() {
override fun onSlide(bottomSheet: View, progress: Float) { override fun onSlide(bottomSheet: View, progress: Float) {
val trueProgress = max(progress, 0f) val trueProgress = max(progress, 0f)
binding.pill.alpha = (1 - trueProgress) * 0.25f
binding.chaptersButton.alpha = 1 - trueProgress binding.chaptersButton.alpha = 1 - trueProgress
binding.webviewButton.alpha = trueProgress binding.webviewButton.alpha = trueProgress
binding.webviewButton.isVisible = binding.webviewButton.alpha > 0 binding.webviewButton.isVisible = binding.webviewButton.alpha > 0
binding.chaptersButton.isInvisible = binding.chaptersButton.alpha <= 0 binding.chaptersButton.isInvisible = binding.chaptersButton.alpha <= 0
backgroundTintList =
ColorStateList.valueOf(lerpColor(primary, fullPrimary, trueProgress))
binding.chapterRecycler.alpha = trueProgress
} }
override fun onStateChanged(p0: View, state: Int) { override fun onStateChanged(p0: View, state: Int) {
@ -77,6 +92,7 @@ class ReaderChapterSheet @JvmOverloads constructor(context: Context, attrs: Attr
binding.webviewButton.alpha = 0f binding.webviewButton.alpha = 0f
} }
if (state == BottomSheetBehavior.STATE_EXPANDED) { if (state == BottomSheetBehavior.STATE_EXPANDED) {
binding.chapterRecycler.alpha = 1F
binding.chaptersButton.alpha = 0f binding.chaptersButton.alpha = 0f
binding.webviewButton.alpha = 1f binding.webviewButton.alpha = 1f
} }
@ -120,6 +136,11 @@ class ReaderChapterSheet @JvmOverloads constructor(context: Context, attrs: Attr
} }
}) })
backgroundTintList = ColorStateList.valueOf(
if (!sheetBehavior.isExpanded()) primary
else fullPrimary
)
binding.chapterRecycler.layoutManager = LinearLayoutManager(context) binding.chapterRecycler.layoutManager = LinearLayoutManager(context)
refreshList() refreshList()
} }
@ -138,4 +159,22 @@ class ReaderChapterSheet @JvmOverloads constructor(context: Context, attrs: Attr
) )
} }
} }
fun lerpColor(colorStart: Int, colorEnd: Int, percent: Float): Int {
val perc = (percent * 100).roundToInt()
return Color.argb(
lerpColorCalc(Color.alpha(colorStart), Color.alpha(colorEnd), perc),
lerpColorCalc(Color.red(colorStart), Color.red(colorEnd), perc),
lerpColorCalc(Color.green(colorStart), Color.green(colorEnd), perc),
lerpColorCalc(Color.blue(colorStart), Color.blue(colorEnd), perc)
)
}
fun lerpColorCalc(colorStart: Int, colorEnd: Int, percent: Int): Int {
return (
min(colorStart, colorEnd) * (100 - percent) + max(
colorStart, colorEnd
) * percent
) / 100
}
} }

View File

@ -1,4 +1,4 @@
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" <FrameLayout 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"
@ -42,7 +42,7 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:visibility="gone" /> android:visibility="gone" />
<FrameLayout <androidx.coordinatorlayout.widget.CoordinatorLayout
android:id="@+id/reader_menu" android:id="@+id/reader_menu"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
@ -151,11 +151,11 @@
app:srcCompat="@drawable/ic_keyboard_arrow_down_white_32dp" /> app:srcCompat="@drawable/ic_keyboard_arrow_down_white_32dp" />
</com.google.android.material.appbar.AppBarLayout> </com.google.android.material.appbar.AppBarLayout>
</FrameLayout> <include
android:id="@+id/reader_chapters_sheet"
layout="@layout/reader_chapters_sheet" />
<include </androidx.coordinatorlayout.widget.CoordinatorLayout>
android:id="@+id/reader_chapters_sheet"
layout="@layout/reader_chapters_sheet" />
<View <View
android:id="@+id/brightness_overlay" android:id="@+id/brightness_overlay"
@ -163,4 +163,4 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:visibility="gone" /> android:visibility="gone" />
</androidx.coordinatorlayout.widget.CoordinatorLayout> </FrameLayout>

View File

@ -7,6 +7,7 @@
android:layout_height="300dp" android:layout_height="300dp"
android:background="?attr/colorSurface" android:background="?attr/colorSurface"
android:orientation="vertical" android:orientation="vertical"
android:alpha="1"
app:behavior_peekHeight="?attr/actionBarSize" app:behavior_peekHeight="?attr/actionBarSize"
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior"> app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior">
@ -22,6 +23,7 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="5dp" android:layout_marginTop="5dp"
android:alpha="0.25"
android:contentDescription="@string/action_sort_drag_and_drop" android:contentDescription="@string/action_sort_drag_and_drop"
android:src="@drawable/ic_drag_pill_24dp" android:src="@drawable/ic_drag_pill_24dp"
android:tint="?attr/colorOnSurface" android:tint="?attr/colorOnSurface"
@ -84,5 +86,6 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="?attr/colorSurface" android:background="?attr/colorSurface"
android:clipToPadding="false" android:clipToPadding="false"
android:alpha="0"
tools:listitem="@layout/reader_chapter_item" /> tools:listitem="@layout/reader_chapter_item" />
</eu.kanade.tachiyomi.ui.reader.chapter.ReaderChapterSheet> </eu.kanade.tachiyomi.ui.reader.chapter.ReaderChapterSheet>