Fix UI bugs in ChatActivity
This commit is contained in:
parent
b20fded45b
commit
cc31423cc4
|
@ -45,13 +45,13 @@ class ChatActivity : ServiceBoundActivity() {
|
||||||
override fun onNewSession(sessionId: Int, ip: String) {
|
override fun onNewSession(sessionId: Int, ip: String) {
|
||||||
if (this@ChatActivity.sessionId == sessionId) {
|
if (this@ChatActivity.sessionId == sessionId) {
|
||||||
val contact = airaService.contacts[sessionId]
|
val contact = airaService.contacts[sessionId]
|
||||||
val hasPendingMsg = airaService.pendingMsgs[sessionId]?.size ?: 0 > 0
|
val hasPendingMsgs = airaService.pendingMsgs[sessionId]?.size ?: 0 > 0
|
||||||
runOnUiThread {
|
runOnUiThread {
|
||||||
if (contact == null) {
|
if (contact == null) {
|
||||||
binding.bottomPanel.visibility = View.VISIBLE
|
binding.bottomPanel.visibility = View.VISIBLE
|
||||||
} else {
|
} else {
|
||||||
binding.offlineWarning.visibility = View.GONE
|
binding.offlineWarning.visibility = View.GONE
|
||||||
if (hasPendingMsg) {
|
if (hasPendingMsgs) {
|
||||||
binding.sendingPendingMsgsIndicator.visibility = View.VISIBLE
|
binding.sendingPendingMsgsIndicator.visibility = View.VISIBLE
|
||||||
chatAdapter.removePendingMessages()
|
chatAdapter.removePendingMessages()
|
||||||
scrollToBottom()
|
scrollToBottom()
|
||||||
|
@ -223,10 +223,14 @@ class ChatActivity : ServiceBoundActivity() {
|
||||||
chatAdapter.newLoadedMessage(ChatItem(msg.outgoing, msg.timestamp, msg.data))
|
chatAdapter.newLoadedMessage(ChatItem(msg.outgoing, msg.timestamp, msg.data))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
var hasPendingMsgs = false
|
||||||
airaService.pendingMsgs[sessionId]?.let {
|
airaService.pendingMsgs[sessionId]?.let {
|
||||||
for (msg in it) {
|
if (it.size > 0) {
|
||||||
if (msg[0] == Protocol.MESSAGE ||msg[0] == Protocol.FILE) {
|
hasPendingMsgs = true
|
||||||
chatAdapter.newMessage(ChatItem(true, 0, msg))
|
for (msg in it) {
|
||||||
|
if (msg[0] == Protocol.MESSAGE ||msg[0] == Protocol.FILE) {
|
||||||
|
chatAdapter.newMessage(ChatItem(true, 0, msg))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -238,12 +242,20 @@ class ChatActivity : ServiceBoundActivity() {
|
||||||
it.ask(this@ChatActivity, ipName)
|
it.ask(this@ChatActivity, ipName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (session == null) {
|
binding.sendingPendingMsgsIndicator.visibility = if (session == null) {
|
||||||
if (contact == null) {
|
if (contact == null) {
|
||||||
hideBottomPanel()
|
hideBottomPanel()
|
||||||
} else {
|
} else {
|
||||||
binding.offlineWarning.visibility = View.VISIBLE
|
binding.offlineWarning.visibility = View.VISIBLE
|
||||||
}
|
}
|
||||||
|
View.GONE
|
||||||
|
} else {
|
||||||
|
binding.offlineWarning.visibility = View.GONE
|
||||||
|
if (hasPendingMsgs) {
|
||||||
|
View.VISIBLE
|
||||||
|
} else {
|
||||||
|
View.GONE
|
||||||
|
}
|
||||||
}
|
}
|
||||||
airaService.setSeen(sessionId, true)
|
airaService.setSeen(sessionId, true)
|
||||||
}
|
}
|
||||||
|
@ -348,6 +360,10 @@ class ChatActivity : ServiceBoundActivity() {
|
||||||
if (airaService.removeContact(sessionId)) {
|
if (airaService.removeContact(sessionId)) {
|
||||||
invalidateOptionsMenu()
|
invalidateOptionsMenu()
|
||||||
displayIconTrustLevel(false, false)
|
displayIconTrustLevel(false, false)
|
||||||
|
if (!airaService.isOnline(sessionId)) {
|
||||||
|
hideBottomPanel()
|
||||||
|
binding.offlineWarning.visibility = View.GONE
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.setNegativeButton(R.string.cancel, null)
|
.setNegativeButton(R.string.cancel, null)
|
||||||
|
|
Loading…
Reference in New Issue