fun clean(currentWallpaper: Wallpaper, availableWallpapers: List<Wallpaper>) { CoroutineScope(coroutineDispatcher).launch { val wallpapersToKeep = (listOf(currentWallpaper) + availableWallpapers).map { it.name } wallpapersDirectory.listFiles()?.forEach { file -> if (file.isDirectory && !wallpapersToKeep.contains(file.name)) { file.deleteRecursively() } } } }
Remove all wallpapers that are not the [currentWallpaper] or in [availableWallpapers].