Move asset response to separate function
This commit is contained in:
parent
18d36e1ae4
commit
0bbdef5724
2 changed files with 10 additions and 6 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -8,6 +8,7 @@
|
|||
/.idea/caches
|
||||
/.idea/codeStyles/
|
||||
/.idea/gradle.xml
|
||||
/.idea/inspectionProfiles/
|
||||
/.idea/libraries/
|
||||
/.idea/misc.xml
|
||||
/.idea/modules/
|
||||
|
|
|
@ -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))
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue