- Renamed "history" file to more intuitive "calls" file.
This commit is contained in:
@@ -13,45 +13,41 @@ class CallHistory(val aor: String, val peerURI: String, val direction: String,
|
||||
|
||||
const val CALL_HISTORY_SIZE = 100
|
||||
|
||||
fun history(): ArrayList<CallHistory> {
|
||||
return BaresipService.history
|
||||
}
|
||||
|
||||
fun add(history: CallHistory) {
|
||||
BaresipService.history.add(history)
|
||||
BaresipService.callHistory.add(history)
|
||||
if (aorHistorySize(history.aor) > CALL_HISTORY_SIZE) {
|
||||
var i = 0
|
||||
for (h in BaresipService.history)
|
||||
for (h in BaresipService.callHistory)
|
||||
if (h.aor == history.aor)
|
||||
break
|
||||
else
|
||||
i++
|
||||
BaresipService.history.removeAt(i)
|
||||
BaresipService.callHistory.removeAt(i)
|
||||
}
|
||||
}
|
||||
|
||||
fun clear(aor: String) {
|
||||
val it = BaresipService.history.iterator()
|
||||
val it = BaresipService.callHistory.iterator()
|
||||
while (it.hasNext()) if (it.next().aor == aor) it.remove()
|
||||
}
|
||||
|
||||
fun aorHistorySize(aor: String): Int {
|
||||
return BaresipService.history.filter { it.aor == aor }.count()
|
||||
return BaresipService.callHistory.filter { it.aor == aor }.count()
|
||||
}
|
||||
|
||||
fun aorLatestHistory(aor: String): CallHistory? {
|
||||
for (h in BaresipService.history.reversed())
|
||||
for (h in BaresipService.callHistory.reversed())
|
||||
if (h.aor == aor) return h
|
||||
return null
|
||||
}
|
||||
|
||||
fun save() {
|
||||
Log.d("Baresip", "Saving call history of size ${BaresipService.history.size}")
|
||||
val file = File(BaresipService.filesPath, "history")
|
||||
Log.d("Baresip", "Saving history of ${BaresipService.callHistory.size} calls")
|
||||
val file = File(BaresipService.filesPath, "calls")
|
||||
try {
|
||||
val fos = FileOutputStream(file)
|
||||
val oos = ObjectOutputStream(fos)
|
||||
oos.writeObject(BaresipService.history)
|
||||
oos.writeObject(BaresipService.callHistory)
|
||||
oos.close()
|
||||
fos.close()
|
||||
} catch (e: IOException) {
|
||||
@@ -61,22 +57,22 @@ class CallHistory(val aor: String, val peerURI: String, val direction: String,
|
||||
}
|
||||
|
||||
fun restore() {
|
||||
val file = File(BaresipService.filesPath, "history")
|
||||
val file = File(BaresipService.filesPath, "calls")
|
||||
if (file.exists())
|
||||
try {
|
||||
val fis = FileInputStream(file)
|
||||
val ois = ObjectInputStream(fis)
|
||||
BaresipService.history = ois.readObject() as ArrayList<CallHistory>
|
||||
BaresipService.callHistory = ois.readObject() as ArrayList<CallHistory>
|
||||
ois.close()
|
||||
fis.close()
|
||||
Log.d("Baresip", "Restored call history of size ${BaresipService.history.size}")
|
||||
Log.d("Baresip", "Restored history of ${BaresipService.callHistory.size} calls")
|
||||
} catch (e: Exception) {
|
||||
Log.e("Baresip", "InputStream exception: - " + e.toString())
|
||||
}
|
||||
}
|
||||
|
||||
fun print() {
|
||||
for (h in BaresipService.history)
|
||||
for (h in BaresipService.callHistory)
|
||||
Log.d("Baresip", "[${h.aor}, ${h.peerURI}, ${h.direction}, ${h.connected}]")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user