Backported chat crash fixes and code improvements from video branch.
This commit is contained in:
@ -785,8 +785,8 @@ class BaresipService: Service() {
|
||||
}
|
||||
val timeStamp = System.currentTimeMillis().toString()
|
||||
Log.d(LOG_TAG, "Message event for $uap from $peer at $timeStamp")
|
||||
Message.add(Message(ua.account.aor, peer, text, timeStamp.toLong(),
|
||||
R.drawable.arrow_down_green, 0, "", true))
|
||||
Message(ua.account.aor, peer, text, timeStamp.toLong(),
|
||||
R.drawable.arrow_down_green, 0, "", true).add()
|
||||
Message.save()
|
||||
ua.account.unreadMessages = true
|
||||
if (!Utils.isVisible()) {
|
||||
|
||||
@ -137,7 +137,7 @@ class ChatActivity : AppCompatActivity() {
|
||||
val time = System.currentTimeMillis()
|
||||
val msg = Message(aor, peerUri, msgText, time, R.drawable.arrow_up_yellow,
|
||||
0, "", true)
|
||||
Message.add(msg)
|
||||
msg.add()
|
||||
chatMessages.add(msg)
|
||||
if (Api.message_send(ua.uap, peerUri, msgText, time.toString()) != 0) {
|
||||
Toast.makeText(getApplicationContext(), "${getString(R.string.message_failed)}!",
|
||||
@ -159,6 +159,7 @@ class ChatActivity : AppCompatActivity() {
|
||||
intent.getStringExtra("time")!!)
|
||||
}
|
||||
}
|
||||
|
||||
LocalBroadcastManager.getInstance(this).registerReceiver(messageResponseReceiver,
|
||||
IntentFilter("message response"))
|
||||
|
||||
@ -177,12 +178,13 @@ class ChatActivity : AppCompatActivity() {
|
||||
BaresipService.chatTexts.put("$aor::$peerUri", newMessage.text.toString())
|
||||
}
|
||||
MainActivity.activityAor = aor
|
||||
LocalBroadcastManager.getInstance(this).unregisterReceiver(messageResponseReceiver)
|
||||
super.onPause()
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
val chatText = BaresipService.chatTexts.get("$aor::$peerUri")
|
||||
val chatText = BaresipService.chatTexts["$aor::$peerUri"]
|
||||
if (chatText != null) {
|
||||
Log.d("Baresip", "Restoring newMessage ${newMessage.text} for $aor::$peerUri")
|
||||
newMessage.setText(chatText)
|
||||
@ -195,11 +197,6 @@ class ChatActivity : AppCompatActivity() {
|
||||
listView.adapter = mlAdapter
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
LocalBroadcastManager.getInstance(this).unregisterReceiver(messageResponseReceiver)
|
||||
super.onDestroy()
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
|
||||
if ((BaresipService.activities.indexOf("chat,$aor,$peerUri,false") == -1) &&
|
||||
|
||||
@ -73,14 +73,5 @@ class Contact(var name: String, var uri: String, var color: Int, val id: Long) {
|
||||
return true
|
||||
}
|
||||
|
||||
fun import(): Boolean {
|
||||
val contacts = Utils.getFileContents(BaresipService.downloadsPath + "/contacts.bs")
|
||||
if (contacts != null) {
|
||||
Utils.putFileContents(BaresipService.filesPath + "/contacts", contacts)
|
||||
return restore()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -614,8 +614,8 @@ class MainActivity : AppCompatActivity() {
|
||||
}
|
||||
val ev = event.split(",")
|
||||
Log.d("Baresip", "Handling service event '${ev[0]}' for $uap")
|
||||
val aor = ua.account.aor
|
||||
val acc = ua.account
|
||||
val aor = ua.account.aor
|
||||
for (account_index in UserAgent.uas().indices) {
|
||||
if (UserAgent.uas()[account_index].account.aor == aor) {
|
||||
when (ev[0]) {
|
||||
@ -640,7 +640,7 @@ class MainActivity : AppCompatActivity() {
|
||||
volumeControlStream = AudioManager.STREAM_VOICE_CALL
|
||||
}
|
||||
"call rejected" -> {
|
||||
if (ua.account.aor == aorSpinner.tag) {
|
||||
if (aor == aorSpinner.tag) {
|
||||
callsButton.setImageResource(R.drawable.calls_missed)
|
||||
}
|
||||
}
|
||||
@ -652,8 +652,8 @@ class MainActivity : AppCompatActivity() {
|
||||
}
|
||||
volumeControlStream = AudioManager.STREAM_RING
|
||||
if (visible) {
|
||||
if (ua.account.aor != aorSpinner.tag)
|
||||
spinToAor(ua.account.aor)
|
||||
if (aor != aorSpinner.tag)
|
||||
spinToAor(aor)
|
||||
showCall(ua)
|
||||
} else {
|
||||
Log.d("Baresip", "Reordering to front")
|
||||
@ -666,7 +666,7 @@ class MainActivity : AppCompatActivity() {
|
||||
}
|
||||
"call established" -> {
|
||||
volumeControlStream = AudioManager.STREAM_VOICE_CALL
|
||||
if (ua.account.aor == aorSpinner.tag) {
|
||||
if (aor == aorSpinner.tag) {
|
||||
dtmf.setText("")
|
||||
dtmf.hint = getString(R.string.dtmf)
|
||||
showCall(ua)
|
||||
@ -693,7 +693,7 @@ class MainActivity : AppCompatActivity() {
|
||||
}
|
||||
call.security = security
|
||||
call.zid = ev[3]
|
||||
if (ua.account.aor == aorSpinner.tag) {
|
||||
if (aor == aorSpinner.tag) {
|
||||
securityButton.setImageResource(security)
|
||||
setSecurityButtonTag(securityButton, security)
|
||||
securityButton.visibility = View.VISIBLE
|
||||
@ -703,7 +703,7 @@ class MainActivity : AppCompatActivity() {
|
||||
verifyDialog.setNegativeButton(getString(R.string.no)) { dialog, _ ->
|
||||
call.security = R.drawable.box_yellow
|
||||
call.zid = ev[3]
|
||||
if (ua.account.aor == aorSpinner.tag) {
|
||||
if (aor == aorSpinner.tag) {
|
||||
securityButton.setImageResource(R.drawable.box_yellow)
|
||||
securityButton.tag = "yellow"
|
||||
securityButton.visibility = View.VISIBLE
|
||||
@ -724,7 +724,7 @@ class MainActivity : AppCompatActivity() {
|
||||
tag = "yellow"
|
||||
else
|
||||
tag = "green"
|
||||
if (ua.account.aor == aorSpinner.tag) {
|
||||
if (aor == aorSpinner.tag) {
|
||||
securityButton.setImageResource(call.security)
|
||||
securityButton.tag = tag
|
||||
}
|
||||
@ -768,9 +768,9 @@ class MainActivity : AppCompatActivity() {
|
||||
showCall(ua)
|
||||
}
|
||||
"call closed" -> {
|
||||
if (ua.account.aor == aorSpinner.tag) {
|
||||
if (aor == aorSpinner.tag) {
|
||||
showCall(ua)
|
||||
if (ua.account.missedCalls)
|
||||
if (acc.missedCalls)
|
||||
callsButton.setImageResource(R.drawable.calls_missed)
|
||||
}
|
||||
speakerIcon.setIcon(R.drawable.speaker_off)
|
||||
@ -811,7 +811,7 @@ class MainActivity : AppCompatActivity() {
|
||||
break
|
||||
}
|
||||
}
|
||||
if (ua.account.aor == aorSpinner.tag) {
|
||||
if (aor == aorSpinner.tag) {
|
||||
if (acc.vmNew > 0)
|
||||
voicemailButton.setImageResource(R.drawable.voicemail_new)
|
||||
else
|
||||
@ -1433,7 +1433,7 @@ class MainActivity : AppCompatActivity() {
|
||||
val b = Bundle()
|
||||
b.putString("aor", activity[1])
|
||||
b.putString("peer", activity[2])
|
||||
b.putString("focus", activity[3])
|
||||
b.putBoolean("focus", activity[3] == "true")
|
||||
i.putExtras(b)
|
||||
startActivityForResult(i, CHAT_CODE)
|
||||
}
|
||||
|
||||
@ -7,6 +7,22 @@ class Message(val aor: String, val peerUri: String, val message: String, val tim
|
||||
var direction: Int, var responseCode: Int, var responseReason: String,
|
||||
var new: Boolean): Serializable {
|
||||
|
||||
fun add() {
|
||||
BaresipService.messages.add(this)
|
||||
var count = 0
|
||||
var firstIndex = -1
|
||||
for (i in BaresipService.messages.indices)
|
||||
if (BaresipService.messages[i].aor == this.aor) {
|
||||
if (count == 0) firstIndex = i
|
||||
count++
|
||||
if (count > MESSAGE_HISTORY_SIZE) {
|
||||
break
|
||||
}
|
||||
}
|
||||
if (count > MESSAGE_HISTORY_SIZE)
|
||||
BaresipService.messages.removeAt(firstIndex)
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
val MESSAGE_HISTORY_SIZE = 100
|
||||
@ -15,22 +31,6 @@ class Message(val aor: String, val peerUri: String, val message: String, val tim
|
||||
return BaresipService.messages
|
||||
}
|
||||
|
||||
fun add(message: Message) {
|
||||
BaresipService.messages.add(message)
|
||||
var count = 0
|
||||
var firstIndex = -1
|
||||
for (i in BaresipService.messages.indices)
|
||||
if (BaresipService.messages[i].aor == message.aor) {
|
||||
if (count == 0) firstIndex = i
|
||||
count++
|
||||
if (count > MESSAGE_HISTORY_SIZE) {
|
||||
break
|
||||
}
|
||||
}
|
||||
if (count > MESSAGE_HISTORY_SIZE)
|
||||
BaresipService.messages.removeAt(firstIndex)
|
||||
}
|
||||
|
||||
fun clear(aor: String) {
|
||||
val it = BaresipService.messages.iterator()
|
||||
while (it.hasNext()) if (it.next().aor == aor) it.remove()
|
||||
|
||||
Reference in New Issue
Block a user