diff --git a/app/src/main/java/org/linphone/ui/call/fragment/ActiveCallFragment.kt b/app/src/main/java/org/linphone/ui/call/fragment/ActiveCallFragment.kt index 74892026b..843eab1af 100644 --- a/app/src/main/java/org/linphone/ui/call/fragment/ActiveCallFragment.kt +++ b/app/src/main/java/org/linphone/ui/call/fragment/ActiveCallFragment.kt @@ -46,6 +46,8 @@ import org.linphone.ui.call.viewmodel.SharedCallViewModel import org.linphone.utils.AppUtils import org.linphone.utils.DialogUtils import org.linphone.utils.Event +import org.linphone.utils.addCharacterAtPosition +import org.linphone.utils.removeCharacterAtPosition @UiThread class ActiveCallFragment : GenericCallFragment() { @@ -117,9 +119,13 @@ class ActiveCallFragment : GenericCallFragment() { binding.lifecycleOwner = viewLifecycleOwner binding.viewModel = callViewModel binding.callsViewModel = callsViewModel + binding.numpadModel = callViewModel.numpadModel - val bottomSheetBehavior = BottomSheetBehavior.from(binding.bottomBar.root) - bottomSheetBehavior.state = BottomSheetBehavior.STATE_COLLAPSED + val actionsBottomSheetBehavior = BottomSheetBehavior.from(binding.bottomBar.root) + actionsBottomSheetBehavior.state = BottomSheetBehavior.STATE_COLLAPSED + + val numpadBottomSheetBehavior = BottomSheetBehavior.from(binding.callNumpad.root) + numpadBottomSheetBehavior.state = BottomSheetBehavior.STATE_COLLAPSED binding.setNewCallClickListener { val action = ActiveCallFragmentDirections.actionActiveCallFragmentToNewCallFragment() @@ -185,16 +191,35 @@ class ActiveCallFragment : GenericCallFragment() { callViewModel.toggleExtraActionsBottomSheetEvent.observe(viewLifecycleOwner) { it.consume { - val state = bottomSheetBehavior.state + val state = actionsBottomSheetBehavior.state if (state == BottomSheetBehavior.STATE_COLLAPSED) { - bottomSheetBehavior.state = BottomSheetBehavior.STATE_EXPANDED + actionsBottomSheetBehavior.state = BottomSheetBehavior.STATE_EXPANDED } else if (state == BottomSheetBehavior.STATE_EXPANDED) { - bottomSheetBehavior.state = BottomSheetBehavior.STATE_COLLAPSED + actionsBottomSheetBehavior.state = BottomSheetBehavior.STATE_COLLAPSED } } } - bottomSheetBehavior.addBottomSheetCallback(object : BottomSheetBehavior.BottomSheetCallback() { + callViewModel.showNumpadBottomSheetEvent.observe(viewLifecycleOwner) { + it.consume { + actionsBottomSheetBehavior.state = BottomSheetBehavior.STATE_COLLAPSED + numpadBottomSheetBehavior.state = BottomSheetBehavior.STATE_EXPANDED + } + } + + callViewModel.removedCharacterAtCurrentPositionEvent.observe(viewLifecycleOwner) { + it.consume { + binding.callNumpad.digitsHistory.removeCharacterAtPosition() + } + } + + callViewModel.appendDigitToSearchBarEvent.observe(viewLifecycleOwner) { + it.consume { digit -> + binding.callNumpad.digitsHistory.addCharacterAtPosition(digit) + } + } + + actionsBottomSheetBehavior.addBottomSheetCallback(object : BottomSheetBehavior.BottomSheetCallback() { override fun onStateChanged(bottomSheet: View, newState: Int) { when (newState) { BottomSheetBehavior.STATE_COLLAPSED, BottomSheetBehavior.STATE_HIDDEN -> { diff --git a/app/src/main/java/org/linphone/ui/call/viewmodel/CurrentCallViewModel.kt b/app/src/main/java/org/linphone/ui/call/viewmodel/CurrentCallViewModel.kt index 6ce25818e..604ba3c91 100644 --- a/app/src/main/java/org/linphone/ui/call/viewmodel/CurrentCallViewModel.kt +++ b/app/src/main/java/org/linphone/ui/call/viewmodel/CurrentCallViewModel.kt @@ -37,6 +37,7 @@ import org.linphone.core.MediaEncryption import org.linphone.core.tools.Log import org.linphone.ui.call.model.AudioDeviceModel import org.linphone.ui.main.contacts.model.ContactAvatarModel +import org.linphone.ui.main.history.model.NumpadModel import org.linphone.utils.AppUtils import org.linphone.utils.AudioRouteUtils import org.linphone.utils.Event @@ -100,6 +101,20 @@ class CurrentCallViewModel @UiThread constructor() : ViewModel() { MutableLiveData>() } + val showNumpadBottomSheetEvent: MutableLiveData> by lazy { + MutableLiveData>() + } + + val numpadModel: NumpadModel + + val appendDigitToSearchBarEvent: MutableLiveData> by lazy { + MutableLiveData>() + } + + val removedCharacterAtCurrentPositionEvent: MutableLiveData> by lazy { + MutableLiveData>() + } + private lateinit var call: Call private val callListener = object : CallListenerStub() { @@ -158,6 +173,21 @@ class CurrentCallViewModel @UiThread constructor() : ViewModel() { showSwitchCamera.postValue(coreContext.showSwitchCameraButton()) } + + numpadModel = NumpadModel( + { digit -> // onDigitClicked + appendDigitToSearchBarEvent.value = Event(digit) + coreContext.postOnCoreThread { + Log.i("$TAG Sending DTMF [${digit.first()}]") + call.sendDtmf(digit.first()) + } + }, + { // OnBackspaceClicked + removedCharacterAtCurrentPositionEvent.value = Event(true) + }, + { // OnCallClicked + } + ) } @UiThread @@ -323,6 +353,11 @@ class CurrentCallViewModel @UiThread constructor() : ViewModel() { toggleExtraActionsBottomSheetEvent.value = Event(true) } + @UiThread + fun showNumpad() { + showNumpadBottomSheetEvent.value = Event(true) + } + @WorkerThread private fun showZrtpSasDialog(authToken: String) { val toRead: String diff --git a/app/src/main/java/org/linphone/ui/main/history/fragment/StartCallFragment.kt b/app/src/main/java/org/linphone/ui/main/history/fragment/StartCallFragment.kt index 59be542c3..6fcae2b11 100644 --- a/app/src/main/java/org/linphone/ui/main/history/fragment/StartCallFragment.kt +++ b/app/src/main/java/org/linphone/ui/main/history/fragment/StartCallFragment.kt @@ -44,7 +44,9 @@ import org.linphone.ui.main.history.viewmodel.StartCallViewModel import org.linphone.ui.main.model.isInSecureMode import org.linphone.utils.DialogUtils import org.linphone.utils.RecyclerViewHeaderDecoration +import org.linphone.utils.addCharacterAtPosition import org.linphone.utils.hideKeyboard +import org.linphone.utils.removeCharacterAtPosition import org.linphone.utils.setKeyboardInsetListener import org.linphone.utils.showKeyboard @@ -140,24 +142,13 @@ class StartCallFragment : GenericFragment() { viewModel.removedCharacterAtCurrentPositionEvent.observe(viewLifecycleOwner) { it.consume { - val selectionStart = binding.searchBar.selectionStart - val selectionEnd = binding.searchBar.selectionEnd - if (selectionStart > 0) { - binding.searchBar.text = - binding.searchBar.text?.delete( - selectionStart - 1, - selectionEnd - ) - binding.searchBar.setSelection(selectionStart - 1) - } + binding.searchBar.removeCharacterAtPosition() } } viewModel.appendDigitToSearchBarEvent.observe(viewLifecycleOwner) { it.consume { digit -> - val newValue = "${binding.searchBar.text}$digit" - binding.searchBar.setText(newValue) - binding.searchBar.setSelection(newValue.length) + binding.searchBar.addCharacterAtPosition(digit) } } diff --git a/app/src/main/java/org/linphone/ui/main/history/model/NumpadModel.kt b/app/src/main/java/org/linphone/ui/main/history/model/NumpadModel.kt index aac42b7ad..21629d71a 100644 --- a/app/src/main/java/org/linphone/ui/main/history/model/NumpadModel.kt +++ b/app/src/main/java/org/linphone/ui/main/history/model/NumpadModel.kt @@ -20,9 +20,10 @@ package org.linphone.ui.main.history.model import androidx.annotation.UiThread +import androidx.lifecycle.MutableLiveData import org.linphone.core.tools.Log -class NumpadModel @UiThread constructor( +open class NumpadModel @UiThread constructor( private val onDigitClicked: (value: String) -> (Unit), private val onBackspaceClicked: () -> (Unit), private val onCallClicked: () -> (Unit) @@ -31,6 +32,8 @@ class NumpadModel @UiThread constructor( private const val TAG = "[Numpad Model]" } + val digits = MutableLiveData() + @UiThread fun onDigitClicked(value: String) { Log.i("$TAG Clicked on digit [$value]") diff --git a/app/src/main/java/org/linphone/utils/DataBindingUtils.kt b/app/src/main/java/org/linphone/utils/DataBindingUtils.kt index f6f97596f..a39690e05 100644 --- a/app/src/main/java/org/linphone/utils/DataBindingUtils.kt +++ b/app/src/main/java/org/linphone/utils/DataBindingUtils.kt @@ -113,6 +113,27 @@ fun View.hideKeyboard() { imm.hideSoftInputFromWindow(this.windowToken, 0) } +@UiThread +fun AppCompatEditText.removeCharacterAtPosition() { + val start = selectionStart + val end = selectionEnd + if (start > 0) { + text = + text?.delete( + start - 1, + end + ) + setSelection(start - 1) + } +} + +@UiThread +fun AppCompatEditText.addCharacterAtPosition(character: String) { + val newValue = "${text}$character" + setText(newValue) + setSelection(newValue.length) +} + @UiThread fun View.setKeyboardInsetListener(lambda: (visible: Boolean) -> Unit) { doOnLayout { diff --git a/app/src/main/res/drawable/shape_numpad_call_background.xml b/app/src/main/res/drawable/shape_numpad_call_background.xml new file mode 100644 index 000000000..a1f42b973 --- /dev/null +++ b/app/src/main/res/drawable/shape_numpad_call_background.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout-land/call_extra_actions.xml b/app/src/main/res/layout-land/call_extra_actions.xml index ae8aea999..769866bf9 100644 --- a/app/src/main/res/layout-land/call_extra_actions.xml +++ b/app/src/main/res/layout-land/call_extra_actions.xml @@ -25,7 +25,7 @@ @@ -103,6 +103,7 @@ + + android:background="@color/gray_900"> + + \ No newline at end of file diff --git a/app/src/main/res/layout/call_extra_actions.xml b/app/src/main/res/layout/call_extra_actions.xml index 7e9b41c5e..a86569738 100644 --- a/app/src/main/res/layout/call_extra_actions.xml +++ b/app/src/main/res/layout/call_extra_actions.xml @@ -25,7 +25,7 @@ @@ -103,6 +103,7 @@ diff --git a/app/src/main/res/layout/call_incoming_fragment.xml b/app/src/main/res/layout/call_incoming_fragment.xml index c1bebf2dd..f1f34fb7e 100644 --- a/app/src/main/res/layout/call_incoming_fragment.xml +++ b/app/src/main/res/layout/call_incoming_fragment.xml @@ -13,7 +13,7 @@ + android:background="@color/gray_900"> + android:background="@color/gray_900"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/call_outgoing_fragment.xml b/app/src/main/res/layout/call_outgoing_fragment.xml index 3dbf6c6bf..3241fda7b 100644 --- a/app/src/main/res/layout/call_outgoing_fragment.xml +++ b/app/src/main/res/layout/call_outgoing_fragment.xml @@ -13,7 +13,7 @@ + android:background="@color/gray_900"> #949494 #4E4E4E #2E3030 - #070707 + #070707 #F5CCBE #DD5F5F diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index ef05398b3..49c0466d2 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -119,6 +119,14 @@ 3dp @drawable/circle_white_button_background +