diff --git a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/NavigationBarWidget.java b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/NavigationBarWidget.java index c233a482f..0607031b1 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/NavigationBarWidget.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/NavigationBarWidget.java @@ -494,7 +494,6 @@ public void detachFromWindow() { mTrackingDelegate.removeListener(mTrackingListener); if (mViewModel != null) { - mViewModel.getIsFullscreen().removeObserver(mIsFullscreenObserver); mViewModel.getIsActiveWindow().removeObserver(mIsActiveWindowObserver); mViewModel.getIsPopUpBlocked().removeObserver(mIsPopUpBlockedListener); mViewModel = null; @@ -520,7 +519,6 @@ public void attachToWindow(@NonNull WindowWidget aWindow) { mBinding.setViewmodel(mViewModel); - mViewModel.getIsFullscreen().observeForever( mIsFullscreenObserver); mViewModel.getIsActiveWindow().observeForever(mIsActiveWindowObserver); mViewModel.getIsPopUpBlocked().observeForever(mIsPopUpBlockedListener); mBinding.navigationBarNavigation.urlBar.attachToWindow(mAttachedWindow); @@ -566,6 +564,33 @@ public void onSessionChanged(@NonNull Session aOldSession, @NonNull Session aSes exitFullScreenMode(); } + @Override + public void onFullScreen(@NonNull WindowWidget aWindow, boolean aFullScreen) { + if (aFullScreen) { + enterFullScreenMode(); + + if (mAttachedWindow.isResizing()) { + exitResizeMode(ResizeAction.KEEP_SIZE); + } + AtomicBoolean autoEnter = new AtomicBoolean(false); + mAutoSelectedProjection = VideoProjectionMenuWidget.getAutomaticProjection(getSession().getCurrentUri(), autoEnter); + if (mAutoSelectedProjection != VIDEO_PROJECTION_NONE && autoEnter.get()) { + mViewModel.setAutoEnteredVRVideo(true); + postDelayed(() -> enterVRVideo(mAutoSelectedProjection), 300); + } else { + mViewModel.setAutoEnteredVRVideo(false); + if (mProjectionMenu != null) { + mProjectionMenu.setSelectedProjection(mAutoSelectedProjection); + } + } + } else { + if (mViewModel.getIsInVRVideo().getValue().get()) { + exitVRVideo(); + } + exitFullScreenMode(); + } + } + @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); @@ -607,7 +632,7 @@ private void enterFullScreenMode() { } private void exitFullScreenMode() { - if (mAttachedWindow == null) { + if (mAttachedWindow == null || !mAttachedWindow.isFullScreen()) { return; } @@ -818,36 +843,6 @@ public void onLocationChange(@NonNull GeckoSession geckoSession, @Nullable Strin // Content delegate - private Observer mIsFullscreenObserver = isFullScreen -> { - if (!mIsWindowAttached) { - return; - } - - if (isFullScreen.get()) { - enterFullScreenMode(); - - if (mAttachedWindow.isResizing()) { - exitResizeMode(ResizeAction.KEEP_SIZE); - } - AtomicBoolean autoEnter = new AtomicBoolean(false); - mAutoSelectedProjection = VideoProjectionMenuWidget.getAutomaticProjection(getSession().getCurrentUri(), autoEnter); - if (mAutoSelectedProjection != VIDEO_PROJECTION_NONE && autoEnter.get()) { - mViewModel.setAutoEnteredVRVideo(true); - postDelayed(() -> enterVRVideo(mAutoSelectedProjection), 300); - } else { - mViewModel.setAutoEnteredVRVideo(false); - if (mProjectionMenu != null) { - mProjectionMenu.setSelectedProjection(mAutoSelectedProjection); - } - } - } else { - if (mViewModel.getIsInVRVideo().getValue().get()) { - exitVRVideo(); - } - exitFullScreenMode(); - } - }; - private Observer mIsActiveWindowObserver = aIsActiveWindow -> updateTrackingProtection(); private Observer mIsPopUpBlockedListener = observableBoolean -> {