From 3a50ab3b914df0513b84c988246c6b7f8b211939 Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Sun, 13 Aug 2023 20:13:22 +0200 Subject: [PATCH] Added call history in call log details --- .../main/calls/model/CallLogHistoryModel.kt | 34 ++++++++ .../main/calls/viewmodel/CallLogViewModel.kt | 37 +++++++-- .../java/org/linphone/utils/TimestampUtils.kt | 10 +++ app/src/main/res/layout/call_fragment.xml | 16 +++- .../res/layout/call_history_list_cell.xml | 83 +++++++++++++++++++ 5 files changed, 174 insertions(+), 6 deletions(-) create mode 100644 app/src/main/java/org/linphone/ui/main/calls/model/CallLogHistoryModel.kt create mode 100644 app/src/main/res/layout/call_history_list_cell.xml diff --git a/app/src/main/java/org/linphone/ui/main/calls/model/CallLogHistoryModel.kt b/app/src/main/java/org/linphone/ui/main/calls/model/CallLogHistoryModel.kt new file mode 100644 index 000000000..b376019aa --- /dev/null +++ b/app/src/main/java/org/linphone/ui/main/calls/model/CallLogHistoryModel.kt @@ -0,0 +1,34 @@ +package org.linphone.ui.main.calls.model + +import androidx.lifecycle.MutableLiveData +import org.linphone.core.Call.Dir +import org.linphone.core.CallLog +import org.linphone.utils.TimestampUtils + +class CallLogHistoryModel(callLog: CallLog) { + val isOutgoing = MutableLiveData() + + val dateTime = MutableLiveData() + + val duration = MutableLiveData() + + init { + // Core thread + isOutgoing.postValue(callLog.dir == Dir.Outgoing) + + val startDate = callLog.startDate + val date = if (TimestampUtils.isToday(startDate)) { + "Aujourd'hui" + } else if (TimestampUtils.isYesterday(startDate)) { + "Hier" + } else { + TimestampUtils.dateToString(callLog.startDate) + } + val time = TimestampUtils.timeToString(startDate) + dateTime.postValue("$date | $time") + + duration.postValue( + TimestampUtils.durationToString(callLog.duration) + ) + } +} diff --git a/app/src/main/java/org/linphone/ui/main/calls/viewmodel/CallLogViewModel.kt b/app/src/main/java/org/linphone/ui/main/calls/viewmodel/CallLogViewModel.kt index 66b8f0a2f..c9a22512e 100644 --- a/app/src/main/java/org/linphone/ui/main/calls/viewmodel/CallLogViewModel.kt +++ b/app/src/main/java/org/linphone/ui/main/calls/viewmodel/CallLogViewModel.kt @@ -3,33 +3,60 @@ package org.linphone.ui.main.calls.viewmodel import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import org.linphone.LinphoneApplication.Companion.coreContext +import org.linphone.core.Address +import org.linphone.core.Call +import org.linphone.ui.main.calls.model.CallLogHistoryModel import org.linphone.ui.main.calls.model.CallLogModel import org.linphone.utils.Event class CallLogViewModel : ViewModel() { - val callLogModel = MutableLiveData() - val showBackButton = MutableLiveData() + val callLogModel = MutableLiveData() + + val historyCallLogs = MutableLiveData>() + val callLogFoundEvent = MutableLiveData>() + private lateinit var address: Address + fun findCallLogByCallId(callId: String) { // UI thread coreContext.postOnCoreThread { core -> val callLog = core.findCallLogFromCallId(callId) if (callLog != null) { - callLogModel.postValue(CallLogModel(callLog)) + val model = CallLogModel(callLog) + callLogModel.postValue(model) + + val localAddress = if (callLog.dir == Call.Dir.Outgoing) callLog.fromAddress else callLog.toAddress + val peerAddress = if (callLog.dir == Call.Dir.Outgoing) callLog.toAddress else callLog.fromAddress + val history = arrayListOf() + for (log in core.getCallHistory(peerAddress, localAddress)) { + val historyModel = CallLogHistoryModel(log) + history.add(historyModel) + } + historyCallLogs.postValue(history) + + address = model.address callLogFoundEvent.postValue(Event(true)) } } } fun startAudioCall() { - // TODO + coreContext.postOnCoreThread { core -> + val params = core.createCallParams(null) + params?.isVideoEnabled = false + coreContext.startCall(address, params) + } } fun startVideoCall() { - // TODO + coreContext.postOnCoreThread { core -> + val params = core.createCallParams(null) + params?.isVideoEnabled = true + coreContext.startCall(address, params) + } } fun sendMessage() { diff --git a/app/src/main/java/org/linphone/utils/TimestampUtils.kt b/app/src/main/java/org/linphone/utils/TimestampUtils.kt index baf0e7262..89214ee3e 100644 --- a/app/src/main/java/org/linphone/utils/TimestampUtils.kt +++ b/app/src/main/java/org/linphone/utils/TimestampUtils.kt @@ -100,6 +100,16 @@ class TimestampUtils { } } + fun durationToString(duration: Int): String { + val dateFormat = SimpleDateFormat( + if (duration >= 3600) "HH:mm:ss" else "mm:ss", + Locale.getDefault() + ) + val cal = Calendar.getInstance() + cal[0, 0, 0, 0, 0] = duration + return dateFormat.format(cal.time) + } + fun durationToString(hours: Int, minutes: Int): String { val calendar = Calendar.getInstance() calendar.set(Calendar.HOUR_OF_DAY, hours) diff --git a/app/src/main/res/layout/call_fragment.xml b/app/src/main/res/layout/call_fragment.xml index 94a6d534e..4e67b9aff 100644 --- a/app/src/main/res/layout/call_fragment.xml +++ b/app/src/main/res/layout/call_fragment.xml @@ -193,7 +193,21 @@ app:layout_constraintStart_toStartOf="@id/video_call" app:layout_constraintEnd_toEndOf="@id/video_call"/> - + diff --git a/app/src/main/res/layout/call_history_list_cell.xml b/app/src/main/res/layout/call_history_list_cell.xml new file mode 100644 index 000000000..87d495152 --- /dev/null +++ b/app/src/main/res/layout/call_history_list_cell.xml @@ -0,0 +1,83 @@ + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file