Use constants for message directions

This commit is contained in:
Juha Heinanen
2023-04-03 11:35:35 +03:00
parent 111ae9a3ad
commit 7f9003413b
10 changed files with 18 additions and 13 deletions
@@ -997,8 +997,7 @@ class BaresipService: Service() {
val timeStamp = System.currentTimeMillis() val timeStamp = System.currentTimeMillis()
val timeStampString = timeStamp.toString() val timeStampString = timeStamp.toString()
Log.d(TAG, "Message event for $uap from $peerUri at $timeStampString") Log.d(TAG, "Message event for $uap from $peerUri at $timeStampString")
Message(ua.account.aor, peerUri, text, timeStamp, Message(ua.account.aor, peerUri, text, timeStamp, MESSAGE_DOWN, 0, "", true).add()
R.drawable.arrow_down_green, 0, "", true).add()
Message.save() Message.save()
ua.account.unreadMessages = true ua.account.unreadMessages = true
if (!Utils.isVisible()) { if (!Utils.isVisible()) {
@@ -1068,9 +1067,9 @@ class BaresipService: Service() {
for (m in messages.reversed()) for (m in messages.reversed())
if (m.timeStamp == timeStamp) { if (m.timeStamp == timeStamp) {
if (responseCode < 300) { if (responseCode < 300) {
m.direction = R.drawable.arrow_up_green m.direction = MESSAGE_UP
} else { } else {
m.direction = R.drawable.arrow_up_red m.direction = MESSAGE_UP_FAIL
m.responseCode = responseCode m.responseCode = responseCode
m.responseReason = responseReason m.responseReason = responseReason
} }
@@ -118,8 +118,7 @@ class ChatActivity : AppCompatActivity() {
if (msgText.isNotEmpty()) { if (msgText.isNotEmpty()) {
imm.hideSoftInputFromWindow(newMessage.windowToken, 0) imm.hideSoftInputFromWindow(newMessage.windowToken, 0)
val time = System.currentTimeMillis() val time = System.currentTimeMillis()
val msg = Message(aor, peerUri, msgText, time, R.drawable.arrow_up_yellow, val msg = Message(aor, peerUri, msgText, time, MESSAGE_UP_WAIT, 0, "", true)
0, "", true)
msg.add() msg.add()
var msgUri = "" var msgUri = ""
chatMessages.add(msg) chatMessages.add(msg)
@@ -137,7 +136,7 @@ class ChatActivity : AppCompatActivity() {
if (Api.message_send(ua.uap, msgUri, msgText, time.toString()) != 0) { if (Api.message_send(ua.uap, msgUri, msgText, time.toString()) != 0) {
Toast.makeText(applicationContext, "${getString(R.string.message_failed)}!", Toast.makeText(applicationContext, "${getString(R.string.message_failed)}!",
Toast.LENGTH_SHORT).show() Toast.LENGTH_SHORT).show()
msg.direction = R.drawable.arrow_up_red msg.direction = MESSAGE_UP_FAIL
msg.responseReason = getString(R.string.message_failed) msg.responseReason = getString(R.string.message_failed)
} else { } else {
newMessage.text.clear() newMessage.text.clear()
@@ -51,8 +51,7 @@ class ChatListAdapter(private val ctx: Context, private val account: Account, pr
else else
message.peerUri) message.peerUri)
if ((message.direction == R.drawable.arrow_down_green) || if (message.direction == MESSAGE_DOWN)
(message.direction == R.drawable.arrow_down_red))
viewHolder.layoutView.setBackgroundResource(R.drawable.message_in_bg) viewHolder.layoutView.setBackgroundResource(R.drawable.message_in_bg)
else else
viewHolder.layoutView.setBackgroundResource(R.drawable.message_out_bg) viewHolder.layoutView.setBackgroundResource(R.drawable.message_out_bg)
@@ -64,7 +63,7 @@ class ChatListAdapter(private val ctx: Context, private val account: Account, pr
else else
DateFormat.getDateInstance(DateFormat.SHORT) DateFormat.getDateInstance(DateFormat.SHORT)
viewHolder.infoView.text = fmt.format(cal.time) viewHolder.infoView.text = fmt.format(cal.time)
if (message.direction == R.drawable.arrow_up_red) { if (message.direction == MESSAGE_UP_FAIL) {
val info: String = if (message.responseCode != 0) val info: String = if (message.responseCode != 0)
"${viewHolder.infoView.text} - ${ctx.getString(R.string.message_failed)}: " + "${viewHolder.infoView.text} - ${ctx.getString(R.string.message_failed)}: " +
"${message.responseCode} ${message.responseReason}" "${message.responseCode} ${message.responseReason}"
@@ -29,3 +29,12 @@ const val DELETE_REQ_CODE = 11
const val REGISTRATION_INTERVAL = 900 const val REGISTRATION_INTERVAL = 900
const val NO_AUTH_PASS = "t%Qa?~?J8,~6" const val NO_AUTH_PASS = "t%Qa?~?J8,~6"
const val MESSAGE_DOWN = 2131165304
const val MESSAGE_UP = 2131165306
const val MESSAGE_UP_FAIL = 2131165307
const val MESSAGE_UP_WAIT = 2131165308
@@ -94,8 +94,7 @@ class MessageListAdapter(private val ctx: Context, private val peerUri: String,
val message = rows[position] val message = rows[position]
val down = (message.direction == R.drawable.arrow_down_green) || val down = message.direction == MESSAGE_DOWN
(message.direction == R.drawable.arrow_down_red)
val lp = viewHolder.layoutView.layoutParams as LinearLayout.LayoutParams val lp = viewHolder.layoutView.layoutParams as LinearLayout.LayoutParams
val peer: String = if (down) { val peer: String = if (down) {
lp.setMargins(0, 10, 75, 10) lp.setMargins(0, 10, 75, 10)
@@ -123,7 +122,7 @@ class MessageListAdapter(private val ctx: Context, private val peerUri: String,
info = fmt.format(cal.time) info = fmt.format(cal.time)
if (info.length < 6) info = "${ctx.getString(R.string.today)} $info" if (info.length < 6) info = "${ctx.getString(R.string.today)} $info"
info = "$info - $peer" info = "$info - $peer"
if (message.direction == R.drawable.arrow_up_red) { if (message.direction == MESSAGE_UP_FAIL) {
info = if (message.responseCode != 0) info = if (message.responseCode != 0)
"$info - ${ctx.getString(R.string.message_failed)}: " + "${message.responseCode} ${message.responseReason}" "$info - ${ctx.getString(R.string.message_failed)}: " + "${message.responseCode} ${message.responseReason}"
else else
Binary file not shown.

Before

Width:  |  Height:  |  Size: 351 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 305 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 320 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 286 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 297 B