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

Commit

Permalink
Better update of binding states
Browse files Browse the repository at this point in the history
Revert "Use Future instead of SyncListener to sync History/Bookmarks sync states (#2171)"

This reverts commit 1e9e4a8.

Revert "Revert "Use Future instead of SyncListener to sync History/Bookmarks sync states (#2171)""

This reverts commit 3299a6503e6bf1cffea6bd9fc7913a8da1af06e2.
  • Loading branch information
keianhzo committed Nov 6, 2019
1 parent 8870225 commit a17b62d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -241,19 +241,12 @@ public void removeBookmarksListener(@NonNull BookmarksCallback listener) {
private SyncStatusObserver mSyncListener = new SyncStatusObserver() {
@Override
public void onStarted() {
boolean isSyncEnabled = mAccounts.isEngineEnabled(SyncEngine.Bookmarks.INSTANCE);
mBinding.setIsSyncEnabled(isSyncEnabled);
mBinding.setIsSyncing(true);
mBinding.executePendingBindings();
updateSyncBindings(true);
}

@Override
public void onIdle() {
mBinding.setIsSyncing(false);
if (mAccounts.isEngineEnabled(SyncEngine.Bookmarks.INSTANCE)) {
mBinding.setLastSync(mAccounts.lastSync());
}
mBinding.executePendingBindings();
updateSyncBindings(false);

// This shouldn't be necessary but for some reason the buttons stays hovered after the sync.
// I guess Android is after enabling it it's state is restored to the latest one (hovered)
Expand All @@ -264,12 +257,20 @@ public void onIdle() {

@Override
public void onError(@Nullable Exception e) {
mBinding.setIsSyncing(false);
mBinding.setIsSyncEnabled(mAccounts.isEngineEnabled(SyncEngine.Bookmarks.INSTANCE));
mBinding.executePendingBindings();
updateSyncBindings(false);
}
};

private void updateSyncBindings(boolean isSyncing) {
boolean isSyncEnabled = mAccounts.isEngineEnabled(SyncEngine.Bookmarks.INSTANCE);
mBinding.setIsSyncEnabled(isSyncEnabled);
if (isSyncEnabled) {
mBinding.setIsSyncing(isSyncing);
mBinding.setLastSync(mAccounts.lastSync());
}
mBinding.executePendingBindings();
}

private AccountObserver mAccountListener = new AccountObserver() {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,19 +234,12 @@ public void removeHistoryListener(@NonNull HistoryCallback listener) {
private SyncStatusObserver mSyncListener = new SyncStatusObserver() {
@Override
public void onStarted() {
boolean isSyncEnabled = mAccounts.isEngineEnabled(SyncEngine.History.INSTANCE);
mBinding.setIsSyncEnabled(isSyncEnabled);
mBinding.setIsSyncing(true);
mBinding.executePendingBindings();
updateSyncBindings(true);
}

@Override
public void onIdle() {
mBinding.setIsSyncing(false);
if (mAccounts.isEngineEnabled(SyncEngine.History.INSTANCE)) {
mBinding.setLastSync(mAccounts.lastSync());
}
mBinding.executePendingBindings();
updateSyncBindings(false);

// This shouldn't be necessary but for some reason the buttons stays hovered after the sync.
// I guess Android is after enabling it it's state is restored to the latest one (hovered)
Expand All @@ -257,12 +250,20 @@ public void onIdle() {

@Override
public void onError(@Nullable Exception e) {
mBinding.setIsSyncing(false);
mBinding.setIsSyncEnabled(mAccounts.isEngineEnabled(SyncEngine.History.INSTANCE));
mBinding.executePendingBindings();
updateSyncBindings(false);
}
};

private void updateSyncBindings(boolean isSyncing) {
boolean isSyncEnabled = mAccounts.isEngineEnabled(SyncEngine.History.INSTANCE);
mBinding.setIsSyncEnabled(isSyncEnabled);
if (isSyncEnabled) {
mBinding.setIsSyncing(isSyncing);
mBinding.setLastSync(mAccounts.lastSync());
}
mBinding.executePendingBindings();
}

private AccountObserver mAccountListener = new AccountObserver() {

@Override
Expand Down

0 comments on commit a17b62d

Please sign in to comment.