Dial pad tab: first step, remove current way

This commit is contained in:
ganfra 2021-06-02 17:06:10 +02:00
parent 77ffdabd60
commit 74497dadd2
6 changed files with 6 additions and 123 deletions

View File

@ -1,46 +0,0 @@
/*
* Copyright (c) 2021 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 im.vector.app.features.call
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import im.vector.app.core.platform.VectorBaseBottomSheetDialogFragment
import im.vector.app.databinding.BottomSheetCallDialerChoiceBinding
class DialerChoiceBottomSheet : VectorBaseBottomSheetDialogFragment<BottomSheetCallDialerChoiceBinding>() {
override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): BottomSheetCallDialerChoiceBinding {
return BottomSheetCallDialerChoiceBinding.inflate(inflater, container, false)
}
var onDialPadClicked: (() -> Unit)? = null
var onVoiceCallClicked: (() -> Unit)? = null
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
views.dialerChoiceDialPad.views.bottomSheetActionClickableZone.debouncedClicks {
onDialPadClicked?.invoke()
dismiss()
}
views.dialerChoiceVoiceCall.views.bottomSheetActionClickableZone.debouncedClicks {
onVoiceCallClicked?.invoke()
dismiss()
}
}
}

View File

@ -73,7 +73,6 @@ sealed class RoomDetailAction : VectorViewModelAction {
object ResendAll : RoomDetailAction()
data class StartCallWithPhoneNumber(val phoneNumber: String, val videoCall: Boolean): RoomDetailAction()
data class StartCall(val isVideo: Boolean) : RoomDetailAction()
data class AcceptCall(val callId: String): RoomDetailAction()
object EndCall : RoomDetailAction()

View File

@ -320,7 +320,7 @@ class RoomDetailFragment @Inject constructor(
startCallActivityResultLauncher = startCallActivityResultLauncher,
showDialogWithMessage = ::showDialogWithMessage,
onTapToReturnToCall = ::onTapToReturnToCall
).register()
)
keyboardStateUtils = KeyboardStateUtils(requireActivity())
setupToolbar(views.roomToolbar)
setupRecyclerView()

View File

@ -176,7 +176,6 @@ class RoomDetailViewModel @AssistedInject constructor(
observeMyRoomMember()
observeActiveRoomWidgets()
observePowerLevel()
updateShowDialerOptionState()
room.getRoomSummaryLive()
viewModelScope.launch(Dispatchers.IO) {
tryOrNull { room.markAsRead(ReadService.MarkAsReadParams.READ_RECEIPT) }
@ -301,7 +300,6 @@ class RoomDetailViewModel @AssistedInject constructor(
is RoomDetailAction.TapOnFailedToDecrypt -> handleTapOnFailedToDecrypt(action)
is RoomDetailAction.SelectStickerAttachment -> handleSelectStickerAttachment()
is RoomDetailAction.OpenIntegrationManager -> handleOpenIntegrationManager()
is RoomDetailAction.StartCallWithPhoneNumber -> handleStartCallWithPhoneNumber(action)
is RoomDetailAction.StartCall -> handleStartCall(action)
is RoomDetailAction.AcceptCall -> handleAcceptCall(action)
is RoomDetailAction.EndCall -> handleEndCall()
@ -327,17 +325,6 @@ class RoomDetailViewModel @AssistedInject constructor(
}.exhaustive
}
private fun handleStartCallWithPhoneNumber(action: RoomDetailAction.StartCallWithPhoneNumber) {
viewModelScope.launch {
try {
val result = DialPadLookup(session, callManager, directRoomHelper).lookupPhoneNumber(action.phoneNumber)
callManager.startOutgoingCall(result.roomId, result.userId, action.videoCall)
} catch (failure: Throwable) {
_viewEvents.post(RoomDetailViewEvents.ActionFailure(action, failure))
}
}
}
private fun handleAcceptCall(action: RoomDetailAction.AcceptCall) {
callManager.getCallById(action.callId)?.also {
_viewEvents.post(RoomDetailViewEvents.DisplayAndAcceptCall(it))
@ -1491,16 +1478,6 @@ class RoomDetailViewModel @AssistedInject constructor(
_viewEvents.post(RoomDetailViewEvents.OnNewTimelineEvents(eventIds))
}
override fun onPSTNSupportUpdated() {
updateShowDialerOptionState()
}
private fun updateShowDialerOptionState() {
setState {
copy(showDialerOption = callManager.supportsPSTNProtocol)
}
}
override fun onCleared() {
roomSummariesHolder.remove(room.roomId)
timeline.dispose()

View File

@ -75,7 +75,6 @@ data class RoomDetailViewState(
val canInvite: Boolean = true,
val isAllowedToManageWidgets: Boolean = false,
val isAllowedToStartWebRTCCall: Boolean = true,
val showDialerOption: Boolean = false,
val hasFailedSending: Boolean = false
) : MvRxState {

View File

@ -22,19 +22,13 @@ 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.features.call.DialerChoiceBottomSheet
import im.vector.app.features.call.dialpad.CallDialPadBottomSheet
import im.vector.app.features.call.dialpad.DialPadFragment
import im.vector.app.features.call.webrtc.WebRtcCallManager
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,
@ -44,47 +38,15 @@ class StartCallActionsHandler(
private val roomDetailViewModel: RoomDetailViewModel,
private val startCallActivityResultLauncher: ActivityResultLauncher<Array<String>>,
private val showDialogWithMessage: (String) -> Unit,
private val onTapToReturnToCall: () -> Unit): Restorable {
private val onTapToReturnToCall: () -> Unit) {
fun onVideoCallClicked() {
handleCallRequest(true)
}
fun onVoiceCallClicked() = withState(roomDetailViewModel) {
if (it.showDialerOption) {
displayDialerChoiceBottomSheet()
} else {
fun onVoiceCallClicked() {
handleCallRequest(false)
}
}
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()
.applyListeners()
.show(fragment.parentFragmentManager, DIALER_OPTION_TAG)
}
private fun displayDialPadBottomSheet() {
CallDialPadBottomSheet.newInstance(true)
.applyCallback()
.show(fragment.parentFragmentManager, DIAL_PAD_TAG)
}
private fun handleCallRequest(isVideoCall: Boolean) = withState(roomDetailViewModel) { state ->
val roomSummary = state.asyncRoomSummary.invoke() ?: return@withState
@ -191,12 +153,4 @@ 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()
}
}
}