Merge pull request #3118 from element-hq/feature/bma/localeCall
Give locale and theme to Element Call
This commit is contained in:
commit
ef2d04c474
7 changed files with 87 additions and 7 deletions
|
|
@ -30,6 +30,7 @@ import dagger.assisted.Assisted
|
||||||
import dagger.assisted.AssistedFactory
|
import dagger.assisted.AssistedFactory
|
||||||
import dagger.assisted.AssistedInject
|
import dagger.assisted.AssistedInject
|
||||||
import im.vector.app.features.analytics.plan.MobileScreen
|
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.api.CallType
|
||||||
import io.element.android.features.call.impl.data.WidgetMessage
|
import io.element.android.features.call.impl.data.WidgetMessage
|
||||||
import io.element.android.features.call.impl.utils.ActiveCallManager
|
import io.element.android.features.call.impl.utils.ActiveCallManager
|
||||||
|
|
@ -68,6 +69,7 @@ class CallScreenPresenter @AssistedInject constructor(
|
||||||
private val screenTracker: ScreenTracker,
|
private val screenTracker: ScreenTracker,
|
||||||
private val appCoroutineScope: CoroutineScope,
|
private val appCoroutineScope: CoroutineScope,
|
||||||
private val activeCallManager: ActiveCallManager,
|
private val activeCallManager: ActiveCallManager,
|
||||||
|
private val languageTagProvider: LanguageTagProvider,
|
||||||
) : Presenter<CallScreenState> {
|
) : Presenter<CallScreenState> {
|
||||||
@AssistedFactory
|
@AssistedFactory
|
||||||
interface Factory {
|
interface Factory {
|
||||||
|
|
@ -85,12 +87,19 @@ class CallScreenPresenter @AssistedInject constructor(
|
||||||
val callWidgetDriver = remember { mutableStateOf<MatrixWidgetDriver?>(null) }
|
val callWidgetDriver = remember { mutableStateOf<MatrixWidgetDriver?>(null) }
|
||||||
val messageInterceptor = remember { mutableStateOf<WidgetMessageInterceptor?>(null) }
|
val messageInterceptor = remember { mutableStateOf<WidgetMessageInterceptor?>(null) }
|
||||||
var isJoinedCall by rememberSaveable { mutableStateOf(false) }
|
var isJoinedCall by rememberSaveable { mutableStateOf(false) }
|
||||||
|
val languageTag = languageTagProvider.provideLanguageTag()
|
||||||
|
val theme = if (ElementTheme.isLightTheme) "light" else "dark"
|
||||||
DisposableEffect(Unit) {
|
DisposableEffect(Unit) {
|
||||||
coroutineScope.launch {
|
coroutineScope.launch {
|
||||||
// Sets the call as joined
|
// Sets the call as joined
|
||||||
activeCallManager.joinedCall(callType)
|
activeCallManager.joinedCall(callType)
|
||||||
loadUrl(callType, urlState, callWidgetDriver)
|
loadUrl(
|
||||||
|
inputs = callType,
|
||||||
|
urlState = urlState,
|
||||||
|
callWidgetDriver = callWidgetDriver,
|
||||||
|
languageTag = languageTag,
|
||||||
|
theme = theme,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
onDispose {
|
onDispose {
|
||||||
activeCallManager.hungUpCall(callType)
|
activeCallManager.hungUpCall(callType)
|
||||||
|
|
@ -178,6 +187,8 @@ class CallScreenPresenter @AssistedInject constructor(
|
||||||
inputs: CallType,
|
inputs: CallType,
|
||||||
urlState: MutableState<AsyncData<String>>,
|
urlState: MutableState<AsyncData<String>>,
|
||||||
callWidgetDriver: MutableState<MatrixWidgetDriver?>,
|
callWidgetDriver: MutableState<MatrixWidgetDriver?>,
|
||||||
|
languageTag: String?,
|
||||||
|
theme: String?,
|
||||||
) {
|
) {
|
||||||
urlState.runCatchingUpdatingState {
|
urlState.runCatchingUpdatingState {
|
||||||
when (inputs) {
|
when (inputs) {
|
||||||
|
|
@ -189,6 +200,8 @@ class CallScreenPresenter @AssistedInject constructor(
|
||||||
sessionId = inputs.sessionId,
|
sessionId = inputs.sessionId,
|
||||||
roomId = inputs.roomId,
|
roomId = inputs.roomId,
|
||||||
clientId = UUID.randomUUID().toString(),
|
clientId = UUID.randomUUID().toString(),
|
||||||
|
languageTag = languageTag,
|
||||||
|
theme = theme,
|
||||||
).getOrThrow()
|
).getOrThrow()
|
||||||
callWidgetDriver.value = result.driver
|
callWidgetDriver.value = result.driver
|
||||||
result.url
|
result.url
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,36 @@
|
||||||
|
/*
|
||||||
|
* 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
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
interface LanguageTagProvider {
|
||||||
|
@Composable
|
||||||
|
fun provideLanguageTag(): String?
|
||||||
|
}
|
||||||
|
|
||||||
|
@ContributesBinding(AppScope::class)
|
||||||
|
class DefaultLanguageTagProvider @Inject constructor() : LanguageTagProvider {
|
||||||
|
@Composable
|
||||||
|
override fun provideLanguageTag(): String? {
|
||||||
|
return LocalConfiguration.current.locales.get(0)?.toLanguageTag()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -25,8 +25,8 @@ interface CallWidgetProvider {
|
||||||
sessionId: SessionId,
|
sessionId: SessionId,
|
||||||
roomId: RoomId,
|
roomId: RoomId,
|
||||||
clientId: String,
|
clientId: String,
|
||||||
languageTag: String? = null,
|
languageTag: String?,
|
||||||
theme: String? = null,
|
theme: String?,
|
||||||
): Result<GetWidgetResult>
|
): Result<GetWidgetResult>
|
||||||
|
|
||||||
data class GetWidgetResult(
|
data class GetWidgetResult(
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,12 @@ class DefaultCallWidgetProvider @Inject constructor(
|
||||||
?: elementCallBaseUrlProvider.provides(sessionId)
|
?: elementCallBaseUrlProvider.provides(sessionId)
|
||||||
?: ElementCallConfig.DEFAULT_BASE_URL
|
?: ElementCallConfig.DEFAULT_BASE_URL
|
||||||
val widgetSettings = callWidgetSettingsProvider.provide(baseUrl, encrypted = room.isEncrypted)
|
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(
|
CallWidgetProvider.GetWidgetResult(
|
||||||
driver = room.getWidgetDriver(widgetSettings).getOrThrow(),
|
driver = room.getWidgetDriver(widgetSettings).getOrThrow(),
|
||||||
url = callUrl
|
url = callUrl
|
||||||
|
|
|
||||||
|
|
@ -292,6 +292,7 @@ class CallScreenPresenterTest {
|
||||||
appCoroutineScope = this,
|
appCoroutineScope = this,
|
||||||
activeCallManager = activeCallManager,
|
activeCallManager = activeCallManager,
|
||||||
screenTracker = screenTracker,
|
screenTracker = screenTracker,
|
||||||
|
languageTagProvider = FakeLanguageTagProvider("en-US"),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
}
|
||||||
|
|
@ -308,8 +308,8 @@ interface MatrixRoom : Closeable {
|
||||||
suspend fun generateWidgetWebViewUrl(
|
suspend fun generateWidgetWebViewUrl(
|
||||||
widgetSettings: MatrixWidgetSettings,
|
widgetSettings: MatrixWidgetSettings,
|
||||||
clientId: String,
|
clientId: String,
|
||||||
languageTag: String? = null,
|
languageTag: String?,
|
||||||
theme: String? = null,
|
theme: String?,
|
||||||
): Result<String>
|
): Result<String>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue