Commit a36928fd authored by Christophe Deschamps's avatar Christophe Deschamps
Browse files

Added an option to define default actions in configuration for calls not associated with a device

parent d859e67c
......@@ -21,6 +21,7 @@ package org.linhome.linphonecore
import android.content.Context
import org.linhome.LinhomeApplication.Companion.coreContext
import org.linhome.entities.Action
import org.linphone.compatibility.Compatibility
import org.linphone.core.Config
import org.linphone.mediastream.Log
......@@ -49,6 +50,38 @@ class CorePreferences constructor(private val context: Context) {
}
// Default actions to be displayed when no device is associated with the call. Taken from configuration.
//[default_actions]
//default_actions_method_type=[method_dtmf_sip_info|method_dtmf_rfc_4733|method_sip_message]
//action_1_type=[action_open_door|action_open_gate|action_lightup|action_unlock] (match name in shared theme action_types.xml)
//action_1_code=yyyy (dtmf code)
//action_2... up to 3 actions
val defaultActionsMethodType: String?
get() = config.getString("default_actions", "method_type", null)
val defaultAction1: Action?
get() = config.getString("default_actions", "action_1_type", null)?.let { type ->
config.getString("default_actions", "action_1_code", null)?.let { code ->
Action(type,code)
} ?: null
} ?:null
val defaultAction2: Action?
get() = config.getString("default_actions", "action_2_type", null)?.let { type ->
config.getString("default_actions", "action_2_code", null)?.let { code ->
Action(type,code)
} ?: null
} ?:null
val defaultAction3: Action?
get() = config.getString("default_actions", "action_3_type", null)?.let { type ->
config.getString("default_actions", "action_3_code", null)?.let { code ->
Action(type,code)
} ?: null
} ?:null
// Todo - review necessary portion (copied from Linphone)
/* App settings */
......
......@@ -22,6 +22,7 @@ package org.linhome.linphonecore.extensions
import org.linhome.LinhomeApplication
import org.linhome.LinhomeApplication.Companion.coreContext
import org.linhome.LinhomeApplication.Companion.corePreferences
import org.linhome.store.DeviceStore
import org.linphone.core.Call
import org.linphone.core.CallParams
......@@ -42,9 +43,13 @@ fun Call.extendedAccept() {
inCallParams?.recordFile = callLog.historyEvent().mediaFileName
enableCamera(false)
DeviceStore.findDeviceByAddress(remoteAddress)?.also {
LinhomeApplication.coreContext.core.useRfc2833ForDtmf = it.actionsMethodType == "method_dtmf_rfc_4733"
LinhomeApplication.coreContext.core.useInfoForDtmf = it.actionsMethodType == "method_dtmf_sip_info"
val device = DeviceStore.findDeviceByAddress(remoteAddress)
if (device != null) {
coreContext.core.useRfc2833ForDtmf = device.actionsMethodType == "method_dtmf_rfc_4733"
coreContext.core.useInfoForDtmf = device.actionsMethodType == "method_dtmf_sip_info"
} else {
coreContext.core.useRfc2833ForDtmf = corePreferences.defaultActionsMethodType == "method_dtmf_rfc_4733"
coreContext.core.useInfoForDtmf = corePreferences.defaultActionsMethodType == "method_dtmf_sip_info"
}
acceptWithParams(inCallParams)
......
......@@ -40,10 +40,11 @@ import org.linphone.core.AudioDevice
import org.linphone.core.Call
import org.linphone.core.CallListenerStub
import org.linphone.core.Reason
import java.util.ArrayList
class CallViewModelFactory(private val call: Call) :
ViewModelProvider.NewInstanceFactory() {
ViewModelProvider.NewInstanceFactory() {
@Suppress("UNCHECKED_CAST")
override fun <T : ViewModel?> create(modelClass: Class<T>): T {
return CallViewModel(call) as T
......@@ -52,15 +53,18 @@ class CallViewModelFactory(private val call: Call) :
class CallViewModel(val call: Call) : ViewModel() {
val device: MutableLiveData<Device?> =
MutableLiveData(DeviceStore.findDeviceByAddress(call.remoteAddress))
MutableLiveData(DeviceStore.findDeviceByAddress(call.remoteAddress))
val defaultDeviceType: MutableLiveData<String?> = MutableLiveData(DeviceTypes.defaultType)
val actions: ArrayList<Action> = device.value?.let {
it.actions
} ?: defaultActionsIfAny()
val callState: MutableLiveData<Call.State> = MutableLiveData(call.state)
val videoContent: MutableLiveData<Boolean> = MutableLiveData()
val videoFullScreen: MutableLiveData<Boolean> = MutableLiveData(false)
val speakerDisabled: MutableLiveData<Boolean> =
MutableLiveData(coreContext.core.outputAudioDevice?.type != AudioDevice.Type.Speaker)
MutableLiveData(coreContext.core.outputAudioDevice?.type != AudioDevice.Type.Speaker)
val microphoneMuted: MutableLiveData<Boolean> = MutableLiveData(!coreContext.core.micEnabled())
private var historyEvent: HistoryEvent
......@@ -212,4 +216,20 @@ class CallViewModel(val call: Call) : ViewModel() {
call.extendedAccept()
}
// Default actions to be displayed when no device is associated with the call. Taken from configuration.
//[default_actions]
//default_actions_method_type=[method_dtmf_sip_info|method_dtmf_rfc_4733|method_sip_message]
//action_1_type=[action_open_door|action_open_gate|action_lightup|action_unlock] (match name in shared theme action_types.xml)
//action_1_code=yyyy (dtmf code)
//action_2... up to 3 actions
fun defaultActionsIfAny() : ArrayList<Action> {
var actions = ArrayList<Action>()
corePreferences.defaultAction1?.also {actions.add(it)}
corePreferences.defaultAction2?.also {actions.add(it)}
corePreferences.defaultAction3?.also {actions.add(it)}
return actions
}
}
......@@ -25,12 +25,12 @@
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
android:layout_weight="1"
android:visibility='@{callmodel.device != null &amp;&amp; callmodel.device.actions.size()>0 ? View.VISIBLE : View.INVISIBLE}'
android:visibility='@{callmodel.actions.size()>0 ? View.VISIBLE : View.INVISIBLE}'
bind:backgroundeffect='@{"incall_call_button"}'
bind:icon='@{callmodel.device != null &amp;&amp; callmodel.device.actions.size()>0 ? callmodel.device.actions.get(0).iconName() : null}'
bind:onClick="@{()->callmodel.performAction(callmodel.device.actions.get(0))}"
bind:icon='@{callmodel.actions.size()>0 ? callmodel.actions.get(0).iconName() : null}'
bind:onClick="@{()->callmodel.performAction(callmodel.actions.get(0))}"
bind:outline='@{true}'
bind:text="@{callmodel.device != null &amp;&amp; callmodel.device.actions.size()>0 ? callmodel.device.actions.get(0).actionText() : null}"
bind:text="@{callmodel.actions.size()>0 ? callmodel.actions.get(0).actionText() : null}"
bind:tint='@{"color_c"}' />
......@@ -41,12 +41,12 @@
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
android:layout_weight="1"
android:visibility='@{callmodel.device != null &amp;&amp; callmodel.device.actions.size()>1 ? View.VISIBLE : View.GONE}'
android:visibility='@{callmodel.actions.size()>1 ? View.VISIBLE : View.INVISIBLE}'
bind:backgroundeffect='@{"incall_call_button"}'
bind:icon='@{callmodel.device != null &amp;&amp; callmodel.device.actions.size()>1 ? callmodel.device.actions.get(1).iconName() : null}'
bind:onClick="@{()->callmodel.performAction(callmodel.device.actions.get(1))}"
bind:icon='@{callmodel.actions.size()>1 ? callmodel.actions.get(1).iconName() : null}'
bind:onClick="@{()->callmodel.performAction(callmodel.actions.get(1))}"
bind:outline='@{true}'
bind:text="@{callmodel.device != null &amp;&amp; callmodel.device.actions.size()>1 ? callmodel.device.actions.get(1).actionText() : null}"
bind:text="@{callmodel.actions.size()>1 ? callmodel.actions.get(1).actionText() : null}"
bind:tint='@{"color_c"}' />
<include
......@@ -56,12 +56,12 @@
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
android:layout_weight="1"
android:visibility='@{callmodel.device != null &amp;&amp; callmodel.device.actions.size()>2 ? View.VISIBLE : View.GONE}'
android:visibility='@{callmodel.actions.size()>2 ? View.VISIBLE : View.INVISIBLE}'
bind:backgroundeffect='@{"incall_call_button"}'
bind:icon='@{callmodel.device != null &amp;&amp; callmodel.device.actions.size()>2 ? callmodel.device.actions.get(2).iconName() : null}'
bind:onClick="@{()->callmodel.performAction(callmodel.device.actions.get(2))}"
bind:icon='@{callmodel.actions.size()>2 ? callmodel.actions.get(2).iconName() : null}'
bind:onClick="@{()->callmodel.performAction(callmodel.actions.get(2))}"
bind:outline='@{true}'
bind:text="@{callmodel.device != null &amp;&amp; callmodel.device.actions.size()>2 ? callmodel.device.actions.get(2).actionText() : null}"
bind:text="@{callmodel.actions.size()>2 ? callmodel.actions.get(2).actionText() : null}"
bind:tint='@{"color_c"}' />
</LinearLayout>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment