Skip to content

Commit

Permalink
Dialog stacking (#2573)
Browse files Browse the repository at this point in the history
* Use a single global connection dialog instead of per window

* Dialog stacking
  • Loading branch information
keianhzo authored and MortimerGoro committed Jan 8, 2020
1 parent 35b6984 commit 34c12f5
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 118 deletions.
12 changes: 0 additions & 12 deletions app/src/common/shared/org/mozilla/vrbrowser/VRBrowserActivity.java
Expand Up @@ -338,18 +338,6 @@ public void onWindowVideoAvailabilityChanged(@NonNull WindowWidget aWindow) {
final WhatsNewWidget whatsNew = new WhatsNewWidget(this);
whatsNew.setLoginOrigin(Accounts.LoginOrigin.NONE);
whatsNew.getPlacement().parentHandle = mWindows.getFocusedWindow().getHandle();
whatsNew.setStartBrowsingCallback(() -> {
whatsNew.hide(UIWidget.REMOVE_WIDGET);
whatsNew.releaseWidget();
});
whatsNew.setSignInCallback(() -> {
whatsNew.hide(UIWidget.REMOVE_WIDGET);
whatsNew.releaseWidget();
});
whatsNew.setDelegate(() -> {
whatsNew.hide(UIWidget.REMOVE_WIDGET);
whatsNew.releaseWidget();
});
whatsNew.show(UIWidget.REQUEST_FOCUS);
}
}
Expand Down
Expand Up @@ -1193,14 +1193,11 @@ private void hideMenu() {
}

public void showSendTabDialog() {
mSendTabDialog = new SendTabDialogWidget(getContext());
if (mSendTabDialog == null) {
mSendTabDialog = new SendTabDialogWidget(getContext());
}
mSendTabDialog.mWidgetPlacement.parentHandle = mWidgetManager.getFocusedWindow().getHandle();
mSendTabDialog.setSessionId(mAttachedWindow.getSession().getId());
mSendTabDialog.setDelegate(() -> {
mSendTabDialog.releaseWidget();
mSendTabDialog = null;
NavigationBarWidget.this.show(REQUEST_FOCUS);
});
mSendTabDialog.show(UIWidget.REQUEST_FOCUS);
}

Expand Down
Expand Up @@ -158,7 +158,9 @@ public void show(int aShowFlags) {
@Override
public void hide(@HideFlags int aHideFlags) {
super.hide(aHideFlags);
mRenderer.clearSurface();
if (mRenderer != null) {
mRenderer.clearSurface();
}
}

public void setTabDelegate(TabDelegate aDelegate) {
Expand Down Expand Up @@ -269,15 +271,11 @@ public void onAdd(TabView aSender) {

@Override
public void onSend(TabView aSender) {
hide(KEEP_WIDGET);
mSendTabDialog = new SendTabDialogWidget(getContext());
if (mSendTabDialog == null) {
mSendTabDialog = new SendTabDialogWidget(getContext());
}
mSendTabDialog.setSessionId(aSender.getSession().getId());
mSendTabDialog.mWidgetPlacement.parentHandle = mWidgetManager.getFocusedWindow().getHandle();
mSendTabDialog.setDelegate(() -> {
mSendTabDialog.releaseWidget();
mSendTabDialog = null;
TabsWidget.this.show(REQUEST_FOCUS);
});
mSendTabDialog.show(UIWidget.REQUEST_FOCUS);
}
});
Expand Down
Expand Up @@ -52,7 +52,6 @@
import org.mozilla.vrbrowser.ui.widgets.menus.ContextMenuWidget;
import org.mozilla.vrbrowser.ui.widgets.menus.LibraryMenuWidget;
import org.mozilla.vrbrowser.ui.widgets.settings.SettingsWidget;
import org.mozilla.vrbrowser.utils.ConnectivityReceiver;
import org.mozilla.vrbrowser.utils.ViewUtils;

import java.util.ArrayList;
Expand Down Expand Up @@ -101,7 +100,6 @@ default void onBookmarksHidden(WindowWidget aWindow) {}
private WidgetManagerDelegate mWidgetManager;
private PromptDialogWidget mAlertDialog;
private PromptDialogWidget mConfirmDialog;
private PromptDialogWidget mNoInternetDialog;
private PromptDialogWidget mAppDialog;
private ClearHistoryDialogWidget mClearHistoryDialog;
private ContextMenuWidget mContextMenu;
Expand Down Expand Up @@ -236,8 +234,6 @@ void setupListeners(Session aSession) {
aSession.addProgressListener(this);
aSession.setHistoryDelegate(this);
aSession.addSelectionActionListener(this);

mWidgetManager.addConnectivityListener(mConnectivityDelegate);
}

void cleanListeners(Session aSession) {
Expand All @@ -248,8 +244,6 @@ void cleanListeners(Session aSession) {
aSession.removeProgressListener(this);
aSession.setHistoryDelegate(null);
aSession.removeSelectionActionListener(this);

mWidgetManager.removeConnectivityListener(mConnectivityDelegate);
}

@Override
Expand Down Expand Up @@ -330,31 +324,6 @@ public void close() {
mListeners.clear();
}

private ConnectivityReceiver.Delegate mConnectivityDelegate = connected -> {
if (mActive) {
if (mNoInternetDialog == null) {
mNoInternetDialog = new PromptDialogWidget(getContext());
mNoInternetDialog.setButtons(new int[] {
R.string.ok_button
});
mNoInternetDialog.setCheckboxVisible(false);
mNoInternetDialog.setDescriptionVisible(false);
mNoInternetDialog.setTitle(R.string.no_internet_title);
mNoInternetDialog.setBody(R.string.no_internet_message);
mNoInternetDialog.setButtonsDelegate(index -> {
mNoInternetDialog.hide(REMOVE_WIDGET);
});
}

if (!connected && !mNoInternetDialog.isVisible()) {
mNoInternetDialog.show(REQUEST_FOCUS);

} else if (connected && mNoInternetDialog.isVisible()) {
mNoInternetDialog.hide(REMOVE_WIDGET);
}
}
};

public void loadHomeIfNotRestored() {
if (!mIsRestored) {
loadHome();
Expand Down
Expand Up @@ -22,8 +22,11 @@
import org.mozilla.vrbrowser.browser.engine.SessionStore;
import org.mozilla.vrbrowser.telemetry.GleanMetricsService;
import org.mozilla.vrbrowser.telemetry.TelemetryWrapper;
import org.mozilla.vrbrowser.ui.widgets.dialogs.PromptDialogWidget;
import org.mozilla.vrbrowser.ui.widgets.dialogs.UIDialog;
import org.mozilla.vrbrowser.ui.widgets.settings.SettingsWidget;
import org.mozilla.vrbrowser.utils.BitmapCache;
import org.mozilla.vrbrowser.utils.ConnectivityReceiver;
import org.mozilla.vrbrowser.utils.SystemUtils;

import java.io.File;
Expand Down Expand Up @@ -103,6 +106,7 @@ class WindowsState {
private TabsWidget mTabsWidget;
private Accounts mAccounts;
private Services mServices;
private PromptDialogWidget mNoInternetDialog;

public enum WindowPlacement{
FRONT(0),
Expand Down Expand Up @@ -142,6 +146,8 @@ public Windows(Context aContext) {
mServices = ((VRBrowserApplication)mContext.getApplicationContext()).getServices();
mServices.setTabReceivedDelegate(this);

mWidgetManager.addConnectivityListener(mConnectivityDelegate);

restoreWindows();
}

Expand Down Expand Up @@ -435,6 +441,7 @@ public void onDestroy() {
}
mAccounts.removeAccountListener(mAccountObserver);
mServices.setTabReceivedDelegate(null);
mWidgetManager.removeConnectivityListener(mConnectivityDelegate);
}

public boolean isInPrivateMode() {
Expand Down Expand Up @@ -894,6 +901,7 @@ public void onLoggedOut() {
@Override
public void onAuthenticated(@NonNull OAuthAccount oAuthAccount, @NonNull AuthType authType) {
if (authType == AuthType.Signin.INSTANCE || authType == AuthType.Signup.INSTANCE) {
UIDialog.closeAllDialogs();
Session session = mFocusedWindow.getSession();
addTab(mFocusedWindow, mAccounts.getConnectionSuccessURL());
onTabsClose(new ArrayList<>(Collections.singletonList(session)));
Expand Down Expand Up @@ -1276,4 +1284,27 @@ public void onTabsReceived(@NonNull List<TabData> aTabs) {
mTabsWidget.refreshTabs();
}
}

private ConnectivityReceiver.Delegate mConnectivityDelegate = connected -> {
if (mNoInternetDialog == null) {
mNoInternetDialog = new PromptDialogWidget(mContext);
mNoInternetDialog.setButtons(new int[] {
R.string.ok_button
});
mNoInternetDialog.setCheckboxVisible(false);
mNoInternetDialog.setDescriptionVisible(false);
mNoInternetDialog.setTitle(R.string.no_internet_title);
mNoInternetDialog.setBody(R.string.no_internet_message);
mNoInternetDialog.setButtonsDelegate(index -> {
mNoInternetDialog.hide(UIWidget.REMOVE_WIDGET);
});
}

if (!connected && !mNoInternetDialog.isVisible()) {
mNoInternetDialog.show(UIWidget.REQUEST_FOCUS);

} else if (connected && mNoInternetDialog.isVisible()) {
mNoInternetDialog.hide(UIWidget.REMOVE_WIDGET);
}
};
}
Expand Up @@ -61,25 +61,18 @@ protected void initialize(@NonNull Context aContext) {
mSendTabsDialogBinding.setIsEmpty(false);

mAccounts = ((VRBrowserApplication)getContext().getApplicationContext()).getAccounts();
mAccounts.addAccountListener(this);
mAccounts.addDeviceConstellationListener(this);

mBinding.headerLayout.setTitle(getResources().getString(R.string.send_tab_dialog_title));
mBinding.headerLayout.setDescription(R.string.send_tab_dialog_description);
mBinding.footerLayout.setFooterButtonText(R.string.send_tab_dialog_button);
mBinding.footerLayout.setFooterButtonClickListener(this::sendTabButtonClick);
}

@Override
public void releaseWidget() {
mAccounts.removeAccountListener(this);
mAccounts.removeDeviceConstellationListener(this);

super.releaseWidget();
}

@Override
public void show(int aShowFlags) {
mAccounts.addAccountListener(this);
mAccounts.addDeviceConstellationListener(this);

if (mAccounts.isSignedIn()) {
mBinding.footerLayout.setFooterButtonVisibility(View.GONE);
mAccounts.refreshDevicesAsync();
Expand All @@ -96,7 +89,8 @@ public void show(int aShowFlags) {
public void hide(int aHideFlags) {
super.hide(aHideFlags);

mWidgetManager.removeWorldClickListener(this);
mAccounts.removeAccountListener(this);
mAccounts.removeDeviceConstellationListener(this);
}

public void setSessionId(@Nullable String sessionId) {
Expand All @@ -122,24 +116,6 @@ private void sendTabButtonClick(View v) {
private void showWhatsNewDialog() {
mWhatsNew = new WhatsNewWidget(getContext());
mWhatsNew.setLoginOrigin(Accounts.LoginOrigin.SEND_TABS);
mWhatsNew.setStartBrowsingCallback(() -> {
mWhatsNew.hide(REMOVE_WIDGET);
mWhatsNew.releaseWidget();
mWhatsNew = null;
onDismiss();
});
mWhatsNew.setSignInCallback(() -> {
mWhatsNew.hide(REMOVE_WIDGET);
mWhatsNew.releaseWidget();
mWhatsNew = null;
hide(KEEP_WIDGET);
});
mWhatsNew.setDelegate(() -> {
mWhatsNew.hide(REMOVE_WIDGET);
mWhatsNew.releaseWidget();
mWhatsNew = null;
onDismiss();
});
mWhatsNew.show(UIWidget.REQUEST_FOCUS);
}

Expand Down
Expand Up @@ -6,7 +6,12 @@
import org.mozilla.vrbrowser.ui.widgets.UIWidget;
import org.mozilla.vrbrowser.ui.widgets.WidgetManagerDelegate;

import java.util.LinkedList;

public abstract class UIDialog extends UIWidget implements WidgetManagerDelegate.WorldClickListener {

private static LinkedList<UIDialog> mDialogs = new LinkedList<>();

public UIDialog(Context aContext) {
super(aContext);
initialize();
Expand Down Expand Up @@ -43,6 +48,12 @@ public void show(int aShowFlags) {
super.show(aShowFlags);

mWidgetManager.pushWorldBrightness(this, WidgetManagerDelegate.DEFAULT_DIM_BRIGHTNESS);

UIDialog head = mDialogs.peek();
if (head != null && head.isVisible()) {
head.hide();
}
mDialogs.push(this);
}
}

Expand All @@ -51,12 +62,36 @@ public void hide(int aHideFlags) {
super.hide(aHideFlags);

mWidgetManager.popWorldBrightness(this);

mDialogs.remove(this);
UIDialog head = mDialogs.peek();
if (head != null) {
head.show();
}
}

private void show() {
if (!isVisible()) {
super.show(REQUEST_FOCUS);

mWidgetManager.pushWorldBrightness(this, WidgetManagerDelegate.DEFAULT_DIM_BRIGHTNESS);
}
}

private void hide() {
super.hide(KEEP_WIDGET);

mWidgetManager.popWorldBrightness(this);
}

@Override
public void onWorldClick() {
if (this.isVisible()) {
onDismiss();
if (isVisible()) {
post(() -> hide(REMOVE_WIDGET));
}
}

public static void closeAllDialogs() {
new LinkedList<>(mDialogs).forEach(dialog -> dialog.onDismiss());
}
}

0 comments on commit 34c12f5

Please sign in to comment.