mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-27 03:49:04 +03:00
Better Kotlin code
This commit is contained in:
parent
5652140f5d
commit
ac07fb47d7
1 changed files with 21 additions and 15 deletions
|
@ -31,27 +31,33 @@ internal class DefaultContentUrlResolver @Inject constructor(homeServerConnectio
|
||||||
override val uploadUrl = baseUrl + sep + NetworkConstants.URI_API_MEDIA_PREFIX_PATH_R0 + "upload"
|
override val uploadUrl = baseUrl + sep + NetworkConstants.URI_API_MEDIA_PREFIX_PATH_R0 + "upload"
|
||||||
|
|
||||||
override fun resolveFullSize(contentUrl: String?): String? {
|
override fun resolveFullSize(contentUrl: String?): String? {
|
||||||
if (contentUrl?.isValidMatrixContentUrl() == true) {
|
return contentUrl
|
||||||
val prefix = NetworkConstants.URI_API_MEDIA_PREFIX_PATH_R0 + "download/"
|
// do not allow non-mxc content URLs
|
||||||
return resolve(contentUrl, prefix)
|
?.takeIf { it.isValidMatrixContentUrl() }
|
||||||
}
|
?.let {
|
||||||
// do not allow non-mxc content URLs
|
resolve(
|
||||||
return null
|
contentUrl = it,
|
||||||
|
prefix = NetworkConstants.URI_API_MEDIA_PREFIX_PATH_R0 + "download/"
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun resolveThumbnail(contentUrl: String?, width: Int, height: Int, method: ContentUrlResolver.ThumbnailMethod): String? {
|
override fun resolveThumbnail(contentUrl: String?, width: Int, height: Int, method: ContentUrlResolver.ThumbnailMethod): String? {
|
||||||
if (contentUrl?.isValidMatrixContentUrl() == true) {
|
return contentUrl
|
||||||
val prefix = NetworkConstants.URI_API_MEDIA_PREFIX_PATH_R0 + "thumbnail/"
|
// do not allow non-mxc content URLs
|
||||||
val params = "?width=$width&height=$height&method=${method.value}"
|
?.takeIf { it.isValidMatrixContentUrl() }
|
||||||
return resolve(contentUrl, prefix, params)
|
?.let {
|
||||||
}
|
resolve(
|
||||||
// do not allow non-mxc content URLs
|
contentUrl = it,
|
||||||
return null
|
prefix = NetworkConstants.URI_API_MEDIA_PREFIX_PATH_R0 + "thumbnail/",
|
||||||
|
params = "?width=$width&height=$height&method=${method.value}"
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun resolve(contentUrl: String,
|
private fun resolve(contentUrl: String,
|
||||||
prefix: String,
|
prefix: String,
|
||||||
params: String? = null): String? {
|
params: String = ""): String? {
|
||||||
var serverAndMediaId = contentUrl.removePrefix(MATRIX_CONTENT_URI_SCHEME)
|
var serverAndMediaId = contentUrl.removePrefix(MATRIX_CONTENT_URI_SCHEME)
|
||||||
val fragmentOffset = serverAndMediaId.indexOf("#")
|
val fragmentOffset = serverAndMediaId.indexOf("#")
|
||||||
var fragment = ""
|
var fragment = ""
|
||||||
|
@ -60,7 +66,7 @@ internal class DefaultContentUrlResolver @Inject constructor(homeServerConnectio
|
||||||
serverAndMediaId = serverAndMediaId.substring(0, fragmentOffset)
|
serverAndMediaId = serverAndMediaId.substring(0, fragmentOffset)
|
||||||
}
|
}
|
||||||
|
|
||||||
return baseUrl + sep + prefix + serverAndMediaId + (params ?: "") + fragment
|
return baseUrl + sep + prefix + serverAndMediaId + params + fragment
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun String.isValidMatrixContentUrl(): Boolean {
|
private fun String.isValidMatrixContentUrl(): Boolean {
|
||||||
|
|
Loading…
Reference in a new issue