Improved call and message implementation
This commit is contained in:
@ -452,7 +452,7 @@ class BaresipService: Service() {
|
||||
new.stopTime = old.stopTime
|
||||
new.startTime = old.startTime
|
||||
new.recording = old.recording
|
||||
callHistory.add(new)
|
||||
new.add()
|
||||
}
|
||||
CallHistoryNew.save()
|
||||
}
|
||||
@ -826,8 +826,7 @@ class BaresipService: Service() {
|
||||
Log.e(TAG, "Callwaiting tone $name.wav not found\")")
|
||||
}
|
||||
if (ua.account.callHistory) {
|
||||
CallHistoryNew.add(CallHistoryNew(aor, peerUri, "in"))
|
||||
CallHistoryNew.save()
|
||||
CallHistoryNew(aor, peerUri, "in").add()
|
||||
ua.account.missedCalls = true
|
||||
}
|
||||
return
|
||||
@ -839,7 +838,7 @@ class BaresipService: Service() {
|
||||
"call incoming" -> {
|
||||
val peerUri = ev[1]
|
||||
Log.d(TAG, "Incoming call $uap/$callp/$peerUri")
|
||||
Call(callp, ua, peerUri, "in", "incoming", null).add()
|
||||
Call(callp, ua, peerUri, "in", "incoming").add()
|
||||
if (speakerPhone && !Utils.isSpeakerPhoneOn(am))
|
||||
Utils.toggleSpeakerPhone(ContextCompat.getMainExecutor(this), am)
|
||||
if (ua.account.answerMode == Api.ANSWERMODE_MANUAL) {
|
||||
@ -1036,8 +1035,7 @@ class BaresipService: Service() {
|
||||
history.rejected = call.rejected
|
||||
if (call.startTime != null && call.dumpfiles[0] != "")
|
||||
history.recording = call.dumpfiles
|
||||
CallHistoryNew.add(history)
|
||||
CallHistoryNew.save()
|
||||
history.add()
|
||||
ua.account.missedCalls = ua.account.missedCalls || missed
|
||||
}
|
||||
if (!Utils.isVisible()) {
|
||||
|
||||
@ -1,10 +1,8 @@
|
||||
package com.tutpro.baresip
|
||||
|
||||
import android.text.TextWatcher
|
||||
import java.util.*
|
||||
|
||||
class Call(val callp: Long, val ua: UserAgent, val peerUri: String, val dir: String,
|
||||
var status: String, val dtmfWatcher: TextWatcher?) {
|
||||
class Call(val callp: Long, val ua: UserAgent, val peerUri: String, val dir: String, var status: String) {
|
||||
|
||||
var onhold = false
|
||||
var held = false
|
||||
|
||||
@ -16,22 +16,35 @@ class CallHistoryNew(val aor: String, val peerUri: String, val direction: String
|
||||
var rejected = false
|
||||
var recording = arrayOf("", "") // Encoder and decoder recording files
|
||||
|
||||
fun add() {
|
||||
BaresipService.callHistory.add(this)
|
||||
var count = 0
|
||||
var remove: CallHistoryNew? = null
|
||||
for (h in BaresipService.callHistory)
|
||||
if (h.aor == this.aor) {
|
||||
count++
|
||||
if (count > CALL_HISTORY_SIZE) {
|
||||
remove = h
|
||||
break
|
||||
}
|
||||
}
|
||||
if (remove != null) {
|
||||
if (remove.recording[0] != "")
|
||||
deleteRecording(remove.recording)
|
||||
BaresipService.callHistory.remove(remove)
|
||||
}
|
||||
save()
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
private const val serialVersionUID: Long = 3
|
||||
private const val CALL_HISTORY_SIZE = 256
|
||||
|
||||
fun add(history: CallHistoryNew) {
|
||||
BaresipService.callHistory.add(history)
|
||||
if (aorHistorySize(history.aor) > CALL_HISTORY_SIZE) {
|
||||
for (h in BaresipService.callHistory)
|
||||
if (h.aor == history.aor) {
|
||||
if (h.recording[0] != "")
|
||||
deleteRecording(h.recording)
|
||||
BaresipService.callHistory.remove(h)
|
||||
break
|
||||
}
|
||||
}
|
||||
fun aorLatestPeerUri(aor: String): String? {
|
||||
for (h in BaresipService.callHistory.reversed())
|
||||
if (h.aor == aor) return h.peerUri
|
||||
return null
|
||||
}
|
||||
|
||||
fun clear(aor: String) {
|
||||
@ -43,15 +56,7 @@ class CallHistoryNew(val aor: String, val peerUri: String, val direction: String
|
||||
BaresipService.callHistory.removeAt(i)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun aorHistorySize(aor: String): Int {
|
||||
return BaresipService.callHistory.count { it.aor == aor }
|
||||
}
|
||||
fun aorLatestPeerUri(aor: String): String? {
|
||||
for (h in BaresipService.callHistory.reversed())
|
||||
if (h.aor == aor) return h.peerUri
|
||||
return null
|
||||
save()
|
||||
}
|
||||
|
||||
fun save() {
|
||||
|
||||
@ -2759,7 +2759,7 @@ class MainActivity : ComponentActivity() {
|
||||
val callp = ua.callAlloc(0L, Api.VIDMODE_OFF)
|
||||
return if (callp != 0L) {
|
||||
Log.d(TAG, "Adding outgoing call ${ua.uap}/$callp/$uri")
|
||||
val call = Call(callp, ua, uri, "out", "outgoing", null)
|
||||
val call = Call(callp, ua, uri, "out", "outgoing")
|
||||
call.onHoldCall = onHoldCall
|
||||
call.add()
|
||||
if (onHoldCall != null)
|
||||
@ -2786,7 +2786,7 @@ class MainActivity : ComponentActivity() {
|
||||
val newCallp = ua.callAlloc(call.callp, Api.VIDMODE_OFF)
|
||||
if (newCallp != 0L) {
|
||||
Log.d(TAG, "Adding outgoing call ${ua.uap}/$newCallp/$uri")
|
||||
val newCall = Call(newCallp, ua, uri, "out", "transferring", null)
|
||||
val newCall = Call(newCallp, ua, uri, "out", "transferring")
|
||||
newCall.add()
|
||||
if (newCall.connect(uri)) {
|
||||
if (ua.account.aor != viewModel.selectedAor.value)
|
||||
|
||||
@ -47,6 +47,7 @@ class Message(val aor: String, val peerUri: String, val message: String, val tim
|
||||
val it = updatedMessages.iterator()
|
||||
while (it.hasNext()) if (it.next().aor == aor) it.remove()
|
||||
BaresipService.messages = updatedMessages.toList()
|
||||
save()
|
||||
}
|
||||
|
||||
fun deleteAorMessage(aor: String, time: Long) {
|
||||
|
||||
Reference in New Issue
Block a user