Skip to content

Commit

Permalink
Whats new dialog fixes (#2101)
Browse files Browse the repository at this point in the history
* Whats new dialog fixes

* Always select the first element after reloading the list
  • Loading branch information
keianhzo authored and MortimerGoro committed Oct 31, 2019
1 parent 435567d commit 0267c8d
Show file tree
Hide file tree
Showing 6 changed files with 154 additions and 128 deletions.
19 changes: 15 additions & 4 deletions app/src/common/shared/org/mozilla/vrbrowser/VRBrowserActivity.java
Expand Up @@ -10,7 +10,6 @@
import android.content.Intent;
import android.content.IntentFilter;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
Expand Down Expand Up @@ -43,6 +42,7 @@
import org.mozilla.geckoview.GeckoSession;
import org.mozilla.geckoview.GeckoVRManager;
import org.mozilla.vrbrowser.audio.AudioEngine;
import org.mozilla.vrbrowser.browser.Accounts;
import org.mozilla.vrbrowser.browser.PermissionDelegate;
import org.mozilla.vrbrowser.browser.SettingsStore;
import org.mozilla.vrbrowser.browser.engine.Session;
Expand Down Expand Up @@ -326,10 +326,21 @@ public void onWindowClosed() {

// Show the what's upp dialog if we haven't showed it yet and this is v6.
if (!SettingsStore.getInstance(this).isWhatsNewDisplayed() && BuildConfig.VERSION_NAME.equals("6")) {
WhatsNewWidget whatsNew = new WhatsNewWidget(this);
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.setSignInCallback(() -> whatsNew.hide(UIWidget.REMOVE_WIDGET));
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 @@ -41,10 +41,10 @@ class Accounts constructor(val context: Context) {
HISTORY,
SETTINGS,
SEND_TABS,
UNDEFINED
NONE
}

var loginOrigin: LoginOrigin = LoginOrigin.UNDEFINED
var loginOrigin: LoginOrigin = LoginOrigin.NONE
var accountStatus = AccountStatus.SIGNED_OUT
private val accountListeners = ArrayList<AccountObserver>()
private val syncListeners = ArrayList<SyncStatusObserver>()
Expand Down
Expand Up @@ -20,15 +20,12 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import org.jetbrains.annotations.NotNull;
import org.mozilla.geckoview.AllowOrDeny;
import org.mozilla.geckoview.GeckoResult;
import org.mozilla.geckoview.GeckoSession;
import org.mozilla.geckoview.GeckoSessionSettings;
import org.mozilla.vrbrowser.R;
import org.mozilla.vrbrowser.VRBrowserApplication;
import org.mozilla.vrbrowser.audio.AudioEngine;
import org.mozilla.vrbrowser.browser.Accounts;
import org.mozilla.vrbrowser.browser.Media;
import org.mozilla.vrbrowser.browser.PromptDelegate;
import org.mozilla.vrbrowser.browser.SessionChangeListener;
Expand All @@ -43,7 +40,6 @@
import org.mozilla.vrbrowser.ui.widgets.dialogs.SelectionActionWidget;
import org.mozilla.vrbrowser.ui.widgets.dialogs.SendTabDialogWidget;
import org.mozilla.vrbrowser.ui.widgets.dialogs.VoiceSearchWidget;
import org.mozilla.vrbrowser.ui.widgets.dialogs.WhatsNewWidget;
import org.mozilla.vrbrowser.ui.widgets.menus.BrightnessMenuWidget;
import org.mozilla.vrbrowser.ui.widgets.menus.HamburgerMenuWidget;
import org.mozilla.vrbrowser.ui.widgets.menus.VideoProjectionMenuWidget;
Expand All @@ -55,11 +51,6 @@
import java.util.Arrays;
import java.util.concurrent.atomic.AtomicBoolean;

import mozilla.components.concept.sync.AccountObserver;
import mozilla.components.concept.sync.AuthType;
import mozilla.components.concept.sync.OAuthAccount;
import mozilla.components.concept.sync.Profile;

public class NavigationBarWidget extends UIWidget implements GeckoSession.NavigationDelegate,
GeckoSession.ProgressDelegate, GeckoSession.ContentDelegate, WidgetManagerDelegate.WorldClickListener,
WidgetManagerDelegate.UpdateListener, SessionChangeListener,
Expand Down Expand Up @@ -112,7 +103,6 @@ public class NavigationBarWidget extends UIWidget implements GeckoSession.Naviga
private HamburgerMenuWidget mHamburgerMenu;
private SendTabDialogWidget mSendTabDialog;
private TooltipWidget mPopUpNotification;
protected Accounts mAccounts;

public NavigationBarWidget(Context aContext) {
super(aContext);
Expand All @@ -133,8 +123,6 @@ private void initialize(@NonNull Context aContext) {
mAppContext = aContext.getApplicationContext();
inflate(aContext, R.layout.navigation_bar, this);

mAccounts = ((VRBrowserApplication)getContext().getApplicationContext()).getAccounts();
mAccounts.addAccountListener(mAccountObserver);
mAudio = AudioEngine.fromContext(aContext);
mBackButton = findViewById(R.id.backButton);
mForwardButton = findViewById(R.id.forwardButton);
Expand Down Expand Up @@ -363,7 +351,6 @@ public void onResume() {

@Override
public void releaseWidget() {
mAccounts.removeAccountListener(mAccountObserver);
mWidgetManager.removeUpdateListener(this);
mWidgetManager.removeWorldClickListener(this);
mPrefs.unregisterOnSharedPreferenceChangeListener(this);
Expand Down Expand Up @@ -1182,23 +1169,15 @@ private void hideMenu() {
}

public void showSendTabDialog() {
if (mAccounts.isSignedIn()) {
mSendTabDialog = new SendTabDialogWidget(getContext());
mSendTabDialog.mWidgetPlacement.parentHandle = mWidgetManager.getFocusedWindow().getHandle();
mSendTabDialog.setDelegate(() -> {
mSendTabDialog.releaseWidget();
mSendTabDialog = null;
show(REQUEST_FOCUS);
});
mSendTabDialog.show(UIWidget.REQUEST_FOCUS);

} else {
final WhatsNewWidget whatsNew = new WhatsNewWidget(getContext());
whatsNew.getPlacement().parentHandle = mWidgetManager.getFocusedWindow().getHandle();
whatsNew.setStartBrowsingCallback(() -> whatsNew.hide(UIWidget.REMOVE_WIDGET));
whatsNew.setSignInCallback(() -> whatsNew.hide(UIWidget.REMOVE_WIDGET));
whatsNew.show(UIWidget.REQUEST_FOCUS);
}
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);
}

private PromptDelegate.PopUpDelegate mPopUpDelegate = new PromptDelegate.PopUpDelegate() {
Expand Down Expand Up @@ -1251,27 +1230,4 @@ private void hideNotification(UIButton button) {
button.setNotificationMode(false);
}

private AccountObserver mAccountObserver = new AccountObserver() {
@Override
public void onLoggedOut() {

}

@Override
public void onAuthenticated(@NotNull OAuthAccount oAuthAccount, @NotNull AuthType authType) {
if (mAccounts.getLoginOrigin() == Accounts.LoginOrigin.SEND_TABS) {
showSendTabDialog();
}
}

@Override
public void onProfileUpdated(@NotNull Profile profile) {

}

@Override
public void onAuthenticationProblems() {

}
};
}
Expand Up @@ -12,16 +12,13 @@
import androidx.recyclerview.widget.RecyclerView;

import org.mozilla.vrbrowser.R;
import org.mozilla.vrbrowser.VRBrowserApplication;
import org.mozilla.vrbrowser.browser.Accounts;
import org.mozilla.vrbrowser.browser.engine.Session;
import org.mozilla.vrbrowser.browser.engine.SessionStore;
import org.mozilla.vrbrowser.ui.views.TabView;
import org.mozilla.vrbrowser.ui.views.UIButton;
import org.mozilla.vrbrowser.ui.views.UITextButton;
import org.mozilla.vrbrowser.ui.widgets.dialogs.SendTabDialogWidget;
import org.mozilla.vrbrowser.ui.widgets.dialogs.UIDialog;
import org.mozilla.vrbrowser.ui.widgets.dialogs.WhatsNewWidget;
import org.mozilla.vrbrowser.utils.BitmapCache;
import org.mozilla.vrbrowser.utils.ViewUtils;

Expand All @@ -44,7 +41,6 @@ public class TabsWidget extends UIDialog implements WidgetManagerDelegate.WorldC
protected UITextButton mUnselectTabs;
protected LinearLayout mTabsSelectModeView;
protected SendTabDialogWidget mSendTabDialog;
protected Accounts mAccounts;

protected boolean mSelecting;
protected ArrayList<Session> mSelectedTabs = new ArrayList<>();
Expand Down Expand Up @@ -78,7 +74,7 @@ protected void initializeWidgetPlacement(WidgetPlacement aPlacement) {

private void initialize() {
inflate(getContext(), R.layout.tabs, this);
mAccounts = ((VRBrowserApplication)getContext().getApplicationContext()).getAccounts();

mTabsList = findViewById(R.id.tabsRecyclerView);
mTabsList.setHasFixedSize(true);
final int columns = 4;
Expand Down Expand Up @@ -281,30 +277,15 @@ public void onAdd(TabView aSender) {
@Override
public void onSend(TabView aSender) {
hide(KEEP_WIDGET);
if (mAccounts.isSignedIn()) {
mSendTabDialog = new SendTabDialogWidget(getContext());
mSendTabDialog.mWidgetPlacement.parentHandle = mWidgetManager.getFocusedWindow().getHandle();
mSendTabDialog.setDelegate(() -> {
mSendTabDialog.releaseWidget();
mSendTabDialog = null;
show(REQUEST_FOCUS);
});
mSendTabDialog.show(UIWidget.REQUEST_FOCUS);

} else {
final WhatsNewWidget whatsNew = new WhatsNewWidget(getContext());
whatsNew.getPlacement().parentHandle = mWidgetManager.getFocusedWindow().getHandle();
whatsNew.setStartBrowsingCallback(() -> {
whatsNew.hide(REMOVE_WIDGET);
show(REQUEST_FOCUS);
});
whatsNew.setSignInCallback(() -> {
whatsNew.hide(REMOVE_WIDGET);
onDismiss();
});
whatsNew.setDelegate(() -> show(REQUEST_FOCUS));
whatsNew.show(UIWidget.REQUEST_FOCUS);
}
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 All @@ -315,7 +296,7 @@ public int getItemCount() {
}
}

private Runnable mSelectModeBackHandler = () -> exitSelectMode();
private Runnable mSelectModeBackHandler = this::exitSelectMode;

private void enterSelectMode() {
if (mSelecting) {
Expand Down

0 comments on commit 0267c8d

Please sign in to comment.