Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Fixes #2794 Dismiss Library panels when navigating back/forward #2804

Merged
merged 1 commit into from
Feb 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions app/src/common/shared/org/mozilla/vrbrowser/VRBrowserActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand All @@ -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;
Expand All @@ -92,6 +102,7 @@ public class NavigationBarWidget extends UIWidget implements GeckoSession.Naviga
private SendTabDialogWidget mSendTabDialog;
private int mBlockedCount;
private Executor mUIThreadExecutor;
private ArrayList<NavigationListener> mNavigationListeners;

public NavigationBarWidget(Context aContext) {
super(aContext);
Expand Down Expand Up @@ -119,6 +130,8 @@ private void initialize(@NonNull Context aContext) {

mResizeBackHandler = () -> exitResizeMode(ResizeAction.RESTORE_SIZE);

mNavigationListeners = new ArrayList<>();

mFullScreenBackHandler = this::exitFullScreenMode;
mVRVideoBackHandler = () -> {
exitVRVideo();
Expand Down Expand Up @@ -157,6 +170,7 @@ private void updateUI() {
if (mAudio != null) {
mAudio.playSound(AudioEngine.Sound.BACK);
}
mNavigationListeners.forEach(NavigationListener::onBack);
});

mBinding.navigationBarNavigation.forwardButton.setOnClickListener(v -> {
Expand All @@ -165,6 +179,7 @@ private void updateUI() {
if (mAudio != null) {
mAudio.playSound(AudioEngine.Sound.CLICK);
}
mNavigationListeners.forEach(NavigationListener::onForward);
});

mBinding.navigationBarNavigation.reloadButton.setOnClickListener(v -> {
Expand All @@ -177,6 +192,7 @@ private void updateUI() {
if (mAudio != null) {
mAudio.playSound(AudioEngine.Sound.CLICK);
}
mNavigationListeners.forEach(NavigationListener::onReload);
});

mBinding.navigationBarNavigation.homeButton.setOnClickListener(v -> {
Expand All @@ -185,6 +201,7 @@ private void updateUI() {
if (mAudio != null) {
mAudio.playSound(AudioEngine.Sound.CLICK);
}
mNavigationListeners.forEach(NavigationListener::onHome);
});

mBinding.navigationBarNavigation.servoButton.setOnClickListener(v -> {
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -915,6 +919,7 @@ public void releaseWidget() {
}
mBookmarksView.removeBookmarksListener(mBookmarksListener);
mHistoryView.removeHistoryListener(mHistoryListener);
mWidgetManager.getNavigationBar().removeNavigationBarListener(mNavigationBarListener);
mPromptDelegate.detachFromWindow();
super.releaseWidget();
}
Expand Down Expand Up @@ -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()) {
Expand Down