Skip to content

Commit

Permalink
Attach Tabs widget to the tray
Browse files Browse the repository at this point in the history
The Tabs widget is opened from the tray, but currently there isn't
a clear visual connection between the two.

This PR moves the Tabs widget right next to the tray and also sets
as active the associated tray button.
  • Loading branch information
felipeerias committed Jan 7, 2025
1 parent 4ce2ede commit 55d8380
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class TrayViewModel extends AndroidViewModel {
private MutableLiveData<ObservableBoolean> isKeyboardVisible;
private MutableLiveData<ObservableInt> downloadsNumber;
private MediatorLiveData<ObservableBoolean> isVisible;
private MutableLiveData<ObservableBoolean> isTabsWidgetVisible;
private MutableLiveData<String> time;
private MutableLiveData<String> pm;
private MutableLiveData<ObservableBoolean> wifiConnected;
Expand All @@ -41,6 +42,7 @@ public TrayViewModel(@NonNull Application application) {
isVisible.addSource(shouldBeVisible, mIsVisibleObserver);
isVisible.addSource(isKeyboardVisible, mIsVisibleObserver);
isVisible.setValue(new ObservableBoolean(false));
isTabsWidgetVisible = new MutableLiveData<>(new ObservableBoolean(false));
time = new MutableLiveData<>();
pm = new MutableLiveData<>();
pm = new MutableLiveData<>();
Expand All @@ -67,6 +69,7 @@ public void refresh() {
isMaxWindows.setValue(isMaxWindows.getValue());
shouldBeVisible.setValue(shouldBeVisible.getValue());
isKeyboardVisible.setValue(isKeyboardVisible.getValue());
isTabsWidgetVisible.postValue(isTabsWidgetVisible.getValue());
time.postValue(time.getValue());
pm.postValue(pm.getValue());
wifiConnected.postValue(wifiConnected.getValue());
Expand Down Expand Up @@ -95,6 +98,14 @@ public void setIsKeyboardVisible(boolean isVisible) {
this.isKeyboardVisible.setValue(new ObservableBoolean(isVisible));
}

public void setIsTabsWidgetVisible(boolean isTabsWidgetVisible) {
this.isTabsWidgetVisible.setValue(new ObservableBoolean(isTabsWidgetVisible));
}

public MutableLiveData<ObservableBoolean> getIsTabsWidgetVisible() {
return isTabsWidgetVisible;
}

public void setIsVisible(boolean isVisible) {
this.isVisible.setValue(new ObservableBoolean(isVisible));
}
Expand Down
24 changes: 10 additions & 14 deletions app/src/common/shared/com/igalia/wolvic/ui/widgets/TabsWidget.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,12 @@ protected void initializeWidgetPlacement(WidgetPlacement aPlacement) {
aPlacement.width = WidgetPlacement.dpDimension(getContext(), R.dimen.tabs_width);
aPlacement.height = WidgetPlacement.dpDimension(getContext(), R.dimen.tabs_height);
aPlacement.parentAnchorX = 0.5f;
aPlacement.parentAnchorY = 0.0f;
aPlacement.parentAnchorY = 1.0f;
aPlacement.anchorX = 0.5f;
aPlacement.anchorY = 0.5f;
aPlacement.translationY = WidgetPlacement.unitFromMeters(getContext(), R.dimen.settings_world_y) -
WidgetPlacement.unitFromMeters(getContext(), R.dimen.window_world_y);
updatePlacementTranslationZ();
}

@Override
public void updatePlacementTranslationZ() {
getPlacement().translationZ = WidgetPlacement.unitFromMeters(getContext(), R.dimen.tray_world_z) -
WidgetPlacement.getWindowWorldZMeters(getContext());
aPlacement.anchorY = 0.0f;
// Undo the rotation of the parent widget (tray).
aPlacement.rotationAxisX = 1.0f;
aPlacement.rotation = (float) Math.toRadians(45);
}

private void initialize() {
Expand Down Expand Up @@ -168,9 +162,8 @@ public void onConfigurationChanged(Configuration newConfig) {
updateUI();
}

public void attachToWindow(WindowWidget aWindow) {
mPrivateMode = aWindow.getSession().isPrivateMode();
mWidgetPlacement.parentHandle = aWindow.getHandle();
public void setPrivateMode(boolean privateMode) {
mPrivateMode = privateMode;
}

@Override
Expand Down Expand Up @@ -394,6 +387,9 @@ private void updateSelectionMode() {
protected void onDismiss() {
exitSelectMode();
hide(KEEP_WIDGET);
if (mDelegate != null) {
mDelegate.onDismiss();
}
}

public class GridSpacingItemDecoration extends RecyclerView.ItemDecoration {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,10 @@ public void setAddWindowVisible(boolean aVisible) {
mTrayViewModel.setIsMaxWindows(!aVisible);
}

public void setTabsWidgetVisible(boolean aVisible) {
mTrayViewModel.setIsTabsWidgetVisible(aVisible);
}

// WidgetManagerDelegate.UpdateListener

@Override
Expand Down
19 changes: 10 additions & 9 deletions app/src/common/shared/com/igalia/wolvic/ui/widgets/Windows.java
Original file line number Diff line number Diff line change
Expand Up @@ -1225,15 +1225,16 @@ public void onTabsClicked() {
mTabsWidget.setTabDelegate(this);
}

if (mFocusedWindow != null) {
mTabsWidget.getPlacement().parentHandle = mFocusedWindow.getHandle();
mTabsWidget.attachToWindow(mFocusedWindow);
mTabsWidget.show(UIWidget.KEEP_FOCUS);
// If we're signed-in, poll for any new device events (e.g. received tabs)
// There's no push support right now, so this helps with the perception of speedy tab delivery.
((VRBrowserApplication)mContext.getApplicationContext()).getAccounts().refreshDevicesAsync();
((VRBrowserApplication)mContext.getApplicationContext()).getAccounts().pollForEventsAsync();
}
mTabsWidget.getPlacement().parentHandle = mWidgetManager.getTray().getHandle();
mTabsWidget.setPrivateMode(mPrivateMode);
mTabsWidget.setDelegate(() -> mWidgetManager.getTray().setTabsWidgetVisible(false));
mWidgetManager.getTray().setTabsWidgetVisible(true);
mTabsWidget.show(UIWidget.KEEP_FOCUS);

// If we're signed-in, poll for any new device events (e.g. received tabs)
// There's no push support right now, so this helps with the perception of speedy tab delivery.
((VRBrowserApplication)mContext.getApplicationContext()).getAccounts().refreshDevicesAsync();
((VRBrowserApplication)mContext.getApplicationContext()).getAccounts().pollForEventsAsync();

// Capture active session snapshots when showing the tabs menu
for (WindowWidget window: getCurrentWindows()) {
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/tray.xml
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@
app:tooltipPosition="bottom"
app:tooltipLayout="@layout/tooltip_tray"
android:src="@drawable/ic_icon_tray_tabs"
app:activeMode="@{traymodel.isTabsWidgetVisible}"
app:regularModeBackground="@{traymodel.isMaxWindows ? @drawable/tray_background_unchecked_start : @drawable/tray_background_unchecked_middle}"
app:privateModeBackground="@{traymodel.isMaxWindows ? @drawable/tray_background_start_private : @drawable/tray_background_middle_private}"
app:activeModeBackground="@{traymodel.isMaxWindows ? @drawable/tray_background_checked_start : @drawable/tray_background_checked_middle}"/>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/dimen.xml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@

<!-- Tabs -->
<dimen name="tabs_width">650dp</dimen>
<dimen name="tabs_height">380dp</dimen>
<dimen name="tabs_height">490dp</dimen>
<dimen name="tabs_spacing_h">6dp</dimen>
<dimen name="tab_view_height">87dp</dimen>
<dimen name="tab_view_url_height">16dp</dimen>
Expand Down

0 comments on commit 55d8380

Please sign in to comment.