Search in sources :

Example 1 with ISyncService

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);
    }
}
Also used : SyncServiceException(de.danoeh.antennapod.net.sync.model.SyncServiceException) SyncServiceEvent(de.danoeh.antennapod.event.SyncServiceEvent) ISyncService(de.danoeh.antennapod.net.sync.model.ISyncService) SyncServiceException(de.danoeh.antennapod.net.sync.model.SyncServiceException) NonNull(androidx.annotation.NonNull)

Aggregations

NonNull (androidx.annotation.NonNull)1 SyncServiceEvent (de.danoeh.antennapod.event.SyncServiceEvent)1 ISyncService (de.danoeh.antennapod.net.sync.model.ISyncService)1 SyncServiceException (de.danoeh.antennapod.net.sync.model.SyncServiceException)1