Skip to content

Commit

Permalink
Add a new Sync icon in the tabs bar
Browse files Browse the repository at this point in the history
In order to receive tabs through the FxA SendTabTo service we need
to poll the API; the new button will perform this action.

Ideally, we should be able to observe events from the FxA push
service, but for now we need to depend on user intervention to
ask the server for new tabs.
  • Loading branch information
javifernandez committed Jan 26, 2025
1 parent 90d0f73 commit d5a41c0
Show file tree
Hide file tree
Showing 9 changed files with 129 additions and 29 deletions.
55 changes: 28 additions & 27 deletions app/src/common/shared/com/igalia/wolvic/VRBrowserActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -461,13 +461,7 @@ public void onWindowVideoAvailabilityChanged(@NonNull WindowWidget aWindow) {
mTray.setAddWindowVisible(mWindows.canOpenNewWindow());

// Create Tabs bar widget
if (mSettings.getTabsLocation() == SettingsStore.TABS_LOCATION_HORIZONTAL) {
mTabsBar = new HorizontalTabsBar(this, mWindows);
} else if (mSettings.getTabsLocation() == SettingsStore.TABS_LOCATION_VERTICAL) {
mTabsBar = new VerticalTabsBar(this, mWindows);
} else {
mTabsBar = null;
}
createTabsBar();

attachToWindow(mWindows.getFocusedWindow(), null);

Expand Down Expand Up @@ -763,30 +757,37 @@ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, Strin
if (!isHeadLockEnabled)
recenterUIYaw(WidgetManagerDelegate.YAW_TARGET_ALL);
} else if (Objects.equals(key, getString(R.string.settings_key_tabs_location))) {
// remove the previous widget
createTabsBar();
if (mTabsBar != null) {
removeWidget(mTabsBar);
mTabsBar.releaseWidget();
addWidget(mTabsBar);
mTabsBar.attachToWindow(mWindows.getFocusedWindow());
updateWidget(mTabsBar);
mWindows.adjustWindowOffsets();
}
}
}

switch (mSettings.getTabsLocation()) {
case SettingsStore.TABS_LOCATION_HORIZONTAL:
mTabsBar = new HorizontalTabsBar(this, mWindows);
break;
case SettingsStore.TABS_LOCATION_VERTICAL:
mTabsBar = new VerticalTabsBar(this, mWindows);
break;
case SettingsStore.TABS_LOCATION_TRAY:
default:
mTabsBar = null;
mWindows.adjustWindowOffsets();
return;
}
addWidget(mTabsBar);
mTabsBar.attachToWindow(mWindows.getFocusedWindow());
updateWidget(mTabsBar);
mWindows.adjustWindowOffsets();
private void createTabsBar() {
// remove the previous widget
if (mTabsBar != null) {
((VRBrowserApplication)getApplicationContext()).getAccounts().removeAccountListener(mTabsBar);
removeWidget(mTabsBar);
mTabsBar.releaseWidget();
}

switch (mSettings.getTabsLocation()) {
case SettingsStore.TABS_LOCATION_HORIZONTAL:
mTabsBar = new HorizontalTabsBar(this, mWindows);
break;
case SettingsStore.TABS_LOCATION_VERTICAL:
mTabsBar = new VerticalTabsBar(this, mWindows);
break;
case SettingsStore.TABS_LOCATION_TRAY:
default:
mTabsBar = null;
return;
}
((VRBrowserApplication)getApplicationContext()).getAccounts().addAccountListener(mTabsBar);
}

void loadFromIntent(final Intent intent) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.igalia.wolvic.ui.widgets;

import android.content.Context;
import android.widget.Button;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.databinding.ObservableBoolean;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
Expand All @@ -15,13 +17,22 @@
import com.igalia.wolvic.ui.viewmodel.WindowViewModel;
import com.igalia.wolvic.utils.SystemUtils;

public abstract class AbstractTabsBar extends UIWidget implements SessionChangeListener, WidgetManagerDelegate.UpdateListener {
import org.jetbrains.annotations.NotNull;

import mozilla.components.concept.sync.AccountObserver;
import mozilla.components.concept.sync.AuthFlowError;
import mozilla.components.concept.sync.AuthType;
import mozilla.components.concept.sync.OAuthAccount;
import mozilla.components.concept.sync.Profile;

public abstract class AbstractTabsBar extends UIWidget implements SessionChangeListener, WidgetManagerDelegate.UpdateListener, AccountObserver {

protected final String LOGTAG = SystemUtils.createLogtag(this.getClass());

protected boolean mPrivateMode;
protected WindowWidget mAttachedWindow;
protected WindowViewModel mWindowViewModel;
protected Button mSyncTabButton;

public AbstractTabsBar(Context aContext) {
super(aContext);
Expand Down Expand Up @@ -143,4 +154,32 @@ public void onStackSession(Session aSession) {
public void onUnstackSession(Session aSession, Session aParent) {
refreshTabs();
}

// AccountObserver

@Override
public void onLoggedOut() {
if (mSyncTabButton != null) {
mSyncTabButton.setVisibility(GONE);
}
}

@Override
public void onAuthenticated(@NonNull OAuthAccount oAuthAccount, @NonNull AuthType authType) {
if (mSyncTabButton != null) {
mSyncTabButton.setVisibility(VISIBLE);
}
}

@Override
public void onProfileUpdated(@NonNull Profile profile) {}

@Override
public void onAuthenticationProblems() {}

@Override
public void onFlowError(@NotNull AuthFlowError authFlowError) {}

@Override
public void onReady(@Nullable OAuthAccount oAuthAccount) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.content.Context;
import android.widget.Button;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

Expand Down Expand Up @@ -33,6 +34,10 @@ private void updateUI() {
mAddTabButton = findViewById(R.id.add_tab);
mAddTabButton.setOnClickListener(v -> mTabDelegate.onTabAdd());

mSyncTabButton = findViewById(R.id.sync_tabs);
mSyncTabButton.setOnClickListener(v -> mTabDelegate.onTabSync());
mSyncTabButton.setVisibility(mTabDelegate.accountIsConnected() ? VISIBLE : GONE);

mTabsList = findViewById(R.id.tabsRecyclerView);
mLayoutManager = new LinearLayoutManager(getContext());
mLayoutManager.setOrientation(RecyclerView.HORIZONTAL);
Expand Down Expand Up @@ -68,4 +73,5 @@ public void updateWidgetPlacement() {
public void refreshTabs() {
mAdapter.updateTabs(SessionStore.get().getSessions(mPrivateMode));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@

import java.util.List;

import mozilla.components.concept.sync.AccountObserver;

public interface TabDelegate {
void onTabAdd();
void onTabSelect(Session aTab);
void onTabsClose(List<Session> aTabs);
void onTabsBookmark(List<Session> aTabs);
void onTabSync();
boolean accountIsConnected();
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import android.content.Context;
import android.widget.Button;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

Expand Down Expand Up @@ -34,6 +33,10 @@ private void updateUI() {
mAddTabButton = findViewById(R.id.add_tab);
mAddTabButton.setOnClickListener(v -> mTabDelegate.onTabAdd());

mSyncTabButton = findViewById(R.id.sync_tabs);
mSyncTabButton.setOnClickListener(v -> mTabDelegate.onTabSync());
mSyncTabButton.setVisibility(mTabDelegate.accountIsConnected() ? VISIBLE : GONE);

mTabsList = findViewById(R.id.tabsRecyclerView);
mLayoutManager = new LinearLayoutManager(getContext());
mLayoutManager.setOrientation(RecyclerView.VERTICAL);
Expand Down Expand Up @@ -69,3 +72,4 @@ public void refreshTabs() {
mAdapter.updateTabs(SessionStore.get().getSessions(mPrivateMode));
}
}

13 changes: 13 additions & 0 deletions app/src/common/shared/com/igalia/wolvic/ui/widgets/Windows.java
Original file line number Diff line number Diff line change
Expand Up @@ -1617,6 +1617,19 @@ public void onTabsBookmark(List<Session> aTabs) {
}
}

@Override
public void onTabSync() {
// 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.
mAccounts.refreshDevicesAsync();
mAccounts.pollForEventsAsync();
}

@Override
public boolean accountIsConnected() {
return mAccounts.isSignedIn();
}

public void closeTab(@NonNull Session aTab) {
if (isSessionFocused(aTab)) {
closeTabs(Collections.singletonList(aTab), mPrivateMode, true);
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/ic_icon_tabs_sync.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:tint="#FFFFFF" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp">

<path android:fillColor="@android:color/white" android:pathData="M12,4L12,1L8,5l4,4L12,6c3.31,0 6,2.69 6,6 0,1.01 -0.25,1.97 -0.7,2.8l1.46,1.46C19.54,15.03 20,13.57 20,12c0,-4.42 -3.58,-8 -8,-8zM12,18c-3.31,0 -6,-2.69 -6,-6 0,-1.01 0.25,-1.97 0.7,-2.8L5.24,7.74C4.46,8.97 4,10.43 4,12c0,4.42 3.58,8 8,8v3l4,-4 -4,-4v3z"/>

</vector>
14 changes: 14 additions & 0 deletions app/src/main/res/layout/tabs_bar_horizontal.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@
android:background="@drawable/tabs_bar_bg"
android:orientation="horizontal">

<com.google.android.material.button.MaterialButton
android:id="@+id/sync_tabs"
android:layout_width="64dp"
android:layout_height="match_parent"
android:layout_margin="4dp"
android:background="@drawable/tab_add_background"
android:scaleType="fitCenter"
app:backgroundTint="@null"
app:icon="@drawable/ic_icon_tabs_sync"
app:iconGravity="textStart"
app:iconPadding="0dp"
app:iconSize="24dp"
app:iconTint="@color/fog" />

<com.google.android.material.button.MaterialButton
android:id="@+id/add_tab"
android:layout_width="64dp"
Expand Down
14 changes: 14 additions & 0 deletions app/src/main/res/layout/tabs_bar_vertical.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@
android:background="@drawable/tabs_bar_bg"
android:orientation="vertical">

<com.google.android.material.button.MaterialButton
android:id="@+id/sync_tabs"
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_margin="4dp"
android:background="@drawable/tab_add_background"
android:scaleType="fitCenter"
app:backgroundTint="@null"
app:icon="@drawable/ic_icon_tabs_sync"
app:iconGravity="textStart"
app:iconPadding="0dp"
app:iconSize="36dp"
app:iconTint="@color/rhino" />

<com.google.android.material.button.MaterialButton
android:id="@+id/add_tab"
android:layout_width="match_parent"
Expand Down

0 comments on commit d5a41c0

Please sign in to comment.