Skip to content

Commit afdeec9

Browse files
committed
feat: implement landscape immersive mode for editor toolbars
Adds LandscapeImmersiveController, touch observation, and UI toggles to handle auto-hiding toolbars.
1 parent 0a1d98c commit afdeec9

File tree

6 files changed

+534
-48
lines changed

6 files changed

+534
-48
lines changed

app/src/main/java/com/itsaky/androidide/activities/editor/BaseEditorActivity.kt

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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,47 @@ 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+
497+
val appBarContent = content.editorAppbarContent
498+
if (appBarContent != null) {
499+
content.editorAppBarLayout.updatePadding(top = 0)
500+
appBarContent.updatePadding(top = systemBars.top)
501+
} else {
502+
content.editorAppBarLayout.updatePadding(top = systemBars.top)
503+
}
504+
505+
immersiveController?.onSystemBarInsetsChanged(systemBars.top)
484506
applySidebarInsets(systemBars)
485-
486-
_binding?.root?.applyBottomWindowInsetsPadding(insets)
507+
_binding?.root?.applyBottomWindowInsetsPadding(windowInsets)
508+
}
509+
510+
private fun applyImmersiveModeInsets(systemBars: Insets) {
511+
val content = _binding?.content ?: return
512+
val baseMargin = SizeUtils.dp2px(16f)
487513

514+
content.btnToggleTopBar.updateLayoutParams<ViewGroup.MarginLayoutParams> {
515+
topMargin = baseMargin + systemBars.top
516+
marginEnd = baseMargin + systemBars.right
517+
}
518+
519+
content.btnToggleBottomBar.updateLayoutParams<ViewGroup.MarginLayoutParams> {
520+
bottomMargin = baseMargin + systemBars.bottom
521+
marginEnd = baseMargin + systemBars.right
522+
}
523+
524+
content.bottomSheet.updatePadding(top = systemBars.top)
525+
}
526+
527+
private fun handleKeyboardInsets(imeInsets: Insets) {
488528
val isImeVisible = imeInsets.bottom > 0
489529
_binding?.content?.bottomSheet?.setImeVisible(isImeVisible)
490530

@@ -612,6 +652,15 @@ abstract class BaseEditorActivity :
612652
setupStateObservers()
613653
setupViews()
614654

655+
immersiveController = LandscapeImmersiveController(
656+
contentBinding = content,
657+
bottomSheetBehavior = editorBottomSheet!!,
658+
coroutineScope = lifecycleScope,
659+
).also {
660+
it.bind()
661+
it.onConfigurationChanged(resources.configuration)
662+
}
663+
615664
setupContainers()
616665
setupDiagnosticInfo()
617666

@@ -643,6 +692,7 @@ abstract class BaseEditorActivity :
643692

644693
override fun onConfigurationChanged(newConfig: Configuration) {
645694
super.onConfigurationChanged(newConfig)
695+
immersiveController?.onConfigurationChanged(newConfig)
646696
}
647697

648698
private fun setupToolbar() {
@@ -792,6 +842,7 @@ abstract class BaseEditorActivity :
792842
}
793843

794844
override fun onPause() {
845+
immersiveController?.onPause()
795846
super.onPause()
796847
memoryUsageWatcher.listener = null
797848
memoryUsageWatcher.stopWatching(false)
@@ -1299,7 +1350,8 @@ abstract class BaseEditorActivity :
12991350
slideOffset: Float,
13001351
) {
13011352
content.apply {
1302-
val editorScale = 1 - slideOffset * (1 - EDITOR_CONTAINER_SCALE_FACTOR)
1353+
val safeOffset = slideOffset.coerceAtLeast(0f)
1354+
val editorScale = 1 - safeOffset * (1 - EDITOR_CONTAINER_SCALE_FACTOR)
13031355
this.bottomSheet.onSlide(slideOffset)
13041356
this.viewContainer.scaleX = editorScale
13051357
this.viewContainer.scaleY = editorScale

0 commit comments

Comments
 (0)