Skip to content

Commit

Permalink
ResourceUriFetcher: use request.context.resouces to load drawable (#968)
Browse files Browse the repository at this point in the history
It will load drawable in correct (context) configuration.
Closes #752
Closes #954
  • Loading branch information
Khang-NT authored Nov 8, 2021
1 parent 9e15294 commit 38c3a5a
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion coil-base/src/main/java/coil/fetch/ResourceUriFetcher.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ internal class ResourceUriFetcher(
val resId = data.pathSegments.lastOrNull()?.toIntOrNull() ?: throwInvalidUriException(data)

val context = options.context
val resources = context.packageManager.getResourcesForApplication(packageName)
val resources = if (packageName == context.packageName) {
context.resources
} else {
context.packageManager.getResourcesForApplication(packageName)
}
val path = TypedValue().apply { resources.getValue(resId, this, true) }.string
val entryName = path.substring(path.lastIndexOf('/'))
val mimeType = MimeTypeMap.getSingleton().getMimeTypeFromUrl(entryName)
Expand Down

0 comments on commit 38c3a5a

Please sign in to comment.