1
0
Fork 0

Move asset response to separate function

This commit is contained in:
Alex Kotov 2021-08-17 04:34:27 +05:00
parent 18d36e1ae4
commit 0bbdef5724
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08
2 changed files with 10 additions and 6 deletions

1
.gitignore vendored
View file

@ -8,6 +8,7 @@
/.idea/caches
/.idea/codeStyles/
/.idea/gradle.xml
/.idea/inspectionProfiles/
/.idea/libraries/
/.idea/misc.xml
/.idea/modules/

View file

@ -24,13 +24,11 @@ class CustomWebViewClient(private val context: Context) : WebViewClient() {
return when (request.url.path) {
"/assets/images/blog/decentralized-vs-distributed-wrong.png" ->
WebResourceResponse("image/png", "utf-8",
context.assets.open("decentralized-vs-distributed-wrong.png"))
assetResponse("image/png",
"decentralized-vs-distributed-wrong.png")
"/assets/images/blog/network-topologies.png" ->
WebResourceResponse("image/png", "utf-8",
context.assets.open("network-topologies.png"))
else ->
teapotResponse()
assetResponse("image/png", "network-topologies.png")
else -> teapotResponse()
}
}
@ -52,4 +50,9 @@ class CustomWebViewClient(private val context: Context) : WebViewClient() {
null, null,
)
}
private fun assetResponse(mimeType: String, assetFileName: String):
WebResourceResponse {
return WebResourceResponse(mimeType, "utf-8", context.assets.open(assetFileName))
}
}