mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-09 19:55:11 +01:00
More window insets extensions
This commit is contained in:
parent
b1fa07aedd
commit
1ffe7511f2
@ -55,6 +55,8 @@ import eu.kanade.tachiyomi.ui.setting.SettingsMainController
|
||||
import eu.kanade.tachiyomi.ui.source.SourceController
|
||||
import eu.kanade.tachiyomi.ui.source.global_search.SourceSearchController
|
||||
import eu.kanade.tachiyomi.util.system.getResourceColor
|
||||
import eu.kanade.tachiyomi.util.system.hasSideNavBar
|
||||
import eu.kanade.tachiyomi.util.system.isBottomTappable
|
||||
import eu.kanade.tachiyomi.util.system.launchUI
|
||||
import eu.kanade.tachiyomi.util.view.doOnApplyWindowInsets
|
||||
import eu.kanade.tachiyomi.util.view.updateLayoutParams
|
||||
@ -266,18 +268,17 @@ open class MainActivity : BaseActivity(), DownloadServiceListener {
|
||||
window.navigationBarColor = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O_MR1) {
|
||||
// basically if in landscape on a phone
|
||||
// For lollipop, draw opaque nav bar
|
||||
if (insets.systemWindowInsetLeft > 0 || insets.systemWindowInsetRight > 0)
|
||||
if (insets.hasSideNavBar())
|
||||
Color.BLACK
|
||||
else Color.argb(179, 0, 0, 0)
|
||||
}
|
||||
// if the android q+ device has gesture nav, transparent nav bar
|
||||
// this is here in case some crazy with a notch uses landscape
|
||||
else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && (insets
|
||||
.systemWindowInsetBottom != insets.tappableElementInsets.bottom)) {
|
||||
else if (insets.isBottomTappable()) {
|
||||
getColor(android.R.color.transparent)
|
||||
}
|
||||
// if in landscape with 2/3 button mode, fully opaque nav bar
|
||||
else if (insets.systemWindowInsetLeft > 0 || insets.systemWindowInsetRight > 0) {
|
||||
else if (insets.hasSideNavBar()) {
|
||||
getResourceColor(R.attr.colorPrimaryVariant)
|
||||
}
|
||||
// if in portrait with 2/3 button mode, translucent nav bar
|
||||
|
@ -51,6 +51,8 @@ import eu.kanade.tachiyomi.util.storage.getUriCompat
|
||||
import eu.kanade.tachiyomi.util.system.GLUtil
|
||||
import eu.kanade.tachiyomi.util.system.ThemeUtil
|
||||
import eu.kanade.tachiyomi.util.system.getResourceColor
|
||||
import eu.kanade.tachiyomi.util.system.hasSideNavBar
|
||||
import eu.kanade.tachiyomi.util.system.isBottomTappable
|
||||
import eu.kanade.tachiyomi.util.system.launchUI
|
||||
import eu.kanade.tachiyomi.util.system.toast
|
||||
import eu.kanade.tachiyomi.util.view.doOnApplyWindowInsets
|
||||
@ -340,20 +342,19 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>(),
|
||||
if (!menuVisible)
|
||||
chapters_bottom_sheet.sheetBehavior?.state = BottomSheetBehavior.STATE_HIDDEN
|
||||
reader_menu.doOnApplyWindowInsets { v, insets, _ ->
|
||||
sheetManageNavColor = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && (insets
|
||||
.systemWindowInsetBottom != insets.tappableElementInsets.bottom)
|
||||
) {
|
||||
window.navigationBarColor = Color.TRANSPARENT
|
||||
false
|
||||
}
|
||||
// if in landscape with 2/3 button mode, fully opaque nav bar
|
||||
else if (insets.systemWindowInsetLeft > 0 || insets.systemWindowInsetRight > 0) {
|
||||
window.navigationBarColor = getResourceColor(R.attr.colorSecondary)
|
||||
false
|
||||
}
|
||||
// if in portrait with 2/3 button mode, translucent nav bar
|
||||
else {
|
||||
true
|
||||
sheetManageNavColor = when {
|
||||
insets.isBottomTappable() -> {
|
||||
window.navigationBarColor = Color.TRANSPARENT
|
||||
false
|
||||
}
|
||||
insets.hasSideNavBar() -> {
|
||||
window.navigationBarColor = getResourceColor(R.attr.colorSecondary)
|
||||
false
|
||||
}
|
||||
// if in portrait with 2/3 button mode, translucent nav bar
|
||||
else -> {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
toolbar.updateLayoutParams<ViewGroup.MarginLayoutParams> {
|
||||
|
@ -15,7 +15,7 @@ import com.mikepenz.fastadapter.adapters.ItemAdapter
|
||||
import com.mikepenz.fastadapter.listeners.ClickEventHook
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.util.system.dpToPx
|
||||
import eu.kanade.tachiyomi.util.system.getBottomInsets
|
||||
import eu.kanade.tachiyomi.util.system.getBottomGestureInsets
|
||||
import eu.kanade.tachiyomi.util.system.getResourceColor
|
||||
import eu.kanade.tachiyomi.util.system.launchUI
|
||||
import eu.kanade.tachiyomi.util.view.doOnApplyWindowInsets
|
||||
@ -59,7 +59,7 @@ class ReaderChapterSheet @JvmOverloads constructor(context: Context, attrs: Attr
|
||||
}
|
||||
|
||||
chapters_bottom_sheet.doOnApplyWindowInsets { _, insets, _ ->
|
||||
sheetBehavior?.peekHeight = peek + insets.getBottomInsets()
|
||||
sheetBehavior?.peekHeight = peek + insets.getBottomGestureInsets()
|
||||
|
||||
chapters_bottom_sheet.updateLayoutParams<MarginLayoutParams> {
|
||||
height = 280.dpToPx + insets.systemWindowInsetBottom
|
||||
|
@ -12,6 +12,7 @@ import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
||||
import eu.kanade.tachiyomi.util.lang.plusAssign
|
||||
import eu.kanade.tachiyomi.util.system.hasSideNavBar
|
||||
import eu.kanade.tachiyomi.util.view.setBottomEdge
|
||||
import eu.kanade.tachiyomi.util.view.setEdgeToEdge
|
||||
import eu.kanade.tachiyomi.widget.IgnoreFirstSpinnerListener
|
||||
@ -58,8 +59,7 @@ class ReaderColorFilterSheet(activity: ReaderActivity) : BottomSheetDialog
|
||||
window?.navigationBarColor = Color.TRANSPARENT
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O &&
|
||||
preferences.readerTheme().getOrDefault() == 0 &&
|
||||
activity.window.decorView.rootWindowInsets.systemWindowInsetRight == 0 &&
|
||||
activity.window.decorView.rootWindowInsets.systemWindowInsetLeft == 0)
|
||||
!activity.window.decorView.rootWindowInsets.hasSideNavBar())
|
||||
window?.decorView?.systemUiVisibility = View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR
|
||||
setBottomEdge(brightness_seekbar, activity)
|
||||
|
||||
|
@ -12,6 +12,7 @@ import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
||||
import eu.kanade.tachiyomi.source.model.Page
|
||||
import eu.kanade.tachiyomi.ui.reader.model.ReaderPage
|
||||
import eu.kanade.tachiyomi.util.system.hasSideNavBar
|
||||
import eu.kanade.tachiyomi.util.view.setBottomEdge
|
||||
import eu.kanade.tachiyomi.util.view.setEdgeToEdge
|
||||
import kotlinx.android.synthetic.main.reader_page_sheet.*
|
||||
@ -37,8 +38,7 @@ class ReaderPageSheet(
|
||||
window?.navigationBarColor = Color.TRANSPARENT
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O &&
|
||||
Injekt.get<PreferencesHelper>().readerTheme().getOrDefault() == 0 &&
|
||||
activity.window.decorView.rootWindowInsets.systemWindowInsetRight == 0 &&
|
||||
activity.window.decorView.rootWindowInsets.systemWindowInsetLeft == 0)
|
||||
!activity.window.decorView.rootWindowInsets.hasSideNavBar())
|
||||
window?.decorView?.systemUiVisibility = View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR
|
||||
|
||||
setBottomEdge(save_layout, activity)
|
||||
|
@ -18,6 +18,7 @@ import eu.kanade.tachiyomi.data.preference.getOrDefault
|
||||
import eu.kanade.tachiyomi.ui.reader.viewer.pager.PagerViewer
|
||||
import eu.kanade.tachiyomi.ui.reader.viewer.webtoon.WebtoonViewer
|
||||
import eu.kanade.tachiyomi.util.system.dpToPx
|
||||
import eu.kanade.tachiyomi.util.system.hasSideNavBar
|
||||
import eu.kanade.tachiyomi.util.view.gone
|
||||
import eu.kanade.tachiyomi.util.view.setBottomEdge
|
||||
import eu.kanade.tachiyomi.util.view.setEdgeToEdge
|
||||
@ -54,8 +55,7 @@ class ReaderSettingsSheet(private val activity: ReaderActivity) :
|
||||
window?.navigationBarColor = Color.TRANSPARENT
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O &&
|
||||
preferences.readerTheme().getOrDefault() == 0 &&
|
||||
activity.window.decorView.rootWindowInsets.systemWindowInsetRight == 0 &&
|
||||
activity.window.decorView.rootWindowInsets.systemWindowInsetLeft == 0
|
||||
!activity.window.decorView.rootWindowInsets.hasSideNavBar()
|
||||
) {
|
||||
window?.decorView?.systemUiVisibility = View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR
|
||||
}
|
||||
@ -92,9 +92,7 @@ class ReaderSettingsSheet(private val activity: ReaderActivity) :
|
||||
is WebtoonViewer -> initWebtoonPreferences()
|
||||
}
|
||||
|
||||
|
||||
|
||||
val bottomEdgeView = when(activity.viewer is PagerViewer){
|
||||
val bottomEdgeView = when (activity.viewer is PagerViewer) {
|
||||
true -> page_transitions
|
||||
false -> webtoon_side_padding
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
||||
import eu.kanade.tachiyomi.util.system.dpToPx
|
||||
import eu.kanade.tachiyomi.util.system.hasSideNavBar
|
||||
import eu.kanade.tachiyomi.util.view.setEdgeToEdge
|
||||
import kotlinx.android.synthetic.main.source_filter_sheet.*
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
@ -59,9 +60,10 @@ class SourceSearchSheet(activity: Activity) :
|
||||
setEdgeToEdge(
|
||||
activity, view, 50.dpToPx
|
||||
)
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && preferences.readerTheme()
|
||||
.getOrDefault() == 0 && activity.window.decorView.rootWindowInsets.systemWindowInsetRight == 0 && activity.window.decorView.rootWindowInsets.systemWindowInsetLeft == 0
|
||||
) window?.decorView?.systemUiVisibility = View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O &&
|
||||
preferences.readerTheme().getOrDefault() == 0 &&
|
||||
!activity.window.decorView.rootWindowInsets.hasSideNavBar())
|
||||
window?.decorView?.systemUiVisibility = View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR
|
||||
|
||||
sheetBehavior.addBottomSheetCallback(object : BottomSheetBehavior.BottomSheetCallback() {
|
||||
override fun onSlide(bottomSheet: View, progress: Float) {}
|
||||
|
@ -1,13 +1,18 @@
|
||||
package eu.kanade.tachiyomi.util.system
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.os.Build
|
||||
import android.view.WindowInsets
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
fun WindowInsets.getBottomInsets(): Int {
|
||||
return when (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||
true -> mandatorySystemGestureInsets.bottom
|
||||
false -> systemWindowInsetBottom
|
||||
}
|
||||
fun WindowInsets.getBottomGestureInsets(): Int {
|
||||
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) mandatorySystemGestureInsets.bottom
|
||||
else systemWindowInsetBottom
|
||||
}
|
||||
|
||||
/** returns if device using gesture nav and supports true edge to edge */
|
||||
fun WindowInsets.isBottomTappable(): Boolean {
|
||||
return (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q &&
|
||||
systemWindowInsetBottom != tappableElementInsets.bottom)
|
||||
}
|
||||
|
||||
/** returns if device is in landscape with 2/3 button mode */
|
||||
fun WindowInsets.hasSideNavBar(): Boolean = systemWindowInsetLeft > 0 || systemWindowInsetRight > 0
|
||||
|
@ -29,6 +29,7 @@ import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.util.system.ThemeUtil
|
||||
import eu.kanade.tachiyomi.util.system.getResourceColor
|
||||
import eu.kanade.tachiyomi.util.system.hasSideNavBar
|
||||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.get
|
||||
import kotlin.math.min
|
||||
@ -289,8 +290,7 @@ fun BottomSheetDialog.setEdgeToEdge(
|
||||
View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN //
|
||||
// or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
|
||||
|
||||
if (activity.window.decorView.rootWindowInsets.systemWindowInsetLeft +
|
||||
activity.window.decorView.rootWindowInsets.systemWindowInsetRight == 0)
|
||||
if (!activity.window.decorView.rootWindowInsets.hasSideNavBar())
|
||||
contentView.systemUiVisibility = contentView.systemUiVisibility
|
||||
.or(View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)
|
||||
if (setTopMargin > 0) (contentView.parent as View).updateLayoutParams<ViewGroup.MarginLayoutParams> {
|
||||
|
Loading…
Reference in New Issue
Block a user