Added missing call update dialog
This commit is contained in:
parent
03f0f49c71
commit
74cd0f1bf8
5 changed files with 79 additions and 12 deletions
|
@ -19,6 +19,7 @@
|
||||||
*/
|
*/
|
||||||
package org.linphone.activities.call.fragments
|
package org.linphone.activities.call.fragments
|
||||||
|
|
||||||
|
import android.app.Dialog
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.os.SystemClock
|
import android.os.SystemClock
|
||||||
|
@ -28,11 +29,16 @@ import android.view.ViewGroup
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.lifecycle.Observer
|
import androidx.lifecycle.Observer
|
||||||
import androidx.lifecycle.ViewModelProvider
|
import androidx.lifecycle.ViewModelProvider
|
||||||
|
import org.linphone.R
|
||||||
import org.linphone.activities.call.viewmodels.CallsViewModel
|
import org.linphone.activities.call.viewmodels.CallsViewModel
|
||||||
import org.linphone.activities.call.viewmodels.ControlsViewModel
|
import org.linphone.activities.call.viewmodels.ControlsViewModel
|
||||||
import org.linphone.activities.call.viewmodels.SharedCallViewModel
|
import org.linphone.activities.call.viewmodels.SharedCallViewModel
|
||||||
import org.linphone.activities.main.MainActivity
|
import org.linphone.activities.main.MainActivity
|
||||||
|
import org.linphone.activities.main.viewmodels.DialogViewModel
|
||||||
|
import org.linphone.core.Call
|
||||||
import org.linphone.databinding.CallControlsFragmentBinding
|
import org.linphone.databinding.CallControlsFragmentBinding
|
||||||
|
import org.linphone.utils.AppUtils
|
||||||
|
import org.linphone.utils.DialogUtils
|
||||||
import org.linphone.utils.Event
|
import org.linphone.utils.Event
|
||||||
|
|
||||||
class ControlsFragment : Fragment() {
|
class ControlsFragment : Fragment() {
|
||||||
|
@ -79,6 +85,12 @@ class ControlsFragment : Fragment() {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
callsViewModel.callUpdateEvent.observe(viewLifecycleOwner, Observer {
|
||||||
|
it.consume { call ->
|
||||||
|
showCallUpdateDialog(call)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
controlsViewModel.chatClickedEvent.observe(viewLifecycleOwner, Observer {
|
controlsViewModel.chatClickedEvent.observe(viewLifecycleOwner, Observer {
|
||||||
it.consume {
|
it.consume {
|
||||||
val intent = Intent()
|
val intent = Intent()
|
||||||
|
@ -117,4 +129,21 @@ class ControlsFragment : Fragment() {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun showCallUpdateDialog(call: Call) {
|
||||||
|
val viewModel = DialogViewModel(AppUtils.getString(R.string.call_video_update_requested_dialog))
|
||||||
|
val dialog: Dialog = DialogUtils.getDialog(requireContext(), viewModel)
|
||||||
|
|
||||||
|
viewModel.showCancelButton({
|
||||||
|
callsViewModel.answerCallUpdateRequest(call, false)
|
||||||
|
dialog.dismiss()
|
||||||
|
}, getString(R.string.dialog_decline))
|
||||||
|
|
||||||
|
viewModel.showOkButton({
|
||||||
|
callsViewModel.answerCallUpdateRequest(call, true)
|
||||||
|
dialog.dismiss()
|
||||||
|
}, getString(R.string.dialog_accept))
|
||||||
|
|
||||||
|
dialog.show()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,6 +42,10 @@ class CallsViewModel : ViewModel() {
|
||||||
MutableLiveData<Event<Boolean>>()
|
MutableLiveData<Event<Boolean>>()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val callUpdateEvent: MutableLiveData<Event<Call>> by lazy {
|
||||||
|
MutableLiveData<Event<Call>>()
|
||||||
|
}
|
||||||
|
|
||||||
private val listener = object : CoreListenerStub() {
|
private val listener = object : CoreListenerStub() {
|
||||||
override fun onCallStateChanged(
|
override fun onCallStateChanged(
|
||||||
core: Core,
|
core: Core,
|
||||||
|
@ -67,11 +71,21 @@ class CallsViewModel : ViewModel() {
|
||||||
removeCallFromPausedListIfPresent(call)
|
removeCallFromPausedListIfPresent(call)
|
||||||
removeCallFromConferenceIfPresent(call)
|
removeCallFromConferenceIfPresent(call)
|
||||||
}
|
}
|
||||||
} else {
|
} else if (state == Call.State.Pausing) {
|
||||||
if (state == Call.State.Pausing) {
|
|
||||||
addCallToPausedList(call)
|
addCallToPausedList(call)
|
||||||
} else if (state == Call.State.Resuming) {
|
} else if (state == Call.State.Resuming) {
|
||||||
removeCallFromPausedListIfPresent(call)
|
removeCallFromPausedListIfPresent(call)
|
||||||
|
} else if (call.state == Call.State.UpdatedByRemote) {
|
||||||
|
// If the correspondent proposes video while audio call,
|
||||||
|
// defer update until user has chosen whether to accept it or not
|
||||||
|
val remoteVideo = call.remoteParams?.videoEnabled() ?: false
|
||||||
|
val localVideo = call.currentParams.videoEnabled()
|
||||||
|
val autoAccept = call.core.videoActivationPolicy.automaticallyAccept
|
||||||
|
if (remoteVideo && !localVideo && !autoAccept) {
|
||||||
|
call.deferUpdate()
|
||||||
|
// TODO: start 30 secs timer and decline update if no answer when it triggers
|
||||||
|
callUpdateEvent.value = Event(call)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (call.conference != null) {
|
if (call.conference != null) {
|
||||||
addCallToConferenceListIfNotAlreadyInIt(call)
|
addCallToConferenceListIfNotAlreadyInIt(call)
|
||||||
|
@ -81,7 +95,6 @@ class CallsViewModel : ViewModel() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
init {
|
init {
|
||||||
coreContext.core.addListener(listener)
|
coreContext.core.addListener(listener)
|
||||||
|
@ -112,6 +125,19 @@ class CallsViewModel : ViewModel() {
|
||||||
super.onCleared()
|
super.onCleared()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun answerCallUpdateRequest(call: Call, accept: Boolean) {
|
||||||
|
val core = call.core
|
||||||
|
val params = core.createCallParams(call)
|
||||||
|
|
||||||
|
if (accept) {
|
||||||
|
params?.enableVideo(true)
|
||||||
|
core.enableVideoCapture(true)
|
||||||
|
core.enableVideoDisplay(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
call.acceptUpdate(params)
|
||||||
|
}
|
||||||
|
|
||||||
fun pauseConference() {
|
fun pauseConference() {
|
||||||
if (coreContext.core.isInConference) {
|
if (coreContext.core.isInConference) {
|
||||||
coreContext.core.leaveConference()
|
coreContext.core.leaveConference()
|
||||||
|
|
|
@ -21,6 +21,8 @@ package org.linphone.activities.main.viewmodels
|
||||||
|
|
||||||
import androidx.lifecycle.MutableLiveData
|
import androidx.lifecycle.MutableLiveData
|
||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
|
import org.linphone.R
|
||||||
|
import org.linphone.utils.AppUtils
|
||||||
|
|
||||||
class DialogViewModel(val message: String, val title: String = "") : ViewModel() {
|
class DialogViewModel(val message: String, val title: String = "") : ViewModel() {
|
||||||
var showDoNotAskAgain: Boolean = false
|
var showDoNotAskAgain: Boolean = false
|
||||||
|
@ -45,6 +47,7 @@ class DialogViewModel(val message: String, val title: String = "") : ViewModel()
|
||||||
}
|
}
|
||||||
|
|
||||||
var showCancel: Boolean = false
|
var showCancel: Boolean = false
|
||||||
|
var cancelLabel: String = AppUtils.getString(R.string.dialog_cancel)
|
||||||
private var onCancel: (Boolean) -> Unit = {}
|
private var onCancel: (Boolean) -> Unit = {}
|
||||||
|
|
||||||
fun showCancelButton(cancel: (Boolean) -> Unit) {
|
fun showCancelButton(cancel: (Boolean) -> Unit) {
|
||||||
|
@ -52,12 +55,18 @@ class DialogViewModel(val message: String, val title: String = "") : ViewModel()
|
||||||
onCancel = cancel
|
onCancel = cancel
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun showCancelButton(cancel: (Boolean) -> Unit, label: String = cancelLabel) {
|
||||||
|
showCancel = true
|
||||||
|
onCancel = cancel
|
||||||
|
cancelLabel = label
|
||||||
|
}
|
||||||
|
|
||||||
fun onCancelClicked() {
|
fun onCancelClicked() {
|
||||||
onCancel(doNotAskAgain.value == true)
|
onCancel(doNotAskAgain.value == true)
|
||||||
}
|
}
|
||||||
|
|
||||||
var showDelete: Boolean = false
|
var showDelete: Boolean = false
|
||||||
var deleteLabel: String = "Delete"
|
var deleteLabel: String = AppUtils.getString(R.string.dialog_delete)
|
||||||
private var onDelete: (Boolean) -> Unit = {}
|
private var onDelete: (Boolean) -> Unit = {}
|
||||||
|
|
||||||
fun showDeleteButton(delete: (Boolean) -> Unit, label: String) {
|
fun showDeleteButton(delete: (Boolean) -> Unit, label: String) {
|
||||||
|
@ -71,7 +80,7 @@ class DialogViewModel(val message: String, val title: String = "") : ViewModel()
|
||||||
}
|
}
|
||||||
|
|
||||||
var showOk: Boolean = false
|
var showOk: Boolean = false
|
||||||
var okLabel: String = "OK"
|
var okLabel: String = AppUtils.getString(R.string.dialog_ok)
|
||||||
private var onOk: (Boolean) -> Unit = {}
|
private var onOk: (Boolean) -> Unit = {}
|
||||||
|
|
||||||
fun showOkButton(ok: (Boolean) -> Unit, label: String = okLabel) {
|
fun showOkButton(ok: (Boolean) -> Unit, label: String = okLabel) {
|
||||||
|
|
|
@ -141,7 +141,7 @@
|
||||||
android:background="@drawable/resizable_assistant_button"
|
android:background="@drawable/resizable_assistant_button"
|
||||||
android:ellipsize="end"
|
android:ellipsize="end"
|
||||||
android:padding="10dp"
|
android:padding="10dp"
|
||||||
android:text="@string/dialog_cancel"
|
android:text="@{viewModel.cancelLabel ?? @string/dialog_cancel, default=@string/dialog_cancel}"
|
||||||
android:visibility="@{viewModel.showCancel ? View.VISIBLE : View.GONE}" />
|
android:visibility="@{viewModel.showCancel ? View.VISIBLE : View.GONE}" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
|
|
|
@ -217,6 +217,7 @@
|
||||||
<string name="call_error_network_unreachable">Network is unreachable</string>
|
<string name="call_error_network_unreachable">Network is unreachable</string>
|
||||||
<string name="call_error_io_error">Network error</string>
|
<string name="call_error_io_error">Network error</string>
|
||||||
<string name="call_error_unknown">Unknown error</string>
|
<string name="call_error_unknown">Unknown error</string>
|
||||||
|
<string name="call_video_update_requested_dialog">Correspondent would like to turn the video on</string>
|
||||||
|
|
||||||
<!-- Call stats -->
|
<!-- Call stats -->
|
||||||
<string name="call_stats_audio">Audio</string>
|
<string name="call_stats_audio">Audio</string>
|
||||||
|
@ -553,6 +554,8 @@
|
||||||
<string name="dialog_cancel">Cancel</string>
|
<string name="dialog_cancel">Cancel</string>
|
||||||
<string name="dialog_delete">Delete</string>
|
<string name="dialog_delete">Delete</string>
|
||||||
<string name="dialog_ok">OK</string>
|
<string name="dialog_ok">OK</string>
|
||||||
|
<string name="dialog_accept">Accept</string>
|
||||||
|
<string name="dialog_decline">Decline</string>
|
||||||
<string name="dialog_call">Call</string>
|
<string name="dialog_call">Call</string>
|
||||||
<string name="dialog_lime_security_message">Instant messages are end-to-end encrypted in secured conversations. It is possible to upgrade the security level of a conversation by authenticating participants. To do so, call the contact and follow the authentication process.</string>
|
<string name="dialog_lime_security_message">Instant messages are end-to-end encrypted in secured conversations. It is possible to upgrade the security level of a conversation by authenticating participants. To do so, call the contact and follow the authentication process.</string>
|
||||||
<string name="operation_in_progress_wait">Operation in progress, please wait</string>
|
<string name="operation_in_progress_wait">Operation in progress, please wait</string>
|
||||||
|
|
Loading…
Reference in a new issue