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

View File

@ -997,8 +997,7 @@ class BaresipService: Service() {
val timeStamp = System.currentTimeMillis()
val timeStampString = timeStamp.toString()
Log.d(TAG, "Message event for $uap from $peerUri at $timeStampString")
Message(ua.account.aor, peerUri, text, timeStamp,
R.drawable.arrow_down_green, 0, "", true).add()
Message(ua.account.aor, peerUri, text, timeStamp, MESSAGE_DOWN, 0, "", true).add()
Message.save()
ua.account.unreadMessages = true
if (!Utils.isVisible()) {
@ -1068,9 +1067,9 @@ class BaresipService: Service() {
for (m in messages.reversed())
if (m.timeStamp == timeStamp) {
if (responseCode < 300) {
m.direction = R.drawable.arrow_up_green
m.direction = MESSAGE_UP
} else {
m.direction = R.drawable.arrow_up_red
m.direction = MESSAGE_UP_FAIL
m.responseCode = responseCode
m.responseReason = responseReason
}

View File

@ -118,8 +118,7 @@ class ChatActivity : AppCompatActivity() {
if (msgText.isNotEmpty()) {
imm.hideSoftInputFromWindow(newMessage.windowToken, 0)
val time = System.currentTimeMillis()
val msg = Message(aor, peerUri, msgText, time, R.drawable.arrow_up_yellow,
0, "", true)
val msg = Message(aor, peerUri, msgText, time, MESSAGE_UP_WAIT, 0, "", true)
msg.add()
var msgUri = ""
chatMessages.add(msg)
@ -137,7 +136,7 @@ class ChatActivity : AppCompatActivity() {
if (Api.message_send(ua.uap, msgUri, msgText, time.toString()) != 0) {
Toast.makeText(applicationContext, "${getString(R.string.message_failed)}!",
Toast.LENGTH_SHORT).show()
msg.direction = R.drawable.arrow_up_red
msg.direction = MESSAGE_UP_FAIL
msg.responseReason = getString(R.string.message_failed)
} else {
newMessage.text.clear()

View File

@ -51,8 +51,7 @@ class ChatListAdapter(private val ctx: Context, private val account: Account, pr
else
message.peerUri)
if ((message.direction == R.drawable.arrow_down_green) ||
(message.direction == R.drawable.arrow_down_red))
if (message.direction == MESSAGE_DOWN)
viewHolder.layoutView.setBackgroundResource(R.drawable.message_in_bg)
else
viewHolder.layoutView.setBackgroundResource(R.drawable.message_out_bg)
@ -64,7 +63,7 @@ class ChatListAdapter(private val ctx: Context, private val account: Account, pr
else
DateFormat.getDateInstance(DateFormat.SHORT)
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)
"${viewHolder.infoView.text} - ${ctx.getString(R.string.message_failed)}: " +
"${message.responseCode} ${message.responseReason}"

View File

@ -29,3 +29,12 @@ const val DELETE_REQ_CODE = 11
const val REGISTRATION_INTERVAL = 900
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

View File

@ -94,8 +94,7 @@ class MessageListAdapter(private val ctx: Context, private val peerUri: String,
val message = rows[position]
val down = (message.direction == R.drawable.arrow_down_green) ||
(message.direction == R.drawable.arrow_down_red)
val down = message.direction == MESSAGE_DOWN
val lp = viewHolder.layoutView.layoutParams as LinearLayout.LayoutParams
val peer: String = if (down) {
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)
if (info.length < 6) info = "${ctx.getString(R.string.today)} $info"
info = "$info - $peer"
if (message.direction == R.drawable.arrow_up_red) {
if (message.direction == MESSAGE_UP_FAIL) {
info = if (message.responseCode != 0)
"$info - ${ctx.getString(R.string.message_failed)}: " + "${message.responseCode} ${message.responseReason}"
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