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