Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 55
ADFA-3569 | Refactor editor fullscreen state handling#1149
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -177,7 +177,7 @@ abstract class BaseEditorActivity : | ||
| private val fileManagerViewModel by viewModels<FileManagerViewModel>() | ||
| private var feedbackButtonManager: FeedbackButtonManager? = null | ||
| private var immersiveController: LandscapeImmersiveController? = null | ||
| private var fullscreenManager: FullscreenManager? = null | ||
| private val topEdgeThreshold by lazy { SizeUtils.dp2px(TOP_EDGE_SWIPE_THRESHOLD_DP) } | ||
| var isDestroying = false | ||
| @@ -455,8 +455,8 @@ abstract class BaseEditorActivity : | ||
| editorBottomSheet = null | ||
| gestureDetector = null | ||
| immersiveController?.destroy() | ||
| immersiveController = null | ||
| fullscreenManager?.destroy() | ||
| fullscreenManager = null | ||
| _binding = null | ||
| @@ -498,7 +498,6 @@ abstract class BaseEditorActivity : | ||
| } | ||
| private fun applyStandardInsets(systemBars: Insets) { | ||
| immersiveController?.onSystemBarInsetsChanged(systemBars.top) | ||
| val root = _binding?.root ?: return | ||
| val initial = root.getOrStoreInitialPadding() | ||
| root.updatePadding(bottom = initial.bottom + systemBars.bottom) | ||
| @@ -627,14 +626,21 @@ abstract class BaseEditorActivity : | ||
| content.tabs.addOnTabSelectedListener(this) | ||
| setupStateObservers() | ||
| setupFullscreenObserver() | ||
| setupViews() | ||
| immersiveController = LandscapeImmersiveController( | ||
| fullscreenManager = FullscreenManager( | ||
| contentBinding = content, | ||
| bottomSheetBehavior = editorBottomSheet!!, | ||
| closeDrawerAction = { | ||
| binding.editorDrawerLayout.closeDrawer(GravityCompat.START) | ||
| }, | ||
| onFullscreenToggleRequested = { | ||
| editorViewModel.toggleFullscreen() | ||
| }, | ||
| ).also { | ||
| it.bind() | ||
| it.onConfigurationChanged(resources.configuration) | ||
| it.render(editorViewModel.isFullscreen, animate = false) | ||
| } | ||
| setupContainers() | ||
| @@ -668,16 +674,17 @@ abstract class BaseEditorActivity : | ||
| override fun onConfigurationChanged(newConfig: Configuration) { | ||
| super.onConfigurationChanged(newConfig) | ||
| immersiveController?.onConfigurationChanged(newConfig) | ||
| window?.decorView?.let { ViewCompat.requestApplyInsets(it) } | ||
| reapplySystemBarInsetsFromRoot() | ||
| _binding?.content?.applyBottomSheetAnchorForOrientation(newConfig.orientation) | ||
| fullscreenManager?.render(editorViewModel.isFullscreen, animate = false) | ||
| } | ||
| private fun reapplySystemBarInsetsFromRoot() { | ||
| val root = _binding?.root ?: return | ||
| val rootInsets = ViewCompat.getRootWindowInsets(root) | ||
| if (rootInsets == null) { | ||
| // Insets can be temporarily unavailable right after a configuration change. | ||
| root.post { reapplySystemBarInsetsFromRoot() } | ||
| return | ||
| } | ||
| @@ -844,7 +851,6 @@ abstract class BaseEditorActivity : | ||
| } | ||
| override fun onPause() { | ||
| immersiveController?.onPause() | ||
| super.onPause() | ||
| memoryUsageWatcher.listener = null | ||
| memoryUsageWatcher.stopWatching(false) | ||
| @@ -1223,6 +1229,16 @@ abstract class BaseEditorActivity : | ||
| } | ||
| } | ||
| private fun setupFullscreenObserver() { | ||
| lifecycleScope.launch { | ||
| repeatOnLifecycle(Lifecycle.State.STARTED) { | ||
| editorViewModel.uiState.collectLatest { uiState -> | ||
| fullscreenManager?.render(uiState.isFullscreen, animate = true) | ||
| } | ||
| } | ||
| } | ||
| } | ||
| private fun setupViews() { | ||
| setupNoEditorView() | ||
| setupBottomSheet() | ||
| @@ -1383,7 +1399,7 @@ abstract class BaseEditorActivity : | ||
| content.apply { | ||
| viewContainer.viewTreeObserver.addOnGlobalLayoutListener(observer) | ||
| bottomSheet.setOffsetAnchor(editorAppBarLayout) | ||
| applyBottomSheetAnchorForOrientation(resources.configuration.orientation) | ||
| } | ||
| } | ||
| @@ -1447,31 +1463,48 @@ abstract class BaseEditorActivity : | ||
| val isHorizontalSwipe = abs(diffX) > abs(diffY) | ||
| val hasDownFlingDistance = diffY > flingDistanceThreshold | ||
| val hasRightFlingDistance = diffX > flingDistanceThreshold | ||
| val hasUpFlingDistance = diffY < -flingDistanceThreshold | ||
| val hasVerticalVelocity = abs(velocityY) > flingVelocityThreshold | ||
| val hasHorizontalVelocity = abs(velocityX) > flingVelocityThreshold | ||
| val hasRightFlingDistance = diffX > flingDistanceThreshold | ||
| val screenHeight = resources.displayMetrics.heightPixels | ||
| val bottomEdgeThreshold = screenHeight - topEdgeThreshold | ||
| // Check for a swipe down (to show top bar) | ||
| // This is placed before the noFilesOpen check so it works while editing | ||
| val isLandscape = resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE | ||
| val startedNearTopEdge = e1.y < topEdgeThreshold | ||
| val startedNearBottomEdge = e1.y > bottomEdgeThreshold | ||
| val isTopEdgeDismissFling = isVerticalSwipe && | ||
| hasVerticalVelocity && | ||
| startedNearTopEdge && | ||
| hasDownFlingDistance | ||
| val isBottomEdgeDismissFling = isVerticalSwipe && | ||
| hasVerticalVelocity && | ||
| startedNearBottomEdge && | ||
| hasUpFlingDistance | ||
| val isDrawerOpenFling = hasRightFlingDistance && | ||
| hasHorizontalVelocity && | ||
| isHorizontalSwipe | ||
| // Fullscreen mode can be dismissed with an inward fling from either vertical edge. | ||
| if (isTopEdgeDismissFling && editorViewModel.isFullscreen) { | ||
| editorViewModel.exitFullscreen() | ||
| return true | ||
| } | ||
| if (isLandscape && startedNearTopEdge && hasDownFlingDistance && hasVerticalVelocity && isVerticalSwipe) { | ||
| immersiveController?.showTopBar() | ||
| if (isBottomEdgeDismissFling && editorViewModel.isFullscreen) { | ||
| editorViewModel.exitFullscreen() | ||
| return true | ||
| } | ||
| // Check if no files are open by looking at the displayedChild of the view flipper | ||
| // Preserve the editor interaction area; drawer gestures are only enabled on the empty state. | ||
| val noFilesOpen = content.viewContainer.displayedChild == 1 | ||
| if (!noFilesOpen) { | ||
| return false // If files are open, do nothing | ||
| return false | ||
| } | ||
| // Check for a right swipe (to open left drawer) - This part is still correct | ||
| // Added abs(diffX) > abs(diffY) to prevent diagonal swipes from triggering this | ||
| if (hasRightFlingDistance && hasHorizontalVelocity && isHorizontalSwipe) { | ||
| // Use the correct binding for the drawer layout | ||
| // Filter out diagonal flings so only an intentional right swipe opens the drawer. | ||
| if (isDrawerOpenFling) { | ||
jatezzz marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| binding.editorDrawerLayout.openDrawer(GravityCompat.START) | ||
| return true | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.