Skip to content

Commit

Permalink
Treat dotLottie files loaded as content provider URIs a zip files (#2556
Browse files Browse the repository at this point in the history
)

Fixes #2553
  • Loading branch information
gpeal authored Sep 29, 2024
1 parent d00c638 commit b851583
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,15 @@ private fun lottieTask(
LottieCompositionFactory.fromRawRes(context, spec.resId, cacheKey)
}
}

is LottieCompositionSpec.Url -> {
if (cacheKey == DefaultCacheKey) {
LottieCompositionFactory.fromUrl(context, spec.url)
} else {
LottieCompositionFactory.fromUrl(context, spec.url, cacheKey)
}
}

is LottieCompositionSpec.File -> {
if (isWarmingCache) {
// Warming the cache is done from the main thread so we can't
Expand All @@ -164,40 +166,48 @@ private fun lottieTask(
ZipInputStream(fis),
actualCacheKey,
)

spec.fileName.endsWith("tgs") -> LottieCompositionFactory.fromJsonInputStream(
GZIPInputStream(fis),
actualCacheKey,
)

else -> LottieCompositionFactory.fromJsonInputStream(
fis,
actualCacheKey,
)
}
}
}

is LottieCompositionSpec.Asset -> {
if (cacheKey == DefaultCacheKey) {
LottieCompositionFactory.fromAsset(context, spec.assetName)
} else {
LottieCompositionFactory.fromAsset(context, spec.assetName, cacheKey)
}
}

is LottieCompositionSpec.JsonString -> {
val jsonStringCacheKey = if (cacheKey == DefaultCacheKey) spec.jsonString.hashCode().toString() else cacheKey
LottieCompositionFactory.fromJsonString(spec.jsonString, jsonStringCacheKey)
}

is LottieCompositionSpec.ContentProvider -> {
val fis = context.contentResolver.openInputStream(spec.uri)
val actualCacheKey = if (cacheKey == DefaultCacheKey) spec.uri.toString() else cacheKey
when {
spec.uri.toString().endsWith("zip") -> LottieCompositionFactory.fromZipStream(
spec.uri.toString().endsWith("zip") ||
spec.uri.toString().endsWith("lottie") -> LottieCompositionFactory.fromZipStream(
ZipInputStream(fis),
actualCacheKey,
)

spec.uri.toString().endsWith("tgs") -> LottieCompositionFactory.fromJsonInputStream(
GZIPInputStream(fis),
actualCacheKey,
)

else -> LottieCompositionFactory.fromJsonInputStream(
fis,
actualCacheKey,
Expand Down

0 comments on commit b851583

Please sign in to comment.