From e321e20dc226f47d2e625d5b5e0500d95d374631 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 10 Feb 2021 15:09:53 +0100 Subject: [PATCH] Avoid lazy blocks --- .../call/conference/JitsiCallViewModel.kt | 2 +- .../call/conference/JitsiWidgetProperties.kt | 36 ++++++++++++------- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/call/conference/JitsiCallViewModel.kt b/vector/src/main/java/im/vector/app/features/call/conference/JitsiCallViewModel.kt index d5097daf08..b3c29752d8 100644 --- a/vector/src/main/java/im/vector/app/features/call/conference/JitsiCallViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/call/conference/JitsiCallViewModel.kt @@ -68,7 +68,7 @@ class JitsiCallViewModel @AssistedInject constructor( val jitsiWidget = it.firstOrNull() if (jitsiWidget != null) { val ppt = widgetService.getWidgetComputedUrl(jitsiWidget, themeProvider.isLightTheme()) - ?.let { url -> JitsiWidgetProperties(url, stringProvider) } + ?.let { url -> JitsiWidgetProperties.fromUrl(url, stringProvider) } setState { copy( widget = Success(jitsiWidget), diff --git a/vector/src/main/java/im/vector/app/features/call/conference/JitsiWidgetProperties.kt b/vector/src/main/java/im/vector/app/features/call/conference/JitsiWidgetProperties.kt index 46e2e68dd6..f1af3ae052 100644 --- a/vector/src/main/java/im/vector/app/features/call/conference/JitsiWidgetProperties.kt +++ b/vector/src/main/java/im/vector/app/features/call/conference/JitsiWidgetProperties.kt @@ -19,22 +19,32 @@ package im.vector.app.features.call.conference import android.net.Uri import im.vector.app.R import im.vector.app.core.resources.StringProvider +import org.matrix.android.sdk.api.extensions.tryOrNull import java.net.URLDecoder -class JitsiWidgetProperties(private val uriString: String, val stringProvider: StringProvider) { - val domain: String by lazy { configs["conferenceDomain"] ?: stringProvider.getString(R.string.preferred_jitsi_domain) } - val confId: String? by lazy { configs["conferenceId"] } - val displayName: String? by lazy { configs["displayName"] } - val avatarUrl: String? by lazy { configs["avatarUrl"] } +data class JitsiWidgetProperties( + val domain: String, + val confId: String?, + val displayName: String?, + val avatarUrl: String? +) { + companion object { + fun fromUrl(url: String, stringProvider: StringProvider): JitsiWidgetProperties { + val configString: String? = tryOrNull { Uri.parse(url) }?.fragment - private val configString: String? by lazy { Uri.parse(uriString).fragment } + val configs: Map = configString?.split("&") + ?.map { it.split("=") } + ?.filter { it.size == 2 } + ?.map { (key, value) -> key to URLDecoder.decode(value, "UTF-8") } + ?.toMap() + .orEmpty() - private val configs: Map by lazy { - configString?.split("&") - ?.map { it.split("=") } - ?.filter { it.size == 2 } - ?.map { (key, value) -> key to URLDecoder.decode(value, "UTF-8") } - ?.toMap() - .orEmpty() + return JitsiWidgetProperties( + domain = configs["conferenceDomain"] ?: stringProvider.getString(R.string.preferred_jitsi_domain), + confId = configs["conferenceId"], + displayName = configs["displayName"], + avatarUrl = configs["avatarUrl"] + ) + } } }