- fixed callee completion from contacts
- moved restoring of call and message history from baresip service to main activity - small cleanups
This commit is contained in:
@@ -5,5 +5,7 @@ object Api {
|
||||
external fun audio_codecs(): String
|
||||
external fun call_peeruri(callp: String): String
|
||||
external fun cmd_exec(cmd: String): Int
|
||||
external fun contact_add(contact: String)
|
||||
external fun contacts_remove()
|
||||
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ class BaresipService: Service() {
|
||||
}
|
||||
|
||||
val pm = getSystemService(Context.POWER_SERVICE) as PowerManager
|
||||
wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Baresip")
|
||||
wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "com.tutpro.baresip:wakelog")
|
||||
|
||||
/* if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
val intent = Intent()
|
||||
@@ -145,38 +145,6 @@ class BaresipService: Service() {
|
||||
}
|
||||
}
|
||||
|
||||
file = File(path, "history")
|
||||
if (file.exists()) {
|
||||
try {
|
||||
val fis = FileInputStream(file)
|
||||
val ois = ObjectInputStream(fis)
|
||||
@SuppressWarnings("unchecked")
|
||||
MainActivity.history = ois.readObject() as ArrayList<CallHistory>
|
||||
Log.d(LOG_TAG, "Restored History of ${MainActivity.history.size} entries")
|
||||
ois.close()
|
||||
fis.close()
|
||||
} catch (e: Exception) {
|
||||
Log.w(LOG_TAG, "InputStream exception: - " + e.toString())
|
||||
}
|
||||
}
|
||||
|
||||
file = File(path, "messages")
|
||||
if (file.exists()) {
|
||||
try {
|
||||
val fis = FileInputStream(file)
|
||||
val ois = ObjectInputStream(fis)
|
||||
@SuppressWarnings("unchecked")
|
||||
MainActivity.messages = ois.readObject() as ArrayList<Message>
|
||||
Log.d(LOG_TAG, "Restored ${MainActivity.messages.size} messages")
|
||||
ois.close()
|
||||
fis.close()
|
||||
} catch (e: Exception) {
|
||||
Log.w(LOG_TAG, "InputStream exception: - " + e.toString())
|
||||
}
|
||||
}
|
||||
|
||||
ContactsActivity.generateContacts(path + "/contacts")
|
||||
|
||||
wl.acquire()
|
||||
Thread(Runnable { baresipStart(path) }).start()
|
||||
BaresipService.IS_SERVICE_RUNNING = true
|
||||
@@ -492,6 +460,7 @@ class BaresipService: Service() {
|
||||
}
|
||||
|
||||
init {
|
||||
Log.d(LOG_TAG, "Loading baresip library")
|
||||
System.loadLibrary("baresip")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,5 +35,4 @@ class CallHistory(val aor: String, val peerURI: String, val direction: String,
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -11,8 +11,10 @@ import android.view.MenuItem
|
||||
import android.widget.AdapterView
|
||||
import android.widget.ListView
|
||||
import java.io.File
|
||||
import java.io.FileInputStream
|
||||
import java.io.FileOutputStream
|
||||
import java.io.IOException
|
||||
import java.io.ObjectInputStream
|
||||
import java.io.ObjectOutputStream
|
||||
|
||||
import java.text.SimpleDateFormat
|
||||
@@ -163,5 +165,23 @@ class CallsActivity : AppCompatActivity() {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
fun restoreHistory(path: String) {
|
||||
val file = File(path + "/history")
|
||||
if (file.exists()) {
|
||||
try {
|
||||
val fis = FileInputStream(file)
|
||||
val ois = ObjectInputStream(fis)
|
||||
@SuppressWarnings("unchecked")
|
||||
MainActivity.history = ois.readObject() as ArrayList<CallHistory>
|
||||
Log.d("Baresip", "Restored History of ${MainActivity.history.size} entries")
|
||||
ois.close()
|
||||
fis.close()
|
||||
} catch (e: Exception) {
|
||||
Log.w("Baresip", "InputStream exception: - " + e.toString())
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,30 +91,30 @@ class ContactsActivity : AppCompatActivity() {
|
||||
|
||||
var contacts = ArrayList<Contact>()
|
||||
|
||||
fun generateContacts(path: String) {
|
||||
val content = Utils.getFileContents(File(path))
|
||||
contacts_remove()
|
||||
fun saveContacts() {
|
||||
var contents = ""
|
||||
for (c in contacts)
|
||||
contents += "\"${c.name}\" ${c.uri}\n"
|
||||
val path = MainActivity.filesPath + "/contacts"
|
||||
Utils.putFileContents(File(path), contents)
|
||||
Log.d("Baresip", "Saved contacts '${contents}' to '$path")
|
||||
}
|
||||
|
||||
fun restoreContacts(path: String) {
|
||||
val content = Utils.getFileContents(File(path + "/contacts"))
|
||||
Api.contacts_remove()
|
||||
contacts.clear()
|
||||
content.lines().forEach {
|
||||
val parts = it.split("\"")
|
||||
if (parts.size == 3) {
|
||||
val name = parts[1]
|
||||
val uri = parts[2].trim()
|
||||
contact_add("\"$name\" $uri")
|
||||
Api.contact_add("\"$name\" $uri")
|
||||
contacts.add(Contact(name, uri))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun saveContacts() {
|
||||
var contents = ""
|
||||
for (c in contacts)
|
||||
contents += "\"${c.name}\" ${c.uri}\n"
|
||||
val path = MainActivity.filesPath + "/contacts"
|
||||
Utils.putFileContents(File(path), contents)
|
||||
Log.d("Baresip", "Saved contacts '${contents}' to '$path")
|
||||
}
|
||||
|
||||
fun findContactURI(name: String): String {
|
||||
for (c in contacts)
|
||||
if (c.name == name)
|
||||
@@ -137,10 +137,5 @@ class ContactsActivity : AppCompatActivity() {
|
||||
return c.name
|
||||
return uri
|
||||
}
|
||||
|
||||
external fun contacts_remove()
|
||||
external fun contact_add(contact: String)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -165,6 +165,11 @@ class MainActivity : AppCompatActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
callUri.threshold = 2
|
||||
ContactsActivity.restoreContacts(applicationContext.filesDir.path)
|
||||
callUri.setAdapter(ArrayAdapter(this, android.R.layout.select_dialog_item,
|
||||
ContactsActivity.contacts.map{Contact -> Contact.name}))
|
||||
|
||||
securityButton.setOnClickListener {
|
||||
when (securityButton.tag) {
|
||||
"red" -> {
|
||||
@@ -318,6 +323,7 @@ class MainActivity : AppCompatActivity() {
|
||||
startActivityForResult(i, CONTACTS_CODE)
|
||||
}
|
||||
|
||||
MessagesActivity.restoreMessages(applicationContext.filesDir.path)
|
||||
messagesButton.setOnClickListener {
|
||||
if (aorSpinner.selectedItemPosition >= 0) {
|
||||
val i = Intent(this@MainActivity, MessagesActivity::class.java)
|
||||
@@ -328,6 +334,7 @@ class MainActivity : AppCompatActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
CallsActivity.restoreHistory(applicationContext.filesDir.path)
|
||||
callsButton.setOnClickListener {
|
||||
if (aorSpinner.selectedItemPosition >= 0) {
|
||||
val i = Intent(this@MainActivity, CallsActivity::class.java)
|
||||
@@ -344,10 +351,6 @@ class MainActivity : AppCompatActivity() {
|
||||
startService(baresipService)
|
||||
}
|
||||
|
||||
callUri.threshold = 2
|
||||
callUri.setAdapter(ArrayAdapter(this, android.R.layout.select_dialog_item,
|
||||
ContactsActivity.contacts.map { Contact -> Contact.name }))
|
||||
|
||||
if (intent.hasExtra("onStartup"))
|
||||
moveTaskToBack(true)
|
||||
|
||||
@@ -833,7 +836,6 @@ class MainActivity : AppCompatActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
|
||||
when (requestCode) {
|
||||
@@ -1148,4 +1150,9 @@ class MainActivity : AppCompatActivity() {
|
||||
const val ONE_CALL_ONLY = true
|
||||
|
||||
}
|
||||
|
||||
init {
|
||||
Log.d("Baresip", "Loading baresip library")
|
||||
System.loadLibrary("baresip")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,8 +13,10 @@ import android.widget.ImageButton
|
||||
import android.widget.ListView
|
||||
|
||||
import java.io.File
|
||||
import java.io.FileInputStream
|
||||
import java.io.FileOutputStream
|
||||
import java.io.IOException
|
||||
import java.io.ObjectInputStream
|
||||
import java.io.ObjectOutputStream
|
||||
import java.util.*
|
||||
|
||||
@@ -221,5 +223,22 @@ class MessagesActivity: AppCompatActivity() {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
fun restoreMessages(path: String) {
|
||||
val file = File(path, "messages")
|
||||
if (file.exists()) {
|
||||
try {
|
||||
val fis = FileInputStream(file)
|
||||
val ois = ObjectInputStream(fis)
|
||||
@SuppressWarnings("unchecked")
|
||||
MainActivity.messages = ois.readObject() as ArrayList<Message>
|
||||
Log.d("Baresip", "Restored ${MainActivity.messages.size} messages")
|
||||
ois.close()
|
||||
fis.close()
|
||||
} catch (e: Exception) {
|
||||
Log.w("Baresip", "InputStream exception: - " + e.toString())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,5 +58,4 @@ class UserAgent (val uap: String) {
|
||||
}
|
||||
|
||||
external fun ua_account(ua: String): String
|
||||
external fun ua_aor(ua: String): String
|
||||
|
||||
|
||||
Reference in New Issue
Block a user