DialPad: fix listeners

This commit is contained in:
ganfra 2021-01-14 12:23:58 +01:00
parent 1f96367286
commit b31bb9eb4f
4 changed files with 51 additions and 32 deletions

View file

@ -26,7 +26,7 @@ import im.vector.app.core.platform.VectorBaseBottomSheetDialogFragment
import im.vector.app.databinding.BottomSheetCallDialPadBinding
import im.vector.app.features.settings.VectorLocale
class CallDialPadBottomSheet private constructor() : VectorBaseBottomSheetDialogFragment<BottomSheetCallDialPadBinding>() {
class CallDialPadBottomSheet : VectorBaseBottomSheetDialogFragment<BottomSheetCallDialPadBinding>() {
companion object {

View file

@ -104,7 +104,7 @@ class WebRtcCallManager @Inject constructor(
private set
val supportsPSTNProtocol: Boolean
get() = supportedPSTNProtocol != null
get() = true//supportedPSTNProtocol != null
private val rootEglBase by lazy { EglUtils.rootEglBase }

View file

@ -265,19 +265,6 @@ class RoomDetailFragment @Inject constructor(
pillsPostProcessorFactory.create(roomDetailArgs.roomId)
}
private val callActionsHandler by lazy {
StartCallActionsHandler(
roomId = roomDetailArgs.roomId,
fragment = this,
vectorPreferences = vectorPreferences,
roomDetailViewModel = roomDetailViewModel,
sharedActiveCallViewModel = sharedCallActionViewModel,
startCallActivityResultLauncher = startCallActivityResultLauncher,
showDialogWithMessage = ::showDialogWithMessage,
onTapToReturnToCall = ::onTapToReturnToCall
)
}
private val autoCompleter: AutoCompleter by lazy {
autoCompleterFactory.create(roomDetailArgs.roomId)
}
@ -302,6 +289,7 @@ class RoomDetailFragment @Inject constructor(
private lateinit var attachmentsHelper: AttachmentsHelper
private lateinit var keyboardStateUtils: KeyboardStateUtils
private lateinit var callActionsHandler : StartCallActionsHandler
private lateinit var attachmentTypeSelector: AttachmentTypeSelectorView
@ -313,6 +301,16 @@ class RoomDetailFragment @Inject constructor(
sharedActionViewModel = activityViewModelProvider.get(MessageSharedActionViewModel::class.java)
sharedCallActionViewModel = activityViewModelProvider.get(SharedActiveCallViewModel::class.java)
attachmentsHelper = AttachmentsHelper(requireContext(), this).register()
callActionsHandler = StartCallActionsHandler(
roomId = roomDetailArgs.roomId,
fragment = this,
vectorPreferences = vectorPreferences,
roomDetailViewModel = roomDetailViewModel,
sharedActiveCallViewModel = sharedCallActionViewModel,
startCallActivityResultLauncher = startCallActivityResultLauncher,
showDialogWithMessage = ::showDialogWithMessage,
onTapToReturnToCall = ::onTapToReturnToCall
).register()
keyboardStateUtils = KeyboardStateUtils(requireActivity())
setupToolbar(views.roomToolbar)
setupRecyclerView()

View file

@ -16,16 +16,16 @@
package im.vector.app.features.home.room.detail
import androidx.activity.result.ActivityResult
import android.os.Bundle
import androidx.activity.result.ActivityResultLauncher
import androidx.appcompat.app.AlertDialog
import androidx.fragment.app.Fragment
import com.airbnb.mvrx.withState
import im.vector.app.R
import im.vector.app.core.platform.Restorable
import im.vector.app.core.utils.PERMISSIONS_FOR_AUDIO_IP_CALL
import im.vector.app.core.utils.PERMISSIONS_FOR_VIDEO_IP_CALL
import im.vector.app.core.utils.checkPermissions
import im.vector.app.core.utils.registerForPermissionsResult
import im.vector.app.core.utils.toast
import im.vector.app.features.call.DialerChoiceBottomSheet
import im.vector.app.features.call.SharedActiveCallViewModel
import im.vector.app.features.call.dialpad.CallDialPadBottomSheet
@ -33,15 +33,18 @@ import im.vector.app.features.call.dialpad.DialPadFragment
import im.vector.app.features.settings.VectorPreferences
import org.matrix.android.sdk.api.session.widgets.model.WidgetType
private const val DIALER_OPTION_TAG = "DIALER_OPTION_TAG"
private const val DIAL_PAD_TAG = "DIAL_PAD_TAG"
class StartCallActionsHandler(
private val roomId: String,
private val fragment: RoomDetailFragment,
private val fragment: Fragment,
private val vectorPreferences: VectorPreferences,
private val roomDetailViewModel: RoomDetailViewModel,
private val sharedActiveCallViewModel: SharedActiveCallViewModel,
private val startCallActivityResultLauncher: ActivityResultLauncher<Array<String>>,
private val showDialogWithMessage: (String) -> Unit,
private val onTapToReturnToCall: () -> Unit) {
private val onTapToReturnToCall: () -> Unit): Restorable {
fun onVideoCallClicked() {
handleCallRequest(true)
@ -55,22 +58,32 @@ class StartCallActionsHandler(
}
}
private fun DialerChoiceBottomSheet.applyListeners(): DialerChoiceBottomSheet {
onDialPadClicked = ::displayDialPadBottomSheet
onVoiceCallClicked = { handleCallRequest(false) }
return this
}
private fun CallDialPadBottomSheet.applyCallback(): CallDialPadBottomSheet {
callback = object : DialPadFragment.Callback {
override fun onOkClicked(formatted: String?, raw: String?) {
if (raw.isNullOrEmpty()) return
roomDetailViewModel.handle(RoomDetailAction.StartCallWithPhoneNumber(raw, false))
}
}
return this
}
private fun displayDialerChoiceBottomSheet() {
DialerChoiceBottomSheet().apply {
onDialPadClicked = ::displayDialPadBottomSheet
onVoiceCallClicked = { handleCallRequest(false) }
}.show(fragment.parentFragmentManager, "DIALER_OPTION")
DialerChoiceBottomSheet()
.applyListeners()
.show(fragment.parentFragmentManager, DIALER_OPTION_TAG)
}
private fun displayDialPadBottomSheet() {
CallDialPadBottomSheet.newInstance(true).apply {
callback = object : DialPadFragment.Callback {
override fun onOkClicked(formatted: String?, raw: String?) {
if (raw.isNullOrEmpty()) return
roomDetailViewModel.handle(RoomDetailAction.StartCallWithPhoneNumber(raw, false))
}
}
}.show(fragment.parentFragmentManager, "DIAL_PAD")
CallDialPadBottomSheet.newInstance(true)
.applyCallback()
.show(fragment.parentFragmentManager, DIAL_PAD_TAG)
}
private fun handleCallRequest(isVideoCall: Boolean) = withState(roomDetailViewModel) { state ->
@ -178,4 +191,12 @@ class StartCallActionsHandler(
}
}
override fun onSaveInstanceState(outState: Bundle) = Unit
override fun onRestoreInstanceState(savedInstanceState: Bundle?) {
if(savedInstanceState != null){
(fragment.parentFragmentManager.findFragmentByTag(DIALER_OPTION_TAG) as? DialerChoiceBottomSheet)?.applyListeners()
(fragment.parentFragmentManager.findFragmentByTag(DIAL_PAD_TAG) as? CallDialPadBottomSheet)?.applyCallback()
}
}
}