mirror of
https://gitlab.linphone.org/BC/public/linphone-android.git
synced 2026-05-07 05:53:07 +00:00
Added call history in call log details
This commit is contained in:
parent
0a83695c45
commit
3a50ab3b91
5 changed files with 174 additions and 6 deletions
|
|
@ -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<Boolean>()
|
||||
|
||||
val dateTime = MutableLiveData<String>()
|
||||
|
||||
val duration = MutableLiveData<String>()
|
||||
|
||||
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)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -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<CallLogModel>()
|
||||
|
||||
val showBackButton = MutableLiveData<Boolean>()
|
||||
|
||||
val callLogModel = MutableLiveData<CallLogModel>()
|
||||
|
||||
val historyCallLogs = MutableLiveData<ArrayList<CallLogHistoryModel>>()
|
||||
|
||||
val callLogFoundEvent = MutableLiveData<Event<Boolean>>()
|
||||
|
||||
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<CallLogHistoryModel>()
|
||||
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() {
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -193,7 +193,21 @@
|
|||
app:layout_constraintStart_toStartOf="@id/video_call"
|
||||
app:layout_constraintEnd_toEndOf="@id/video_call"/>
|
||||
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/call_history"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="45dp"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:background="@drawable/shape_round_white_background"
|
||||
android:orientation="vertical"
|
||||
entries="@{viewModel.historyCallLogs}"
|
||||
layout="@{@layout/call_history_list_cell}"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/call_label"
|
||||
app:layout_constraintBottom_toBottomOf="parent" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
|
|
|
|||
83
app/src/main/res/layout/call_history_list_cell.xml
Normal file
83
app/src/main/res/layout/call_history_list_cell.xml
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<data>
|
||||
<import type="android.view.View" />
|
||||
<import type="android.graphics.Typeface" />
|
||||
<variable
|
||||
name="model"
|
||||
type="org.linphone.ui.main.calls.model.CallLogHistoryModel" />
|
||||
</data>
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="16dp"
|
||||
android:layout_marginStart="17dp"
|
||||
android:layout_marginEnd="17dp">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/call_status"
|
||||
android:layout_width="16dp"
|
||||
android:layout_height="16dp"
|
||||
android:layout_marginTop="20dp"
|
||||
android:layout_marginStart="2dp"
|
||||
android:src="@{model.isOutgoing() ? @drawable/outgoing_call : @drawable/incoming_call, default=@drawable/outgoing_call}"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView
|
||||
style="@style/default_text_style"
|
||||
android:id="@+id/direction_label"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
android:text="@{model.isOutgoing() ? `Appel sortant` : `Appel entrant`, default=`Appel sortant`}"
|
||||
android:textSize="14sp"
|
||||
android:textColor="@color/gray_8"
|
||||
app:layout_constraintStart_toEndOf="@id/call_status"
|
||||
app:layout_constraintTop_toTopOf="@id/call_status"
|
||||
app:layout_constraintBottom_toBottomOf="@id/call_status"/>
|
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView
|
||||
style="@style/default_text_style_300"
|
||||
android:id="@+id/date_time"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="16dp"
|
||||
android:layout_marginStart="5dp"
|
||||
android:gravity="center"
|
||||
android:text="@{model.dateTime, default=`13 aout 2023 | 19:47`}"
|
||||
android:textSize="12sp"
|
||||
app:layout_constraintStart_toEndOf="@id/call_status"
|
||||
app:layout_constraintTop_toBottomOf="@id/direction_label"
|
||||
app:layout_constraintBottom_toTopOf="@id/separator"/>
|
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView
|
||||
style="@style/default_text_style_300"
|
||||
android:id="@+id/duration"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="12dp"
|
||||
android:gravity="center"
|
||||
android:text="@{model.duration, default=`1min 34s`}"
|
||||
android:textSize="12sp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="@id/direction_label"
|
||||
app:layout_constraintBottom_toBottomOf="@id/date_time"/>
|
||||
|
||||
<View
|
||||
android:id="@+id/separator"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="1dp"
|
||||
android:layout_marginEnd="10dp"
|
||||
android:background="@color/blue_outgoing_message"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"/>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
</layout>
|
||||
Loading…
Add table
Reference in a new issue