All methods that return Flow must not be suspendable

This commit is contained in:
2021-09-06 21:54:09 +02:00
parent 64fbf09026
commit f61c456caa
3 changed files with 10 additions and 10 deletions
@@ -10,19 +10,19 @@ import javax.inject.Inject
class LocalLottieFileDataSource @Inject constructor( class LocalLottieFileDataSource @Inject constructor(
private val lottieFileDao: LottieFilesDao private val lottieFileDao: LottieFilesDao
) : LottieFileDataSource { ) : LottieFileDataSource {
override suspend fun findRecent(): Flow<Result<List<Lottiefile>>> { override fun findRecent(): Flow<Result<List<Lottiefile>>> {
return lottieFileDao.findRecent().map { return lottieFileDao.findRecent().map {
Result.Success(it) Result.Success(it)
} }
} }
override suspend fun findPopular(): Flow<Result<List<Lottiefile>>> { override fun findPopular(): Flow<Result<List<Lottiefile>>> {
return lottieFileDao.findPopular().map { return lottieFileDao.findPopular().map {
Result.Success(it) Result.Success(it)
} }
} }
override suspend fun findFeatured(): Flow<Result<List<Lottiefile>>> { override fun findFeatured(): Flow<Result<List<Lottiefile>>> {
return lottieFileDao.findFeatured().map { return lottieFileDao.findFeatured().map {
Result.Success(it) Result.Success(it)
} }
@@ -5,8 +5,8 @@ import com.ericampire.android.androidstudycase.util.Result
import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow
interface LottieFileDataSource { interface LottieFileDataSource {
suspend fun findRecent(): Flow<Result<List<Lottiefile>>> fun findRecent(): Flow<Result<List<Lottiefile>>>
suspend fun findPopular(): Flow<Result<List<Lottiefile>>> fun findPopular(): Flow<Result<List<Lottiefile>>>
suspend fun findFeatured(): Flow<Result<List<Lottiefile>>> fun findFeatured(): Flow<Result<List<Lottiefile>>>
suspend fun save(lottiefile: Lottiefile) suspend fun save(lottiefile: Lottiefile)
} }
@@ -14,7 +14,7 @@ class RemoteLottieFileDataSource @Inject constructor(
private val httpClient: HttpClient private val httpClient: HttpClient
) : LottieFileDataSource { ) : LottieFileDataSource {
private suspend fun find(url: String): Flow<Result<List<Lottiefile>>> { private fun find(url: String): Flow<Result<List<Lottiefile>>> {
return flow { return flow {
try { try {
val data = httpClient.get<LottieFilesApiResponse>(url) val data = httpClient.get<LottieFilesApiResponse>(url)
@@ -25,15 +25,15 @@ class RemoteLottieFileDataSource @Inject constructor(
} }
} }
override suspend fun findRecent(): Flow<Result<List<Lottiefile>>> { override fun findRecent(): Flow<Result<List<Lottiefile>>> {
return find(ApiUrl.LottieFile.recent) return find(ApiUrl.LottieFile.recent)
} }
override suspend fun findPopular(): Flow<Result<List<Lottiefile>>> { override fun findPopular(): Flow<Result<List<Lottiefile>>> {
return find(ApiUrl.LottieFile.popular) return find(ApiUrl.LottieFile.popular)
} }
override suspend fun findFeatured(): Flow<Result<List<Lottiefile>>> { override fun findFeatured(): Flow<Result<List<Lottiefile>>> {
return find(ApiUrl.LottieFile.featured) return find(ApiUrl.LottieFile.featured)
} }