Closes #26213: Add wallpaper use case to load thumbnails.
This commit is contained in:
parent
0d51d2b0f9
commit
2cd8a41ea5
|
@ -43,6 +43,7 @@ class WallpapersUseCases(
|
|||
store: AppStore,
|
||||
client: Client,
|
||||
strictMode: StrictModeManager,
|
||||
filesDir: File,
|
||||
) {
|
||||
val initialize: InitializeWallpapersUseCase by lazy {
|
||||
if (FeatureFlags.wallpaperV2Enabled) {
|
||||
|
@ -89,6 +90,13 @@ class WallpapersUseCases(
|
|||
LegacyLoadBitmapUseCase(context)
|
||||
}
|
||||
}
|
||||
val loadThumbnail: LoadThumbnailUseCase by lazy {
|
||||
if (FeatureFlags.wallpaperV2Enabled) {
|
||||
DefaultLoadThumbnailUseCase(filesDir)
|
||||
} else {
|
||||
LegacyLoadThumbnailUseCase(context)
|
||||
}
|
||||
}
|
||||
val selectWallpaper: SelectWallpaperUseCase by lazy { DefaultSelectWallpaperUseCase(context.settings(), store) }
|
||||
|
||||
/**
|
||||
|
@ -380,6 +388,37 @@ class WallpapersUseCases(
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Contract for usecase for loading thumbnail bitmaps related to a specific wallpaper.
|
||||
*/
|
||||
interface LoadThumbnailUseCase {
|
||||
/**
|
||||
* Load the bitmap for a [wallpaper] thumbnail, if available.
|
||||
*
|
||||
* @param wallpaper The wallpaper to load a thumbnail for.
|
||||
*/
|
||||
suspend operator fun invoke(wallpaper: Wallpaper): Bitmap?
|
||||
}
|
||||
|
||||
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
|
||||
internal class LegacyLoadThumbnailUseCase(private val context: Context): LoadThumbnailUseCase {
|
||||
override suspend fun invoke(wallpaper: Wallpaper): Bitmap? =
|
||||
LegacyLoadBitmapUseCase(context).invoke(wallpaper)
|
||||
}
|
||||
|
||||
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
|
||||
internal class DefaultLoadThumbnailUseCase(private val filesDir: File): LoadThumbnailUseCase {
|
||||
override suspend fun invoke(wallpaper: Wallpaper): Bitmap? = withContext(Dispatchers.IO) {
|
||||
Result.runCatching {
|
||||
val path = Wallpaper.getLocalPath(wallpaper.name, Wallpaper.ImageType.Thumbnail)
|
||||
withContext(Dispatchers.IO) {
|
||||
val file = File(filesDir, path)
|
||||
BitmapFactory.decodeStream(file.inputStream())
|
||||
}
|
||||
}.getOrNull()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Contract for usecase of selecting a new wallpaper.
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue
Block a user