Skip to content

Commit

Permalink
For mozilla-mobile#26424 - Allow migrated wallpapers to be visible in…
Browse files Browse the repository at this point in the history
… the wallpaper settings page
  • Loading branch information
Alexandru2909 committed Sep 5, 2022
1 parent cce7177 commit 722edac
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,27 @@ class WallpaperFileManager(
File(storageRootDirectory, getLocalPath(name, type)).exists()
}

/**
* Get the list of migrated legacy wallpapers.
*
* @param remoteAvailableWallpapers List of wallpapers available remote.
* @param localAvailableWallpapers List of wallpapers available locally.
* @return List of migrated wallpapers.
*/
suspend fun getMigratedWallpapers(
remoteAvailableWallpapers: List<Wallpaper>,
localAvailableWallpapers: List<Wallpaper>,
) = withContext(Dispatchers.IO) {
File(storageRootDirectory, "wallpapers").listFiles()
?.filter { file ->
file.isDirectory && !localAvailableWallpapers.map { it.name }
.contains(file.nameWithoutExtension)
}
?.map { file ->
getWallpaperByName(file.name, remoteAvailableWallpapers)
} ?: listOf()
}

/**
* Migrate the legacy wallpapers to the new path and delete the remaining legacy files.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,22 @@ class WallpaperFileManagerTest {
assertEquals(null, result)
}

@Test
fun `WHEN looking for migrated wallpapers THEN only the legacy wallpaper is retrieved`() = runTest {
val firstWallpaper = "wallpaper1"
val secondWallpaper = "wallpaper2"
createAllFiles(firstWallpaper)
createAllFiles(secondWallpaper)

val migratedWallpapers = fileManager.getMigratedWallpapers(
listOf(),
listOf(generateWallpaper(firstWallpaper))
)

assertEquals(1, migratedWallpapers.size)
assertEquals(secondWallpaper, migratedWallpapers.single().name)
}

@Test
fun `WHEN legacy wallpapers are migrated AND the migrated file already exists in local wallpapers THEN the legacy wallpaper is not migrated`() = runTest {
val wallpaperName = "wallpaper"
Expand Down

0 comments on commit 722edac

Please sign in to comment.