Guest User

Untitled

a guest
Oct 23rd, 2019
85
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class AccountRepository
  2. @Inject
  3. constructor(
  4. val openApiMainService: OpenApiMainService,
  5. val accountPropertiesDao: AccountPropertiesDao,
  6. val sessionManager: SessionManager
  7. )
  8. {
  9.  
  10. private val TAG: String = "AppDebug"
  11.  
  12. private var repositoryJob: Job? = null
  13.  
  14. fun getAccountProperties(authToken: AuthToken): LiveData<DataState<AccountViewState>> {
  15. return object: NetworkBoundResource<AccountProperties, AccountViewState>(
  16. sessionManager.isConnectedToTheInternet(),
  17. true
  18. ){
  19.  
  20. // if network is down, view the cache and return
  21. override suspend fun createCacheRequestAndReturn() {
  22.  
  23. }
  24.  
  25. override suspend fun handleApiSuccessResponse(response: ApiSuccessResponse<AccountProperties>) {
  26.  
  27.  
  28. }
  29.  
  30.  
  31. override fun createCall(): LiveData<GenericApiResponse<AccountProperties>> {
  32. return openApiMainService
  33. .getAccountProperties(
  34. "Token ${authToken.token!!}"
  35. )
  36. }
  37.  
  38.  
  39. override fun setJob(job: Job) {
  40. repositoryJob?.cancel()
  41. repositoryJob = job
  42. }
  43.  
  44.  
  45. }.asLiveData()
  46. }
  47.  
  48. fun cancelActiveJobs(){
  49. Log.d(TAG, "AuthRepository: Cancelling on-going jobs...")
  50. repositoryJob?.cancel()
  51. }
  52.  
  53. }
RAW Paste Data