- more chat related improvements

This commit is contained in:
Juha Heinanen
2019-03-13 05:58:32 +02:00
parent 63746216f1
commit e87333b305
9 changed files with 42 additions and 19 deletions
@@ -501,10 +501,11 @@ class BaresipService: Service() {
}
@Keep
fun messageResponse(responseCode: Int, time: String) {
Log.d(LOG_TAG, "Message response $responseCode at $time")
fun messageResponse(responseCode: Int, responseReason: String, time: String) {
Log.d(LOG_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)
}
@@ -118,23 +118,27 @@ class ChatActivity : AppCompatActivity() {
if (msgText.length > 0) {
imm.hideSoftInputFromWindow(newMessage.windowToken, 0)
val time = System.currentTimeMillis()
val msg = Message(aor, peerUri, R.drawable.arrow_up_yellow, msgText, time, true)
val msg = Message(aor, peerUri, msgText, time, R.drawable.arrow_up_yellow,
0, "", true)
Message.add(msg)
chatMessages.add(msg)
mlAdapter.notifyDataSetChanged()
if (Api.message_send(ua.uap, peerUri, msgText, time.toString()) != 0) {
Toast.makeText(getApplicationContext(), "Sending of message failed!",
Toast.LENGTH_SHORT).show()
msg.direction = R.drawable.arrow_up_red
msg.responseReason = "Sending of message failed"
} else {
newMessage.text.clear()
BaresipService.chatTexts.remove("$aor::$peerUri")
}
mlAdapter.notifyDataSetChanged()
}
}
messageResponseReceiver = object : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
handleMessageResponse(intent.getIntExtra("response code", 0),
intent.getStringExtra("response reason"),
intent.getStringExtra("time"))
}
}
@@ -208,14 +212,17 @@ class ChatActivity : AppCompatActivity() {
return res
}
private fun handleMessageResponse(responseCode: Int, time: String) {
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)
if (responseCode < 300) {
m.direction = R.drawable.arrow_up_green
else
} else {
m.direction = R.drawable.arrow_up_red
m.responseCode = responseCode
m.responseReason = responseReason
}
mlAdapter.notifyDataSetChanged()
return
}
@@ -56,7 +56,11 @@ class ChatListAdapter(private val cxt: Context, private var rows: ArrayList<Mess
if (info.length < 6) info = "Today $info"
infoView.text = "$info - $sender"
if (message.direction == R.drawable.arrow_up_red) {
infoView.text = "${infoView.text} - Message Delivery Failed"
if (message.responseCode != 0)
infoView.text = "${infoView.text} - Failed: ${message.responseCode} " +
"${message.responseReason}"
else
infoView.text = "${infoView.text} - Sending of message failed!"
infoView.setTextColor(ContextCompat.getColor(cxt, R.color.colorAccent))
}
val textView = chatView.findViewById(R.id.text) as TextView
@@ -650,8 +650,9 @@ class MainActivity : AppCompatActivity() {
val msgText = params[2]
val time = params[3]
Log.d("Baresip", "Incoming message $aor/$peerUri/$msgText")
Message.add(Message(aor, peerUri, R.drawable.arrow_down_green, msgText,
time.toLong(), true))
Message.add(Message(aor, peerUri, msgText, time.toLong(),
R.drawable.arrow_down_green, 0, "",
true))
if (Utils.isVisible()) {
if ((aorSpinner.selectedItemPosition == -1) ||
(ua != UserAgent.uas()[aorSpinner.selectedItemPosition]))
@@ -3,8 +3,9 @@ package com.tutpro.baresip
import java.io.*
import java.util.ArrayList
class Message(val aor: String, val peerUri: String, var direction: Int, val message: String,
val timeStamp: Long, var new: Boolean): Serializable {
class Message(val aor: String, val peerUri: String, val message: String, val timeStamp: Long,
var direction: Int, var responseCode: Int, var responseReason: String,
var new: Boolean): Serializable {
companion object {
@@ -54,7 +54,11 @@ class MessageListAdapter(private val cxt: Context, private val rows: ArrayList<M
if (info.length < 6) info = "Today $info"
infoView.text = "$info - $peer"
if (message.direction == R.drawable.arrow_up_red) {
infoView.text = "${infoView.text} - Message Delivery Failed"
if (message.responseCode != 0)
infoView.text = "${infoView.text} - Failed: ${message.responseCode} " +
"${message.responseReason}"
else
infoView.text = "${infoView.text} - Sending of message failed!"
infoView.setTextColor(ContextCompat.getColor(cxt, R.color.colorAccent))
}
val textView = messageView.findViewById(R.id.text) as TextView