Added setting to automatically start call when app is launched from another
This commit is contained in:
parent
8e330ce664
commit
df42812afc
6 changed files with 62 additions and 1 deletions
|
@ -28,6 +28,7 @@ import androidx.fragment.app.Fragment
|
|||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import org.linphone.LinphoneApplication.Companion.coreContext
|
||||
import org.linphone.LinphoneApplication.Companion.corePreferences
|
||||
import org.linphone.R
|
||||
import org.linphone.activities.main.dialer.viewmodels.DialerViewModel
|
||||
import org.linphone.activities.main.viewmodels.SharedMainViewModel
|
||||
|
@ -90,7 +91,14 @@ class DialerFragment : Fragment() {
|
|||
sharedViewModel.pendingCallTransfer = arguments?.getBoolean("Transfer") ?: false
|
||||
}
|
||||
if (arguments?.containsKey("URI") == true) {
|
||||
viewModel.enteredUri.value = arguments?.getString("URI")
|
||||
val address = arguments?.getString("URI") ?: ""
|
||||
|
||||
if (corePreferences.callRightAway) {
|
||||
Log.i("[Dialer] Call right away setting is enabled, start the call to $address")
|
||||
viewModel.directCall(address)
|
||||
} else {
|
||||
viewModel.enteredUri.value = address
|
||||
}
|
||||
}
|
||||
|
||||
Log.i("[Dialer] Pending call transfer mode = ${sharedViewModel.pendingCallTransfer}")
|
||||
|
|
|
@ -25,6 +25,7 @@ import org.linphone.LinphoneApplication.Companion.coreContext
|
|||
import org.linphone.LinphoneApplication.Companion.corePreferences
|
||||
import org.linphone.activities.main.dialer.NumpadDigitListener
|
||||
import org.linphone.core.*
|
||||
import org.linphone.core.tools.Log
|
||||
|
||||
class DialerViewModel : ViewModel() {
|
||||
val enteredUri = MutableLiveData<String>()
|
||||
|
@ -37,6 +38,9 @@ class DialerViewModel : ViewModel() {
|
|||
|
||||
val showSwitchCamera = MutableLiveData<Boolean>()
|
||||
|
||||
private var addressWaitingNetworkToBeCalled: String? = null
|
||||
private var timeAtWitchWeTriedToCall: Long = 0
|
||||
|
||||
val onKeyClick: NumpadDigitListener = object : NumpadDigitListener {
|
||||
override fun handleClick(key: Char) {
|
||||
enteredUri.value += key.toString()
|
||||
|
@ -67,6 +71,22 @@ class DialerViewModel : ViewModel() {
|
|||
) {
|
||||
atLeastOneCall.value = core.callsNb > 0
|
||||
}
|
||||
|
||||
override fun onNetworkReachable(core: Core, reachable: Boolean) {
|
||||
if (reachable && addressWaitingNetworkToBeCalled.orEmpty().isNotEmpty()) {
|
||||
val now = System.currentTimeMillis()
|
||||
if (now - timeAtWitchWeTriedToCall > 1000) {
|
||||
Log.e("[Dialer] More than 1 second has passed waiting for network, abort auto call to $addressWaitingNetworkToBeCalled")
|
||||
enteredUri.value = addressWaitingNetworkToBeCalled
|
||||
} else {
|
||||
Log.i("[Dialer] Network is available, continue auto call to $addressWaitingNetworkToBeCalled")
|
||||
coreContext.startCall(addressWaitingNetworkToBeCalled.orEmpty())
|
||||
}
|
||||
|
||||
addressWaitingNetworkToBeCalled = null
|
||||
timeAtWitchWeTriedToCall = 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
init {
|
||||
|
@ -100,6 +120,16 @@ class DialerViewModel : ViewModel() {
|
|||
return true
|
||||
}
|
||||
|
||||
fun directCall(to: String) {
|
||||
if (coreContext.core.isNetworkReachable) {
|
||||
coreContext.startCall(to)
|
||||
} else {
|
||||
Log.w("[Dialer] Network isnt't reachable at the time, wait for network to start call (happens mainly when app is cold started)")
|
||||
timeAtWitchWeTriedToCall = System.currentTimeMillis()
|
||||
addressWaitingNetworkToBeCalled = to
|
||||
}
|
||||
}
|
||||
|
||||
fun startCall() {
|
||||
val addressToCall = enteredUri.value.orEmpty()
|
||||
if (addressToCall.isNotEmpty()) {
|
||||
|
|
|
@ -83,6 +83,13 @@ class CallSettingsViewModel : GenericSettingsViewModel() {
|
|||
}
|
||||
val rfc2833Dtmf = MutableLiveData<Boolean>()
|
||||
|
||||
val autoStartListener = object : SettingListenerStub() {
|
||||
override fun onBoolValueChanged(newValue: Boolean) {
|
||||
prefs.callRightAway = newValue
|
||||
}
|
||||
}
|
||||
val autoStart = MutableLiveData<Boolean>()
|
||||
|
||||
val autoAnswerListener = object : SettingListenerStub() {
|
||||
override fun onBoolValueChanged(newValue: Boolean) {
|
||||
prefs.autoAnswerEnabled = newValue
|
||||
|
@ -121,6 +128,7 @@ class CallSettingsViewModel : GenericSettingsViewModel() {
|
|||
overlay.value = prefs.showCallOverlay
|
||||
sipInfoDtmf.value = core.useInfoForDtmf
|
||||
rfc2833Dtmf.value = core.useRfc2833ForDtmf
|
||||
autoStart.value = prefs.callRightAway
|
||||
autoAnswer.value = prefs.autoAnswerEnabled
|
||||
autoAnswerDelay.value = prefs.autoAnswerDelay
|
||||
incomingTimeout.value = core.incTimeout
|
||||
|
|
|
@ -163,6 +163,12 @@ class CorePreferences constructor(private val context: Context) {
|
|||
config.setBool("app", "call_overlay", value)
|
||||
}
|
||||
|
||||
var callRightAway: Boolean
|
||||
get() = config.getBool("app", "call_right_away", false)
|
||||
set(value) {
|
||||
config.setBool("app", "call_right_away", value)
|
||||
}
|
||||
|
||||
/* Assistant */
|
||||
|
||||
var firstStart: Boolean
|
||||
|
|
|
@ -117,6 +117,13 @@
|
|||
linphone:listener="@{viewModel.rfc2833DtmfListener}"
|
||||
linphone:checked="@={viewModel.rfc2833Dtmf}"/>
|
||||
|
||||
<include
|
||||
layout="@layout/settings_widget_switch"
|
||||
linphone:title="@{@string/call_settings_auto_start_title}"
|
||||
linphone:subtitle="@{@string/call_settings_auto_start_summary}"
|
||||
linphone:listener="@{viewModel.autoStartListener}"
|
||||
linphone:checked="@={viewModel.autoStart}"/>
|
||||
|
||||
<include
|
||||
layout="@layout/settings_widget_switch"
|
||||
linphone:title="@{@string/call_settings_auto_answer_title}"
|
||||
|
|
|
@ -333,6 +333,8 @@
|
|||
<string name="call_settings_sipinfo_dtmf_summary"></string>
|
||||
<string name="call_settings_rfc2833_dtmf_title">Send in-band DTMFs (RFC 2833)</string>
|
||||
<string name="call_settings_rfc2833_dtmf_summary"></string>
|
||||
<string name="call_settings_auto_start_title">Start call immediately</string>
|
||||
<string name="call_settings_auto_start_summary">The call will start automatically if started from another application</string>
|
||||
<string name="call_settings_auto_answer_title">Auto answer incoming calls</string>
|
||||
<string name="call_settings_auto_answer_summary"></string>
|
||||
<string name="call_settings_auto_answer_delay_title">Auto answer time</string>
|
||||
|
|
Loading…
Reference in a new issue