Skip to content

Commit

Permalink
Fixing caching
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinSchildhorn committed Dec 20, 2023
1 parent ef996bc commit 2faea4c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
2 changes: 1 addition & 1 deletion shared/src/commonMain/kotlin/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ fun App(
Screen.PLAYLIST -> {
PlaylistScreen(playlistViewModel, overlaid = false) {
slideshowViewModel.setSlideshowFromPlaylist(it)
currentScreen.value = Screen.PLAYLIST
currentScreen.value = Screen.SLIDESHOW
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,28 @@ class RetrieveImageUseCase(
}

logger.i { "Getting Image Bitmap from File ${directory.name}" }
val imageBitmap: ImageBitmap? = directory.image?.getImageBitmap(50) // TODO
callback(
imageBitmap?.let {
State.SUCCESS(it)
} ?: State.ERROR("No Image Found"),
)
val smallImageBitmap = downloadAndStoreImage(directory, 64)
callback(smallImageBitmap.asState)

val largeImageBitmap = downloadAndStoreImage(directory, 256)
callback(largeImageBitmap.asState)
}

private fun downloadAndStoreImage(
directory: ImageDirectory,
bitmapSize: Int,
): ImageBitmap? {
logger.i { "Getting Image Bitmap from File ${directory.name}" }
val imageBitmap: ImageBitmap? = directory.image?.getImageBitmap(bitmapSize)
imageBitmap?.let {
logger.i { "Caching new Image ${directory.name}" }
imageCacheDataSource.saveImage(directory.details, it)
}
return imageBitmap
}

private val ImageBitmap?.asState: State<ImageBitmap>
get() = this?.let {
State.SUCCESS(it)
} ?: State.ERROR("No Image Found")
}

0 comments on commit 2faea4c

Please sign in to comment.