Handle message rerponse already in baresip service

This commit is contained in:
Juha Heinanen
2022-01-25 10:23:53 +02:00
parent 21c7e6f8b2
commit 29fff4fa13
2 changed files with 20 additions and 24 deletions

View File

@ -960,11 +960,25 @@ class BaresipService: Service() {
@Suppress("UNUSED")
fun messageResponse(responseCode: Int, responseReason: String, time: String) {
Log.d(TAG, "Message response '$responseCode $responseReason' at $time")
val intent = Intent("message response")
intent.putExtra("response code", responseCode)
intent.putExtra("response reason", responseReason)
intent.putExtra("time", time)
LocalBroadcastManager.getInstance(this).sendBroadcast(intent)
val timeStamp = time.toLong()
for (m in messages.reversed())
if (m.timeStamp == timeStamp) {
if (responseCode < 300) {
m.direction = R.drawable.arrow_up_green
} else {
m.direction = R.drawable.arrow_up_red
m.responseCode = responseCode
m.responseReason = responseReason
}
break
}
if (Utils.isVisible()) {
val intent = Intent("message response")
intent.putExtra("response code", responseCode)
intent.putExtra("response reason", responseReason)
intent.putExtra("time", time)
LocalBroadcastManager.getInstance(this).sendBroadcast(intent)
}
}
@Keep

View File

@ -161,9 +161,7 @@ class ChatActivity : AppCompatActivity() {
messageResponseReceiver = object : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
handleMessageResponse(intent.getIntExtra("response code", 0),
intent.getStringExtra("response reason")!!,
intent.getStringExtra("time")!!)
mlAdapter.notifyDataSetChanged()
}
}
@ -274,20 +272,4 @@ class ChatActivity : AppCompatActivity() {
return res
}
private fun handleMessageResponse(responseCode: Int, responseReason: String, time: String) {
val timeStamp = time.toLong()
for (m in chatMessages.reversed())
if (m.timeStamp == timeStamp) {
if (responseCode < 300) {
m.direction = R.drawable.arrow_up_green
} else {
m.direction = R.drawable.arrow_up_red
m.responseCode = responseCode
m.responseReason = responseReason
}
mlAdapter.notifyDataSetChanged()
return
}
}
}