@@ -172,6 +172,7 @@ abstract class BaseEditorActivity :
172172
173173 private val fileManagerViewModel by viewModels<FileManagerViewModel >()
174174 private var feedbackButtonManager: FeedbackButtonManager ? = null
175+ private var immersiveController: LandscapeImmersiveController ? = null
175176
176177 var isDestroying = false
177178 protected set
@@ -448,6 +449,9 @@ abstract class BaseEditorActivity :
448449 editorBottomSheet = null
449450 gestureDetector = null
450451
452+ immersiveController?.destroy()
453+ immersiveController = null
454+
451455 _binding = null
452456
453457 if (isDestroying) {
@@ -480,11 +484,50 @@ abstract class BaseEditorActivity :
480484 val imeInsets = insets.getInsets(WindowInsetsCompat .Type .ime())
481485 val systemBars = insets.getInsets(WindowInsetsCompat .Type .systemBars())
482486
483- _binding ?.content?.editorAppBarLayout?.updatePadding(top = systemBars.top)
487+ applyStandardInsets(systemBars, insets)
488+
489+ applyImmersiveModeInsets(systemBars)
490+
491+ handleKeyboardInsets(imeInsets)
492+ }
493+
494+ private fun applyStandardInsets (systemBars : Insets , windowInsets : WindowInsetsCompat ) {
495+ val content = _binding ?.content ? : return
496+ val isLandscape = resources.configuration.orientation == Configuration .ORIENTATION_LANDSCAPE
497+
498+ if (isLandscape) {
499+ content.editorAppBarLayout.updatePadding(top = 0 )
500+ content.editorAppbarContent.updatePadding(top = systemBars.top)
501+ } else {
502+ content.editorAppBarLayout.updatePadding(top = systemBars.top)
503+ content.editorAppbarContent.updatePadding(top = 0 )
504+ }
505+
506+ immersiveController?.onSystemBarInsetsChanged(systemBars.top)
484507 applySidebarInsets(systemBars)
485-
486- _binding ?.root?.applyBottomWindowInsetsPadding(insets)
508+ _binding ?.root?.applyBottomWindowInsetsPadding(windowInsets)
509+ }
510+
511+ private fun applyImmersiveModeInsets (systemBars : Insets ) {
512+ val content = _binding ?.content ? : return
513+ val baseMargin = SizeUtils .dp2px(16f )
514+ val isRtl = content.root.layoutDirection == View .LAYOUT_DIRECTION_RTL
515+ val endInset = if (isRtl) systemBars.left else systemBars.right
487516
517+ content.btnToggleTopBar.updateLayoutParams<ViewGroup .MarginLayoutParams > {
518+ topMargin = baseMargin + systemBars.top
519+ marginEnd = baseMargin + endInset
520+ }
521+
522+ content.btnToggleBottomBar.updateLayoutParams<ViewGroup .MarginLayoutParams > {
523+ bottomMargin = baseMargin + systemBars.bottom
524+ marginEnd = baseMargin + endInset
525+ }
526+
527+ content.bottomSheet.updatePadding(top = systemBars.top)
528+ }
529+
530+ private fun handleKeyboardInsets (imeInsets : Insets ) {
488531 val isImeVisible = imeInsets.bottom > 0
489532 _binding ?.content?.bottomSheet?.setImeVisible(isImeVisible)
490533
@@ -612,6 +655,15 @@ abstract class BaseEditorActivity :
612655 setupStateObservers()
613656 setupViews()
614657
658+ immersiveController = LandscapeImmersiveController (
659+ contentBinding = content,
660+ bottomSheetBehavior = editorBottomSheet!! ,
661+ coroutineScope = lifecycleScope,
662+ ).also {
663+ it.bind()
664+ it.onConfigurationChanged(resources.configuration)
665+ }
666+
615667 setupContainers()
616668 setupDiagnosticInfo()
617669
@@ -643,6 +695,7 @@ abstract class BaseEditorActivity :
643695
644696 override fun onConfigurationChanged (newConfig : Configuration ) {
645697 super .onConfigurationChanged(newConfig)
698+ immersiveController?.onConfigurationChanged(newConfig)
646699 }
647700
648701 private fun setupToolbar () {
@@ -700,9 +753,10 @@ abstract class BaseEditorActivity :
700753 _binding ?.apply {
701754 contentCard.progress = progress
702755 val insetsTop = systemBarInsets?.top ? : 0
703- content.editorAppBarLayout.updatePadding(
704- top = (insetsTop * (1f - progress)).roundToInt(),
705- )
756+ val topInset = (insetsTop * (1f - progress)).roundToInt()
757+
758+ content.editorAppbarContent.updatePadding(top = topInset)
759+
706760 memUsageView.chart.updateLayoutParams<ViewGroup .MarginLayoutParams > {
707761 topMargin = (insetsTop * progress).roundToInt()
708762 }
@@ -792,6 +846,7 @@ abstract class BaseEditorActivity :
792846 }
793847
794848 override fun onPause () {
849+ immersiveController?.onPause()
795850 super .onPause()
796851 memoryUsageWatcher.listener = null
797852 memoryUsageWatcher.stopWatching(false )
@@ -801,6 +856,7 @@ abstract class BaseEditorActivity :
801856 }
802857
803858 override fun onResume () {
859+ immersiveController?.onResume()
804860 super .onResume()
805861 invalidateOptionsMenu()
806862
@@ -1299,7 +1355,8 @@ abstract class BaseEditorActivity :
12991355 slideOffset : Float ,
13001356 ) {
13011357 content.apply {
1302- val editorScale = 1 - slideOffset * (1 - EDITOR_CONTAINER_SCALE_FACTOR )
1358+ val safeOffset = slideOffset.coerceAtLeast(0f )
1359+ val editorScale = 1 - safeOffset * (1 - EDITOR_CONTAINER_SCALE_FACTOR )
13031360 this .bottomSheet.onSlide(slideOffset)
13041361 this .viewContainer.scaleX = editorScale
13051362 this .viewContainer.scaleY = editorScale
0 commit comments