Reworked how call logs are handled, should be more efficient
This commit is contained in:
parent
70f7f8c100
commit
c6b49080af
6 changed files with 37 additions and 68 deletions
|
@ -28,7 +28,6 @@ import org.linphone.R
|
||||||
import org.linphone.activities.*
|
import org.linphone.activities.*
|
||||||
import org.linphone.activities.main.*
|
import org.linphone.activities.main.*
|
||||||
import org.linphone.activities.main.history.viewmodels.CallLogViewModel
|
import org.linphone.activities.main.history.viewmodels.CallLogViewModel
|
||||||
import org.linphone.activities.main.history.viewmodels.CallLogViewModelFactory
|
|
||||||
import org.linphone.activities.main.viewmodels.SharedMainViewModel
|
import org.linphone.activities.main.viewmodels.SharedMainViewModel
|
||||||
import org.linphone.activities.navigateToContact
|
import org.linphone.activities.navigateToContact
|
||||||
import org.linphone.activities.navigateToContacts
|
import org.linphone.activities.navigateToContacts
|
||||||
|
@ -61,16 +60,12 @@ class DetailCallLogFragment : GenericFragment<HistoryDetailFragmentBinding>() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
viewModel = ViewModelProvider(
|
viewModel = callLogGroup.lastCallLogViewModel
|
||||||
this,
|
|
||||||
CallLogViewModelFactory(callLogGroup.lastCallLog)
|
|
||||||
)[CallLogViewModel::class.java]
|
|
||||||
binding.viewModel = viewModel
|
binding.viewModel = viewModel
|
||||||
|
viewModel.addRelatedCallLogs(callLogGroup.callLogs)
|
||||||
|
|
||||||
useMaterialSharedAxisXForwardAnimation = sharedViewModel.isSlidingPaneSlideable.value == false
|
useMaterialSharedAxisXForwardAnimation = sharedViewModel.isSlidingPaneSlideable.value == false
|
||||||
|
|
||||||
viewModel.addRelatedCallLogs(callLogGroup.callLogs)
|
|
||||||
|
|
||||||
binding.setBackClickListener {
|
binding.setBackClickListener {
|
||||||
goBack()
|
goBack()
|
||||||
}
|
}
|
||||||
|
@ -149,4 +144,14 @@ class DetailCallLogFragment : GenericFragment<HistoryDetailFragmentBinding>() {
|
||||||
navigateToEmptyCallHistory()
|
navigateToEmptyCallHistory()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onResume() {
|
||||||
|
super.onResume()
|
||||||
|
viewModel.enableListener(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onPause() {
|
||||||
|
viewModel.enableListener(false)
|
||||||
|
super.onPause()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,6 @@ import org.linphone.R
|
||||||
import org.linphone.activities.*
|
import org.linphone.activities.*
|
||||||
import org.linphone.activities.main.*
|
import org.linphone.activities.main.*
|
||||||
import org.linphone.activities.main.history.viewmodels.CallLogViewModel
|
import org.linphone.activities.main.history.viewmodels.CallLogViewModel
|
||||||
import org.linphone.activities.main.history.viewmodels.CallLogViewModelFactory
|
|
||||||
import org.linphone.activities.main.viewmodels.SharedMainViewModel
|
import org.linphone.activities.main.viewmodels.SharedMainViewModel
|
||||||
import org.linphone.core.tools.Log
|
import org.linphone.core.tools.Log
|
||||||
import org.linphone.databinding.HistoryConfDetailFragmentBinding
|
import org.linphone.databinding.HistoryConfDetailFragmentBinding
|
||||||
|
@ -56,16 +55,12 @@ class DetailConferenceCallLogFragment : GenericFragment<HistoryConfDetailFragmen
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
viewModel = ViewModelProvider(
|
viewModel = callLogGroup.lastCallLogViewModel
|
||||||
this,
|
|
||||||
CallLogViewModelFactory(callLogGroup.lastCallLog)
|
|
||||||
)[CallLogViewModel::class.java]
|
|
||||||
binding.viewModel = viewModel
|
binding.viewModel = viewModel
|
||||||
|
viewModel.addRelatedCallLogs(callLogGroup.callLogs)
|
||||||
|
|
||||||
useMaterialSharedAxisXForwardAnimation = sharedViewModel.isSlidingPaneSlideable.value == false
|
useMaterialSharedAxisXForwardAnimation = sharedViewModel.isSlidingPaneSlideable.value == false
|
||||||
|
|
||||||
viewModel.addRelatedCallLogs(callLogGroup.callLogs)
|
|
||||||
|
|
||||||
binding.setBackClickListener {
|
binding.setBackClickListener {
|
||||||
goBack()
|
goBack()
|
||||||
}
|
}
|
||||||
|
|
|
@ -192,7 +192,7 @@ class MasterCallLogsFragment : MasterFragment<HistoryMasterFragmentBinding, Call
|
||||||
val headerItemDecoration = RecyclerViewHeaderDecoration(requireContext(), adapter)
|
val headerItemDecoration = RecyclerViewHeaderDecoration(requireContext(), adapter)
|
||||||
binding.callLogsList.addItemDecoration(headerItemDecoration)
|
binding.callLogsList.addItemDecoration(headerItemDecoration)
|
||||||
|
|
||||||
listViewModel.displayedCallLogs.observe(
|
listViewModel.callLogs.observe(
|
||||||
viewLifecycleOwner
|
viewLifecycleOwner
|
||||||
) { callLogs ->
|
) { callLogs ->
|
||||||
adapter.submitList(callLogs)
|
adapter.submitList(callLogs)
|
||||||
|
|
|
@ -20,8 +20,6 @@
|
||||||
package org.linphone.activities.main.history.viewmodels
|
package org.linphone.activities.main.history.viewmodels
|
||||||
|
|
||||||
import androidx.lifecycle.MutableLiveData
|
import androidx.lifecycle.MutableLiveData
|
||||||
import androidx.lifecycle.ViewModel
|
|
||||||
import androidx.lifecycle.ViewModelProvider
|
|
||||||
import java.text.SimpleDateFormat
|
import java.text.SimpleDateFormat
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import kotlin.collections.ArrayList
|
import kotlin.collections.ArrayList
|
||||||
|
@ -37,15 +35,6 @@ import org.linphone.utils.Event
|
||||||
import org.linphone.utils.LinphoneUtils
|
import org.linphone.utils.LinphoneUtils
|
||||||
import org.linphone.utils.TimestampUtils
|
import org.linphone.utils.TimestampUtils
|
||||||
|
|
||||||
class CallLogViewModelFactory(private val callLog: CallLog) :
|
|
||||||
ViewModelProvider.NewInstanceFactory() {
|
|
||||||
|
|
||||||
@Suppress("UNCHECKED_CAST")
|
|
||||||
override fun <T : ViewModel> create(modelClass: Class<T>): T {
|
|
||||||
return CallLogViewModel(callLog) as T
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class CallLogViewModel(val callLog: CallLog, private val isRelated: Boolean = false) : 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)
|
||||||
|
@ -150,8 +139,6 @@ class CallLogViewModel(val callLog: CallLog, private val isRelated: Boolean = fa
|
||||||
waitForChatRoomCreation.value = false
|
waitForChatRoomCreation.value = false
|
||||||
|
|
||||||
if (!isRelated) {
|
if (!isRelated) {
|
||||||
coreContext.core.addListener(listener)
|
|
||||||
|
|
||||||
val conferenceInfo = callLog.conferenceInfo
|
val conferenceInfo = callLog.conferenceInfo
|
||||||
if (conferenceInfo != null) {
|
if (conferenceInfo != null) {
|
||||||
conferenceTime.value = TimestampUtils.timeToString(conferenceInfo.dateTime)
|
conferenceTime.value = TimestampUtils.timeToString(conferenceInfo.dateTime)
|
||||||
|
@ -181,8 +168,6 @@ class CallLogViewModel(val callLog: CallLog, private val isRelated: Boolean = fa
|
||||||
|
|
||||||
fun destroy() {
|
fun destroy() {
|
||||||
if (!isRelated) {
|
if (!isRelated) {
|
||||||
coreContext.core.removeListener(listener)
|
|
||||||
|
|
||||||
relatedCallLogs.value.orEmpty().forEach(CallLogViewModel::destroy)
|
relatedCallLogs.value.orEmpty().forEach(CallLogViewModel::destroy)
|
||||||
conferenceParticipantsData.value.orEmpty()
|
conferenceParticipantsData.value.orEmpty()
|
||||||
.forEach(ConferenceSchedulingParticipantData::destroy)
|
.forEach(ConferenceSchedulingParticipantData::destroy)
|
||||||
|
@ -221,4 +206,12 @@ class CallLogViewModel(val callLog: CallLog, private val isRelated: Boolean = fa
|
||||||
|
|
||||||
relatedCallLogs.value = list
|
relatedCallLogs.value = list
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun enableListener(enable: Boolean) {
|
||||||
|
if (enable) {
|
||||||
|
coreContext.core.addListener(listener)
|
||||||
|
} else {
|
||||||
|
coreContext.core.removeListener(listener)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@ import org.linphone.utils.LinphoneUtils
|
||||||
import org.linphone.utils.TimestampUtils
|
import org.linphone.utils.TimestampUtils
|
||||||
|
|
||||||
class CallLogsListViewModel : ViewModel() {
|
class CallLogsListViewModel : ViewModel() {
|
||||||
val displayedCallLogs = MutableLiveData<List<GroupedCallLogData>>()
|
val callLogs = MutableLiveData<List<GroupedCallLogData>>()
|
||||||
|
|
||||||
val filter = MutableLiveData<CallLogsFilter>()
|
val filter = MutableLiveData<CallLogsFilter>()
|
||||||
|
|
||||||
|
@ -41,17 +41,8 @@ class CallLogsListViewModel : ViewModel() {
|
||||||
MutableLiveData<Event<Boolean>>()
|
MutableLiveData<Event<Boolean>>()
|
||||||
}
|
}
|
||||||
|
|
||||||
private val callLogs = MutableLiveData<ArrayList<GroupedCallLogData>>()
|
|
||||||
private val missedCallLogs = MutableLiveData<ArrayList<GroupedCallLogData>>()
|
|
||||||
private val conferenceCallLogs = MutableLiveData<ArrayList<GroupedCallLogData>>()
|
|
||||||
|
|
||||||
private val listener: CoreListenerStub = object : CoreListenerStub() {
|
private val listener: CoreListenerStub = object : CoreListenerStub() {
|
||||||
override fun onCallStateChanged(
|
override fun onCallLogUpdated(core: Core, log: CallLog) {
|
||||||
core: Core,
|
|
||||||
call: Call,
|
|
||||||
state: Call.State,
|
|
||||||
message: String
|
|
||||||
) {
|
|
||||||
updateCallLogs()
|
updateCallLogs()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -75,9 +66,6 @@ class CallLogsListViewModel : ViewModel() {
|
||||||
|
|
||||||
override fun onCleared() {
|
override fun onCleared() {
|
||||||
callLogs.value.orEmpty().forEach(GroupedCallLogData::destroy)
|
callLogs.value.orEmpty().forEach(GroupedCallLogData::destroy)
|
||||||
missedCallLogs.value.orEmpty().forEach(GroupedCallLogData::destroy)
|
|
||||||
conferenceCallLogs.value.orEmpty().forEach(GroupedCallLogData::destroy)
|
|
||||||
displayedCallLogs.value.orEmpty().forEach(GroupedCallLogData::destroy)
|
|
||||||
|
|
||||||
coreContext.contactsManager.removeListener(contactsUpdatedListener)
|
coreContext.contactsManager.removeListener(contactsUpdatedListener)
|
||||||
coreContext.core.removeListener(listener)
|
coreContext.core.removeListener(listener)
|
||||||
|
@ -87,17 +75,17 @@ class CallLogsListViewModel : ViewModel() {
|
||||||
|
|
||||||
fun showAllCallLogs() {
|
fun showAllCallLogs() {
|
||||||
filter.value = CallLogsFilter.ALL
|
filter.value = CallLogsFilter.ALL
|
||||||
applyFilter()
|
updateCallLogs()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun showOnlyMissedCallLogs() {
|
fun showOnlyMissedCallLogs() {
|
||||||
filter.value = CallLogsFilter.MISSED
|
filter.value = CallLogsFilter.MISSED
|
||||||
applyFilter()
|
updateCallLogs()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun showOnlyConferenceCallLogs() {
|
fun showOnlyConferenceCallLogs() {
|
||||||
filter.value = CallLogsFilter.CONFERENCE
|
filter.value = CallLogsFilter.CONFERENCE
|
||||||
applyFilter()
|
updateCallLogs()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun deleteCallLogGroup(callLog: GroupedCallLogData?) {
|
fun deleteCallLogGroup(callLog: GroupedCallLogData?) {
|
||||||
|
@ -157,27 +145,15 @@ class CallLogsListViewModel : ViewModel() {
|
||||||
|
|
||||||
private fun updateCallLogs() {
|
private fun updateCallLogs() {
|
||||||
callLogs.value.orEmpty().forEach(GroupedCallLogData::destroy)
|
callLogs.value.orEmpty().forEach(GroupedCallLogData::destroy)
|
||||||
missedCallLogs.value.orEmpty().forEach(GroupedCallLogData::destroy)
|
|
||||||
conferenceCallLogs.value.orEmpty().forEach(GroupedCallLogData::destroy)
|
|
||||||
|
|
||||||
val allCallLogs = coreContext.core.callLogs
|
val allCallLogs = coreContext.core.callLogs
|
||||||
callLogs.value = computeCallLogs(allCallLogs, false, false)
|
Log.i("[Call Logs] ${allCallLogs.size} call logs found")
|
||||||
missedCallLogs.value = computeCallLogs(allCallLogs, true, false)
|
|
||||||
conferenceCallLogs.value = computeCallLogs(allCallLogs, false, true)
|
|
||||||
applyFilter()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun applyFilter() {
|
callLogs.value = when (filter.value) {
|
||||||
displayedCallLogs.value.orEmpty().forEach(GroupedCallLogData::destroy)
|
CallLogsFilter.MISSED -> computeCallLogs(allCallLogs, missed = true, conference = false)
|
||||||
val displayedList = arrayListOf<GroupedCallLogData>()
|
CallLogsFilter.CONFERENCE -> computeCallLogs(allCallLogs, missed = false, conference = true)
|
||||||
|
else -> computeCallLogs(allCallLogs, missed = false, conference = false)
|
||||||
when (filter.value) {
|
|
||||||
CallLogsFilter.MISSED -> displayedList.addAll(missedCallLogs.value.orEmpty())
|
|
||||||
CallLogsFilter.CONFERENCE -> displayedList.addAll(conferenceCallLogs.value.orEmpty())
|
|
||||||
else -> displayedList.addAll(callLogs.value.orEmpty())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
displayedCallLogs.value = displayedList
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -114,7 +114,7 @@
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:onClick="@{editClickListener}"
|
android:onClick="@{editClickListener}"
|
||||||
android:enabled="@{!viewModel.displayedCallLogs.empty}"
|
android:enabled="@{!viewModel.callLogs.empty}"
|
||||||
android:contentDescription="@string/content_description_enter_edition_mode"
|
android:contentDescription="@string/content_description_enter_edition_mode"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
|
@ -145,7 +145,7 @@
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_centerInParent="true"
|
android:layout_centerInParent="true"
|
||||||
android:text="@string/no_call_history"
|
android:text="@string/no_call_history"
|
||||||
android:visibility="@{viewModel.displayedCallLogs.empty && viewModel.filter == CallLogsFilter.ALL ? View.VISIBLE : View.GONE}" />
|
android:visibility="@{viewModel.callLogs.empty && viewModel.filter == CallLogsFilter.ALL ? View.VISIBLE : View.GONE}" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
style="@style/empty_list_font"
|
style="@style/empty_list_font"
|
||||||
|
@ -153,7 +153,7 @@
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_centerInParent="true"
|
android:layout_centerInParent="true"
|
||||||
android:text="@string/no_missed_call_history"
|
android:text="@string/no_missed_call_history"
|
||||||
android:visibility="@{viewModel.displayedCallLogs.empty && viewModel.filter == CallLogsFilter.MISSED ? View.VISIBLE : View.GONE}" />
|
android:visibility="@{viewModel.callLogs.empty && viewModel.filter == CallLogsFilter.MISSED ? View.VISIBLE : View.GONE}" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
style="@style/empty_list_font"
|
style="@style/empty_list_font"
|
||||||
|
@ -161,7 +161,7 @@
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_centerInParent="true"
|
android:layout_centerInParent="true"
|
||||||
android:text="@string/no_conference_call_history"
|
android:text="@string/no_conference_call_history"
|
||||||
android:visibility="@{viewModel.displayedCallLogs.empty && viewModel.filter == CallLogsFilter.CONFERENCE ? View.VISIBLE : View.GONE}" />
|
android:visibility="@{viewModel.callLogs.empty && viewModel.filter == CallLogsFilter.CONFERENCE ? View.VISIBLE : View.GONE}" />
|
||||||
|
|
||||||
<View
|
<View
|
||||||
android:layout_width="1dp"
|
android:layout_width="1dp"
|
||||||
|
|
Loading…
Reference in a new issue