From 4c28d7c5709280c390b3d1a38495c17d0dc48d6f Mon Sep 17 00:00:00 2001 From: Manuel Martin Date: Thu, 20 Feb 2020 12:48:28 +0100 Subject: [PATCH] Dismiss Library panels when navigating back/forward (#2804) --- .../mozilla/vrbrowser/VRBrowserActivity.java | 32 +++++++++---------- .../ui/widgets/NavigationBarWidget.java | 25 +++++++++++++++ .../vrbrowser/ui/widgets/WindowWidget.java | 32 +++++++++++++++++++ 3 files changed, 73 insertions(+), 16 deletions(-) diff --git a/app/src/common/shared/org/mozilla/vrbrowser/VRBrowserActivity.java b/app/src/common/shared/org/mozilla/vrbrowser/VRBrowserActivity.java index 075d7595b..af7bcb0f8 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/VRBrowserActivity.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/VRBrowserActivity.java @@ -304,6 +304,22 @@ protected void onCreate(Bundle savedInstanceState) { protected void initializeWidgets() { UISurfaceTextureRenderer.setUseHardwareAcceleration(SettingsStore.getInstance(getBaseContext()).isUIHardwareAccelerationEnabled()); UISurfaceTextureRenderer.setRenderActive(true); + + // Empty widget just for handling focus on empty space + mRootWidget = new RootWidget(this); + mRootWidget.setClickCallback(() -> { + for (WorldClickListener listener: mWorldClickListeners) { + listener.onWorldClick(); + } + }); + + // Create Browser navigation widget + mNavigationBar = new NavigationBarWidget(this); + + // Create keyboard widget + mKeyboard = new KeyboardWidget(this); + + // Windows mWindows = new Windows(this); mWindows.setDelegate(new Windows.Delegate() { @Override @@ -339,24 +355,8 @@ public void onWindowVideoAvailabilityChanged(@NonNull WindowWidget aWindow) { } }); - // Create Browser navigation widget - mNavigationBar = new NavigationBarWidget(this); - - // Create keyboard widget - mKeyboard = new KeyboardWidget(this); - // Create the tray mTray = new TrayWidget(this); - - // Empty widget just for handling focus on empty space - mRootWidget = new RootWidget(this); - mRootWidget.setClickCallback(() -> { - for (WorldClickListener listener: mWorldClickListeners) { - listener.onWorldClick(); - } - }); - - // Add widget listeners mTray.addListeners(mWindows); mTray.setAddWindowVisible(mWindows.canOpenNewWindow()); 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 c3c8346e3..1c2cab362 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 @@ -19,6 +19,7 @@ import android.widget.EditText; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import androidx.databinding.DataBindingUtil; import androidx.databinding.ObservableBoolean; import androidx.lifecycle.Observer; @@ -53,6 +54,7 @@ import org.mozilla.vrbrowser.utils.ConnectivityReceiver; import org.mozilla.vrbrowser.utils.UrlUtils; +import java.util.ArrayList; import java.util.concurrent.Executor; import java.util.concurrent.atomic.AtomicBoolean; @@ -70,6 +72,14 @@ public class NavigationBarWidget extends UIWidget implements GeckoSession.Naviga private static final int BOOKMARK_ADDED_NOTIFICATION_ID = 2; private static final int POPUP_NOTIFICATION_ID = 3; + public interface NavigationListener { + void onBack(); + void onForward(); + void onReload(); + void onStop(); + void onHome(); + } + private WindowViewModel mViewModel; private NavigationBarBinding mBinding; private AudioEngine mAudio; @@ -92,6 +102,7 @@ public class NavigationBarWidget extends UIWidget implements GeckoSession.Naviga private SendTabDialogWidget mSendTabDialog; private int mBlockedCount; private Executor mUIThreadExecutor; + private ArrayList mNavigationListeners; public NavigationBarWidget(Context aContext) { super(aContext); @@ -119,6 +130,8 @@ private void initialize(@NonNull Context aContext) { mResizeBackHandler = () -> exitResizeMode(ResizeAction.RESTORE_SIZE); + mNavigationListeners = new ArrayList<>(); + mFullScreenBackHandler = this::exitFullScreenMode; mVRVideoBackHandler = () -> { exitVRVideo(); @@ -157,6 +170,7 @@ private void updateUI() { if (mAudio != null) { mAudio.playSound(AudioEngine.Sound.BACK); } + mNavigationListeners.forEach(NavigationListener::onBack); }); mBinding.navigationBarNavigation.forwardButton.setOnClickListener(v -> { @@ -165,6 +179,7 @@ private void updateUI() { if (mAudio != null) { mAudio.playSound(AudioEngine.Sound.CLICK); } + mNavigationListeners.forEach(NavigationListener::onForward); }); mBinding.navigationBarNavigation.reloadButton.setOnClickListener(v -> { @@ -177,6 +192,7 @@ private void updateUI() { if (mAudio != null) { mAudio.playSound(AudioEngine.Sound.CLICK); } + mNavigationListeners.forEach(NavigationListener::onReload); }); mBinding.navigationBarNavigation.homeButton.setOnClickListener(v -> { @@ -185,6 +201,7 @@ private void updateUI() { if (mAudio != null) { mAudio.playSound(AudioEngine.Sound.CLICK); } + mNavigationListeners.forEach(NavigationListener::onHome); }); mBinding.navigationBarNavigation.servoButton.setOnClickListener(v -> { @@ -376,6 +393,14 @@ protected void initializeWidgetPlacement(WidgetPlacement aPlacement) { aPlacement.cylinder = true; } + public void addNavigationBarListener(@Nullable NavigationListener listener) { + mNavigationListeners.add(listener); + } + + public void removeNavigationBarListener(@Nullable NavigationListener listener) { + mNavigationListeners.remove(listener); + } + @Override public void detachFromWindow() { hideAllNotifications(); diff --git a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/WindowWidget.java b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/WindowWidget.java index 0058ae92b..888cc09d3 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/WindowWidget.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/WindowWidget.java @@ -622,6 +622,10 @@ public void setActiveWindow(boolean active) { session.getTextInput().setView(this); } mSession.updateLastUse(); + mWidgetManager.getNavigationBar().addNavigationBarListener(mNavigationBarListener); + + } else { + mWidgetManager.getNavigationBar().removeNavigationBarListener(mNavigationBarListener); } hideContextMenus(); @@ -915,6 +919,7 @@ public void releaseWidget() { } mBookmarksView.removeBookmarksListener(mBookmarksListener); mHistoryView.removeHistoryListener(mHistoryListener); + mWidgetManager.getNavigationBar().removeNavigationBarListener(mNavigationBarListener); mPromptDelegate.detachFromWindow(); super.releaseWidget(); } @@ -1415,6 +1420,33 @@ public void onClickItem(@NonNull View view, @NonNull VisitInfo item) { } }; + private NavigationBarWidget.NavigationListener mNavigationBarListener = new NavigationBarWidget.NavigationListener() { + @Override + public void onBack() { + hideLibraryPanels(); + } + + @Override + public void onForward() { + hideLibraryPanels(); + } + + @Override + public void onReload() { + hideLibraryPanels(); + } + + @Override + public void onStop() { + // Nothing to do + } + + @Override + public void onHome() { + hideLibraryPanels(); + } + }; + private void hideContextMenus() { if (mContextMenu != null) { if (!mContextMenu.isReleased()) {