-
- All Implemented Interfaces:
public final class SyncRepository
-
-
Field Summary
Fields Modifier and Type Field Description private final BooleanisEnabledprivate final ConsentRepositoryconsentRepositoryprivate final ApiEventsRepositoryapiEventsRepositoryprivate final EventsRepositoryeventsRepositoryprivate final HttpRequestHelperhttpRequestHelperprivate final OrganizationUserRepositoryorganizationUserRepositoryprivate final CoroutineDispatchercoroutineDispatcher
-
Constructor Summary
Constructors Constructor Description SyncRepository(ConfigurationRepository configurationRepository, ConsentRepository consentRepository, ApiEventsRepository apiEventsRepository, EventsRepository eventsRepository, HttpRequestHelper httpRequestHelper, OrganizationUserRepository organizationUserRepository, CoroutineDispatcher coroutineDispatcher)
-
Method Summary
Modifier and Type Method Description final BooleanisEnabled()final ConsentRepositorygetConsentRepository()final ApiEventsRepositorygetApiEventsRepository()final EventsRepositorygetEventsRepository()final HttpRequestHelpergetHttpRequestHelper()final OrganizationUserRepositorygetOrganizationUserRepository()final CoroutineDispatchergetCoroutineDispatcher()final Completion<SyncResponse>getSyncData(SyncParams params)Get the user information to sync final UnitdoSync(SyncParams params)Run the sync logic and update the user status if needed final UnitblockingSync(SyncParams params)Run the sync logic and update the user status if needed This function blocks until the sync is done. final UnitnonBlockingSync(SyncParams params)Run the sync logic and update the user status if needed This function does not block until the sync is done. final BooleanshouldSyncFromFrequency(Integer frequency, Date lastSyncDate)Determine whether we should sync based on the last sync date and the configured frequencyWe sync if: There is no frequency configured or no sync date available
The last sync date is older than the frequency
final BooleanshouldSync(Boolean enabled, Integer frequency, Date lastSyncDate)Determine whether we should run sync or not -
-
Constructor Detail
-
SyncRepository
SyncRepository(ConfigurationRepository configurationRepository, ConsentRepository consentRepository, ApiEventsRepository apiEventsRepository, EventsRepository eventsRepository, HttpRequestHelper httpRequestHelper, OrganizationUserRepository organizationUserRepository, CoroutineDispatcher coroutineDispatcher)
-
-
Method Detail
-
getConsentRepository
final ConsentRepository getConsentRepository()
-
getApiEventsRepository
final ApiEventsRepository getApiEventsRepository()
-
getEventsRepository
final EventsRepository getEventsRepository()
-
getHttpRequestHelper
final HttpRequestHelper getHttpRequestHelper()
-
getOrganizationUserRepository
final OrganizationUserRepository getOrganizationUserRepository()
-
getCoroutineDispatcher
final CoroutineDispatcher getCoroutineDispatcher()
-
getSyncData
final Completion<SyncResponse> getSyncData(SyncParams params)
Get the user information to sync
- Parameters:
params- parameters SyncParams for request
-
doSync
final Unit doSync(SyncParams params)
Run the sync logic and update the user status if needed
- Parameters:
params- parameters SyncParams for request
-
blockingSync
final Unit blockingSync(SyncParams params)
Run the sync logic and update the user status if needed This function blocks until the sync is done. It must never be called from the main/UI thread or it might throw a NetworkOnMainThreadException
This function exposes the suspend function through a regular function that can be safely called from Java with Android minAPI 16
- Parameters:
params- parameters SyncParams for request
-
nonBlockingSync
final Unit nonBlockingSync(SyncParams params)
Run the sync logic and update the user status if needed This function does not block until the sync is done. It can safely be called from the main thread.
This function exposes the suspend function through a regular function that can be safely called from Java with Android minAPI 16
- Parameters:
params- parameters SyncParams for request
-
shouldSyncFromFrequency
final Boolean shouldSyncFromFrequency(Integer frequency, Date lastSyncDate)
Determine whether we should sync based on the last sync date and the configured frequency
We sync if:
There is no frequency configured or no sync date available
The last sync date is older than the frequency
- Parameters:
frequency- as duration between sync in secondslastSyncDate- as the last sync date
-
shouldSync
final Boolean shouldSync(Boolean enabled, Integer frequency, Date lastSyncDate)
Determine whether we should run sync or not
- Parameters:
enabled- is sync is enabledfrequency- as duration between sync in secondslastSyncDate- as the last sync date
-
-
-