diff --git a/app/src/main/kotlin/com/tutpro/baresip/AccountListAdapter.kt b/app/src/main/kotlin/com/tutpro/baresip/AccountListAdapter.kt index f1904c86..71facfe4 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/AccountListAdapter.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/AccountListAdapter.kt @@ -59,7 +59,7 @@ class AccountListAdapter(private val cxt: Context, private val rows: ArrayList Api.ua_destroy(ua.uap) - CallHistory.clear(ua.account.aor) + CallHistoryNew.clear(ua.account.aor) Message.clear(ua.account.aor) ua.remove() AccountsActivity.generateAccounts() diff --git a/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt b/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt index 1ecd8e84..f33e8623 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt @@ -409,17 +409,18 @@ class BaresipService: Service() { } Contact.contactsUpdate() - val history = NewCallHistory.get() + val history = CallHistory.get() if (history.isEmpty()) { - CallHistory.restore() + CallHistoryNew.restore() } else { for (old in history) { - val new = CallHistory(old.aor, old.peerUri, old.direction) + val new = CallHistoryNew(old.aor, old.peerUri, old.direction) new.stopTime = old.stopTime new.startTime = old.startTime + new.recording = old.recording callHistory.add(new) } - CallHistory.save() + CallHistoryNew.save() } Message.restore() @@ -699,8 +700,8 @@ class BaresipService: Service() { toast(toastMsg) playUnInterrupted(R.raw.callwaiting, 1) if (ua.account.callHistory) { - CallHistory.add(CallHistory(aor, peerUri, "in")) - CallHistory.save() + CallHistoryNew.add(CallHistoryNew(aor, peerUri, "in")) + CallHistoryNew.save() ua.account.missedCalls = true } return @@ -881,22 +882,30 @@ class BaresipService: Service() { call.onHoldCall = null } call.remove() - if (ev[2] == "busy") { + val reason = ev[1] + val tone = ev[2] + if (tone == "busy") { playBusy() } else if (!Call.inCall()) { resetCallVolume() abandonAudioFocus(applicationContext) proximitySensing(false) } - val missed = call.startTime == null && call.dir == "in" && !call.rejected + if (call.dir == "out") + call.rejected = call.startTime == null && + !reason.startsWith("408") && + !reason.startsWith("480") && + !reason.startsWith("Connection reset by") + val missed = call.dir == "in" && call.startTime == null && !call.rejected if (ua.account.callHistory) { - val history = CallHistory(aor, call.peerUri, call.dir) + val history = CallHistoryNew(aor, call.peerUri, call.dir) history.startTime = call.startTime history.stopTime = GregorianCalendar() + history.rejected = call.rejected if (call.startTime != null && call.dumpfiles[0] != "") history.recording = call.dumpfiles - CallHistory.add(history) - CallHistory.save() + CallHistoryNew.add(history) + CallHistoryNew.save() ua.account.missedCalls = ua.account.missedCalls || missed } if (!Utils.isVisible()) { @@ -1495,7 +1504,7 @@ class BaresipService: Service() { val uas = ArrayList() val calls = ArrayList() - var callHistory = ArrayList() + var callHistory = ArrayList() var messages = ArrayList() val messageUpdate = MutableLiveData() val contactUpdate = MutableLiveData() diff --git a/app/src/main/kotlin/com/tutpro/baresip/Call.kt b/app/src/main/kotlin/com/tutpro/baresip/Call.kt index aec3b54e..7f4e7d4c 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/Call.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/Call.kt @@ -10,7 +10,7 @@ class Call(val callp: Long, val ua: UserAgent, val peerUri: String, val dir: Str var held = false var onHoldCall: Call? = null var newCall: Call? = null - var rejected = false + var rejected = false // Incoming rejected by user or outgoing fails but not due to 408 or 480 var security = R.drawable.unlocked var zid = "" var startTime: GregorianCalendar? = null // Set when call is established diff --git a/app/src/main/kotlin/com/tutpro/baresip/CallHistory.kt b/app/src/main/kotlin/com/tutpro/baresip/CallHistory.kt index 8b248094..3c9b4f60 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/CallHistory.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/CallHistory.kt @@ -4,18 +4,19 @@ import java.io.* import java.util.ArrayList import java.util.GregorianCalendar -class CallHistory(val aor: String, val peerUri: String, val direction: String) : Serializable { +class CallHistoryNew(val aor: String, val peerUri: String, val direction: String) : Serializable { var startTime: GregorianCalendar? = null // Set to time when call is established (if ever) var stopTime = GregorianCalendar() // Set to time when call is closed + var rejected = false var recording = arrayOf("", "") // Encoder and decoder recording files companion object { - private const val serialVersionUID: Long = 2 + private const val serialVersionUID: Long = 3 private const val CALL_HISTORY_SIZE = 128 - fun add(history: CallHistory) { + fun add(history: CallHistoryNew) { BaresipService.callHistory.add(history) if (aorHistorySize(history.aor) > CALL_HISTORY_SIZE) { for (h in BaresipService.callHistory) @@ -42,7 +43,6 @@ class CallHistory(val aor: String, val peerUri: String, val direction: String) : 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 @@ -51,7 +51,7 @@ class CallHistory(val aor: String, val peerUri: String, val direction: String) : fun save() { Log.d(TAG, "Saving history of ${BaresipService.callHistory.size} calls") - val file = File(BaresipService.filesPath + "/history") + val file = File(BaresipService.filesPath + "/call_history") try { val fos = FileOutputStream(file) val oos = ObjectOutputStream(fos) @@ -65,13 +65,13 @@ class CallHistory(val aor: String, val peerUri: String, val direction: String) : } fun restore() { - val file = File(BaresipService.filesPath + "/history") + val file = File(BaresipService.filesPath + "/call_history") if (file.exists()) { try { val fis = FileInputStream(file) val ois = ObjectInputStream(fis) @Suppress("UNCHECKED_CAST") - BaresipService.callHistory = ois.readObject() as ArrayList + BaresipService.callHistory = ois.readObject() as ArrayList ois.close() fis.close() Log.d(TAG, "Restored history of ${BaresipService.callHistory.size} calls") @@ -90,30 +90,31 @@ class CallHistory(val aor: String, val peerUri: String, val direction: String) : fun print() { for (h in BaresipService.callHistory) Log.d(TAG, "[${h.aor}, ${h.peerUri}, ${h.direction}, ${h.startTime}," + - "${h.stopTime}, ${h.recording}") + "${h.stopTime}, ${h.rejected}, ${h.recording}") } } } -class NewCallHistory(val aor: String, val peerUri: String, val direction: String) : Serializable { +class CallHistory(val aor: String, val peerUri: String, val direction: String) : Serializable { var startTime: GregorianCalendar? = null var stopTime = GregorianCalendar() + var recording = arrayOf("", "") companion object { - private const val serialVersionUID: Long = 1 + private const val serialVersionUID: Long = 2 - fun get(): ArrayList { - val file = File(BaresipService.filesPath, "call_history") - var result = ArrayList() + fun get(): ArrayList { + val file = File(BaresipService.filesPath, "history") + var result = ArrayList() if (file.exists()) { try { val fis = FileInputStream(file) val ois = ObjectInputStream(fis) @Suppress("UNCHECKED_CAST") - result = ois.readObject() as ArrayList + result = ois.readObject() as ArrayList ois.close() fis.close() Log.d(TAG, "Got history of ${result.size} calls") diff --git a/app/src/main/kotlin/com/tutpro/baresip/CallRow.kt b/app/src/main/kotlin/com/tutpro/baresip/CallRow.kt index 24253e14..8175701c 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/CallRow.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/CallRow.kt @@ -3,20 +3,19 @@ package com.tutpro.baresip import java.util.* import kotlin.collections.ArrayList -class CallRow(val aor: String, val peerUri: String, val direction: Int, - startTime: GregorianCalendar?, - val stopTime: GregorianCalendar, +class CallRow(val aor: String, val peerUri: String, val direction: Int, val rejected: Boolean, + startTime: GregorianCalendar?, val stopTime: GregorianCalendar, val recording: Array) - { - class Details(val direction: Int, val startTime: GregorianCalendar?, - val stopTime: GregorianCalendar, val recording: Array) + class Details(val direction: Int, val rejected: Boolean, + val startTime: GregorianCalendar?, val stopTime: GregorianCalendar, + val recording: Array) val details = ArrayList
() init { - details.add(Details(direction, startTime, stopTime, recording)) + details.add(Details(direction, rejected, startTime, stopTime, recording)) } } diff --git a/app/src/main/kotlin/com/tutpro/baresip/CallsActivity.kt b/app/src/main/kotlin/com/tutpro/baresip/CallsActivity.kt index 55ca30f9..99baa1f1 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/CallsActivity.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/CallsActivity.kt @@ -120,7 +120,7 @@ class CallsActivity : AppCompatActivity() { DialogInterface.BUTTON_POSITIVE -> { removeUaHistoryAt(pos) - CallHistory.save() + CallHistoryNew.save() clAdapter.notifyDataSetChanged() } @@ -189,8 +189,8 @@ class CallsActivity : AppCompatActivity() { setMessage(String.format(getString(R.string.delete_history_alert), aor.substringAfter(":"))) setPositiveButton(getText(R.string.delete)) { dialog, _ -> - CallHistory.clear(aor) - CallHistory.save() + CallHistoryNew.clear(aor) + CallHistoryNew.save() aorGenerateHistory(aor) clAdapter.notifyDataSetChanged() dialog.dismiss() @@ -254,21 +254,30 @@ class CallsActivity : AppCompatActivity() { for (i in BaresipService.callHistory.indices.reversed()) { val h = BaresipService.callHistory[i] if (h.aor == aor) { - val direction: Int = if (h.direction == "in") - if (h.startTime != null) + val direction: Int = if (h.direction == "in") { + if (h.startTime != null) { R.drawable.call_down_green - else - R.drawable.call_down_red - else - if (h.startTime != null) + } else { + if (h.rejected) + R.drawable.call_down_red + else + R.drawable.call_missed_in + } + } else { + if (h.startTime != null) { R.drawable.call_up_green - else - R.drawable.call_up_red + } else { + if (h.rejected) + R.drawable.call_up_red + else + R.drawable.call_missed_out + } + } if (uaHistory.isNotEmpty() && (uaHistory.last().peerUri == h.peerUri)) - uaHistory.last().details.add(CallRow.Details(direction, h.startTime, - h.stopTime, h.recording)) + uaHistory.last().details.add(CallRow.Details(direction, h.rejected, + h.startTime, h.stopTime, h.recording)) else - uaHistory.add(CallRow(h.aor, h.peerUri, direction, h.startTime, + uaHistory.add(CallRow(h.aor, h.peerUri, direction, h.rejected, h.startTime, h.stopTime, h.recording)) } } @@ -277,12 +286,12 @@ class CallsActivity : AppCompatActivity() { private fun removeUaHistoryAt(i: Int) { for (details in uaHistory[i].details) { if (details.recording[0] != "") - CallHistory.deleteRecording(details.recording) + CallHistoryNew.deleteRecording(details.recording) BaresipService.callHistory.removeAll { it.startTime == details.startTime && it.stopTime == details.stopTime } } - CallHistory.deleteRecording(uaHistory[i].recording) + CallHistoryNew.deleteRecording(uaHistory[i].recording) uaHistory.removeAt(i) } diff --git a/app/src/main/kotlin/com/tutpro/baresip/MainActivity.kt b/app/src/main/kotlin/com/tutpro/baresip/MainActivity.kt index cba2e54b..d9819af8 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/MainActivity.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/MainActivity.kt @@ -384,8 +384,6 @@ class MainActivity : AppCompatActivity() { val callp = call.callp Log.d(TAG, "AoR $aor hanging up call $callp with ${callUri.text}") hangupButton.isEnabled = false - if (call.status == "answered") - call.rejected = true Api.ua_hangup(ua.uap, callp, 0, "") } } @@ -1907,7 +1905,7 @@ class MainActivity : AppCompatActivity() { } } } else { - val latestPeerUri = CallHistory.aorLatestPeerUri(aor) + val latestPeerUri = CallHistoryNew.aorLatestPeerUri(aor) if (latestPeerUri != null) callUri.setText(Utils.friendlyUri(this, latestPeerUri, ua.account)) } diff --git a/app/src/main/res/drawable/call_down_green.xml b/app/src/main/res/drawable/call_down_green.xml index 08003bbe..3025e62e 100644 --- a/app/src/main/res/drawable/call_down_green.xml +++ b/app/src/main/res/drawable/call_down_green.xml @@ -2,8 +2,9 @@ android:width="20dp" android:height="20dp" android:viewportWidth="960" - android:viewportHeight="960" > + android:viewportHeight="960" + android:tint="@color/colorTrafficGreen" > diff --git a/app/src/main/res/drawable/call_down_red.xml b/app/src/main/res/drawable/call_down_red.xml index d536178d..b950329e 100644 --- a/app/src/main/res/drawable/call_down_red.xml +++ b/app/src/main/res/drawable/call_down_red.xml @@ -2,8 +2,9 @@ android:width="20dp" android:height="20dp" android:viewportWidth="960" - android:viewportHeight="960" > + android:viewportHeight="960" + android:tint="@color/colorTrafficRed" > diff --git a/app/src/main/res/drawable/call_missed_in.xml b/app/src/main/res/drawable/call_missed_in.xml new file mode 100644 index 00000000..41d2ff06 --- /dev/null +++ b/app/src/main/res/drawable/call_missed_in.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/drawable/call_missed_out.xml b/app/src/main/res/drawable/call_missed_out.xml new file mode 100644 index 00000000..15c93a88 --- /dev/null +++ b/app/src/main/res/drawable/call_missed_out.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/drawable/call_up_red.xml b/app/src/main/res/drawable/call_up_red.xml index 0ce35fd0..0fdb1c2b 100644 --- a/app/src/main/res/drawable/call_up_red.xml +++ b/app/src/main/res/drawable/call_up_red.xml @@ -3,7 +3,7 @@ android:height="20dp" android:viewportWidth="960" android:viewportHeight="960" - android:tint="@color/colorTrafficRed"> + android:tint="@color/colorTrafficRed" > diff --git a/app/src/main/res/drawable/calls_missed.xml b/app/src/main/res/drawable/calls_missed.xml index 77ab4138..9fe57e63 100644 --- a/app/src/main/res/drawable/calls_missed.xml +++ b/app/src/main/res/drawable/calls_missed.xml @@ -1,5 +1,6 @@ - +