- all user interface unrelated data is now kept in baresip service
allowing proper recovery in case Android kills other activities - many other improvements and bug fixes
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package com.tutpro.baresip
|
||||
|
||||
import java.io.Serializable
|
||||
import android.util.Log
|
||||
import java.io.*
|
||||
import java.util.ArrayList
|
||||
import java.util.GregorianCalendar
|
||||
|
||||
class CallHistory(val aor: String, val peerURI: String, val direction: String,
|
||||
@@ -10,29 +12,72 @@ class CallHistory(val aor: String, val peerURI: String, val direction: String,
|
||||
|
||||
companion object {
|
||||
|
||||
fun aorHistory(history: ArrayList<CallHistory>, aor: String): Int {
|
||||
const val CALL_HISTORY_SIZE = 100
|
||||
|
||||
fun history(): ArrayList<CallHistory> {
|
||||
return BaresipService.history
|
||||
}
|
||||
|
||||
fun historySet(history: ArrayList<CallHistory>) {
|
||||
BaresipService.history = history
|
||||
}
|
||||
|
||||
fun add(history: CallHistory) {
|
||||
BaresipService.history.add(history)
|
||||
if (aorHistorySize(history.aor) > CALL_HISTORY_SIZE) {
|
||||
var i = 0
|
||||
for (h in BaresipService.history)
|
||||
if (h.aor == history.aor)
|
||||
break
|
||||
else
|
||||
i++
|
||||
BaresipService.history.removeAt(i)
|
||||
}
|
||||
}
|
||||
|
||||
fun aorHistorySize(aor: String): Int {
|
||||
var size = 0;
|
||||
for (h in history) {
|
||||
for (h in BaresipService.history) {
|
||||
if (h.aor == aor) size++
|
||||
}
|
||||
return size
|
||||
}
|
||||
|
||||
fun aorRemoveHistory(history: ArrayList<CallHistory>, aor: String) {
|
||||
for (h in history) {
|
||||
if (h.aor == aor) {
|
||||
history.remove(h)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun aorLatestHistory(history: ArrayList<CallHistory>, aor: String): CallHistory? {
|
||||
for (h in history.reversed())
|
||||
fun aorLatestHistory(aor: String): CallHistory? {
|
||||
for (h in BaresipService.history.reversed())
|
||||
if (h.aor == aor) return h
|
||||
return null
|
||||
}
|
||||
|
||||
fun save(path: String) {
|
||||
val file = File(path, "history")
|
||||
try {
|
||||
val fos = FileOutputStream(file)
|
||||
val oos = ObjectOutputStream(fos)
|
||||
oos.writeObject(history())
|
||||
oos.close()
|
||||
fos.close()
|
||||
} catch (e: IOException) {
|
||||
Log.w("Baresip", "OutputStream exception: " + e.toString())
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
fun restore(path: String) {
|
||||
val file = File(path + "/history")
|
||||
if (file.exists()) {
|
||||
try {
|
||||
val fis = FileInputStream(file)
|
||||
val ois = ObjectInputStream(fis)
|
||||
historySet(ois.readObject() as ArrayList<CallHistory>)
|
||||
ois.close()
|
||||
fis.close()
|
||||
} catch (e: Exception) {
|
||||
Log.w("Baresip", "InputStream exception: - " + e.toString())
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user