Commit 4e2b57ee authored by Christophe Deschamps's avatar Christophe Deschamps
Browse files

Refacto


Former-commit-id: 3a9421210ffe871198e9ead7d727a294dda1c4ae
parent a20690f4
package org.lindoor.ui.history
import androidx.lifecycle.MutableLiveData
import org.lindoor.customisation.Texts
import org.lindoor.entities.Device
import org.lindoor.entities.HistoryEvent
import org.lindoor.linphonecore.extensions.isNew
import org.lindoor.store.DeviceStore
import org.lindoor.store.HistoryEventStore
import org.lindoor.utils.DateUtil
import org.lindoor.utils.databindings.ViewModelWithTools
import org.linphone.core.Call
import org.linphone.core.CallLog
import java.text.SimpleDateFormat
import java.util.*
class HistoryEventViewModel(
val callLog: CallLog,
val showDate: Boolean,
val historyViewModel: HistoryViewModel,
val device: Device? = DeviceStore.findDeviceByAddress(callLog.remoteAddress)
) : ViewModelWithTools() {
val viewMedia = MutableLiveData(false)
var historyEvent: HistoryEvent? = callLog.callId?.let {
HistoryEventStore.findHistoryEventByCallId(it)
}
companion object {
val historyTimePattern = "HH:mm:ss"
}
override fun onCleared() {
historyEvent?.viewedByUser = true
historyEvent?.let { HistoryEventStore.persistHistoryEvent(it) }
super.onCleared()
}
fun callTypeIcon(): String {
return when (callLog.status) {
Call.Status.Missed -> "icons/missed"
Call.Status.Declined, Call.Status.DeclinedElsewhere -> "icons/declined"
Call.Status.Aborted, Call.Status.EarlyAborted -> "icons/declined"
Call.Status.Success, Call.Status.AcceptedElsewhere -> {
if (callLog.dir == Call.Dir.Incoming)
"icons/accepted"
else
"icons/called"
}
}
}
fun callTypeAndDate(): String {
val simpleDateFormat = SimpleDateFormat(historyTimePattern, Locale.getDefault())
val callTime = simpleDateFormat.format(Date(callLog.startDate * 1000))
val typeText = when (callLog.status) {
Call.Status.Missed -> "history_list_call_type_missed"
Call.Status.Declined, Call.Status.DeclinedElsewhere -> "history_list_call_type_declined"
Call.Status.Aborted, Call.Status.EarlyAborted -> "history_list_call_type_aborted"
Call.Status.Success, Call.Status.AcceptedElsewhere -> {
if (callLog.dir == Call.Dir.Incoming)
"history_list_call_type_accepted"
else
"history_list_call_type_called"
}
}
return Texts.get(
"history_list_call_date_type",
Texts.get(typeText),
callTime
)
}
fun dayText(): String {
return DateUtil.todayYesterdayRealDay(callLog.startDate / 86400)
}
fun toggleSelect() {
if (historyViewModel.selectedForDeletion.value!!.contains(callLog.callId))
historyViewModel.selectedForDeletion.value!!.remove(callLog.callId)
else
historyViewModel.selectedForDeletion.value!!.add(callLog.callId)
historyViewModel.notifyDeleteSelectionListUpdated()
}
fun viewMedia() {
viewMedia.value = true
}
fun isNew(): Boolean {
return callLog.isNew()
}
}
\ No newline at end of file
......@@ -10,9 +10,7 @@ import org.lindoor.BR
import org.lindoor.GenericFragment
import org.lindoor.R
import org.lindoor.databinding.ItemHistoryBinding
import org.lindoor.linphonecore.extensions.historyEvent
import org.lindoor.ui.player.PlayerActivity
import org.lindoor.utils.DialogUtil
import org.linphone.core.CallLog
class HistoryEventsAdapter(
......@@ -47,7 +45,7 @@ class HistoryEventsAdapter(
historyViewModel: HistoryViewModel,
lindoorFragment: GenericFragment
) {
val entryViewModel = HistoryEventsViewModel(callLog, showDate, historyViewModel)
val entryViewModel = HistoryEventViewModel(callLog, showDate, historyViewModel)
binding.lifecycleOwner = lindoorFragment
binding.setVariable(BR.model, entryViewModel)
binding.setVariable(BR.historymodel, historyViewModel)
......
......@@ -4,7 +4,7 @@
<data>
<import type="android.view.View"/>
<variable name="model" type="org.lindoor.ui.history.HistoryEventsViewModel" />
<variable name="model" type="org.lindoor.ui.history.HistoryEventViewModel" />
<variable name="historymodel" type="org.lindoor.ui.history.HistoryViewModel" />
</data>
......
......@@ -4,7 +4,7 @@
<data>
<import type="android.view.View"/>
<variable name="model" type="org.lindoor.ui.history.HistoryEventsViewModel" />
<variable name="model" type="org.lindoor.ui.history.HistoryEventViewModel" />
<variable name="historymodel" type="org.lindoor.ui.history.HistoryViewModel" />
</data>
......
......@@ -4,7 +4,7 @@
<data>
<import type="android.view.View"/>
<variable name="model" type="org.lindoor.ui.history.HistoryEventsViewModel" />
<variable name="model" type="org.lindoor.ui.history.HistoryEventViewModel" />
<variable name="historymodel" type="org.lindoor.ui.history.HistoryViewModel" />
</data>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment