diff --git a/app/src/main/java/org/linphone/activities/main/history/fragments/DetailCallLogFragment.kt b/app/src/main/java/org/linphone/activities/main/history/fragments/DetailCallLogFragment.kt index f444e86e2..196468bad 100644 --- a/app/src/main/java/org/linphone/activities/main/history/fragments/DetailCallLogFragment.kt +++ b/app/src/main/java/org/linphone/activities/main/history/fragments/DetailCallLogFragment.kt @@ -69,7 +69,7 @@ class DetailCallLogFragment : GenericFragment() { useMaterialSharedAxisXForwardAnimation = sharedViewModel.isSlidingPaneSlideable.value == false - viewModel.relatedCallLogs.value = callLogGroup.callLogs + viewModel.addRelatedCallLogs(callLogGroup.callLogs) binding.setBackClickListener { goBack() diff --git a/app/src/main/java/org/linphone/activities/main/history/fragments/DetailConferenceCallLogFragment.kt b/app/src/main/java/org/linphone/activities/main/history/fragments/DetailConferenceCallLogFragment.kt index efcd9b5fe..fa62146a8 100644 --- a/app/src/main/java/org/linphone/activities/main/history/fragments/DetailConferenceCallLogFragment.kt +++ b/app/src/main/java/org/linphone/activities/main/history/fragments/DetailConferenceCallLogFragment.kt @@ -64,7 +64,7 @@ class DetailConferenceCallLogFragment : GenericFragment>() + val relatedCallLogs = MutableLiveData>() private val listener = object : CoreListenerStub() { override fun onCallLogUpdated(core: Core, log: CallLog) { if (callLog.remoteAddress.weakEqual(log.remoteAddress) && callLog.localAddress.weakEqual(log.localAddress)) { Log.i("[History Detail] New call log for ${callLog.remoteAddress.asStringUriOnly()} with local address ${callLog.localAddress.asStringUriOnly()}") - val list = arrayListOf() - list.add(callLog) - list.addAll(relatedCallLogs.value.orEmpty()) - relatedCallLogs.value = list + addRelatedCallLogs(arrayListOf(log)) } } } @@ -152,21 +149,28 @@ class CallLogViewModel(val callLog: CallLog) : GenericContactViewModel(callLog.r init { waitForChatRoomCreation.value = false - coreContext.core.addListener(listener) + if (!isRelated) { + coreContext.core.addListener(listener) - val conferenceInfo = callLog.conferenceInfo - if (conferenceInfo != null) { - conferenceTime.value = TimestampUtils.timeToString(conferenceInfo.dateTime) - conferenceDate.value = if (TimestampUtils.isToday(conferenceInfo.dateTime)) { - AppUtils.getString(R.string.today) - } else { - TimestampUtils.toString(conferenceInfo.dateTime, onlyDate = true, shortDate = false, hideYear = false) + val conferenceInfo = callLog.conferenceInfo + if (conferenceInfo != null) { + conferenceTime.value = TimestampUtils.timeToString(conferenceInfo.dateTime) + conferenceDate.value = if (TimestampUtils.isToday(conferenceInfo.dateTime)) { + AppUtils.getString(R.string.today) + } else { + TimestampUtils.toString( + conferenceInfo.dateTime, + onlyDate = true, + shortDate = false, + hideYear = false + ) + } + val list = arrayListOf() + for (participant in conferenceInfo.participants) { + list.add(ConferenceSchedulingParticipantData(participant, false)) + } + conferenceParticipantsData.value = list } - val list = arrayListOf() - for (participant in conferenceInfo.participants) { - list.add(ConferenceSchedulingParticipantData(participant, false)) - } - conferenceParticipantsData.value = list } } @@ -176,8 +180,13 @@ class CallLogViewModel(val callLog: CallLog) : GenericContactViewModel(callLog.r } fun destroy() { - coreContext.core.removeListener(listener) - conferenceParticipantsData.value.orEmpty().forEach(ConferenceSchedulingParticipantData::destroy) + if (!isRelated) { + coreContext.core.removeListener(listener) + + relatedCallLogs.value.orEmpty().forEach(CallLogViewModel::destroy) + conferenceParticipantsData.value.orEmpty() + .forEach(ConferenceSchedulingParticipantData::destroy) + } } fun startCall() { @@ -200,4 +209,16 @@ class CallLogViewModel(val callLog: CallLog) : GenericContactViewModel(callLog.r onMessageToNotifyEvent.value = Event(R.string.chat_room_creation_failed_snack) } } + + fun addRelatedCallLogs(callLogs: ArrayList) { + val list = arrayListOf() + + // We assume new logs are more recent than the ones we already have, so we add them first + for (callLog in callLogs) { + list.add(CallLogViewModel(callLog, true)) + } + list.addAll(relatedCallLogs.value.orEmpty()) + + relatedCallLogs.value = list + } }