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

Commit a83b2bf

Browse files
keianhzobluemarvin
authored andcommitted
What's new dialog (#2091)
* What's new dialog * Show the what's new dialog when sending tabs and not logged in * Fix what's new hide issues
1 parent a34be57 commit a83b2bf

File tree

12 files changed

+657
-16
lines changed

12 files changed

+657
-16
lines changed

app/src/common/shared/org/mozilla/vrbrowser/VRBrowserActivity.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
import org.mozilla.vrbrowser.ui.widgets.WindowWidget;
6767
import org.mozilla.vrbrowser.ui.widgets.Windows;
6868
import org.mozilla.vrbrowser.ui.widgets.dialogs.CrashDialogWidget;
69+
import org.mozilla.vrbrowser.ui.widgets.dialogs.WhatsNewWidget;
6970
import org.mozilla.vrbrowser.ui.widgets.prompts.ConfirmPromptWidget;
7071
import org.mozilla.vrbrowser.utils.BitmapCache;
7172
import org.mozilla.vrbrowser.utils.ConnectivityReceiver;
@@ -322,6 +323,15 @@ public void onWindowClosed() {
322323
attachToWindow(mWindows.getFocusedWindow(), null);
323324

324325
addWidgets(Arrays.asList(mRootWidget, mNavigationBar, mKeyboard, mTray));
326+
327+
// Show the what's upp dialog if we haven't showed it yet and this is v6.
328+
if (!SettingsStore.getInstance(this).isWhatsNewDisplayed() && BuildConfig.VERSION_NAME.equals("6")) {
329+
WhatsNewWidget whatsNew = new WhatsNewWidget(this);
330+
whatsNew.getPlacement().parentHandle = mWindows.getFocusedWindow().getHandle();
331+
whatsNew.setStartBrowsingCallback(() -> whatsNew.hide(UIWidget.REMOVE_WIDGET));
332+
whatsNew.setSignInCallback(() -> whatsNew.hide(UIWidget.REMOVE_WIDGET));
333+
whatsNew.show(UIWidget.REQUEST_FOCUS);
334+
}
325335
}
326336

327337
private void attachToWindow(@NonNull WindowWidget aWindow, @Nullable WindowWidget aPrevWindow) {

app/src/common/shared/org/mozilla/vrbrowser/browser/Accounts.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class Accounts constructor(val context: Context) {
4040
BOOKMARKS,
4141
HISTORY,
4242
SETTINGS,
43+
SEND_TABS,
4344
UNDEFINED
4445
}
4546

app/src/common/shared/org/mozilla/vrbrowser/browser/SettingsStore.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ SettingsStore getInstance(final @NonNull Context aContext) {
7878
public final static boolean TELEMETRY_STATUS_UPDATE_SENT_DEFAULT = false;
7979
public final static boolean BOOKMARKS_SYNC_DEFAULT = true;
8080
public final static boolean HISTORY_SYNC_DEFAULT = true;
81+
public final static boolean WHATS_NEW_DISPLAYED = false;
8182

8283
// Enable telemetry by default (opt-out).
8384
public final static boolean CRASH_REPORTING_DEFAULT = false;
@@ -623,5 +624,15 @@ public boolean isHistorySyncEnabled() {
623624
return mPrefs.getBoolean(mContext.getString(R.string.settings_key_history_sync), HISTORY_SYNC_DEFAULT);
624625
}
625626

627+
public void setWhatsNewDisplayed(boolean isEnabled) {
628+
SharedPreferences.Editor editor = mPrefs.edit();
629+
editor.putBoolean(mContext.getString(R.string.settings_key_whats_new_displayed), isEnabled);
630+
editor.commit();
631+
}
632+
633+
public boolean isWhatsNewDisplayed() {
634+
return mPrefs.getBoolean(mContext.getString(R.string.settings_key_whats_new_displayed), WHATS_NEW_DISPLAYED);
635+
}
636+
626637
}
627638

app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/NavigationBarWidget.java

Lines changed: 54 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,15 @@
2020
import androidx.annotation.NonNull;
2121
import androidx.annotation.Nullable;
2222

23+
import org.jetbrains.annotations.NotNull;
2324
import org.mozilla.geckoview.AllowOrDeny;
2425
import org.mozilla.geckoview.GeckoResult;
2526
import org.mozilla.geckoview.GeckoSession;
2627
import org.mozilla.geckoview.GeckoSessionSettings;
2728
import org.mozilla.vrbrowser.R;
29+
import org.mozilla.vrbrowser.VRBrowserApplication;
2830
import org.mozilla.vrbrowser.audio.AudioEngine;
31+
import org.mozilla.vrbrowser.browser.Accounts;
2932
import org.mozilla.vrbrowser.browser.Media;
3033
import org.mozilla.vrbrowser.browser.PromptDelegate;
3134
import org.mozilla.vrbrowser.browser.SessionChangeListener;
@@ -40,6 +43,7 @@
4043
import org.mozilla.vrbrowser.ui.widgets.dialogs.SelectionActionWidget;
4144
import org.mozilla.vrbrowser.ui.widgets.dialogs.SendTabDialogWidget;
4245
import org.mozilla.vrbrowser.ui.widgets.dialogs.VoiceSearchWidget;
46+
import org.mozilla.vrbrowser.ui.widgets.dialogs.WhatsNewWidget;
4347
import org.mozilla.vrbrowser.ui.widgets.menus.BrightnessMenuWidget;
4448
import org.mozilla.vrbrowser.ui.widgets.menus.HamburgerMenuWidget;
4549
import org.mozilla.vrbrowser.ui.widgets.menus.VideoProjectionMenuWidget;
@@ -51,6 +55,11 @@
5155
import java.util.Arrays;
5256
import java.util.concurrent.atomic.AtomicBoolean;
5357

58+
import mozilla.components.concept.sync.AccountObserver;
59+
import mozilla.components.concept.sync.AuthType;
60+
import mozilla.components.concept.sync.OAuthAccount;
61+
import mozilla.components.concept.sync.Profile;
62+
5463
public class NavigationBarWidget extends UIWidget implements GeckoSession.NavigationDelegate,
5564
GeckoSession.ProgressDelegate, GeckoSession.ContentDelegate, WidgetManagerDelegate.WorldClickListener,
5665
WidgetManagerDelegate.UpdateListener, SessionChangeListener,
@@ -103,6 +112,7 @@ public class NavigationBarWidget extends UIWidget implements GeckoSession.Naviga
103112
private HamburgerMenuWidget mHamburgerMenu;
104113
private SendTabDialogWidget mSendTabDialog;
105114
private TooltipWidget mPopUpNotification;
115+
protected Accounts mAccounts;
106116

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

136+
mAccounts = ((VRBrowserApplication)getContext().getApplicationContext()).getAccounts();
137+
mAccounts.addAccountListener(mAccountObserver);
126138
mAudio = AudioEngine.fromContext(aContext);
127139
mBackButton = findViewById(R.id.backButton);
128140
mForwardButton = findViewById(R.id.forwardButton);
@@ -351,6 +363,7 @@ public void onResume() {
351363

352364
@Override
353365
public void releaseWidget() {
366+
mAccounts.removeAccountListener(mAccountObserver);
354367
mWidgetManager.removeUpdateListener(this);
355368
mWidgetManager.removeWorldClickListener(this);
356369
mPrefs.unregisterOnSharedPreferenceChangeListener(this);
@@ -1169,13 +1182,23 @@ private void hideMenu() {
11691182
}
11701183

11711184
public void showSendTabDialog() {
1172-
mSendTabDialog = new SendTabDialogWidget(getContext());
1173-
mSendTabDialog.mWidgetPlacement.parentHandle = mAttachedWindow.getHandle();
1174-
mSendTabDialog.setDelegate(() -> {
1175-
mSendTabDialog.releaseWidget();
1176-
mSendTabDialog = null;
1177-
});
1178-
mSendTabDialog.show(REQUEST_FOCUS);
1185+
if (mAccounts.isSignedIn()) {
1186+
mSendTabDialog = new SendTabDialogWidget(getContext());
1187+
mSendTabDialog.mWidgetPlacement.parentHandle = mWidgetManager.getFocusedWindow().getHandle();
1188+
mSendTabDialog.setDelegate(() -> {
1189+
mSendTabDialog.releaseWidget();
1190+
mSendTabDialog = null;
1191+
show(REQUEST_FOCUS);
1192+
});
1193+
mSendTabDialog.show(UIWidget.REQUEST_FOCUS);
1194+
1195+
} else {
1196+
final WhatsNewWidget whatsNew = new WhatsNewWidget(getContext());
1197+
whatsNew.getPlacement().parentHandle = mWidgetManager.getFocusedWindow().getHandle();
1198+
whatsNew.setStartBrowsingCallback(() -> whatsNew.hide(UIWidget.REMOVE_WIDGET));
1199+
whatsNew.setSignInCallback(() -> whatsNew.hide(UIWidget.REMOVE_WIDGET));
1200+
whatsNew.show(UIWidget.REQUEST_FOCUS);
1201+
}
11791202
}
11801203

11811204
private PromptDelegate.PopUpDelegate mPopUpDelegate = new PromptDelegate.PopUpDelegate() {
@@ -1227,4 +1250,28 @@ private void hideNotification(UIButton button) {
12271250
}
12281251
button.setNotificationMode(false);
12291252
}
1253+
1254+
private AccountObserver mAccountObserver = new AccountObserver() {
1255+
@Override
1256+
public void onLoggedOut() {
1257+
1258+
}
1259+
1260+
@Override
1261+
public void onAuthenticated(@NotNull OAuthAccount oAuthAccount, @NotNull AuthType authType) {
1262+
if (mAccounts.getLoginOrigin() == Accounts.LoginOrigin.SEND_TABS) {
1263+
showSendTabDialog();
1264+
}
1265+
}
1266+
1267+
@Override
1268+
public void onProfileUpdated(@NotNull Profile profile) {
1269+
1270+
}
1271+
1272+
@Override
1273+
public void onAuthenticationProblems() {
1274+
1275+
}
1276+
};
12301277
}

app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/TabsWidget.java

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,16 @@
1212
import androidx.recyclerview.widget.RecyclerView;
1313

1414
import org.mozilla.vrbrowser.R;
15+
import org.mozilla.vrbrowser.VRBrowserApplication;
16+
import org.mozilla.vrbrowser.browser.Accounts;
1517
import org.mozilla.vrbrowser.browser.engine.Session;
1618
import org.mozilla.vrbrowser.browser.engine.SessionStore;
1719
import org.mozilla.vrbrowser.ui.views.TabView;
1820
import org.mozilla.vrbrowser.ui.views.UIButton;
1921
import org.mozilla.vrbrowser.ui.views.UITextButton;
2022
import org.mozilla.vrbrowser.ui.widgets.dialogs.SendTabDialogWidget;
2123
import org.mozilla.vrbrowser.ui.widgets.dialogs.UIDialog;
24+
import org.mozilla.vrbrowser.ui.widgets.dialogs.WhatsNewWidget;
2225
import org.mozilla.vrbrowser.utils.BitmapCache;
2326
import org.mozilla.vrbrowser.utils.ViewUtils;
2427

@@ -41,6 +44,7 @@ public class TabsWidget extends UIDialog implements WidgetManagerDelegate.WorldC
4144
protected UITextButton mUnselectTabs;
4245
protected LinearLayout mTabsSelectModeView;
4346
protected SendTabDialogWidget mSendTabDialog;
47+
protected Accounts mAccounts;
4448

4549
protected boolean mSelecting;
4650
protected ArrayList<Session> mSelectedTabs = new ArrayList<>();
@@ -74,6 +78,7 @@ protected void initializeWidgetPlacement(WidgetPlacement aPlacement) {
7478

7579
private void initialize() {
7680
inflate(getContext(), R.layout.tabs, this);
81+
mAccounts = ((VRBrowserApplication)getContext().getApplicationContext()).getAccounts();
7782
mTabsList = findViewById(R.id.tabsRecyclerView);
7883
mTabsList.setHasFixedSize(true);
7984
final int columns = 4;
@@ -276,14 +281,30 @@ public void onAdd(TabView aSender) {
276281
@Override
277282
public void onSend(TabView aSender) {
278283
hide(KEEP_WIDGET);
279-
mSendTabDialog = new SendTabDialogWidget(getContext());
280-
mSendTabDialog.mWidgetPlacement.parentHandle = mWidgetManager.getFocusedWindow().getHandle();
281-
mSendTabDialog.setDelegate(() -> {
282-
mSendTabDialog.releaseWidget();
283-
mSendTabDialog = null;
284-
show(REQUEST_FOCUS);
285-
});
286-
mSendTabDialog.show(UIWidget.REQUEST_FOCUS);
284+
if (mAccounts.isSignedIn()) {
285+
mSendTabDialog = new SendTabDialogWidget(getContext());
286+
mSendTabDialog.mWidgetPlacement.parentHandle = mWidgetManager.getFocusedWindow().getHandle();
287+
mSendTabDialog.setDelegate(() -> {
288+
mSendTabDialog.releaseWidget();
289+
mSendTabDialog = null;
290+
show(REQUEST_FOCUS);
291+
});
292+
mSendTabDialog.show(UIWidget.REQUEST_FOCUS);
293+
294+
} else {
295+
final WhatsNewWidget whatsNew = new WhatsNewWidget(getContext());
296+
whatsNew.getPlacement().parentHandle = mWidgetManager.getFocusedWindow().getHandle();
297+
whatsNew.setStartBrowsingCallback(() -> {
298+
whatsNew.hide(REMOVE_WIDGET);
299+
show(REQUEST_FOCUS);
300+
});
301+
whatsNew.setSignInCallback(() -> {
302+
whatsNew.hide(REMOVE_WIDGET);
303+
onDismiss();
304+
});
305+
whatsNew.setDelegate(() -> show(REQUEST_FOCUS));
306+
whatsNew.show(UIWidget.REQUEST_FOCUS);
307+
}
287308
}
288309
});
289310
}
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*-
2+
* This Source Code Form is subject to the terms of the Mozilla Public
3+
* License, v. 2.0. If a copy of the MPL was not distributed with this
4+
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5+
6+
package org.mozilla.vrbrowser.ui.widgets.dialogs;
7+
8+
import android.annotation.SuppressLint;
9+
import android.content.Context;
10+
import android.util.AttributeSet;
11+
import android.view.LayoutInflater;
12+
13+
import androidx.annotation.NonNull;
14+
import androidx.databinding.DataBindingUtil;
15+
16+
import org.mozilla.geckoview.GeckoSessionSettings;
17+
import org.mozilla.vrbrowser.R;
18+
import org.mozilla.vrbrowser.VRBrowserApplication;
19+
import org.mozilla.vrbrowser.browser.Accounts;
20+
import org.mozilla.vrbrowser.browser.SettingsStore;
21+
import org.mozilla.vrbrowser.databinding.WhatsNewBinding;
22+
import org.mozilla.vrbrowser.ui.widgets.WidgetManagerDelegate;
23+
import org.mozilla.vrbrowser.ui.widgets.WidgetPlacement;
24+
import org.mozilla.vrbrowser.utils.UIThreadExecutor;
25+
26+
public class WhatsNewWidget extends UIDialog implements WidgetManagerDelegate.WorldClickListener {
27+
28+
private WhatsNewBinding mBinding;
29+
private Accounts mAccounts;
30+
private Runnable mSignInCallback;
31+
private Runnable mStartBrowsingCallback;
32+
33+
public WhatsNewWidget(Context aContext) {
34+
super(aContext);
35+
initialize();
36+
}
37+
38+
public WhatsNewWidget(Context aContext, AttributeSet aAttrs) {
39+
super(aContext, aAttrs);
40+
initialize();
41+
}
42+
43+
public WhatsNewWidget(Context aContext, AttributeSet aAttrs, int aDefStyle) {
44+
super(aContext, aAttrs, aDefStyle);
45+
initialize();
46+
}
47+
48+
public void setSignInCallback(@NonNull Runnable callback) {
49+
mSignInCallback = callback;
50+
}
51+
52+
public void setStartBrowsingCallback(@NonNull Runnable callback) {
53+
mStartBrowsingCallback = callback;
54+
}
55+
56+
@SuppressLint("ClickableViewAccessibility")
57+
private void initialize() {
58+
LayoutInflater inflater = LayoutInflater.from(getContext());
59+
60+
mAccounts = ((VRBrowserApplication)getContext().getApplicationContext()).getAccounts();
61+
62+
// Inflate this data binding layout
63+
mBinding = DataBindingUtil.inflate(inflater, R.layout.whats_new, this, true);
64+
65+
mBinding.signInButton.setOnClickListener(v -> signIn());
66+
mBinding.startBrowsingButton.setOnClickListener((v) -> {
67+
if (mStartBrowsingCallback != null) {
68+
mStartBrowsingCallback.run();
69+
}
70+
});
71+
}
72+
73+
@Override
74+
protected void initializeWidgetPlacement(WidgetPlacement aPlacement) {
75+
aPlacement.visible = false;
76+
aPlacement.width = WidgetPlacement.dpDimension(getContext(), R.dimen.whats_new_width);
77+
aPlacement.height = WidgetPlacement.dpDimension(getContext(), R.dimen.whats_new_height);
78+
aPlacement.parentAnchorX = 0.5f;
79+
aPlacement.parentAnchorY = 0.0f;
80+
aPlacement.anchorX = 0.5f;
81+
aPlacement.anchorY = 0.5f;
82+
aPlacement.translationY = WidgetPlacement.unitFromMeters(getContext(), R.dimen.settings_world_y) -
83+
WidgetPlacement.unitFromMeters(getContext(), R.dimen.window_world_y);
84+
aPlacement.translationZ = WidgetPlacement.unitFromMeters(getContext(), R.dimen.settings_world_z) -
85+
WidgetPlacement.unitFromMeters(getContext(), R.dimen.window_world_z);
86+
}
87+
88+
@Override
89+
public void show(@ShowFlags int aShowFlags) {
90+
super.show(aShowFlags);
91+
92+
mWidgetManager.addWorldClickListener(this);
93+
mWidgetManager.pushWorldBrightness(this, WidgetManagerDelegate.DEFAULT_DIM_BRIGHTNESS);
94+
}
95+
96+
@Override
97+
public void hide(@HideFlags int aHideFlags) {
98+
super.hide(aHideFlags);
99+
100+
SettingsStore.getInstance(getContext()).setWhatsNewDisplayed(true);
101+
102+
mWidgetManager.popWorldBrightness(this);
103+
mWidgetManager.removeWorldClickListener(this);
104+
}
105+
106+
private void signIn() {
107+
mAccounts.getAuthenticationUrlAsync().thenAcceptAsync((url) -> {
108+
if (url != null) {
109+
mAccounts.setLoginOrigin(Accounts.LoginOrigin.SEND_TABS);
110+
mWidgetManager.openNewTabForeground(url);
111+
mWidgetManager.getFocusedWindow().getSession().setUaMode(GeckoSessionSettings.USER_AGENT_MODE_VR);
112+
mWidgetManager.getFocusedWindow().getSession().loadUri(url);
113+
}
114+
115+
if (mSignInCallback != null) {
116+
mSignInCallback.run();
117+
}
118+
119+
}, new UIThreadExecutor());
120+
}
121+
122+
// WidgetManagerDelegate.WorldClickListener
123+
124+
@Override
125+
public void onWorldClick() {
126+
onDismiss();
127+
}
128+
129+
}

app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/settings/ContentLanguageOptionsView.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
import java.util.Arrays;
2828

29-
class ContentLanguageOptionsView extends SettingsView {
29+
public class ContentLanguageOptionsView extends SettingsView {
3030

3131
private OptionsLanguageContentBinding mBinding;
3232
private LanguagesAdapter mPreferredAdapter;

0 commit comments

Comments
 (0)