Fixed merge issue causing call history detail to crash

This commit is contained in:
Sylvain Berfini 2022-02-14 11:37:39 +01:00
parent 562077606d
commit bd222124ef
3 changed files with 44 additions and 23 deletions

View file

@ -69,7 +69,7 @@ class DetailCallLogFragment : GenericFragment<HistoryDetailFragmentBinding>() {
useMaterialSharedAxisXForwardAnimation = sharedViewModel.isSlidingPaneSlideable.value == false useMaterialSharedAxisXForwardAnimation = sharedViewModel.isSlidingPaneSlideable.value == false
viewModel.relatedCallLogs.value = callLogGroup.callLogs viewModel.addRelatedCallLogs(callLogGroup.callLogs)
binding.setBackClickListener { binding.setBackClickListener {
goBack() goBack()

View file

@ -64,7 +64,7 @@ class DetailConferenceCallLogFragment : GenericFragment<HistoryConfDetailFragmen
useMaterialSharedAxisXForwardAnimation = sharedViewModel.isSlidingPaneSlideable.value == false useMaterialSharedAxisXForwardAnimation = sharedViewModel.isSlidingPaneSlideable.value == false
viewModel.relatedCallLogs.value = callLogGroup.callLogs viewModel.addRelatedCallLogs(callLogGroup.callLogs)
binding.setBackClickListener { binding.setBackClickListener {
goBack() goBack()

View file

@ -46,7 +46,7 @@ class CallLogViewModelFactory(private val callLog: CallLog) :
} }
} }
class CallLogViewModel(val callLog: CallLog) : GenericContactViewModel(callLog.remoteAddress) { class CallLogViewModel(val callLog: CallLog, private val isRelated: Boolean = false) : GenericContactViewModel(callLog.remoteAddress) {
val peerSipUri: String by lazy { val peerSipUri: String by lazy {
LinphoneUtils.getDisplayableAddress(callLog.remoteAddress) LinphoneUtils.getDisplayableAddress(callLog.remoteAddress)
} }
@ -112,16 +112,13 @@ class CallLogViewModel(val callLog: CallLog) : GenericContactViewModel(callLog.r
val secureChatAllowed = contact.value?.friend?.getPresenceModelForUriOrTel(peerSipUri)?.hasCapability(FriendCapability.LimeX3Dh) ?: false val secureChatAllowed = contact.value?.friend?.getPresenceModelForUriOrTel(peerSipUri)?.hasCapability(FriendCapability.LimeX3Dh) ?: false
val relatedCallLogs = MutableLiveData<ArrayList<CallLog>>() val relatedCallLogs = MutableLiveData<ArrayList<CallLogViewModel>>()
private val listener = object : CoreListenerStub() { private val listener = object : CoreListenerStub() {
override fun onCallLogUpdated(core: Core, log: CallLog) { override fun onCallLogUpdated(core: Core, log: CallLog) {
if (callLog.remoteAddress.weakEqual(log.remoteAddress) && callLog.localAddress.weakEqual(log.localAddress)) { 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()}") Log.i("[History Detail] New call log for ${callLog.remoteAddress.asStringUriOnly()} with local address ${callLog.localAddress.asStringUriOnly()}")
val list = arrayListOf<CallLog>() addRelatedCallLogs(arrayListOf(log))
list.add(callLog)
list.addAll(relatedCallLogs.value.orEmpty())
relatedCallLogs.value = list
} }
} }
} }
@ -152,6 +149,7 @@ class CallLogViewModel(val callLog: CallLog) : GenericContactViewModel(callLog.r
init { init {
waitForChatRoomCreation.value = false waitForChatRoomCreation.value = false
if (!isRelated) {
coreContext.core.addListener(listener) coreContext.core.addListener(listener)
val conferenceInfo = callLog.conferenceInfo val conferenceInfo = callLog.conferenceInfo
@ -160,7 +158,12 @@ class CallLogViewModel(val callLog: CallLog) : GenericContactViewModel(callLog.r
conferenceDate.value = if (TimestampUtils.isToday(conferenceInfo.dateTime)) { conferenceDate.value = if (TimestampUtils.isToday(conferenceInfo.dateTime)) {
AppUtils.getString(R.string.today) AppUtils.getString(R.string.today)
} else { } else {
TimestampUtils.toString(conferenceInfo.dateTime, onlyDate = true, shortDate = false, hideYear = false) TimestampUtils.toString(
conferenceInfo.dateTime,
onlyDate = true,
shortDate = false,
hideYear = false
)
} }
val list = arrayListOf<ConferenceSchedulingParticipantData>() val list = arrayListOf<ConferenceSchedulingParticipantData>()
for (participant in conferenceInfo.participants) { for (participant in conferenceInfo.participants) {
@ -169,6 +172,7 @@ class CallLogViewModel(val callLog: CallLog) : GenericContactViewModel(callLog.r
conferenceParticipantsData.value = list conferenceParticipantsData.value = list
} }
} }
}
override fun onCleared() { override fun onCleared() {
destroy() destroy()
@ -176,8 +180,13 @@ class CallLogViewModel(val callLog: CallLog) : GenericContactViewModel(callLog.r
} }
fun destroy() { fun destroy() {
if (!isRelated) {
coreContext.core.removeListener(listener) coreContext.core.removeListener(listener)
conferenceParticipantsData.value.orEmpty().forEach(ConferenceSchedulingParticipantData::destroy)
relatedCallLogs.value.orEmpty().forEach(CallLogViewModel::destroy)
conferenceParticipantsData.value.orEmpty()
.forEach(ConferenceSchedulingParticipantData::destroy)
}
} }
fun startCall() { fun startCall() {
@ -200,4 +209,16 @@ class CallLogViewModel(val callLog: CallLog) : GenericContactViewModel(callLog.r
onMessageToNotifyEvent.value = Event(R.string.chat_room_creation_failed_snack) onMessageToNotifyEvent.value = Event(R.string.chat_room_creation_failed_snack)
} }
} }
fun addRelatedCallLogs(callLogs: ArrayList<CallLog>) {
val list = arrayListOf<CallLogViewModel>()
// 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
}
} }