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

Hide notification if tray is detached or hidden #1708

Merged
merged 1 commit into from
Aug 29, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import android.animation.Animator;
import android.animation.ValueAnimator;
import android.content.Context;
import android.graphics.PointF;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.util.Log;
Expand Down Expand Up @@ -281,6 +280,8 @@ public void show(@ShowFlags int aShowFlags) {

@Override
public void hide(@HideFlags int aHideFlags) {
ThreadUtils.postToUiThread(hideBookmarkNotification);

if (mWidgetPlacement.visible) {
mWidgetPlacement.visible = false;
if (aHideFlags == REMOVE_WIDGET) {
Expand All @@ -293,6 +294,8 @@ public void hide(@HideFlags int aHideFlags) {

@Override
public void detachFromWindow() {
ThreadUtils.postToUiThread(hideBookmarkNotification);

if (mSessionStack != null) {
mSessionStack.removeSessionChangeListener(this);
mSessionStack = null;
Expand Down Expand Up @@ -460,35 +463,45 @@ public void onBookmarksUpdated() {
@Override
public void onBookmarkAdded() {
mBookmarksButton.setNotificationMode(true);
ThreadUtils.postToUiThread(() -> {
if (mLibraryNotification != null && mLibraryNotification.isVisible()) {
return;
}
ThreadUtils.postToUiThread(showBookmarkNotification);
}
};

Rect offsetViewBounds = new Rect();
getDrawingRect(offsetViewBounds);
offsetDescendantRectToMyCoords(mBookmarksButton, offsetViewBounds);

float ratio = WidgetPlacement.viewToWidgetRatio(getContext(), TrayWidget.this);

mLibraryNotification = new TooltipWidget(getContext(), R.layout.library_notification);
mLibraryNotification.getPlacement().parentHandle = getHandle();
mLibraryNotification.getPlacement().anchorY = 0.0f;
mLibraryNotification.getPlacement().translationX = (offsetViewBounds.left + mBookmarksButton.getWidth() / 2.0f) * ratio;
mLibraryNotification.getPlacement().translationY = ((offsetViewBounds.top - 60) * ratio);
mLibraryNotification.getPlacement().translationZ = 25.0f;
mLibraryNotification.getPlacement().density = 3.0f;
mLibraryNotification.setText(R.string.bookmarks_saved_notification);
mLibraryNotification.setCurvedMode(false);
mLibraryNotification.show(UIWidget.CLEAR_FOCUS);

ThreadUtils.postDelayedToUiThread(() -> {
if (mLibraryNotification != null) {
mLibraryNotification.hide(UIWidget.REMOVE_WIDGET);
}
mBookmarksButton.setNotificationMode(false);
}, LIBRARY_NOTIFICATION_DURATION);
});
private Runnable showBookmarkNotification = new Runnable() {
@Override
public void run() {
if (mLibraryNotification != null && mLibraryNotification.isVisible()) {
return;
}

Rect offsetViewBounds = new Rect();
getDrawingRect(offsetViewBounds);
offsetDescendantRectToMyCoords(mBookmarksButton, offsetViewBounds);

float ratio = WidgetPlacement.viewToWidgetRatio(getContext(), TrayWidget.this);

mLibraryNotification = new TooltipWidget(getContext(), R.layout.library_notification);
mLibraryNotification.getPlacement().parentHandle = getHandle();
mLibraryNotification.getPlacement().anchorY = 0.0f;
mLibraryNotification.getPlacement().translationX = (offsetViewBounds.left + mBookmarksButton.getWidth() / 2.0f) * ratio;
mLibraryNotification.getPlacement().translationY = ((offsetViewBounds.top - 60) * ratio);
mLibraryNotification.getPlacement().translationZ = 25.0f;
mLibraryNotification.getPlacement().density = 3.0f;
mLibraryNotification.setText(R.string.bookmarks_saved_notification);
mLibraryNotification.setCurvedMode(false);
mLibraryNotification.show(UIWidget.CLEAR_FOCUS);

ThreadUtils.postDelayedToUiThread(hideBookmarkNotification, LIBRARY_NOTIFICATION_DURATION);
}
};

private Runnable hideBookmarkNotification = new Runnable() {
@Override
public void run() {
if (mLibraryNotification != null) {
mLibraryNotification.hide(UIWidget.REMOVE_WIDGET);
}
mBookmarksButton.setNotificationMode(false);
}
};

Expand Down