suspend fun downloadWallpaper(wallpaper: Wallpaper): Wallpaper.ImageFileState = withContext(dispatcher) { val portraitResult = downloadAsset(wallpaper, Wallpaper.ImageType.Portrait) val landscapeResult = downloadAsset(wallpaper, Wallpaper.ImageType.Landscape) return@withContext if (portraitResult == Wallpaper.ImageFileState.Downloaded && landscapeResult == Wallpaper.ImageFileState.Downloaded ) { Wallpaper.ImageFileState.Downloaded } else { Wallpaper.ImageFileState.Error } }
Downloads a wallpaper from the network. Will try to fetch 2 versions of each wallpaper: portrait and landscape. These are expected to be found at a remote path in the form: <WALLPAPER_URL>/<collection name>/<wallpaper name>/<orientation>.png and will be stored in the local path: wallpapers/<wallpaper name>/<orientation>.png