-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #58 from KevinSchildhorn/ks/AddingNewCache
Updating how we get images
- Loading branch information
Showing
15 changed files
with
230 additions
and
68 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
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
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
26 changes: 19 additions & 7 deletions
26
.../commonMain/kotlin/com/kevinschildhorn/fotopresenter/data/repositories/ImageRepository.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,42 @@ | ||
package com.kevinschildhorn.fotopresenter.data.repositories | ||
|
||
import co.touchlab.kermit.Logger | ||
import coil3.Image | ||
import coil3.fetch.FetchResult | ||
import com.kevinschildhorn.fotopresenter.data.datasources.image.CachedImageDataSource | ||
import com.kevinschildhorn.fotopresenter.data.datasources.image.NetworkImageDataSource | ||
import com.kevinschildhorn.fotopresenter.data.network.NetworkDirectoryDetails | ||
import com.kevinschildhorn.fotopresenter.ui.shared.SharedImage | ||
|
||
class ImageRepository( | ||
private val remoteImageDataSource: NetworkImageDataSource, | ||
private val localImageDataSource: CachedImageDataSource, | ||
private val logger: Logger?, | ||
) { | ||
suspend fun getCoilImage( | ||
suspend fun getFetchResult( | ||
directoryDetails: NetworkDirectoryDetails, | ||
size: Int, | ||
): Image? { | ||
logger?.i { "Getting Image from Cache" } | ||
): FetchResult? { | ||
val image = getImage(directoryDetails, size) | ||
return image?.getFetchResult(size) | ||
} | ||
|
||
private suspend fun getImage( | ||
directoryDetails: NetworkDirectoryDetails, | ||
size: Int, | ||
): SharedImage? { | ||
logger?.i { "Getting Image from Cache: ${directoryDetails.name}" } | ||
val cachedImage = localImageDataSource.getImage(directoryDetails) | ||
if (cachedImage != null) return cachedImage.getCoilImage(size) | ||
if (cachedImage != null) { | ||
logger?.i { "Cached image found from Cache: ${directoryDetails.name}" } | ||
return cachedImage | ||
} | ||
|
||
logger?.i { "No cached image found, getting image from directory" } | ||
val image = remoteImageDataSource.getImage(directoryDetails) | ||
if (image != null) { | ||
logger?.i { "Storing image in cache" } | ||
logger?.i { "Storing image in cache: ${directoryDetails.name}" } | ||
localImageDataSource.saveImage(directoryDetails, image) | ||
} | ||
return image?.getCoilImage(size) | ||
return image | ||
} | ||
} |
Oops, something went wrong.