Skip to content
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

Dialog stacking #2573

Merged
merged 2 commits into from
Jan 8, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 0 additions & 12 deletions app/src/common/shared/org/mozilla/vrbrowser/VRBrowserActivity.java
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -1186,14 +1186,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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 @@ -1274,4 +1282,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);
}
};
}
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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());
}
}