Adding clear input when long pressing backspace button in numpad + playing DTMF tone if enabled at OS level

This commit is contained in:
Sylvain Berfini 2024-06-04 15:30:04 +02:00
parent a71ba2096b
commit 01f6ac29e9
6 changed files with 42 additions and 1 deletions

View file

@ -29,6 +29,7 @@ import android.media.AudioManager
import android.os.Handler
import android.os.HandlerThread
import android.os.Looper
import android.provider.Settings
import androidx.annotation.AnyThread
import androidx.annotation.UiThread
import androidx.annotation.WorkerThread
@ -744,6 +745,15 @@ class CoreContext @UiThread constructor(val context: Context) : HandlerThread("C
}
}
@WorkerThread
fun playDtmf(character: Char, duration: Int = 200) {
if (Settings.System.getInt(context.contentResolver, Settings.System.DTMF_TONE_WHEN_DIALING) != 0) {
core.playDtmf(character, duration)
} else {
Log.w("$TAG Numpad DTMF tones are disabled in system settings, not playing them")
}
}
@WorkerThread
private fun computeUserAgent() {
val deviceName = AppUtils.getDeviceName(context)

View file

@ -473,6 +473,8 @@ class CurrentCallViewModel @UiThread constructor() : GenericViewModel() {
removedCharacterAtCurrentPositionEvent.value = Event(true)
},
{ // OnCallClicked
},
{ // OnClearInput
}
)

View file

@ -110,6 +110,12 @@ class StartCallFragment : GenericAddressPickerFragment() {
}
}
viewModel.clearSearchBarEvent.observe(viewLifecycleOwner) {
it.consume {
binding.searchBar.setText("")
}
}
viewModel.appendDigitToSearchBarEvent.observe(viewLifecycleOwner) {
it.consume { digit ->
binding.searchBar.addCharacterAtPosition(digit)

View file

@ -21,12 +21,14 @@ package org.linphone.ui.main.history.model
import androidx.annotation.UiThread
import androidx.lifecycle.MutableLiveData
import org.linphone.LinphoneApplication.Companion.coreContext
import org.linphone.core.tools.Log
open class NumpadModel @UiThread constructor(
private val onDigitClicked: (value: String) -> (Unit),
private val onBackspaceClicked: () -> (Unit),
private val onCallClicked: () -> (Unit)
private val onCallClicked: () -> (Unit),
private val onClearClicked: () -> (Unit)
) {
companion object {
private const val TAG = "[Numpad Model]"
@ -38,6 +40,12 @@ open class NumpadModel @UiThread constructor(
fun onDigitClicked(value: String) {
Log.i("$TAG Clicked on digit [$value]")
onDigitClicked.invoke(value)
if (value.isNotEmpty()) {
coreContext.postOnCoreThread { core ->
coreContext.playDtmf(value[0])
}
}
}
fun onDigitLongClicked(value: String): Boolean {
@ -52,6 +60,13 @@ open class NumpadModel @UiThread constructor(
onBackspaceClicked.invoke()
}
@UiThread
fun onBackspaceLongClicked(): Boolean {
Log.i("$TAG Long clicked on backspace, clearing input")
onClearClicked.invoke()
return true
}
@UiThread
fun onCallClicked() {
Log.i("$TAG Starting call")

View file

@ -66,6 +66,10 @@ class StartCallViewModel @UiThread constructor() : AddressSelectionViewModel() {
MutableLiveData<Event<Boolean>>()
}
val clearSearchBarEvent: MutableLiveData<Event<Boolean>> by lazy {
MutableLiveData<Event<Boolean>>()
}
val requestKeyboardVisibilityChangedEvent: MutableLiveData<Event<Boolean>> by lazy {
MutableLiveData<Event<Boolean>>()
}
@ -143,6 +147,9 @@ class StartCallViewModel @UiThread constructor() : AddressSelectionViewModel() {
}
}
}
},
{ // OnClearInput
clearSearchBarEvent.value = Event(true)
}
)

View file

@ -192,6 +192,7 @@
<ImageView
android:id="@+id/backspace"
android:onClick="@{() -> model.onBackspaceClicked()}"
android:onLongClick="@{() -> model.onBackspaceLongClicked()}"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"