Do not show Rtt text edit if RTT is not active

This commit is contained in:
Pavel Prystinka 2024-11-20 00:39:03 -08:00
Родитель 7c59a60ddb
Коммит fa994e00dd
3 изменённых файлов: 41 добавлений и 24 удалений

Просмотреть файл

@ -213,6 +213,7 @@ internal class CallingViewModel(
isCaptionsVisibleMutableFlow.value = shouldShowCaptionsUI(state.visibilityState, state.captionsState, state.rttState) isCaptionsVisibleMutableFlow.value = shouldShowCaptionsUI(state.visibilityState, state.captionsState, state.rttState)
captionsLayoutViewModel.init( captionsLayoutViewModel.init(
state.captionsState, state.captionsState,
state.rttState,
isCaptionsVisibleMutableFlow.value, isCaptionsVisibleMutableFlow.value,
state.deviceConfigurationState, state.deviceConfigurationState,
) )
@ -404,6 +405,7 @@ internal class CallingViewModel(
) )
captionsLayoutViewModel.update( captionsLayoutViewModel.update(
state.captionsState, state.captionsState,
state.rttState,
isCaptionsVisibleMutableFlow.value, isCaptionsVisibleMutableFlow.value,
state.deviceConfigurationState, state.deviceConfigurationState,
) )

Просмотреть файл

@ -16,6 +16,7 @@ import android.widget.EditText
import android.widget.FrameLayout import android.widget.FrameLayout
import android.widget.ImageButton import android.widget.ImageButton
import android.widget.LinearLayout import android.widget.LinearLayout
import android.widget.TextView
import androidx.core.view.isVisible import androidx.core.view.isVisible
import androidx.core.view.marginTop import androidx.core.view.marginTop
import androidx.lifecycle.LifecycleOwner import androidx.lifecycle.LifecycleOwner
@ -72,8 +73,7 @@ internal class CaptionsView : FrameLayout {
(recyclerView.itemAnimator as SimpleItemAnimator).supportsChangeAnimations = false (recyclerView.itemAnimator as SimpleItemAnimator).supportsChangeAnimations = false
if (isTablet(context)) { if (isTablet(context)) {
// TODO: check if rtt is enabled via view model rttInputText.isVisible = viewModel.isRttInputVisibleFlow.value
rttInputText.isVisible = true
resizeButton.isVisible = false resizeButton.isVisible = false
headerDragHandle.isVisible = false headerDragHandle.isVisible = false
@ -85,29 +85,31 @@ internal class CaptionsView : FrameLayout {
resizeButton.setOnClickListener { this.onResizeButtonClicked() } resizeButton.setOnClickListener { this.onResizeButtonClicked() }
} }
rttInputText.setOnEditorActionListener { view, actionId, event -> rttInputText.setOnEditorActionListener { view, actionId, _ ->
if (actionId == EditorInfo.IME_ACTION_SEND) { onEditTextAction(view, actionId)
// Handle the "Send" action
val message = view.text.toString()
if (message.isNotBlank()) {
viewModel.sendRttMessage(message)
view.text = ""
// Keep focus on the EditText to prevent the keyboard from hiding
view.requestFocus()
// Ensure the keyboard remains visible
val imm = context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT)
}
true
} else {
false
}
} }
} }
private fun onEditTextAction(view: TextView, actionId: Int): Boolean {
if (actionId == EditorInfo.IME_ACTION_SEND) {
// Handle the "Send" action
val message = view.text.toString()
if (message.isNotBlank()) {
viewModel.sendRttMessage(message)
view.text = ""
view.requestFocus()
// Ensure the keyboard remains visible
val imm = context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT)
}
return true
}
return false
}
@SuppressLint("NotifyDataSetChanged") @SuppressLint("NotifyDataSetChanged")
fun start( fun start(
viewLifecycleOwner: LifecycleOwner, viewLifecycleOwner: LifecycleOwner,
@ -140,6 +142,11 @@ internal class CaptionsView : FrameLayout {
} }
} }
}, },
{
viewModel.isRttInputVisibleFlow.collect {
rttInputText.isVisible = it && isMaximized
}
},
{ {
viewModel.recordUpdatedAtPositionSharedFlow.collect { viewModel.recordUpdatedAtPositionSharedFlow.collect {
onItemUpdated(it) onItemUpdated(it)
@ -233,7 +240,7 @@ internal class CaptionsView : FrameLayout {
} }
private fun maximizeCaptionsLayout() { private fun maximizeCaptionsLayout() {
rttInputText.visibility = View.VISIBLE rttInputText.isVisible = viewModel.isRttInputVisibleFlow.value
resizeButton.setImageResource(R.drawable.azure_communication_ui_calling_ic_fluent_arrow_minimize_20_regular) resizeButton.setImageResource(R.drawable.azure_communication_ui_calling_ic_fluent_arrow_minimize_20_regular)
resizeButton.contentDescription = context.getString(R.string.azure_communication_ui_calling_minimize_captions_and_rtt) resizeButton.contentDescription = context.getString(R.string.azure_communication_ui_calling_minimize_captions_and_rtt)
isMaximized = true isMaximized = true
@ -242,7 +249,7 @@ internal class CaptionsView : FrameLayout {
fun minimizeCaptionsLayout() { fun minimizeCaptionsLayout() {
hideKeyboard(rttInputText) hideKeyboard(rttInputText)
rttInputText.visibility = View.GONE rttInputText.isVisible = false
resizeButton.setImageResource(R.drawable.azure_communication_ui_calling_ic_fluent_arrow_maximize_20_regular) resizeButton.setImageResource(R.drawable.azure_communication_ui_calling_ic_fluent_arrow_maximize_20_regular)
resizeButton.contentDescription = context.getString(R.string.azure_communication_ui_calling_maximize_captions_and_rtt) resizeButton.contentDescription = context.getString(R.string.azure_communication_ui_calling_maximize_captions_and_rtt)
isMaximized = false isMaximized = false

Просмотреть файл

@ -9,6 +9,7 @@ import com.azure.android.communication.ui.calling.redux.action.RttAction
import com.azure.android.communication.ui.calling.redux.state.CaptionsState import com.azure.android.communication.ui.calling.redux.state.CaptionsState
import com.azure.android.communication.ui.calling.redux.state.CaptionsStatus import com.azure.android.communication.ui.calling.redux.state.CaptionsStatus
import com.azure.android.communication.ui.calling.redux.state.DeviceConfigurationState import com.azure.android.communication.ui.calling.redux.state.DeviceConfigurationState
import com.azure.android.communication.ui.calling.redux.state.RttState
import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.StateFlow
@ -17,6 +18,7 @@ internal class CaptionsViewModel(
captionsDataManager: CaptionsDataManager, captionsDataManager: CaptionsDataManager,
) { ) {
private lateinit var isVisibleMutableFlow: MutableStateFlow<Boolean> private lateinit var isVisibleMutableFlow: MutableStateFlow<Boolean>
private lateinit var isRttInputVisibleMutableFlow: MutableStateFlow<Boolean>
private lateinit var captionsStartInProgressStateMutableFlow: MutableStateFlow<Boolean> private lateinit var captionsStartInProgressStateMutableFlow: MutableStateFlow<Boolean>
private lateinit var softwareKeyboardStateMutableFlow: MutableStateFlow<Boolean> private lateinit var softwareKeyboardStateMutableFlow: MutableStateFlow<Boolean>
@ -30,25 +32,31 @@ internal class CaptionsViewModel(
val isVisibleFlow: StateFlow<Boolean> val isVisibleFlow: StateFlow<Boolean>
get() = isVisibleMutableFlow get() = isVisibleMutableFlow
val isRttInputVisibleFlow: StateFlow<Boolean>
get() = isRttInputVisibleMutableFlow
val captionsStartProgressStateFlow: StateFlow<Boolean> val captionsStartProgressStateFlow: StateFlow<Boolean>
get() = captionsStartInProgressStateMutableFlow get() = captionsStartInProgressStateMutableFlow
fun update( fun update(
captionsState: CaptionsState, captionsState: CaptionsState,
rttState: RttState,
isVisible: Boolean, isVisible: Boolean,
deviceConfigurationState: DeviceConfigurationState, deviceConfigurationState: DeviceConfigurationState,
) { ) {
isVisibleMutableFlow.value = isVisible isVisibleMutableFlow.value = isVisible
isRttInputVisibleMutableFlow.value = rttState.isRttActive
captionsStartInProgressStateMutableFlow.value = canShowCaptionsStartInProgressUI(captionsState) captionsStartInProgressStateMutableFlow.value = canShowCaptionsStartInProgressUI(captionsState)
softwareKeyboardStateMutableFlow.value = deviceConfigurationState.isSoftwareKeyboardVisible softwareKeyboardStateMutableFlow.value = deviceConfigurationState.isSoftwareKeyboardVisible
} }
fun init( fun init(
captionsState: CaptionsState, captionsState: CaptionsState,
rttState: RttState,
isVisible: Boolean, isVisible: Boolean,
deviceConfigurationState: DeviceConfigurationState, deviceConfigurationState: DeviceConfigurationState,
) { ) {
isVisibleMutableFlow = MutableStateFlow(isVisible) isVisibleMutableFlow = MutableStateFlow(isVisible)
isRttInputVisibleMutableFlow = MutableStateFlow(rttState.isRttActive)
captionsStartInProgressStateMutableFlow = MutableStateFlow(canShowCaptionsStartInProgressUI(captionsState)) captionsStartInProgressStateMutableFlow = MutableStateFlow(canShowCaptionsStartInProgressUI(captionsState))
softwareKeyboardStateMutableFlow = MutableStateFlow(deviceConfigurationState.isSoftwareKeyboardVisible) softwareKeyboardStateMutableFlow = MutableStateFlow(deviceConfigurationState.isSoftwareKeyboardVisible)
} }