- Renamed "history" file to more intuitive "calls" file.

This commit is contained in:
Juha Heinanen
2019-10-10 10:47:46 +03:00
parent 5e1ac2e337
commit ccee613134
5 changed files with 23 additions and 24 deletions

View File

@ -174,6 +174,9 @@ class BaresipService: Service() {
}
}
if (File(filesDir, "history").exists())
File(filesDir, "history").renameTo(File(filesDir, "calls"))
Contact.restore()
CallHistory.restore()
Message.restore()
@ -887,7 +890,7 @@ class BaresipService: Service() {
private fun cleanService() {
uas.clear()
status.clear()
history.clear()
callHistory.clear()
messages.clear()
if (this::nm.isInitialized)
nm.cancelAll()
@ -937,7 +940,7 @@ class BaresipService: Service() {
var uas = ArrayList<UserAgent>()
var status = ArrayList<Int>()
var calls = ArrayList<Call>()
var history = ArrayList<CallHistory>()
var callHistory = ArrayList<CallHistory>()
var messages = ArrayList<Message>()
var contacts = ArrayList<Contact>()
var chatTexts: MutableMap<String, String> = mutableMapOf<String, String>()

View File

@ -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}]")
}
}

View File

@ -197,8 +197,8 @@ class CallsActivity : AppCompatActivity() {
private fun aorGenerateHistory(aor: String) {
uaHistory.clear()
for (i in CallHistory.history().indices.reversed()) {
val h = CallHistory.history()[i]
for (i in BaresipService.callHistory.indices.reversed()) {
val h = BaresipService.callHistory[i]
if (h.aor == aor) {
var direction: Int
if (h.direction == "in")
@ -231,7 +231,7 @@ class CallsActivity : AppCompatActivity() {
private fun removeUaHistoryAt(i: Int) {
for (index in uaHistory[i].indexes)
CallHistory.history().removeAt(index)
BaresipService.callHistory.removeAt(index)
uaHistory.removeAt(i)
}

View File

@ -959,7 +959,7 @@ class MainActivity : AppCompatActivity() {
}
private fun backup(password: String) {
val files = arrayOf("accounts", "config", "contacts", "history", "messages", "uuid",
val files = arrayOf("accounts", "calls", "config", "contacts", "messages", "uuid",
"zrtp_cache.dat", "zrtp_zid", "cert.pem", "ca_cert", "ca_certs.crt")
val backupFilePath = BaresipService.downloadsPath + "/baresip.bs"
val zipFilePath = BaresipService.filesPath + "/baresip.zip"

View File

@ -414,7 +414,7 @@ object Utils {
}
fun unZip(zipFilePath: String): Boolean {
val allFiles = listOf("accounts", "config", "contacts", "history", "messages", "uuid",
val allFiles = listOf("accounts", "calls", "config", "contacts", "messages", "uuid",
"zrtp_cache.dat", "zrtp_zid", "cert.pem", "ca_cert", "ca_certs.crt")
val zipFiles = mutableListOf<String>()
try {