Use elevated overlay on reader menu (#6347)

This commit is contained in:
Ivan Iskandar
2021-12-17 10:57:31 +07:00
committed by GitHub
parent 0671b530ba
commit 6b52fc1e2d
6 changed files with 36 additions and 43 deletions

View File

@ -13,7 +13,7 @@ import android.graphics.Color
import android.graphics.ColorMatrix
import android.graphics.ColorMatrixColorFilter
import android.graphics.Paint
import android.graphics.PorterDuff
import android.graphics.drawable.RippleDrawable
import android.os.Build
import android.os.Bundle
import android.view.Gravity
@ -76,6 +76,7 @@ import eu.kanade.tachiyomi.util.system.hasDisplayCutout
import eu.kanade.tachiyomi.util.system.isNightMode
import eu.kanade.tachiyomi.util.system.logcat
import eu.kanade.tachiyomi.util.system.toast
import eu.kanade.tachiyomi.util.view.copy
import eu.kanade.tachiyomi.util.view.popupMenu
import eu.kanade.tachiyomi.util.view.setTooltip
import eu.kanade.tachiyomi.widget.listener.SimpleAnimationListener
@ -389,23 +390,32 @@ class ReaderActivity : BaseRxActivity<ReaderActivityBinding, ReaderPresenter>()
initBottomShortcuts()
val alpha = if (isNightMode()) 230 else 242 // 90% dark 95% light
val toolbarColor = ColorUtils.setAlphaComponent(getThemeColor(R.attr.colorToolbar), alpha)
listOf(
binding.toolbarBottom,
binding.leftChapter,
binding.readerSeekbar,
binding.rightChapter
).forEach {
it.backgroundTintMode = PorterDuff.Mode.DST_IN
it.backgroundTintList = ColorStateList.valueOf(toolbarColor)
val toolbarBackground = (binding.toolbar.background as MaterialShapeDrawable).apply {
elevation = resources.getDimension(R.dimen.m3_sys_elevation_level2)
alpha = if (isNightMode()) 230 else 242 // 90% dark 95% light
}
binding.toolbarBottom.background = toolbarBackground.copy(this@ReaderActivity)
binding.readerSeekbar.background = toolbarBackground.copy(this@ReaderActivity)?.apply {
setCornerSize(999F)
}
listOf(binding.leftChapter, binding.rightChapter).forEach {
it.background = binding.readerSeekbar.background.copy(this)
it.foreground = RippleDrawable(
ColorStateList.valueOf(getThemeColor(android.R.attr.colorControlHighlight)),
null,
it.background
)
}
val toolbarColor = ColorUtils.setAlphaComponent(
toolbarBackground.resolvedTintColor,
toolbarBackground.alpha
)
window.statusBarColor = toolbarColor
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
window.navigationBarColor = toolbarColor
}
(binding.toolbar.background as MaterialShapeDrawable).fillColor = ColorStateList.valueOf(toolbarColor)
// Set initial visibility
setMenuVisibility(menuVisible)

View File

@ -3,7 +3,9 @@
package eu.kanade.tachiyomi.util.view
import android.annotation.SuppressLint
import android.content.Context
import android.graphics.Point
import android.graphics.drawable.Drawable
import android.text.TextUtils
import android.view.Gravity
import android.view.Menu
@ -25,6 +27,7 @@ import androidx.viewpager.widget.ViewPager
import com.google.android.material.chip.Chip
import com.google.android.material.chip.ChipGroup
import com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
import com.google.android.material.shape.MaterialShapeDrawable
import com.google.android.material.snackbar.Snackbar
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.util.system.getResourceColor
@ -245,3 +248,14 @@ fun ViewPager.getActivePageView(): View? {
false
}
}
/**
* Returns a deep copy of the provided [Drawable]
*/
inline fun <reified T : Drawable> T.copy(context: Context): T? {
return (constantState?.newDrawable()?.mutate() as? T).apply {
if (this is MaterialShapeDrawable) {
initializeElevationOverlay(context)
}
}
}