Created
December 23, 2023 10:10
-
-
Save chiragthummar/66103a26770708ef33e1d583c2caf8a8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| @Singleton | |
| class ImageRepositoryImpl @Inject constructor( | |
| private val imageApi: ImageApi | |
| ) : ImageRepository { | |
| override fun getImages(text: String): Flow<Resources<List<Image>>> { | |
| return flow { | |
| emit(Resources.Loading(true)) | |
| val remoteList = try { | |
| imageApi.getInfiniteApiImages(text) | |
| } catch (e: IOException) { | |
| e.printStackTrace() | |
| emit(Resources.Error("Could not load data")) | |
| null | |
| } catch (e: HttpException) { | |
| e.printStackTrace() | |
| emit(Resources.Error("Could not load data")) | |
| null | |
| } | |
| remoteList.let { listing -> | |
| emit(Resources.Success(data = listing?.images?.map { it.toImage() })) | |
| emit(Resources.Loading(false)) | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment