Created
July 11, 2019 18:08
-
-
Save leocruzdev/92f660ede513a4e4fdc037d0a3a5f6f7 to your computer and use it in GitHub Desktop.
repository
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.dacruzl2.gitmvpkoin.data.source | |
import android.util.Log | |
import com.dacruzl2.gitmvpkoin.data.Root | |
import com.dacruzl2.gitmvpkoin.data.source.local.GithubDao | |
import com.dacruzl2.gitmvpkoin.data.source.remote.services.GithubService | |
import kotlinx.coroutines.Dispatchers | |
import kotlinx.coroutines.withContext | |
class GithubRepository( | |
private val remoteDataSource: GithubService, | |
private val localDataSource: GithubDao | |
) : GithubDataSource { | |
override suspend fun getIssues(onSuccess: (issues: List<Root>) -> Unit) { | |
withContext(Dispatchers.IO) { | |
try { | |
val request = remoteDataSource.getIssues().await() | |
if (request.isSuccessful) { | |
withContext(Dispatchers.Main) { | |
val issuesList = request.body()!! | |
onSuccess(issuesList) | |
withContext(Dispatchers.IO) { | |
Log.d("DB", "initSaveDB") | |
localDataSource.saveIssues(issuesList) | |
Log.d("DB", "DBsaved: $issuesList") | |
} | |
} | |
} else { | |
} | |
} catch (t: Exception) { | |
} | |
} | |
} | |
override suspend fun saveIssues(issues: List<Root>) { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment