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

Commit ebc151c

Browse files
keianhzobluemarvin
authored andcommitted
Sync updates (#2183)
* Update Sync UI * Do not add accounts listeners if Account UI is disabled * Do not debounce for explicit user sync requests * Fit empty history items in narrow mode
1 parent cb169a2 commit ebc151c

18 files changed

+194
-72
lines changed

app/src/common/shared/org/mozilla/vrbrowser/browser/Accounts.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ class Accounts constructor(val context: Context) {
112112
// Enable syncing after signing in
113113
syncStorage.setStatus(SyncEngine.Bookmarks, SettingsStore.getInstance(context).isBookmarksSyncEnabled)
114114
syncStorage.setStatus(SyncEngine.History, SettingsStore.getInstance(context).isHistorySyncEnabled)
115-
services.accountManager.syncNowAsync(SyncReason.EngineChange, false)
115+
services.accountManager.syncNowAsync(SyncReason.EngineChange, true)
116116

117117
// Update device list
118118
account.deviceConstellation().registerDeviceObserver(

app/src/common/shared/org/mozilla/vrbrowser/ui/adapters/BindingAdapters.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import android.text.style.ImageSpan;
88
import android.view.View;
99
import android.view.ViewGroup;
10+
import android.widget.ImageView;
1011
import android.widget.TextView;
1112

1213
import androidx.annotation.DimenRes;
@@ -18,6 +19,7 @@
1819
import org.mozilla.vrbrowser.R;
1920
import org.mozilla.vrbrowser.ui.views.HoneycombButton;
2021
import org.mozilla.vrbrowser.ui.views.UIButton;
22+
import org.mozilla.vrbrowser.ui.views.settings.ButtonSetting;
2123
import org.mozilla.vrbrowser.ui.views.settings.SwitchSetting;
2224

2325
import java.text.SimpleDateFormat;
@@ -122,4 +124,34 @@ public static void setLayoutWidth(@NonNull UIButton button, @NonNull @Dimension
122124
public static void setEnabled(@NonNull SwitchSetting button, boolean enabled) {
123125
button.setEnabled(enabled);
124126
}
127+
128+
@BindingAdapter("lastSync")
129+
public static void setFxALastSync(@NonNull ButtonSetting view, long lastSync) {
130+
if (lastSync == 0) {
131+
view.setDescription(view.getContext().getString(R.string.fxa_account_last_no_synced));
132+
133+
} else {
134+
long timeDiff = System.currentTimeMillis() - lastSync;
135+
if (timeDiff < 60000) {
136+
view.setDescription(view.getContext().getString(R.string.fxa_account_last_synced_now));
137+
138+
} else {
139+
view.setDescription(view.getContext().getString(R.string.fxa_account_last_synced, timeDiff / 60000));
140+
}
141+
}
142+
}
143+
144+
@BindingAdapter("android:layout_height")
145+
public static void setLayoutHeight(@NonNull ImageView view, @NonNull @Dimension float dimen) {
146+
ViewGroup.LayoutParams params = view.getLayoutParams();
147+
params.width = (int)dimen;
148+
view.setLayoutParams(params);
149+
}
150+
151+
@BindingAdapter("android:layout_width")
152+
public static void setLayoutWidth(@NonNull ImageView view, @NonNull @Dimension float dimen) {
153+
ViewGroup.LayoutParams params = view.getLayoutParams();
154+
params.height = (int)dimen;
155+
view.setLayoutParams(params);
156+
}
125157
}

app/src/common/shared/org/mozilla/vrbrowser/ui/views/BookmarksView.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ public class BookmarksView extends FrameLayout implements BookmarksStore.Bookmar
5656

5757
private static final String LOGTAG = SystemUtils.createLogtag(BookmarksView.class);
5858

59+
private static final boolean ACCOUNTS_UI_ENABLED = false;
60+
5961
private BookmarksBinding mBinding;
6062
private Accounts mAccounts;
6163
private BookmarkAdapter mBookmarkAdapter;
@@ -105,8 +107,10 @@ private void initialize(Context aContext) {
105107
mBinding.setIsLoading(true);
106108

107109
mAccounts = ((VRBrowserApplication)getContext().getApplicationContext()).getAccounts();
108-
mAccounts.addAccountListener(mAccountListener);
109-
mAccounts.addSyncListener(mSyncListener);
110+
if (ACCOUNTS_UI_ENABLED) {
111+
mAccounts.addAccountListener(mAccountListener);
112+
mAccounts.addSyncListener(mSyncListener);
113+
}
110114

111115
mBinding.setIsSignedIn(mAccounts.isSignedIn());
112116
boolean isSyncEnabled = mAccounts.isEngineEnabled(SyncEngine.Bookmarks.INSTANCE);
@@ -116,6 +120,7 @@ private void initialize(Context aContext) {
116120
mBinding.setIsSyncing(mAccounts.isSyncing());
117121
}
118122
mBinding.setIsNarrow(false);
123+
mBinding.setIsAccountsUIEnabled(ACCOUNTS_UI_ENABLED);
119124
mBinding.executePendingBindings();
120125

121126
updateBookmarks();
@@ -135,8 +140,11 @@ public void onShow() {
135140

136141
public void onDestroy() {
137142
SessionStore.get().getBookmarkStore().removeListener(this);
138-
mAccounts.removeAccountListener(mAccountListener);
139-
mAccounts.removeSyncListener(mSyncListener);
143+
144+
if (ACCOUNTS_UI_ENABLED) {
145+
mAccounts.removeAccountListener(mAccountListener);
146+
mAccounts.removeSyncListener(mSyncListener);
147+
}
140148
}
141149

142150
private final BookmarkItemCallback mBookmarkItemCallback = new BookmarkItemCallback() {
@@ -249,7 +257,7 @@ public void onIdle() {
249257
updateSyncBindings(false);
250258

251259
// This shouldn't be necessary but for some reason the buttons stays hovered after the sync.
252-
// I guess Android is after enabling it it's state is restored to the latest one (hovered)
260+
// I guess Android restoring it to the latest state (hovered) before being disabled
253261
// Probably an Android bindings bug.
254262
mBinding.bookmarksNarrow.syncButton.setHovered(false);
255263
mBinding.bookmarksWide.syncButton.setHovered(false);

app/src/common/shared/org/mozilla/vrbrowser/ui/views/HistoryView.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ public class HistoryView extends FrameLayout implements HistoryStore.HistoryList
6262

6363
private static final String LOGTAG = SystemUtils.createLogtag(HistoryView.class);
6464

65+
private static final boolean ACCOUNTS_UI_ENABLED = false;
66+
6567
private HistoryBinding mBinding;
6668
private Accounts mAccounts;
6769
private HistoryAdapter mHistoryAdapter;
@@ -108,8 +110,10 @@ private void initialize(Context aContext) {
108110
mBinding.setIsLoading(true);
109111

110112
mAccounts = ((VRBrowserApplication)getContext().getApplicationContext()).getAccounts();
111-
mAccounts.addAccountListener(mAccountListener);
112-
mAccounts.addSyncListener(mSyncListener);
113+
if (ACCOUNTS_UI_ENABLED) {
114+
mAccounts.addAccountListener(mAccountListener);
115+
mAccounts.addSyncListener(mSyncListener);
116+
}
113117

114118
mBinding.setIsSignedIn(mAccounts.isSignedIn());
115119
boolean isSyncEnabled = mAccounts.isEngineEnabled(SyncEngine.History.INSTANCE);
@@ -119,6 +123,7 @@ private void initialize(Context aContext) {
119123
mBinding.setIsSyncing(mAccounts.isSyncing());
120124
}
121125
mBinding.setIsNarrow(false);
126+
mBinding.setIsAccountsUIEnabled(ACCOUNTS_UI_ENABLED);
122127
mBinding.executePendingBindings();
123128

124129
updateHistory();
@@ -134,8 +139,11 @@ private void initialize(Context aContext) {
134139

135140
public void onDestroy() {
136141
SessionStore.get().getHistoryStore().removeListener(this);
137-
mAccounts.removeAccountListener(mAccountListener);
138-
mAccounts.removeSyncListener(mSyncListener);
142+
143+
if (ACCOUNTS_UI_ENABLED) {
144+
mAccounts.removeAccountListener(mAccountListener);
145+
mAccounts.removeSyncListener(mSyncListener);
146+
}
139147
}
140148

141149
public void onShow() {
@@ -246,7 +254,7 @@ public void onIdle() {
246254
updateSyncBindings(false);
247255

248256
// This shouldn't be necessary but for some reason the buttons stays hovered after the sync.
249-
// I guess Android is after enabling it it's state is restored to the latest one (hovered)
257+
// I guess Android restoring it to the latest state (hovered) before being disabled
250258
// Probably an Android bindings bug.
251259
mBinding.historyNarrow.syncButton.setHovered(false);
252260
mBinding.historyWide.syncButton.setHovered(false);

app/src/common/shared/org/mozilla/vrbrowser/ui/views/settings/ButtonSetting.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,10 @@ public void setFooterButtonVisibility(int visibility) {
108108
mButton.setVisibility(visibility);
109109
}
110110

111+
@Override
112+
public void setEnabled(boolean enabled) {
113+
super.setEnabled(enabled);
114+
115+
mButton.setEnabled(enabled);
116+
}
111117
}

app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/settings/FxAAccountOptionsView.java

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import android.content.Context;
99
import android.util.Log;
1010
import android.view.LayoutInflater;
11+
import android.view.View;
1112

1213
import androidx.databinding.DataBindingUtil;
1314

@@ -40,6 +41,8 @@ class FxAAccountOptionsView extends SettingsView {
4041
private OptionsFxaAccountBinding mBinding;
4142
private Accounts mAccounts;
4243
private Executor mUIThreadExecutor;
44+
private boolean mInitialBookmarksState;
45+
private boolean mInitialHistoryState;
4346

4447
public FxAAccountOptionsView(Context aContext, WidgetManagerDelegate aWidgetManager) {
4548
super(aContext, aWidgetManager);
@@ -62,8 +65,12 @@ private void initialize(Context aContext) {
6265
mUIThreadExecutor = ((VRBrowserApplication)getContext().getApplicationContext()).getExecutors().mainThread();
6366

6467
mBinding.signButton.setOnClickListener(view -> mAccounts.logoutAsync());
65-
mBinding.bookmarksSyncSwitch.setOnCheckedChangeListener(mBookmarksSyncListener);
68+
mBinding.syncButton.setOnClickListener(this::sync);
69+
70+
mBinding.setIsSyncing(mAccounts.isSyncing());
71+
mBinding.setLastSync(mAccounts.lastSync());
6672

73+
mBinding.bookmarksSyncSwitch.setOnCheckedChangeListener(mBookmarksSyncListener);
6774
mBinding.historySyncSwitch.setOnCheckedChangeListener(mHistorySyncListener);
6875

6976
updateCurrentAccountState();
@@ -79,10 +86,13 @@ public void onShown() {
7986
mAccounts.addAccountListener(mAccountListener);
8087
mAccounts.addSyncListener(mSyncListener);
8188

82-
mBinding.bookmarksSyncSwitch.setValue(mAccounts.isEngineEnabled(SyncEngine.Bookmarks.INSTANCE), false);
83-
mBinding.historySyncSwitch.setValue(mAccounts.isEngineEnabled(SyncEngine.History.INSTANCE), false);
89+
mInitialBookmarksState = mAccounts.isEngineEnabled(SyncEngine.Bookmarks.INSTANCE);
90+
mInitialHistoryState = mAccounts.isEngineEnabled(SyncEngine.History.INSTANCE);
8491

85-
mBinding.setIsSyncing(mAccounts.isSyncing());
92+
mBinding.bookmarksSyncSwitch.setValue(mInitialBookmarksState, false);
93+
mBinding.historySyncSwitch.setValue(mInitialHistoryState, false);
94+
95+
updateSyncBindings(mAccounts.isSyncing());
8696
}
8797

8898
@Override
@@ -91,50 +101,60 @@ public void onHidden() {
91101

92102
mAccounts.removeAccountListener(mAccountListener);
93103
mAccounts.removeSyncListener(mSyncListener);
104+
105+
// We only sync engines in case the user has changed the sync engines since previous sync
106+
if (mBinding.bookmarksSyncSwitch.isChecked() != mInitialBookmarksState ||
107+
mBinding.historySyncSwitch.isChecked() != mInitialHistoryState) {
108+
mAccounts.syncNowAsync(SyncReason.EngineChange.INSTANCE, false);
109+
}
94110
}
95111

96112
private SwitchSetting.OnCheckedChangeListener mBookmarksSyncListener = (compoundButton, value, apply) -> {
97113
mAccounts.setSyncStatus(SyncEngine.Bookmarks.INSTANCE, value);
98-
mAccounts.syncNowAsync(SyncReason.EngineChange.INSTANCE, false);
99114
};
100115

101116
private SwitchSetting.OnCheckedChangeListener mHistorySyncListener = (compoundButton, value, apply) -> {
102117
mAccounts.setSyncStatus(SyncEngine.History.INSTANCE, value);
103-
mAccounts.syncNowAsync(SyncReason.EngineChange.INSTANCE, false);
104118
};
105119

106120
private void resetOptions() {
107-
mAccounts.setSyncStatus(SyncEngine.Bookmarks.INSTANCE, SettingsStore.BOOKMARKS_SYNC_DEFAULT);
108-
mAccounts.setSyncStatus(SyncEngine.History.INSTANCE, SettingsStore.HISTORY_SYNC_DEFAULT);
109-
mAccounts.syncNowAsync(SyncReason.EngineChange.INSTANCE, false);
121+
mBinding.bookmarksSyncSwitch.setValue(SettingsStore.BOOKMARKS_SYNC_DEFAULT, true);
122+
mBinding.historySyncSwitch.setValue(SettingsStore.HISTORY_SYNC_DEFAULT, true);
110123
}
111124

112125
private SyncStatusObserver mSyncListener = new SyncStatusObserver() {
113126
@Override
114127
public void onStarted() {
115-
mBinding.setIsSyncing(true);
128+
updateSyncBindings(true);
116129
}
117130

118131
@Override
119132
public void onIdle() {
120-
mBinding.setIsSyncing(false);
133+
updateSyncBindings(false);
121134

122135
mBinding.bookmarksSyncSwitch.setValue(mAccounts.isEngineEnabled(SyncEngine.Bookmarks.INSTANCE), false);
123136
mBinding.historySyncSwitch.setValue(mAccounts.isEngineEnabled(SyncEngine.History.INSTANCE), false);
124137

125138
// This shouldn't be necessary but for some reason the buttons stays hovered after the sync.
126-
// I guess Android is after enabling it it's state is restored to the latest one (hovered)
139+
// I guess Android restoring it to the latest state (hovered) before being disabled
127140
// Probably an Android bindings bug.
128141
mBinding.bookmarksSyncSwitch.setHovered(false);
129142
mBinding.historySyncSwitch.setHovered(false);
143+
mBinding.syncButton.setHovered(false);
130144
}
131145

132146
@Override
133147
public void onError(@Nullable Exception e) {
134-
mBinding.setIsSyncing(false);
148+
updateSyncBindings(false);
135149
}
136150
};
137151

152+
private void updateSyncBindings(boolean isSyncing) {
153+
mBinding.setIsSyncing(isSyncing);
154+
mBinding.setLastSync(mAccounts.lastSync());
155+
mBinding.executePendingBindings();
156+
}
157+
138158
void updateCurrentAccountState() {
139159
switch(mAccounts.getAccountStatus()) {
140160
case NEEDS_RECONNECT:
@@ -173,6 +193,10 @@ private void updateProfile(Profile profile) {
173193
}
174194
}
175195

196+
private void sync(View view) {
197+
mAccounts.syncNowAsync(SyncReason.User.INSTANCE, false);
198+
}
199+
176200
private AccountObserver mAccountListener = new AccountObserver() {
177201

178202
@Override
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<selector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:enterFadeDuration="@integer/ui_fadeAnimTime"
3+
android:exitFadeDuration="@integer/ui_fadeAnimTime">
4+
<item android:state_enabled="false"
5+
android:color="@color/rhino"/>
6+
<item android:state_pressed="true"
7+
android:color="@color/fog"/>
8+
<item android:state_hovered="true"
9+
android:color="@color/asphalt"/>
10+
<item android:color="@color/fog"/>
11+
</selector>

app/src/main/res/drawable/rectangle_button_background.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<item android:state_enabled="false">
66
<shape android:shape="rectangle">
77
<corners android:radius="5dp" />
8-
<solid android:color="@color/asphalt" />
8+
<solid android:color="@color/iron" />
99
</shape>
1010
</item>
1111
<item android:state_pressed="true">

app/src/main/res/layout/bookmarks.xml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
<data>
77
<import type="android.view.View"/>
88

9+
<variable
10+
name="isAccountsUIEnabled"
11+
type="boolean" />
12+
913
<variable
1014
name="isLoading"
1115
type="boolean" />
@@ -54,6 +58,7 @@
5458
android:layout_marginStart="30dp"
5559
android:layout_marginEnd="50dp"
5660
android:layout_marginBottom="20dp"
61+
app:isAccountsUIEnabled="@{isAccountsUIEnabled}"
5762
app:isEmpty="@{isEmpty}"
5863
app:isSignedIn="@{isSignedIn}"
5964
app:isSyncEnabled="@{isSyncEnabled}"
@@ -69,6 +74,7 @@
6974
android:layout_marginStart="30dp"
7075
android:layout_marginEnd="50dp"
7176
android:layout_marginBottom="20dp"
77+
app:isAccountsUIEnabled="@{isAccountsUIEnabled}"
7278
app:isEmpty="@{isEmpty}"
7379
app:isSignedIn="@{isSignedIn}"
7480
app:isSyncEnabled="@{isSyncEnabled}"
@@ -85,8 +91,8 @@
8591
app:visibleGone="@{!isLoading &amp;&amp; isEmpty}">
8692

8793
<ImageView
88-
android:layout_width="75dp"
89-
android:layout_height="75dp"
94+
android:layout_width="@{isNarrow ? @dimen/library_icon_size_narrow : @dimen/library_icon_size_wide, default=wrap_content}"
95+
android:layout_height="@{isNarrow ? @dimen/library_icon_size_narrow : @dimen/library_icon_size_wide, default=wrap_content}"
9096
android:src="@drawable/ic_icon_bookmarks"
9197
app:srcCompat="@drawable/ic_icon_bookmarks" />
9298

app/src/main/res/layout/bookmarks_narrow.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
xmlns:app="http://schemas.android.com/apk/res-auto">
44

55
<data>
6+
<variable
7+
name="isAccountsUIEnabled"
8+
type="boolean" />
9+
610
<variable
711
name="isEmpty"
812
type="boolean" />
@@ -71,7 +75,8 @@
7175
android:layout_width="wrap_content"
7276
android:layout_height="wrap_content"
7377
android:orientation="horizontal"
74-
android:gravity="center_vertical">
78+
android:gravity="center_vertical"
79+
visibleGone="@{isAccountsUIEnabled}">
7580

7681
<FrameLayout
7782
android:id="@+id/buttons_layout"

0 commit comments

Comments
 (0)