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

Fixes #2760 Fixes #2759 Fixes #2762 Notification fixes #2769

Merged
merged 3 commits into from
Feb 10, 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
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ protected void initializeWidgets() {
public void onFocusedWindowChanged(@NonNull WindowWidget aFocusedWindow, @Nullable WindowWidget aPrevFocusedWindow) {
attachToWindow(aFocusedWindow, aPrevFocusedWindow);
mTray.setAddWindowVisible(mWindows.canOpenNewWindow());
mNavigationBar.hideNotifications();
mNavigationBar.hideAllNotifications();
}
@Override
public void onWindowBorderChanged(@NonNull WindowWidget aChangeWindow) {
Expand All @@ -320,14 +320,14 @@ public void onWindowBorderChanged(@NonNull WindowWidget aChangeWindow) {

@Override
public void onWindowsMoved() {
mNavigationBar.hideNotifications();
mNavigationBar.hideAllNotifications();
updateWidget(mTray);
}

@Override
public void onWindowClosed() {
mTray.setAddWindowVisible(mWindows.canOpenNewWindow());
mNavigationBar.hideNotifications();
mNavigationBar.hideAllNotifications();
updateWidget(mTray);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.mozilla.vrbrowser.ui.views.NavigationURLBar;
import org.mozilla.vrbrowser.ui.views.UIButton;
import org.mozilla.vrbrowser.ui.views.UITextButton;
import org.mozilla.vrbrowser.ui.widgets.NotificationManager.Notification.NotificationPosition;
import org.mozilla.vrbrowser.ui.widgets.dialogs.SelectionActionWidget;
import org.mozilla.vrbrowser.ui.widgets.dialogs.SendTabDialogWidget;
import org.mozilla.vrbrowser.ui.widgets.dialogs.VoiceSearchWidget;
Expand Down Expand Up @@ -377,7 +378,7 @@ protected void initializeWidgetPlacement(WidgetPlacement aPlacement) {

@Override
public void detachFromWindow() {
hideNotification();
hideAllNotifications();

if (mAttachedWindow != null && mAttachedWindow.isResizing()) {
exitResizeMode(ResizeAction.RESTORE_SIZE);
Expand Down Expand Up @@ -585,7 +586,7 @@ private void enterResizeMode() {
}
}

hideNotifications();
hideAllNotifications();

// Update preset styles
}
Expand Down Expand Up @@ -1030,7 +1031,10 @@ public void showPopUpsBlockedNotification() {
final int currentCount = mBlockedCount;
postDelayed(() -> {
if (currentCount == mBlockedCount) {
showNotification(POPUP_NOTIFICATION_ID, mBinding.navigationBarNavigation.urlBar.getPopUpButton(), R.string.popup_tooltip);
showNotification(POPUP_NOTIFICATION_ID,
mBinding.navigationBarNavigation.urlBar.getPopUpButton(),
NotificationManager.Notification.TOP,
R.string.popup_tooltip);
}
}, POP_UP_NOTIFICATION_DELAY);
}
Expand All @@ -1040,48 +1044,54 @@ public void hidePopUpsBlockedNotification() {
final int currentCount = mBlockedCount;
post(() -> {
if (currentCount == mBlockedCount) {
hideNotification();
hideNotification(POPUP_NOTIFICATION_ID);
}
});
}

public void hideNotifications() {
hidePopUpsBlockedNotification();
}

public void showTabAddedNotification() {
showNotification(TAB_ADDED_NOTIFICATION_ID, R.string.tab_added_notification);
showNotification(TAB_ADDED_NOTIFICATION_ID,
NotificationManager.Notification.BOTTOM,
R.string.tab_added_notification);
}

public void showTabSentNotification() {
showNotification(TAB_SENT_NOTIFICATION_ID, R.string.tab_sent_notification);
showNotification(TAB_SENT_NOTIFICATION_ID,
NotificationManager.Notification.BOTTOM,
R.string.tab_sent_notification);
}

public void showBookmarkAddedNotification() {
showNotification(BOOKMARK_ADDED_NOTIFICATION_ID, R.string.bookmarks_saved_notification);
showNotification(BOOKMARK_ADDED_NOTIFICATION_ID,
NotificationManager.Notification.BOTTOM,
R.string.bookmarks_saved_notification);
}

private void showNotification(int notificationId, UIButton button, int stringRes) {
private void showNotification(int notificationId, UIButton button, @NotificationPosition int position, int stringRes) {
NotificationManager.Notification notification = new NotificationManager.Builder(this)
.withView(button)
.withString(stringRes)
.withPosition(NotificationManager.Notification.BOTTOM)
.withPosition(position)
.withMargin(20.0f).build();
NotificationManager.show(notificationId, notification);
}

private void showNotification(int notificationId, int stringRes) {
private void showNotification(int notificationId, @NotificationPosition int position, int stringRes) {
NotificationManager.Notification notification = new NotificationManager.Builder(this)
.withString(stringRes)
.withPosition(NotificationManager.Notification.BOTTOM)
.withPosition(position)
.withMargin(20.0f).build();
NotificationManager.show(notificationId, notification);
}

private void hideNotification() {
public void hideAllNotifications() {
NotificationManager.hideAll();
}

private void hideNotification(int notificationId) {
NotificationManager.hide(notificationId);
}

private ConnectivityReceiver.Delegate mConnectivityDelegate = connected -> {
if (mMediaControlsWidget != null) {
mMediaControlsWidget.setVisible(connected && mMediaControlsWidget.isVisible());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
import android.view.View;

import androidx.annotation.DimenRes;
import androidx.annotation.IntDef;
import androidx.annotation.LayoutRes;
import androidx.annotation.NonNull;
import androidx.annotation.StringRes;

import org.mozilla.gecko.util.ThreadUtils;
import org.mozilla.vrbrowser.R;
import org.mozilla.vrbrowser.ui.views.UIButton;
import org.mozilla.vrbrowser.ui.widgets.NotificationManager.Notification.NotificationPosition;

import java.util.HashMap;
import java.util.Iterator;
Expand Down Expand Up @@ -38,6 +40,8 @@ public NotificationData(@NonNull TooltipWidget view, @NonNull Notification notif

public static class Notification {

@IntDef(value = { MIDDLE, TOP, BOTTOM, LEFT, RIGHT})
public @interface NotificationPosition {}
public static final int MIDDLE = 0;
public static final int TOP = 1;
public static final int BOTTOM = 2;
Expand All @@ -49,7 +53,7 @@ public static class Notification {
private String mString;
private float mMargin;
private float mZTranslation;
private int mPositionFlags;
private @NotificationPosition int mPositionFlags;
private @DimenRes int mDensity;
private @LayoutRes int mLayoutRes;
private int mDuration;
Expand All @@ -76,7 +80,7 @@ public static class Builder {
private String string;
private float margin = 0.0f;
private float zTranslation = 0.0f;
private int positionFlags = Notification.MIDDLE;
private @NotificationPosition int positionFlags = Notification.MIDDLE;
private @DimenRes int density;
private @LayoutRes int layoutRes = R.layout.library_notification;
private int duration = DEFAULT_DURATION;
Expand Down Expand Up @@ -107,7 +111,7 @@ public Builder withMargin(float margin){
return this;
}

public Builder withPosition(int positionFlags) {
public Builder withPosition(@NotificationPosition int positionFlags) {
this.positionFlags = positionFlags;
return this;
}
Expand Down Expand Up @@ -150,14 +154,11 @@ public static void show(int notificationId, @NonNull Notification notification)

TooltipWidget notificationView = new TooltipWidget(notification.mParent.getContext(), notification.mLayoutRes);

notification.mParent.requestFocus();
notification.mParent.requestFocusFromTouch();

setPlacement(notificationView, notification);

notificationView.setText(notification.mString);
notificationView.setCurvedMode(false);
notificationView.show(UIWidget.CLEAR_FOCUS);
notificationView.show(UIWidget.KEEP_FOCUS);

if (notification.mView instanceof UIButton) {
((UIButton)notification.mView).setNotificationMode(true);
Expand Down