use of de.danoeh.antennapod.net.sync.model.ISyncService in project AntennaPod by AntennaPod.
the class SyncService method doWork.
@Override
@NonNull
public Result doWork() {
ISyncService activeSyncProvider = getActiveSyncProvider();
if (activeSyncProvider == null) {
return Result.success();
}
SynchronizationSettings.updateLastSynchronizationAttempt();
setCurrentlyActive(true);
try {
activeSyncProvider.login();
syncSubscriptions(activeSyncProvider);
waitForDownloadServiceCompleted();
syncEpisodeActions(activeSyncProvider);
activeSyncProvider.logout();
clearErrorNotifications();
EventBus.getDefault().postSticky(new SyncServiceEvent(R.string.sync_status_success));
SynchronizationSettings.setLastSynchronizationAttemptSuccess(true);
return Result.success();
} catch (Exception e) {
EventBus.getDefault().postSticky(new SyncServiceEvent(R.string.sync_status_error));
SynchronizationSettings.setLastSynchronizationAttemptSuccess(false);
Log.e(TAG, Log.getStackTraceString(e));
if (e instanceof SyncServiceException) {
if (getRunAttemptCount() % 3 == 2) {
// Do not spam users with notification and retry before notifying
updateErrorNotification(e);
}
return Result.retry();
} else {
updateErrorNotification(e);
return Result.failure();
}
} finally {
setCurrentlyActive(false);
}
}
Aggregations