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

Fixes #3236 Fixes tray icons animation issues #3303

Merged
merged 1 commit into from
May 1, 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.
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 @@ -61,6 +61,7 @@ public class TrayWidget extends UIWidget implements WidgetManagerDelegate.Update
private int mMaxPadding;
private Session mSession;
private WindowWidget mAttachedWindow;
private boolean mIsWindowAttached;

public TrayWidget(Context aContext) {
super(aContext);
Expand Down Expand Up @@ -89,6 +90,8 @@ private void initialize(Context aContext) {

updateUI();

mIsWindowAttached = false;

mTrayListeners = new ArrayList<>();

mMinPadding = WidgetPlacement.pixelDimension(getContext(), R.dimen.tray_icon_padding_min);
Expand Down Expand Up @@ -221,18 +224,27 @@ public void onConfigurationChanged(Configuration newConfig) {
int ev = motionEvent.getActionMasked();
switch (ev) {
case MotionEvent.ACTION_HOVER_ENTER:
animateViewPadding(view, mMaxPadding, mMinPadding, ICON_ANIMATION_DURATION);
if (!view.isPressed() && ViewUtils.isInsideView(view, (int)motionEvent.getRawX(), (int)motionEvent.getRawY())) {
animateViewPadding(view, mMaxPadding, mMinPadding, ICON_ANIMATION_DURATION);
}
return false;

case MotionEvent.ACTION_HOVER_EXIT:
animateViewPadding(view, mMinPadding, mMaxPadding, ICON_ANIMATION_DURATION);
if (!ViewUtils.isInsideView(view, (int)motionEvent.getRawX(), (int)motionEvent.getRawY())) {
animateViewPadding(view, mMinPadding, mMaxPadding, ICON_ANIMATION_DURATION);
}
return false;
}

return false;
};

private void animateViewPadding(View view, int paddingStart, int paddingEnd, int duration) {
if (view.isPressed() || !mIsWindowAttached) {
view.setPadding(paddingEnd, paddingEnd, paddingEnd, paddingEnd);
return;
}

ValueAnimator animation = ValueAnimator.ofInt(paddingStart, paddingEnd);
animation.setDuration(duration);
animation.setInterpolator(new AccelerateDecelerateInterpolator());
Expand Down Expand Up @@ -384,6 +396,8 @@ public void detachFromWindow() {
mViewModel.getIsDownloadsVisible().removeObserver(mIsDownloadsVisible);
mViewModel = null;
}

mIsWindowAttached = false;
}

@Override
Expand All @@ -408,9 +422,14 @@ public void attachToWindow(@NonNull WindowWidget aWindow) {
mBinding.setViewmodel(mViewModel);

SessionStore.get().getBookmarkStore().addListener(mBookmarksListener);

mIsWindowAttached = true;
}

private Observer<ObservableBoolean> mIsBookmarksVisible = aBoolean -> {
if (mBinding.bookmarksButton.isHovered()) {
return;
}
if (aBoolean.get()) {
animateViewPadding(mBinding.bookmarksButton, mMaxPadding, mMinPadding, ICON_ANIMATION_DURATION);
} else {
Expand All @@ -419,14 +438,21 @@ public void attachToWindow(@NonNull WindowWidget aWindow) {
};

private Observer<ObservableBoolean> mIsHistoryVisible = aBoolean -> {
if (mBinding.historyButton.isHovered()) {
return;
}
if (aBoolean.get()) {
animateViewPadding(mBinding.historyButton, mMaxPadding, mMinPadding, ICON_ANIMATION_DURATION);

} else {
animateViewPadding(mBinding.historyButton, mMinPadding, mMaxPadding, ICON_ANIMATION_DURATION);
}
};

private Observer<ObservableBoolean> mIsDownloadsVisible = aBoolean -> {
if (mBinding.downloadsButton.isHovered()) {
return;
}
if (aBoolean.get()) {
animateViewPadding(mBinding.downloadsButton, mMaxPadding, mMinPadding, ICON_ANIMATION_DURATION);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -492,8 +492,12 @@ public void switchPanel(@NonNull Windows.PanelType panelType) {
case BOOKMARKS:
if (mViewModel.getIsHistoryVisible().getValue().get() ||
mViewModel.getIsDownloadsVisible().getValue().get()) {
hidePanel(Windows.PanelType.HISTORY, false);
hidePanel(Windows.PanelType.DOWNLOADS, false);
if (isHistoryVisible()) {
hidePanel(Windows.PanelType.HISTORY, false);
}
if (isDownloadsVisible()) {
hidePanel(Windows.PanelType.DOWNLOADS, false);
}
showPanel(Windows.PanelType.BOOKMARKS, false);

} else if (mViewModel.getIsBookmarksVisible().getValue().get()) {
Expand All @@ -506,8 +510,12 @@ public void switchPanel(@NonNull Windows.PanelType panelType) {
case HISTORY:
if (mViewModel.getIsBookmarksVisible().getValue().get() ||
mViewModel.getIsDownloadsVisible().getValue().get()) {
hidePanel(Windows.PanelType.BOOKMARKS, false);
hidePanel(Windows.PanelType.DOWNLOADS, false);
if (isBookmarksVisible()) {
hidePanel(Windows.PanelType.BOOKMARKS, false);
}
if (isDownloadsVisible()) {
hidePanel(Windows.PanelType.DOWNLOADS, false);
}
showPanel(Windows.PanelType.HISTORY, false);

} else if (mViewModel.getIsHistoryVisible().getValue().get()) {
Expand All @@ -520,8 +528,12 @@ public void switchPanel(@NonNull Windows.PanelType panelType) {
case DOWNLOADS:
if (mViewModel.getIsBookmarksVisible().getValue().get() ||
mViewModel.getIsHistoryVisible().getValue().get()) {
hidePanel(Windows.PanelType.BOOKMARKS, false);
hidePanel(Windows.PanelType.HISTORY, false);
if (isBookmarksVisible()) {
hidePanel(Windows.PanelType.BOOKMARKS, false);
}
if (isHistoryVisible()) {
hidePanel(Windows.PanelType.HISTORY, false);
}
showPanel(Windows.PanelType.DOWNLOADS, false);

} else if (mViewModel.getIsDownloadsVisible().getValue().get()) {
Expand Down