Improved call statistics: only compute them when dialog is visible + fixed leak
This commit is contained in:
parent
c93ea7a851
commit
4c616cc395
3 changed files with 52 additions and 11 deletions
|
@ -38,6 +38,7 @@ import org.linphone.activities.navigateToActiveCall
|
|||
import org.linphone.activities.voip.viewmodels.CallsViewModel
|
||||
import org.linphone.activities.voip.viewmodels.ConferenceViewModel
|
||||
import org.linphone.activities.voip.viewmodels.ControlsViewModel
|
||||
import org.linphone.activities.voip.viewmodels.StatisticsListViewModel
|
||||
import org.linphone.compatibility.Compatibility
|
||||
import org.linphone.core.Call
|
||||
import org.linphone.core.tools.Log
|
||||
|
@ -50,6 +51,7 @@ class CallActivity : ProximitySensorActivity() {
|
|||
private lateinit var controlsViewModel: ControlsViewModel
|
||||
private lateinit var callsViewModel: CallsViewModel
|
||||
private lateinit var conferenceViewModel: ConferenceViewModel
|
||||
private lateinit var statsViewModel: StatisticsListViewModel
|
||||
|
||||
private var foldingFeature: FoldingFeature? = null
|
||||
|
||||
|
@ -79,6 +81,8 @@ class CallActivity : ProximitySensorActivity() {
|
|||
|
||||
conferenceViewModel = ViewModelProvider(navControllerStoreOwner)[ConferenceViewModel::class.java]
|
||||
|
||||
statsViewModel = ViewModelProvider(navControllerStoreOwner)[StatisticsListViewModel::class.java]
|
||||
|
||||
callsViewModel.noMoreCallEvent.observe(
|
||||
this
|
||||
) {
|
||||
|
@ -114,6 +118,12 @@ class CallActivity : ProximitySensorActivity() {
|
|||
Compatibility.enableAutoEnterPiP(this, enabled)
|
||||
}
|
||||
|
||||
controlsViewModel.callStatsVisible.observe(
|
||||
this
|
||||
) { visible ->
|
||||
if (visible) statsViewModel.enable() else statsViewModel.disable()
|
||||
}
|
||||
|
||||
callsViewModel.currentCallData.observe(
|
||||
this
|
||||
) { callData ->
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
package org.linphone.activities.voip.data
|
||||
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import org.linphone.LinphoneApplication.Companion.coreContext
|
||||
import org.linphone.contact.GenericContactData
|
||||
import org.linphone.core.*
|
||||
|
||||
|
@ -31,18 +30,17 @@ class CallStatisticsData(val call: Call) : GenericContactData(call.remoteAddress
|
|||
|
||||
val isVideoEnabled = MutableLiveData<Boolean>()
|
||||
|
||||
private val listener = object : CoreListenerStub() {
|
||||
override fun onCallStatsUpdated(core: Core, call: Call, stats: CallStats) {
|
||||
if (call == this@CallStatisticsData.call) {
|
||||
isVideoEnabled.value = call.currentParams.isVideoEnabled
|
||||
updateCallStats(stats)
|
||||
}
|
||||
private var enabled = false
|
||||
|
||||
private val listener = object : CallListenerStub() {
|
||||
override fun onStatsUpdated(call: Call, stats: CallStats) {
|
||||
isVideoEnabled.value = call.currentParams.isVideoEnabled
|
||||
updateCallStats(stats)
|
||||
}
|
||||
}
|
||||
|
||||
init {
|
||||
coreContext.core.addListener(listener)
|
||||
|
||||
enabled = false
|
||||
audioStats.value = arrayListOf()
|
||||
videoStats.value = arrayListOf()
|
||||
|
||||
|
@ -52,8 +50,18 @@ class CallStatisticsData(val call: Call) : GenericContactData(call.remoteAddress
|
|||
isVideoEnabled.value = videoEnabled
|
||||
}
|
||||
|
||||
fun enable() {
|
||||
enabled = true
|
||||
call.addListener(listener)
|
||||
}
|
||||
|
||||
fun disable() {
|
||||
enabled = false
|
||||
call.removeListener(listener)
|
||||
}
|
||||
|
||||
override fun destroy() {
|
||||
coreContext.core.removeListener(listener)
|
||||
if (enabled) disable()
|
||||
super.destroy()
|
||||
}
|
||||
|
||||
|
|
|
@ -30,6 +30,8 @@ import org.linphone.core.CoreListenerStub
|
|||
class StatisticsListViewModel : ViewModel() {
|
||||
val callStatsList = MutableLiveData<ArrayList<CallStatisticsData>>()
|
||||
|
||||
private var enabled = false
|
||||
|
||||
private val listener = object : CoreListenerStub() {
|
||||
override fun onCallStateChanged(
|
||||
core: Core,
|
||||
|
@ -49,6 +51,20 @@ class StatisticsListViewModel : ViewModel() {
|
|||
computeCallsList()
|
||||
}
|
||||
|
||||
fun enable() {
|
||||
enabled = true
|
||||
for (stat in callStatsList.value.orEmpty()) {
|
||||
stat.enable()
|
||||
}
|
||||
}
|
||||
|
||||
fun disable() {
|
||||
enabled = false
|
||||
for (stat in callStatsList.value.orEmpty()) {
|
||||
stat.disable()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCleared() {
|
||||
callStatsList.value.orEmpty().forEach(CallStatisticsData::destroy)
|
||||
coreContext.core.removeListener(listener)
|
||||
|
@ -57,12 +73,19 @@ class StatisticsListViewModel : ViewModel() {
|
|||
}
|
||||
|
||||
private fun computeCallsList() {
|
||||
callStatsList.value.orEmpty().forEach(CallStatisticsData::destroy)
|
||||
|
||||
val list = arrayListOf<CallStatisticsData>()
|
||||
for (call in coreContext.core.calls) {
|
||||
if (call.state != Call.State.End && call.state != Call.State.Released && call.state != Call.State.Error) {
|
||||
list.add(CallStatisticsData(call))
|
||||
val data = CallStatisticsData(call)
|
||||
list.add(data)
|
||||
if (enabled) {
|
||||
data.enable()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
callStatsList.value = list
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue