- 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

View File

@ -239,13 +239,16 @@ static void message_handler(struct ua *ua, const struct pl *peer, const struct p
static void send_resp_handler(int err, const struct sip_msg *msg, void *arg)
{
(void)arg;
char reason_buf[64];
if (err) {
LOGD("send_response_handler received error %d\n", err);
return;
}
LOGD("send_response_handler received response %u at %s\n", msg->scode, (char *)arg);
pl_strcpy(&(msg->reason), reason_buf, 64);
LOGD("send_response_handler received response '%u %s' at %s\n", msg->scode,
reason_buf, (char *)arg);
BaresipContext *pctx = (BaresipContext*)(&g_ctx);
JavaVM *javaVM = pctx->javaVM;
@ -259,11 +262,13 @@ static void send_resp_handler(int err, const struct sip_msg *msg, void *arg)
}
}
jmethodID methodId = (*env)->GetMethodID(env, pctx->mainActivityClz,
"messageResponse", "(ILjava/lang/String;)V");
"messageResponse",
"(ILjava/lang/String;Ljava/lang/String;)V");
jstring javaReason = (*env)->NewStringUTF(env, reason_buf);
jstring javaTime = (*env)->NewStringUTF(env, (char *)arg);
(*env)->CallVoidMethod(env, pctx->mainActivityObj, methodId, msg->scode, javaTime);
(*env)->CallVoidMethod(env, pctx->mainActivityObj, methodId, msg->scode, javaReason, javaTime);
(*env)->DeleteLocalRef(env, javaReason);
(*env)->DeleteLocalRef(env, javaTime);
}
enum {

View File

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

View File

@ -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
}

View File

@ -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

View File

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

View File

@ -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 {

View File

@ -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

View File

@ -3,7 +3,7 @@
<item>
<shape android:shape="rectangle">
<solid android:color="@color/colorSecondaryLight"/>
<solid android:color="@color/colorGrayLight"/>
<corners android:radius="10dp"/>
</shape>
</item>

View File

@ -7,6 +7,6 @@
<color name="colorSecondaryDark">#1c9588</color>
<color name="colorSecondaryLight">#93d3cd</color>
<color name="colorGray">#9e9e9e</color>
<color name="colorGrayLight">#eeeeee</color>
<color name="colorGrayLight">#e0e0e0</color>
<color name="colorAccent">#b00020</color>
</resources>