From 9196adb8b052797c25ac228dca83ed70c500b06b Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 1 Jul 2024 14:30:18 +0200 Subject: [PATCH 1/6] Remove default value for languageTag and theme. --- .../element/android/libraries/matrix/api/room/MatrixRoom.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/matrix/api/src/main/kotlin/io/element/android/libraries/matrix/api/room/MatrixRoom.kt b/libraries/matrix/api/src/main/kotlin/io/element/android/libraries/matrix/api/room/MatrixRoom.kt index 3ff91996d3..44a611a43e 100644 --- a/libraries/matrix/api/src/main/kotlin/io/element/android/libraries/matrix/api/room/MatrixRoom.kt +++ b/libraries/matrix/api/src/main/kotlin/io/element/android/libraries/matrix/api/room/MatrixRoom.kt @@ -308,8 +308,8 @@ interface MatrixRoom : Closeable { suspend fun generateWidgetWebViewUrl( widgetSettings: MatrixWidgetSettings, clientId: String, - languageTag: String? = null, - theme: String? = null, + languageTag: String?, + theme: String?, ): Result /** From 2529a8d844bae62a9f317b1894ca98bc37d2b48f Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 1 Jul 2024 14:30:35 +0200 Subject: [PATCH 2/6] Add parameter names. --- .../features/call/impl/utils/DefaultCallWidgetProvider.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/features/call/impl/src/main/kotlin/io/element/android/features/call/impl/utils/DefaultCallWidgetProvider.kt b/features/call/impl/src/main/kotlin/io/element/android/features/call/impl/utils/DefaultCallWidgetProvider.kt index 0e361962ec..f36269abc6 100644 --- a/features/call/impl/src/main/kotlin/io/element/android/features/call/impl/utils/DefaultCallWidgetProvider.kt +++ b/features/call/impl/src/main/kotlin/io/element/android/features/call/impl/utils/DefaultCallWidgetProvider.kt @@ -46,7 +46,12 @@ class DefaultCallWidgetProvider @Inject constructor( ?: elementCallBaseUrlProvider.provides(sessionId) ?: ElementCallConfig.DEFAULT_BASE_URL val widgetSettings = callWidgetSettingsProvider.provide(baseUrl, encrypted = room.isEncrypted) - val callUrl = room.generateWidgetWebViewUrl(widgetSettings, clientId, languageTag, theme).getOrThrow() + val callUrl = room.generateWidgetWebViewUrl( + widgetSettings = widgetSettings, + clientId = clientId, + languageTag = languageTag, + theme = theme, + ).getOrThrow() CallWidgetProvider.GetWidgetResult( driver = room.getWidgetDriver(widgetSettings).getOrThrow(), url = callUrl From 6a6e66765a0b0f95eace886e50e11a12c587fc9c Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 1 Jul 2024 14:31:26 +0200 Subject: [PATCH 3/6] Remove default value for languageTag and theme. --- .../android/features/call/impl/ui/CallScreenPresenter.kt | 2 ++ .../android/features/call/impl/utils/CallWidgetProvider.kt | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/features/call/impl/src/main/kotlin/io/element/android/features/call/impl/ui/CallScreenPresenter.kt b/features/call/impl/src/main/kotlin/io/element/android/features/call/impl/ui/CallScreenPresenter.kt index 4e23f23501..6246ab6466 100644 --- a/features/call/impl/src/main/kotlin/io/element/android/features/call/impl/ui/CallScreenPresenter.kt +++ b/features/call/impl/src/main/kotlin/io/element/android/features/call/impl/ui/CallScreenPresenter.kt @@ -189,6 +189,8 @@ class CallScreenPresenter @AssistedInject constructor( sessionId = inputs.sessionId, roomId = inputs.roomId, clientId = UUID.randomUUID().toString(), + languageTag = null, + theme = null, ).getOrThrow() callWidgetDriver.value = result.driver result.url diff --git a/features/call/impl/src/main/kotlin/io/element/android/features/call/impl/utils/CallWidgetProvider.kt b/features/call/impl/src/main/kotlin/io/element/android/features/call/impl/utils/CallWidgetProvider.kt index 61843c471a..7152bdddad 100644 --- a/features/call/impl/src/main/kotlin/io/element/android/features/call/impl/utils/CallWidgetProvider.kt +++ b/features/call/impl/src/main/kotlin/io/element/android/features/call/impl/utils/CallWidgetProvider.kt @@ -25,8 +25,8 @@ interface CallWidgetProvider { sessionId: SessionId, roomId: RoomId, clientId: String, - languageTag: String? = null, - theme: String? = null, + languageTag: String?, + theme: String?, ): Result data class GetWidgetResult( From 8ef970e3f7a6c9491bc47822efb61cb732ca96bd Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 1 Jul 2024 14:48:18 +0200 Subject: [PATCH 4/6] Provide language and theme to Element Call. #3079 --- .../call/impl/ui/CallScreenPresenter.kt | 20 ++++++++--- .../call/impl/ui/LanguageTagProvider.kt | 35 +++++++++++++++++++ .../call/ui/CallScreenPresenterTest.kt | 1 + .../call/ui/FakeLanguageTagProvider.kt | 25 +++++++++++++ 4 files changed, 77 insertions(+), 4 deletions(-) create mode 100644 features/call/impl/src/main/kotlin/io/element/android/features/call/impl/ui/LanguageTagProvider.kt create mode 100644 features/call/impl/src/test/kotlin/io/element/android/features/call/ui/FakeLanguageTagProvider.kt diff --git a/features/call/impl/src/main/kotlin/io/element/android/features/call/impl/ui/CallScreenPresenter.kt b/features/call/impl/src/main/kotlin/io/element/android/features/call/impl/ui/CallScreenPresenter.kt index 6246ab6466..feb07f0c6b 100644 --- a/features/call/impl/src/main/kotlin/io/element/android/features/call/impl/ui/CallScreenPresenter.kt +++ b/features/call/impl/src/main/kotlin/io/element/android/features/call/impl/ui/CallScreenPresenter.kt @@ -26,10 +26,12 @@ import androidx.compose.runtime.remember import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.runtime.setValue +import androidx.compose.ui.platform.LocalConfiguration import dagger.assisted.Assisted import dagger.assisted.AssistedFactory import dagger.assisted.AssistedInject import im.vector.app.features.analytics.plan.MobileScreen +import io.element.android.compound.theme.ElementTheme import io.element.android.features.call.api.CallType import io.element.android.features.call.impl.data.WidgetMessage import io.element.android.features.call.impl.utils.ActiveCallManager @@ -68,6 +70,7 @@ class CallScreenPresenter @AssistedInject constructor( private val screenTracker: ScreenTracker, private val appCoroutineScope: CoroutineScope, private val activeCallManager: ActiveCallManager, + private val languageTagProvider: LanguageTagProvider, ) : Presenter { @AssistedFactory interface Factory { @@ -85,12 +88,19 @@ class CallScreenPresenter @AssistedInject constructor( val callWidgetDriver = remember { mutableStateOf(null) } val messageInterceptor = remember { mutableStateOf(null) } var isJoinedCall by rememberSaveable { mutableStateOf(false) } - + val languageTag = languageTagProvider.provideLanguageTag() + val theme = if (ElementTheme.isLightTheme) "light" else "dark" DisposableEffect(Unit) { coroutineScope.launch { // Sets the call as joined activeCallManager.joinedCall(callType) - loadUrl(callType, urlState, callWidgetDriver) + loadUrl( + inputs = callType, + urlState = urlState, + callWidgetDriver = callWidgetDriver, + languageTag = languageTag, + theme = theme, + ) } onDispose { activeCallManager.hungUpCall(callType) @@ -178,6 +188,8 @@ class CallScreenPresenter @AssistedInject constructor( inputs: CallType, urlState: MutableState>, callWidgetDriver: MutableState, + languageTag: String?, + theme: String?, ) { urlState.runCatchingUpdatingState { when (inputs) { @@ -189,8 +201,8 @@ class CallScreenPresenter @AssistedInject constructor( sessionId = inputs.sessionId, roomId = inputs.roomId, clientId = UUID.randomUUID().toString(), - languageTag = null, - theme = null, + languageTag = languageTag, + theme = theme, ).getOrThrow() callWidgetDriver.value = result.driver result.url diff --git a/features/call/impl/src/main/kotlin/io/element/android/features/call/impl/ui/LanguageTagProvider.kt b/features/call/impl/src/main/kotlin/io/element/android/features/call/impl/ui/LanguageTagProvider.kt new file mode 100644 index 0000000000..0835196307 --- /dev/null +++ b/features/call/impl/src/main/kotlin/io/element/android/features/call/impl/ui/LanguageTagProvider.kt @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.element.android.features.call.impl.ui + +import androidx.compose.runtime.Composable +import androidx.compose.ui.platform.LocalConfiguration +import com.squareup.anvil.annotations.ContributesBinding +import io.element.android.libraries.di.AppScope + +interface LanguageTagProvider { + @Composable + fun provideLanguageTag(): String? +} + +@ContributesBinding(AppScope::class) +class DefaultLanguageTagProvider : LanguageTagProvider { + @Composable + override fun provideLanguageTag(): String? { + return LocalConfiguration.current.locales.get(0)?.toLanguageTag() + } +} diff --git a/features/call/impl/src/test/kotlin/io/element/android/features/call/ui/CallScreenPresenterTest.kt b/features/call/impl/src/test/kotlin/io/element/android/features/call/ui/CallScreenPresenterTest.kt index 182f2a13f6..09e6c86158 100644 --- a/features/call/impl/src/test/kotlin/io/element/android/features/call/ui/CallScreenPresenterTest.kt +++ b/features/call/impl/src/test/kotlin/io/element/android/features/call/ui/CallScreenPresenterTest.kt @@ -292,6 +292,7 @@ class CallScreenPresenterTest { appCoroutineScope = this, activeCallManager = activeCallManager, screenTracker = screenTracker, + languageTagProvider = FakeLanguageTagProvider("en-US"), ) } } diff --git a/features/call/impl/src/test/kotlin/io/element/android/features/call/ui/FakeLanguageTagProvider.kt b/features/call/impl/src/test/kotlin/io/element/android/features/call/ui/FakeLanguageTagProvider.kt new file mode 100644 index 0000000000..60c5be23da --- /dev/null +++ b/features/call/impl/src/test/kotlin/io/element/android/features/call/ui/FakeLanguageTagProvider.kt @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.element.android.features.call.ui + +import androidx.compose.runtime.Composable +import io.element.android.features.call.impl.ui.LanguageTagProvider + +class FakeLanguageTagProvider(private val languageTag: String?) : LanguageTagProvider { + @Composable + override fun provideLanguageTag() = languageTag +} From f34ba47906b15b1c149307a103f65b39ae999998 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 1 Jul 2024 16:12:27 +0200 Subject: [PATCH 5/6] Inject constructor --- .../android/features/call/impl/ui/LanguageTagProvider.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/features/call/impl/src/main/kotlin/io/element/android/features/call/impl/ui/LanguageTagProvider.kt b/features/call/impl/src/main/kotlin/io/element/android/features/call/impl/ui/LanguageTagProvider.kt index 0835196307..8073e9b901 100644 --- a/features/call/impl/src/main/kotlin/io/element/android/features/call/impl/ui/LanguageTagProvider.kt +++ b/features/call/impl/src/main/kotlin/io/element/android/features/call/impl/ui/LanguageTagProvider.kt @@ -20,6 +20,7 @@ import androidx.compose.runtime.Composable import androidx.compose.ui.platform.LocalConfiguration import com.squareup.anvil.annotations.ContributesBinding import io.element.android.libraries.di.AppScope +import javax.inject.Inject interface LanguageTagProvider { @Composable @@ -27,7 +28,7 @@ interface LanguageTagProvider { } @ContributesBinding(AppScope::class) -class DefaultLanguageTagProvider : LanguageTagProvider { +class DefaultLanguageTagProvider @Inject constructor() : LanguageTagProvider { @Composable override fun provideLanguageTag(): String? { return LocalConfiguration.current.locales.get(0)?.toLanguageTag() From 4df18eadf4e5e3872de8922194c54396ea985a72 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 1 Jul 2024 16:18:20 +0200 Subject: [PATCH 6/6] Remove unused import --- .../element/android/features/call/impl/ui/CallScreenPresenter.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/features/call/impl/src/main/kotlin/io/element/android/features/call/impl/ui/CallScreenPresenter.kt b/features/call/impl/src/main/kotlin/io/element/android/features/call/impl/ui/CallScreenPresenter.kt index feb07f0c6b..48002ac190 100644 --- a/features/call/impl/src/main/kotlin/io/element/android/features/call/impl/ui/CallScreenPresenter.kt +++ b/features/call/impl/src/main/kotlin/io/element/android/features/call/impl/ui/CallScreenPresenter.kt @@ -26,7 +26,6 @@ import androidx.compose.runtime.remember import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.runtime.setValue -import androidx.compose.ui.platform.LocalConfiguration import dagger.assisted.Assisted import dagger.assisted.AssistedFactory import dagger.assisted.AssistedInject