Skip to content

Commit

Permalink
Revert to realtime sync (#2586)
Browse files Browse the repository at this point in the history
  • Loading branch information
keianhzo authored and bluemarvin committed Jan 14, 2020
1 parent fbde00f commit 174d5bd
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import mozilla.components.service.fxa.sync.SyncStatusObserver
import mozilla.components.service.fxa.sync.getLastSynced
import org.mozilla.vrbrowser.R
import org.mozilla.vrbrowser.VRBrowserApplication
import org.mozilla.vrbrowser.utils.BitmapCache
import org.mozilla.vrbrowser.telemetry.GleanMetricsService
import org.mozilla.vrbrowser.utils.BitmapCache
import org.mozilla.vrbrowser.utils.SystemUtils
import org.mozilla.vrbrowser.utils.ViewUtils
import java.net.URL
Expand Down Expand Up @@ -127,8 +127,6 @@ class Accounts constructor(val context: Context) {
accountStatus = AccountStatus.SIGNED_IN

// Enable syncing after signing in
syncStorage.setStatus(SyncEngine.Bookmarks, SettingsStore.getInstance(context).isBookmarksSyncEnabled)
syncStorage.setStatus(SyncEngine.History, SettingsStore.getInstance(context).isHistorySyncEnabled)
services.accountManager.syncNowAsync(SyncReason.EngineChange, true)

// Update device list
Expand Down Expand Up @@ -319,11 +317,9 @@ class Accounts constructor(val context: Context) {
when(engine) {
SyncEngine.Bookmarks -> {
GleanMetricsService.FxA.bookmarksSyncStatus(value)
SettingsStore.getInstance(context).isBookmarksSyncEnabled = value
}
SyncEngine.History -> {
GleanMetricsService.FxA.historySyncStatus(value)
SettingsStore.getInstance(context).isHistorySyncEnabled = value
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -621,25 +621,6 @@ public void setPopUpsBlockingEnabled(boolean isEnabled) {
editor.putBoolean(mContext.getString(R.string.settings_key_pop_up_blocking), isEnabled);
editor.commit();
}
public void setBookmarksSyncEnabled(boolean isEnabled) {
SharedPreferences.Editor editor = mPrefs.edit();
editor.putBoolean(mContext.getString(R.string.settings_key_bookmarks_sync), isEnabled);
editor.commit();
}

public boolean isBookmarksSyncEnabled() {
return mPrefs.getBoolean(mContext.getString(R.string.settings_key_bookmarks_sync), BOOKMARKS_SYNC_DEFAULT);
}

public void setHistorySyncEnabled(boolean isEnabled) {
SharedPreferences.Editor editor = mPrefs.edit();
editor.putBoolean(mContext.getString(R.string.settings_key_history_sync), isEnabled);
editor.commit();
}

public boolean isHistorySyncEnabled() {
return mPrefs.getBoolean(mContext.getString(R.string.settings_key_history_sync), HISTORY_SYNC_DEFAULT);
}

public void setWhatsNewDisplayed(boolean isEnabled) {
SharedPreferences.Editor editor = mPrefs.edit();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ class FxAAccountOptionsView extends SettingsView {
private Accounts mAccounts;
private Places mPlaces;
private Executor mUIThreadExecutor;
private boolean mInitialBookmarksState;
private boolean mInitialHistoryState;
private SignOutDialogWidget mSignOutDialog;

public FxAAccountOptionsView(Context aContext, WidgetManagerDelegate aWidgetManager) {
Expand Down Expand Up @@ -92,11 +90,8 @@ public void onShown() {
mAccounts.addAccountListener(mAccountListener);
mAccounts.addSyncListener(mSyncListener);

mInitialBookmarksState = mAccounts.isEngineEnabled(SyncEngine.Bookmarks.INSTANCE);
mInitialHistoryState = mAccounts.isEngineEnabled(SyncEngine.History.INSTANCE);

mBinding.bookmarksSyncSwitch.setValue(mInitialBookmarksState, false);
mBinding.historySyncSwitch.setValue(mInitialHistoryState, false);
mBinding.bookmarksSyncSwitch.setValue(mAccounts.isEngineEnabled(SyncEngine.Bookmarks.INSTANCE), false);
mBinding.historySyncSwitch.setValue(mAccounts.isEngineEnabled(SyncEngine.History.INSTANCE), false);

updateSyncBindings(mAccounts.isSyncing());
}
Expand All @@ -107,20 +102,16 @@ public void onHidden() {

mAccounts.removeAccountListener(mAccountListener);
mAccounts.removeSyncListener(mSyncListener);

// We only sync engines in case the user has changed the sync engines since previous sync
if (mBinding.bookmarksSyncSwitch.isChecked() != mInitialBookmarksState ||
mBinding.historySyncSwitch.isChecked() != mInitialHistoryState) {
mAccounts.syncNowAsync(SyncReason.EngineChange.INSTANCE, false);
}
}

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

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

private void resetOptions() {
Expand All @@ -138,6 +129,9 @@ public void onStarted() {
public void onIdle() {
updateSyncBindings(false);

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

// This shouldn't be necessary but for some reason the buttons stays hovered after the sync.
// I guess Android restoring it to the latest state (hovered) before being disabled
// Probably an Android bindings bug.
Expand Down Expand Up @@ -201,12 +195,7 @@ private void updateProfile(Profile profile) {
}

private void sync(View view) {
if (mBinding.bookmarksSyncSwitch.isChecked() != mInitialBookmarksState ||
mBinding.historySyncSwitch.isChecked() != mInitialHistoryState) {
mAccounts.syncNowAsync(SyncReason.EngineChange.INSTANCE, false);
} else {
mAccounts.syncNowAsync(SyncReason.User.INSTANCE, false);
}
mAccounts.syncNowAsync(SyncReason.User.INSTANCE, false);
mAccounts.updateProfileAsync();
}

Expand Down

0 comments on commit 174d5bd

Please sign in to comment.