Using new APIs

This commit is contained in:
Sylvain Berfini 2023-09-05 13:41:53 +02:00
parent 2fe1bcbdff
commit 7b48d41d29
4 changed files with 32 additions and 8 deletions

View file

@ -9,6 +9,7 @@ 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
import org.linphone.utils.LinphoneUtils
class CallLogViewModel @UiThread constructor() : ViewModel() {
val showBackButton = MutableLiveData<Boolean>()
@ -32,10 +33,16 @@ class CallLogViewModel @UiThread constructor() : ViewModel() {
address = model.address
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 account = LinphoneUtils.getDefaultAccount()
val list = if (account == null) {
val localAddress = if (callLog.dir == Call.Dir.Outgoing) callLog.fromAddress else callLog.toAddress
core.getCallHistory(peerAddress, localAddress)
} else {
account.getCallLogsForAddress(peerAddress)
}
for (log in list) {
val historyModel = CallLogHistoryModel(log)
history.add(historyModel)
}

View file

@ -29,6 +29,7 @@ import org.linphone.core.CoreListenerStub
import org.linphone.ui.main.calls.model.CallLogModel
import org.linphone.ui.main.viewmodel.AbstractTopBarViewModel
import org.linphone.utils.Event
import org.linphone.utils.LinphoneUtils
class CallsListViewModel @UiThread constructor() : AbstractTopBarViewModel() {
val callLogs = MutableLiveData<ArrayList<CallLogModel>>()
@ -74,9 +75,15 @@ class CallsListViewModel @UiThread constructor() : AbstractTopBarViewModel() {
@UiThread
fun removeAllCallLogs() {
coreContext.postOnCoreThread { core ->
for (callLog in core.callLogs) {
core.removeCallLog(callLog)
val account = LinphoneUtils.getDefaultAccount()
if (account != null) {
account.clearCallLogs()
} else {
for (callLog in core.callLogs) {
core.removeCallLog(callLog)
}
}
historyDeletedEvent.postValue(Event(true))
computeCallLogsList(currentFilter)
}
@ -86,9 +93,10 @@ class CallsListViewModel @UiThread constructor() : AbstractTopBarViewModel() {
private fun computeCallLogsList(filter: String) {
val list = arrayListOf<CallLogModel>()
// TODO : filter depending on currently selected account
// TODO : Add support for call logs in magic search
for (callLog in coreContext.core.callLogs) {
val account = LinphoneUtils.getDefaultAccount()
val logs = account?.callLogs ?: coreContext.core.callLogs
for (callLog in logs) {
if (callLog.remoteAddress.asStringUriOnly().contains(filter)) {
val model = CallLogModel(callLog)
list.add(model)

View file

@ -29,6 +29,7 @@ import org.linphone.core.Call
import org.linphone.core.Core
import org.linphone.core.CoreListenerStub
import org.linphone.core.tools.Log
import org.linphone.utils.LinphoneUtils
class BottomNavBarViewModel @UiThread constructor() : ViewModel() {
companion object {
@ -84,7 +85,8 @@ class BottomNavBarViewModel @UiThread constructor() : ViewModel() {
@WorkerThread
fun updateMissedCallsCount() {
val count = coreContext.core.missedCallsCount
val account = LinphoneUtils.getDefaultAccount()
val count = account?.missedCallsCount ?: coreContext.core.missedCallsCount
val moreThanOne = count > 1
Log.i(
"$TAG There ${if (moreThanOne) "are" else "is"} [$count] missed ${if (moreThanOne) "calls" else "call"}"
@ -95,7 +97,8 @@ class BottomNavBarViewModel @UiThread constructor() : ViewModel() {
@UiThread
fun resetMissedCallsCount() {
coreContext.postOnCoreThread { core ->
core.resetMissedCallsCount()
val account = LinphoneUtils.getDefaultAccount()
account?.resetMissedCallsCount() ?: core.resetMissedCallsCount()
updateMissedCallsCount()
}
}

View file

@ -30,6 +30,7 @@ import androidx.emoji2.text.EmojiCompat
import java.util.Locale
import org.linphone.LinphoneApplication.Companion.coreContext
import org.linphone.R
import org.linphone.core.Account
import org.linphone.core.Address
import org.linphone.core.Call
import org.linphone.core.Call.Dir
@ -41,6 +42,11 @@ class LinphoneUtils {
companion object {
private const val TAG = "[App Utils]"
@WorkerThread
fun getDefaultAccount(): Account? {
return coreContext.core.defaultAccount ?: coreContext.core.accountList.first()
}
@AnyThread
fun getFirstLetter(displayName: String): String {
return getInitials(displayName, 1)