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)
captionsLayoutViewModel.init(
state.captionsState,
state.rttState,
isCaptionsVisibleMutableFlow.value,
state.deviceConfigurationState,
)
@ -404,6 +405,7 @@ internal class CallingViewModel(
)
captionsLayoutViewModel.update(
state.captionsState,
state.rttState,
isCaptionsVisibleMutableFlow.value,
state.deviceConfigurationState,
)

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

@ -16,6 +16,7 @@ import android.widget.EditText
import android.widget.FrameLayout
import android.widget.ImageButton
import android.widget.LinearLayout
import android.widget.TextView
import androidx.core.view.isVisible
import androidx.core.view.marginTop
import androidx.lifecycle.LifecycleOwner
@ -72,8 +73,7 @@ internal class CaptionsView : FrameLayout {
(recyclerView.itemAnimator as SimpleItemAnimator).supportsChangeAnimations = false
if (isTablet(context)) {
// TODO: check if rtt is enabled via view model
rttInputText.isVisible = true
rttInputText.isVisible = viewModel.isRttInputVisibleFlow.value
resizeButton.isVisible = false
headerDragHandle.isVisible = false
@ -85,7 +85,12 @@ internal class CaptionsView : FrameLayout {
resizeButton.setOnClickListener { this.onResizeButtonClicked() }
}
rttInputText.setOnEditorActionListener { view, actionId, event ->
rttInputText.setOnEditorActionListener { view, actionId, _ ->
onEditTextAction(view, actionId)
}
}
private fun onEditTextAction(view: TextView, actionId: Int): Boolean {
if (actionId == EditorInfo.IME_ACTION_SEND) {
// Handle the "Send" action
val message = view.text.toString()
@ -93,19 +98,16 @@ internal class CaptionsView : FrameLayout {
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
}
return true
}
return false
}
@SuppressLint("NotifyDataSetChanged")
@ -140,6 +142,11 @@ internal class CaptionsView : FrameLayout {
}
}
},
{
viewModel.isRttInputVisibleFlow.collect {
rttInputText.isVisible = it && isMaximized
}
},
{
viewModel.recordUpdatedAtPositionSharedFlow.collect {
onItemUpdated(it)
@ -233,7 +240,7 @@ internal class CaptionsView : FrameLayout {
}
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.contentDescription = context.getString(R.string.azure_communication_ui_calling_minimize_captions_and_rtt)
isMaximized = true
@ -242,7 +249,7 @@ internal class CaptionsView : FrameLayout {
fun minimizeCaptionsLayout() {
hideKeyboard(rttInputText)
rttInputText.visibility = View.GONE
rttInputText.isVisible = false
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)
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.CaptionsStatus
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.StateFlow
@ -17,6 +18,7 @@ internal class CaptionsViewModel(
captionsDataManager: CaptionsDataManager,
) {
private lateinit var isVisibleMutableFlow: MutableStateFlow<Boolean>
private lateinit var isRttInputVisibleMutableFlow: MutableStateFlow<Boolean>
private lateinit var captionsStartInProgressStateMutableFlow: MutableStateFlow<Boolean>
private lateinit var softwareKeyboardStateMutableFlow: MutableStateFlow<Boolean>
@ -30,25 +32,31 @@ internal class CaptionsViewModel(
val isVisibleFlow: StateFlow<Boolean>
get() = isVisibleMutableFlow
val isRttInputVisibleFlow: StateFlow<Boolean>
get() = isRttInputVisibleMutableFlow
val captionsStartProgressStateFlow: StateFlow<Boolean>
get() = captionsStartInProgressStateMutableFlow
fun update(
captionsState: CaptionsState,
rttState: RttState,
isVisible: Boolean,
deviceConfigurationState: DeviceConfigurationState,
) {
isVisibleMutableFlow.value = isVisible
isRttInputVisibleMutableFlow.value = rttState.isRttActive
captionsStartInProgressStateMutableFlow.value = canShowCaptionsStartInProgressUI(captionsState)
softwareKeyboardStateMutableFlow.value = deviceConfigurationState.isSoftwareKeyboardVisible
}
fun init(
captionsState: CaptionsState,
rttState: RttState,
isVisible: Boolean,
deviceConfigurationState: DeviceConfigurationState,
) {
isVisibleMutableFlow = MutableStateFlow(isVisible)
isRttInputVisibleMutableFlow = MutableStateFlow(rttState.isRttActive)
captionsStartInProgressStateMutableFlow = MutableStateFlow(canShowCaptionsStartInProgressUI(captionsState))
softwareKeyboardStateMutableFlow = MutableStateFlow(deviceConfigurationState.isSoftwareKeyboardVisible)
}