From 74497dadd2d4dc599ad9b5f06819745cdd379cd5 Mon Sep 17 00:00:00 2001 From: ganfra Date: Wed, 2 Jun 2021 17:06:10 +0200 Subject: [PATCH] Dial pad tab: first step, remove current way --- .../features/call/DialerChoiceBottomSheet.kt | 46 --------------- .../home/room/detail/RoomDetailAction.kt | 1 - .../home/room/detail/RoomDetailFragment.kt | 2 +- .../home/room/detail/RoomDetailViewModel.kt | 23 -------- .../home/room/detail/RoomDetailViewState.kt | 1 - .../room/detail/StartCallActionsHandler.kt | 56 ++----------------- 6 files changed, 6 insertions(+), 123 deletions(-) delete mode 100644 vector/src/main/java/im/vector/app/features/call/DialerChoiceBottomSheet.kt diff --git a/vector/src/main/java/im/vector/app/features/call/DialerChoiceBottomSheet.kt b/vector/src/main/java/im/vector/app/features/call/DialerChoiceBottomSheet.kt deleted file mode 100644 index 401b3e23d7..0000000000 --- a/vector/src/main/java/im/vector/app/features/call/DialerChoiceBottomSheet.kt +++ /dev/null @@ -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() { - 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() - } - } -} diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailAction.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailAction.kt index 72e614c18c..c0e73823e4 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailAction.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailAction.kt @@ -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() diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailFragment.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailFragment.kt index 7fa36a39d7..b42ec38a3a 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailFragment.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailFragment.kt @@ -320,7 +320,7 @@ class RoomDetailFragment @Inject constructor( startCallActivityResultLauncher = startCallActivityResultLauncher, showDialogWithMessage = ::showDialogWithMessage, onTapToReturnToCall = ::onTapToReturnToCall - ).register() + ) keyboardStateUtils = KeyboardStateUtils(requireActivity()) setupToolbar(views.roomToolbar) setupRecyclerView() diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailViewModel.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailViewModel.kt index a2041c0a80..2be96e07e9 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailViewModel.kt @@ -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() diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailViewState.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailViewState.kt index 965733c424..1ead34fadd 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailViewState.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailViewState.kt @@ -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 { diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/StartCallActionsHandler.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/StartCallActionsHandler.kt index cf508a2dab..e777f6d628 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/StartCallActionsHandler.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/StartCallActionsHandler.kt @@ -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,52 +38,20 @@ class StartCallActionsHandler( private val roomDetailViewModel: RoomDetailViewModel, private val startCallActivityResultLauncher: ActivityResultLauncher>, 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 { - 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) + fun onVoiceCallClicked() { + handleCallRequest(false) } private fun handleCallRequest(isVideoCall: Boolean) = withState(roomDetailViewModel) { state -> val roomSummary = state.asyncRoomSummary.invoke() ?: return@withState when (roomSummary.joinedMembersCount) { - 1 -> { + 1 -> { val pendingInvite = roomSummary.invitedMembersCount ?: 0 > 0 if (pendingInvite) { // wait for other to join @@ -99,7 +61,7 @@ class StartCallActionsHandler( showDialogWithMessage(fragment.getString(R.string.cannot_call_yourself)) } } - 2 -> { + 2 -> { val currentCall = callManager.getCurrentCall() if (currentCall != null) { // resume existing if same room, if not prompt to kill and then restart new call? @@ -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() - } - } }