diff --git a/app/src/main/kotlin/com/tutpro/baresip/AccountListAdapter.kt b/app/src/main/kotlin/com/tutpro/baresip/AccountListAdapter.kt index c42eca22..f1904c86 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) - NewCallHistory.clear(ua.account.aor) + CallHistory.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 9a58c510..96bbead0 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt @@ -43,7 +43,6 @@ import androidx.media.AudioManagerCompat import java.io.File import java.net.InetAddress import java.nio.charset.StandardCharsets -import java.text.SimpleDateFormat import java.util.* import kotlin.concurrent.schedule import kotlin.math.roundToInt @@ -411,18 +410,17 @@ class BaresipService: Service() { } Contact.contactsUpdate() - val history = CallHistory.get() + val history = NewCallHistory.get() if (history.isEmpty()) { - NewCallHistory.restore() + CallHistory.restore() } else { for (old in history) { - val new = NewCallHistory(old.aor, old.peerUri, old.direction) - new.stopTime = old.time - if (old.connected) - new.startTime = GregorianCalendar(0, 0, 0) + val new = CallHistory(old.aor, old.peerUri, old.direction) + new.stopTime = old.stopTime + new.startTime = old.startTime callHistory.add(new) } - NewCallHistory.save() + CallHistory.save() } Message.restore() @@ -593,6 +591,8 @@ class BaresipService: Service() { if (ev[0] == "sndfile dump") { Log.d(TAG, "Got sndfile dump ${ev[1]}") + if (Call.calls().size > 0) + Call.calls()[0].dumpfile = ev[1] return } @@ -679,8 +679,8 @@ class BaresipService: Service() { if (!Utils.checkPermissions(this, arrayOf(Manifest.permission.RECORD_AUDIO))) { toast(getString(R.string.no_calls)) if (ua.account.callHistory) { - NewCallHistory.add(NewCallHistory(aor, peerUri, "in")) - NewCallHistory.save() + CallHistory.add(CallHistory(aor, peerUri, "in")) + CallHistory.save() ua.account.missedCalls = true } if (!isMainVisible) @@ -761,8 +761,8 @@ class BaresipService: Service() { "call rejected" -> { playUnInterrupted(R.raw.callwaiting, 1) if (ua.account.callHistory) { - NewCallHistory.add(NewCallHistory(aor, ev[1], "in")) - NewCallHistory.save() + CallHistory.add(CallHistory(aor, ev[1], "in")) + CallHistory.save() ua.account.missedCalls = true if (!isMainVisible) return @@ -894,29 +894,17 @@ class BaresipService: Service() { } val missed = call.startTime == null && call.dir == "in" && !call.rejected if (ua.account.callHistory) { - val history = NewCallHistory(aor, call.peerUri, call.dir) + val history = CallHistory(aor, call.peerUri, call.dir) history.startTime = call.startTime history.stopTime = GregorianCalendar() - NewCallHistory.add(history) - NewCallHistory.save() - ua.account.missedCalls = ua.account.missedCalls || missed - if (isRecOn && call.startTime != null) { - val format = SimpleDateFormat("yyyy-MM-dd-HH-mm-ss") - val startTime = call.startTime!! - var time = format.format(startTime.time).toString() - var recording = filesDir.absolutePath + "/recordings/" + - "dump-$aor=>${call.peerUri}-$time" - if (File("$recording-dec.wav").exists()) { - recordings[time] = recording - } else { - startTime.add(Calendar.SECOND, 1) - time = format.format(startTime.time).toString() - recording = filesDir.absolutePath + "/recordings/" + - "dump-$aor=>${call.peerUri}-$time" - recordings[time] = recording - } - + if (call.startTime != null && call.dumpfile != "") { + val recording = filesDir.absolutePath + "/recordings/" + + call.dumpfile.substringBeforeLast("-") + history.recording = recording } + CallHistory.add(history) + CallHistory.save() + ua.account.missedCalls = ua.account.missedCalls || missed } if (!Utils.isVisible()) { if (missed) { @@ -1540,7 +1528,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 1884943b..532a7cc5 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/Call.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/Call.kt @@ -15,6 +15,7 @@ class Call(val callp: Long, val ua: UserAgent, val peerUri: String, val dir: Str var zid = "" var startTime: GregorianCalendar? = null // Set when call is established var referTo = "" + var dumpfile = "" fun add() { BaresipService.calls.add(0, this) diff --git a/app/src/main/kotlin/com/tutpro/baresip/CallDetailsAdapter.kt b/app/src/main/kotlin/com/tutpro/baresip/CallDetailsAdapter.kt index 19e1159e..2521d485 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/CallDetailsAdapter.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/CallDetailsAdapter.kt @@ -18,7 +18,8 @@ import java.util.* class CallDetailsAdapter(private val ctx: Context, private val rows: ArrayList) : ArrayAdapter(ctx, R.layout.call_detail_row, rows) { - private val layoutInflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater + private val layoutInflater = + context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater private class ViewHolder(view: View?) { val directionView = view?.findViewById(R.id.direction) as ImageView @@ -72,12 +73,11 @@ class CallDetailsAdapter(private val ctx: Context, private val rows: ArrayList CALL_HISTORY_SIZE) { var i = 0 @@ -44,7 +45,7 @@ class NewCallHistory(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, "call_history") + val file = File(BaresipService.filesPath, "history") try { val fos = FileOutputStream(file) val oos = ObjectOutputStream(fos) @@ -58,13 +59,13 @@ class NewCallHistory(val aor: String, val peerUri: String, val direction: String } fun restore() { - val file = File(BaresipService.filesPath, "call_history") + val file = File(BaresipService.filesPath, "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") @@ -77,28 +78,31 @@ class NewCallHistory(val aor: String, val peerUri: String, val direction: String @Suppress("UNUSED") fun print() { for (h in BaresipService.callHistory) - Log.d(TAG, "[${h.aor}, ${h.peerUri}, ${h.direction}, ${h.startTime}, ${h.stopTime}]") + Log.d(TAG, "[${h.aor}, ${h.peerUri}, ${h.direction}, ${h.startTime}," + + "${h.stopTime}, ${h.recording}]") } } } -class CallHistory(val aor: String, val peerUri: String, val direction: String, - val connected: Boolean) : Serializable { +class NewCallHistory(val aor: String, val peerUri: String, val direction: String) : Serializable { - val time: GregorianCalendar = GregorianCalendar() + var startTime: GregorianCalendar? = null + var stopTime = GregorianCalendar() companion object { - fun get(): ArrayList { - val file = File(BaresipService.filesPath, "calls") - var result = ArrayList() + private const val serialVersionUID: Long = 1 + + fun get(): ArrayList { + val file = File(BaresipService.filesPath, "call_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 6cde97bc..3319f77b 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/CallRow.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/CallRow.kt @@ -4,14 +4,19 @@ import java.util.* import kotlin.collections.ArrayList class CallRow(val aor: String, val peerUri: String, val direction: Int, - startTime: GregorianCalendar?, val stopTime: GregorianCalendar) { + startTime: GregorianCalendar?, + val stopTime: GregorianCalendar, + private val recording: String) - class Details(val direction: Int, val startTime: GregorianCalendar?, val stopTime: GregorianCalendar) +{ + + class Details(val direction: Int, val startTime: GregorianCalendar?, + val stopTime: GregorianCalendar, val recording: String) val details = ArrayList
() init { - details.add(Details(direction, startTime, stopTime)) + details.add(Details(direction, 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 287b1268..3e8b0a99 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/CallsActivity.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/CallsActivity.kt @@ -114,7 +114,7 @@ class CallsActivity : AppCompatActivity() { } DialogInterface.BUTTON_POSITIVE -> { removeUaHistoryAt(pos) - NewCallHistory.save() + CallHistory.save() clAdapter.notifyDataSetChanged() } DialogInterface.BUTTON_NEUTRAL -> { @@ -168,8 +168,8 @@ class CallsActivity : AppCompatActivity() { setMessage(String.format(getString(R.string.delete_history_alert), aor.substringAfter(":"))) setPositiveButton(getText(R.string.delete)) { dialog, _ -> - NewCallHistory.clear(aor) - NewCallHistory.save() + CallHistory.clear(aor) + CallHistory.save() aorGenerateHistory(aor) clAdapter.notifyDataSetChanged() dialog.dismiss() @@ -244,9 +244,11 @@ class CallsActivity : AppCompatActivity() { else R.drawable.arrow_up_red if (uaHistory.isNotEmpty() && (uaHistory.last().peerUri == h.peerUri)) - uaHistory.last().details.add(CallRow.Details(direction, h.startTime, h.stopTime)) + uaHistory.last().details.add(CallRow.Details(direction, h.startTime, + h.stopTime, h.recording)) else - uaHistory.add(CallRow(h.aor, h.peerUri, direction, h.startTime, h.stopTime)) + uaHistory.add(CallRow(h.aor, h.peerUri, direction, h.startTime, + h.stopTime, h.recording)) } } } diff --git a/app/src/main/kotlin/com/tutpro/baresip/MainActivity.kt b/app/src/main/kotlin/com/tutpro/baresip/MainActivity.kt index 6c11a3fa..943130c8 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/MainActivity.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/MainActivity.kt @@ -1200,6 +1200,11 @@ class MainActivity : AppCompatActivity() { } else { callTimer.stop() } + if (BaresipService.isRecOn) { + Api.module_unload("sndfile") + BaresipService.isRecOn = false + recIcon!!.setIcon(R.drawable.rec_off) + } if (aor == aorSpinner.tag) { callUri.inputType = InputType.TYPE_CLASS_TEXT + InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS @@ -1892,7 +1897,7 @@ class MainActivity : AppCompatActivity() { } } } else { - val latestPeerUri = NewCallHistory.aorLatestPeerUri(aor) + val latestPeerUri = CallHistory.aorLatestPeerUri(aor) if (latestPeerUri != null) callUri.setText(Utils.friendlyUri(this, latestPeerUri, ua.account)) }