Restore test for image sending, now that computing Thumbnail can fail.
This commit is contained in:
parent
4cd3faf936
commit
e156cf0515
2 changed files with 27 additions and 31 deletions
|
|
@ -65,24 +65,29 @@ class ThumbnailFactory @Inject constructor(
|
||||||
@SuppressLint("NewApi")
|
@SuppressLint("NewApi")
|
||||||
suspend fun createImageThumbnail(file: File): ThumbnailResult? {
|
suspend fun createImageThumbnail(file: File): ThumbnailResult? {
|
||||||
return createThumbnail { cancellationSignal ->
|
return createThumbnail { cancellationSignal ->
|
||||||
// This API works correctly with GIF
|
try {
|
||||||
if (sdkIntProvider.isAtLeast(Build.VERSION_CODES.Q)) {
|
// This API works correctly with GIF
|
||||||
try {
|
if (sdkIntProvider.isAtLeast(Build.VERSION_CODES.Q)) {
|
||||||
|
try {
|
||||||
|
ThumbnailUtils.createImageThumbnail(
|
||||||
|
file,
|
||||||
|
Size(THUMB_MAX_WIDTH, THUMB_MAX_HEIGHT),
|
||||||
|
cancellationSignal
|
||||||
|
)
|
||||||
|
} catch (ioException: IOException) {
|
||||||
|
Timber.w(ioException, "Failed to create thumbnail for $file")
|
||||||
|
null
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
ThumbnailUtils.createImageThumbnail(
|
ThumbnailUtils.createImageThumbnail(
|
||||||
file,
|
file.path,
|
||||||
Size(THUMB_MAX_WIDTH, THUMB_MAX_HEIGHT),
|
MediaStore.Images.Thumbnails.MINI_KIND,
|
||||||
cancellationSignal
|
|
||||||
)
|
)
|
||||||
} catch (ioException: IOException) {
|
|
||||||
Timber.w(ioException, "Failed to create thumbnail for $file")
|
|
||||||
null
|
|
||||||
}
|
}
|
||||||
} else {
|
} catch (throwable: Throwable) {
|
||||||
@Suppress("DEPRECATION")
|
Timber.w(throwable, "Failed to create thumbnail for $file")
|
||||||
ThumbnailUtils.createImageThumbnail(
|
null
|
||||||
file.path,
|
|
||||||
MediaStore.Images.Thumbnails.MINI_KIND,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -55,15 +55,11 @@ class AndroidMediaPreProcessorTest {
|
||||||
deleteOriginal = false,
|
deleteOriginal = false,
|
||||||
compressIfPossible = true,
|
compressIfPossible = true,
|
||||||
)
|
)
|
||||||
// This is failing for now
|
|
||||||
val error = result.exceptionOrNull()
|
|
||||||
assertThat(error).isInstanceOf(MediaPreProcessor.Failure::class.java)
|
|
||||||
assertThat(error?.cause).isInstanceOf(NullPointerException::class.java)
|
|
||||||
/*
|
|
||||||
val data = result.getOrThrow()
|
val data = result.getOrThrow()
|
||||||
assertThat(data.file.path).endsWith("image.png")
|
assertThat(data.file.path).endsWith("image.png")
|
||||||
val info = data as MediaUploadInfo.Image
|
val info = data as MediaUploadInfo.Image
|
||||||
assertThat(info.thumbnailFile).isNull() // TODO Check this
|
// Computing thumbnailFile is failing with Robolectric
|
||||||
|
assertThat(info.thumbnailFile).isNull()
|
||||||
assertThat(info.imageInfo).isEqualTo(
|
assertThat(info.imageInfo).isEqualTo(
|
||||||
ImageInfo(
|
ImageInfo(
|
||||||
height = 1_178,
|
height = 1_178,
|
||||||
|
|
@ -76,7 +72,6 @@ class AndroidMediaPreProcessorTest {
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
assertThat(file.exists()).isTrue()
|
assertThat(file.exists()).isTrue()
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -90,15 +85,11 @@ class AndroidMediaPreProcessorTest {
|
||||||
deleteOriginal = false,
|
deleteOriginal = false,
|
||||||
compressIfPossible = true,
|
compressIfPossible = true,
|
||||||
)
|
)
|
||||||
// This is not working for now
|
|
||||||
val error = result.exceptionOrNull()
|
|
||||||
assertThat(error).isInstanceOf(MediaPreProcessor.Failure::class.java)
|
|
||||||
assertThat(error?.cause).isInstanceOf(NoSuchMethodError::class.java)
|
|
||||||
/*
|
|
||||||
val data = result.getOrThrow()
|
val data = result.getOrThrow()
|
||||||
assertThat(data.file.path).endsWith("image.png")
|
assertThat(data.file.path).endsWith("image.png")
|
||||||
val info = data as MediaUploadInfo.Image
|
val info = data as MediaUploadInfo.Image
|
||||||
assertThat(info.thumbnailFile).isNull() // TODO Check this
|
// Computing thumbnailFile is failing with Robolectric
|
||||||
|
assertThat(info.thumbnailFile).isNull()
|
||||||
assertThat(info.imageInfo).isEqualTo(
|
assertThat(info.imageInfo).isEqualTo(
|
||||||
ImageInfo(
|
ImageInfo(
|
||||||
height = 1_178,
|
height = 1_178,
|
||||||
|
|
@ -111,7 +102,6 @@ class AndroidMediaPreProcessorTest {
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
assertThat(file.exists()).isTrue()
|
assertThat(file.exists()).isTrue()
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -266,7 +256,8 @@ class AndroidMediaPreProcessorTest {
|
||||||
).getOrThrow()
|
).getOrThrow()
|
||||||
assertThat(result.file.path).endsWith("video.mp4")
|
assertThat(result.file.path).endsWith("video.mp4")
|
||||||
val info = result as MediaUploadInfo.Video
|
val info = result as MediaUploadInfo.Video
|
||||||
assertThat(info.thumbnailFile).isNotNull()
|
// Computing thumbnailFile is failing with Robolectric
|
||||||
|
assertThat(info.thumbnailFile).isNull()
|
||||||
assertThat(info.videoInfo).isEqualTo(
|
assertThat(info.videoInfo).isEqualTo(
|
||||||
VideoInfo(
|
VideoInfo(
|
||||||
duration = Duration.ZERO, // Not available with Robolectric?
|
duration = Duration.ZERO, // Not available with Robolectric?
|
||||||
|
|
@ -274,7 +265,7 @@ class AndroidMediaPreProcessorTest {
|
||||||
width = 0, // Not available with Robolectric?
|
width = 0, // Not available with Robolectric?
|
||||||
mimetype = MimeTypes.Mp4,
|
mimetype = MimeTypes.Mp4,
|
||||||
size = 1_673_712,
|
size = 1_673_712,
|
||||||
thumbnailInfo = ThumbnailInfo(height = null, width = null, mimetype = MimeTypes.Jpeg, size = 0), // Not available with Robolectric?
|
thumbnailInfo = null,
|
||||||
thumbnailSource = null,
|
thumbnailSource = null,
|
||||||
blurhash = null,
|
blurhash = null,
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue