abstract class OnlineRepository<CACHE : Any, GET_DATA_REQUIREMENTS : GetDataRequirements, FETCH_RESPONSE : Any> : Listener
Teller repository that manages cached data that is obtained from a network fetch request.
Using OnlineRepository is quite simple:
OnlineRepository is thread safe. Actions called upon for OnlineRepository can be performed on any thread.
class FetchResponse<FETCH_RESPONSE : Any>
When a OnlineRepository.fetchFreshData task is performed, Teller needs to know if the fetch request is considered to be a success or a failure. |
|
interface GetDataRequirements
Data object that are the requirements to fetch fresh data or get cached data on device. |
|
class RefreshResult
Result object of a call to OnlineRepository.refresh. Understand if a refresh call was successful, not successful, or skipped for some reason. |
OnlineRepository() |
abstract var maxAge: AgeOfData
Used to set how old cached data can be on the device before it is considered too old and new cached data should be fetched. |
|
var requirements: GET_DATA_REQUIREMENTS?
Requirements needed to be able to load cached data from the device and to fetch new cached data from the network. |
fun dispose(): Unit
Dispose of the OnlineRepository to shut down observing of cached data and stops refresh tasks if they have begun. |
|
abstract fun fetchFreshData(requirements: GET_DATA_REQUIREMENTS): Single<FetchResponse<FETCH_RESPONSE>>
Repository does what it needs in order to fetch fresh cacheData. Probably call network API. |
|
abstract fun isDataEmpty(cache: CACHE, requirements: GET_DATA_REQUIREMENTS): Boolean
DataType determines if cacheData is empty or not. Because cacheData can be of |
|
fun observe(): Observable<OnlineDataState<CACHE>>
How to begin observing the state of the data for this OnlineRepository. |
|
abstract fun observeCachedData(requirements: GET_DATA_REQUIREMENTS): Observable<CACHE>
Get existing cached data saved on the device if it exists. If no data exists, return an empty data set in the Observable and return true in isDataEmpty. Do not return nil or an Observable with nil as a value as this will cause an exception. |
|
fun refresh(force: Boolean): Single<RefreshResult>
Manually perform a refresh of the cached data. |
|
open fun refreshBegin(): Unit |
|
open fun <RefreshResultDataType : Any> refreshComplete(response: FetchResponse<RefreshResultDataType>): Unit |
|
abstract fun saveData(data: FETCH_RESPONSE, requirements: GET_DATA_REQUIREMENTS): Unit
Save the new cache data to whatever storage method OnlineRepository chooses. |