From 7f9003413bf98fc2f66685a45cbdf71010e6e070 Mon Sep 17 00:00:00 2001 From: Juha Heinanen Date: Mon, 3 Apr 2023 11:35:35 +0300 Subject: [PATCH] Use constants for message directions --- .../kotlin/com/tutpro/baresip/BaresipService.kt | 7 +++---- .../kotlin/com/tutpro/baresip/ChatActivity.kt | 5 ++--- .../kotlin/com/tutpro/baresip/ChatListAdapter.kt | 5 ++--- .../main/kotlin/com/tutpro/baresip/Constants.kt | 9 +++++++++ .../com/tutpro/baresip/MessageListAdapter.kt | 5 ++--- app/src/main/res/drawable/arrow_down_green.png | Bin 351 -> 0 bytes app/src/main/res/drawable/arrow_down_red.png | Bin 305 -> 0 bytes app/src/main/res/drawable/arrow_up_green.png | Bin 320 -> 0 bytes app/src/main/res/drawable/arrow_up_red.png | Bin 286 -> 0 bytes app/src/main/res/drawable/arrow_up_yellow.png | Bin 297 -> 0 bytes 10 files changed, 18 insertions(+), 13 deletions(-) delete mode 100644 app/src/main/res/drawable/arrow_down_green.png delete mode 100644 app/src/main/res/drawable/arrow_down_red.png delete mode 100644 app/src/main/res/drawable/arrow_up_green.png delete mode 100644 app/src/main/res/drawable/arrow_up_red.png delete mode 100644 app/src/main/res/drawable/arrow_up_yellow.png diff --git a/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt b/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt index 9ed9138a..97b85bc0 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt @@ -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 } diff --git a/app/src/main/kotlin/com/tutpro/baresip/ChatActivity.kt b/app/src/main/kotlin/com/tutpro/baresip/ChatActivity.kt index 27752aa6..dd7c0682 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/ChatActivity.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/ChatActivity.kt @@ -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() diff --git a/app/src/main/kotlin/com/tutpro/baresip/ChatListAdapter.kt b/app/src/main/kotlin/com/tutpro/baresip/ChatListAdapter.kt index bd973a1e..08e9047f 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/ChatListAdapter.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/ChatListAdapter.kt @@ -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}" diff --git a/app/src/main/kotlin/com/tutpro/baresip/Constants.kt b/app/src/main/kotlin/com/tutpro/baresip/Constants.kt index 3521a99a..6fe896bd 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/Constants.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/Constants.kt @@ -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 + + + + diff --git a/app/src/main/kotlin/com/tutpro/baresip/MessageListAdapter.kt b/app/src/main/kotlin/com/tutpro/baresip/MessageListAdapter.kt index 8f7417b8..ef43070d 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/MessageListAdapter.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/MessageListAdapter.kt @@ -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 diff --git a/app/src/main/res/drawable/arrow_down_green.png b/app/src/main/res/drawable/arrow_down_green.png deleted file mode 100644 index b20c9a26365394fcd459220390d46f23b15aa0e9..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 351 zcmeAS@N?(olHy`uVBq!ia0vp^{6H+i!3HFQj;9L&DYhhUcNd2LAh=-f^2tCE&H|6f zVg?3oVGw3ym^DWND9B#o>Fdh=h*g%yK<~TbC1;?}8&4O<5R21qFK_f>b`&`FF}{gW zS}-uiAVFIz;?{d^4k6w3!tYY3VeP$UNAe{zBPJAepOku*!lk-@*mDPl;o4R zR?~9Xg@B7c%>jv~UgQu&X%Q~loCIBsOkHr80 diff --git a/app/src/main/res/drawable/arrow_down_red.png b/app/src/main/res/drawable/arrow_down_red.png deleted file mode 100644 index 04460b1a969eb79557f4dae0b50ca60616c54733..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 305 zcmeAS@N?(olHy`uVBq!ia0vp^{6H+i!3HFQj;9L&DYhhUcNd2LAh=-f^2tCE&H|6f zVg?3oVGw3ym^DWND9B#o>Fdh=h*g%yP)4nHQxi~VpQnpsh{fr*lMT5JIS9DUKiJTl zAu#1gn9_|3wu8(ZjQOd_$_Hn6_LiA7MIFyKj#7<`-B`Tq=G^VZ^XKyK=Wx`R!Q~`x zAvTAlFw{5Tuz5pRZ1V%@%=#PRVkIn{kKea9mEAlVRUqIpO}*)Ku_ue|!N3h#&B2W< zJJ&wr-d3Zn!LoSOMx$y4VIH1$+|$bT70guJerV>~Z+AZRE_i9=qH=?KUDM_VYBxA{ wy|>EJ*%5u*X+mAr$ulc2FRXub<)t+LJ)U@_rlonMK%X#py85}Sb4q9e0IdUXJpcdz diff --git a/app/src/main/res/drawable/arrow_up_green.png b/app/src/main/res/drawable/arrow_up_green.png deleted file mode 100644 index 84131c86756728b8c91e065d0eb7d1371ea83c78..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 320 zcmeAS@N?(olHy`uVBq!ia0vp^{6H+i!3HFQj;9L&DYhhUcNd2LAh=-f^2tCE&H|6f zVg?3oVGw3ym^DWND9B#o>Fdh=h*g$Ho2B*41&}dkJzX3_EKa|@XzRz6D8cf;T~S4> zE#fV!MT_XkvOg;K5|R@)EcnE6DX^&BmZjvjB>zL!Yi>f)NsT7?JQDU3xVV?k+++N{ z#$M8|b@P;o(<7z(XN0)!{ge5;=KR6$6$f6dnEl!4b>cqNud5fu$?!Z+y>`&}-p58U zy~0@0uil?-R?dt~5Nnio@$$JFdh=h*g$Hoqa>Wxt&0v)t)YnAr`0KPB!Fg3J`FSKgOi> z(q~2HUPkr>pAA}!1F9tbozheDI}Ag@`dXO{r2@AsESPlm&&?;fb({Vlexee=Vb=6R zdWVQdKp$&ybL`XkO)D1&zG1blR`$5xI59yxgH`+B!F#*pc@MU(pUF9`X|Zkbeu<`R zN7WgeLWetxRadk>h!FU7=kU3Qk8eHuuGnyS^+CotJ44ss)aQT6Z=c)OUHfG{7whZ1 c_m?k;hUJ8r)t{PO0(3Tmr>mdKI;Vst0B>q*Q~&?~ diff --git a/app/src/main/res/drawable/arrow_up_yellow.png b/app/src/main/res/drawable/arrow_up_yellow.png deleted file mode 100644 index 977cd974259c0ec62a9fb40db25d04b36e7ba1ce..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 297 zcmeAS@N?(olHy`uVBq!ia0vp^{6H+i!3HFQj;9L&DYhhUcNd2LAh=-f^2tCE&H|6f zVg?3oVGw3ym^DWND9B#o>Fdh=h+Tq@NvQfrZzoV_o2QFoh{fr*lMVS89Yxyq-|ToJ z=A?czYIV3p!@0yGl2h~^3uJ8-)^N#id3f2TX~W4&8hcVcJ^MTJ{n?a%l0S9^+&UHW zvWCfDbZTa7fyjf>p18H%`Um7Tu<#w=%wW<@m>~3el`MDa!Z%a*ZR*^^zjsBGdf}Oc zmqNEqY+vZV>cLc_V56lxJ9?^?ty%S;Z_@EUZ0>XIZ(pm}vG>Tk*vC^Wn2uNL{(h$T q_o4dphT