Show session info on toolbar click & Change links color

This commit is contained in:
Matéo Duparc 2021-05-23 20:20:23 +02:00
parent 87e17c818e
commit 004277dc42
Signed by: hardcoresushi
GPG Key ID: 007F84120107191E
4 changed files with 49 additions and 40 deletions

View File

@ -41,16 +41,15 @@ class ChatActivity : ServiceBoundActivity() {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
binding = ActivityChatBinding.inflate(layoutInflater) binding = ActivityChatBinding.inflate(layoutInflater)
setContentView(binding.root) setContentView(binding.root)
setSupportActionBar(binding.toolbar.toolbar)
supportActionBar?.setDisplayHomeAsUpEnabled(true)
sessionId = intent.getIntExtra("sessionId", -1) sessionId = intent.getIntExtra("sessionId", -1)
if (sessionId != -1) { if (sessionId != -1) {
intent.getStringExtra("sessionName")?.let { name -> intent.getStringExtra("sessionName")?.let { name ->
sessionName = name sessionName = name
setSupportActionBar(binding.toolbar.toolbar)
binding.toolbar.textAvatar.setLetterFrom(name) binding.toolbar.textAvatar.setLetterFrom(name)
binding.toolbar.title.text = name binding.toolbar.title.text = name
supportActionBar?.setDisplayHomeAsUpEnabled(true)
chatAdapter = ChatAdapter(this@ChatActivity, ::onClickSaveFile) chatAdapter = ChatAdapter(this@ChatActivity, ::onClickSaveFile)
binding.recyclerChat.apply { binding.recyclerChat.apply {
adapter = chatAdapter adapter = chatAdapter
@ -73,6 +72,9 @@ class ChatActivity : ServiceBoundActivity() {
} }
}) })
} }
binding.toolbar.toolbar.setOnClickListener {
showSessionInfo()
}
binding.buttonSend.setOnClickListener { binding.buttonSend.setOnClickListener {
val msg = binding.editMessage.text.toString() val msg = binding.editMessage.text.toString()
airaService.sendTo(sessionId, Protocol.newMessage(msg)) airaService.sendTo(sessionId, Protocol.newMessage(msg))
@ -219,38 +221,7 @@ class ChatActivity : ServiceBoundActivity() {
true true
} }
R.id.session_info -> { R.id.session_info -> {
val contact = airaService.contacts[sessionId] showSessionInfo()
val session = airaService.sessions[sessionId]
val publicKey = contact?.publicKey ?: session?.peerPublicKey
val dialogBinding = DialogInfoBinding.inflate(layoutInflater)
dialogBinding.textAvatar.setLetterFrom(sessionName)
dialogBinding.textFingerprint.text = StringUtils.beautifyFingerprint(generateFingerprint(publicKey!!))
if (session == null) {
dialogBinding.onlineFields.visibility = View.GONE
} else {
dialogBinding.textIp.text = session.ip
dialogBinding.textOutgoing.text = getString(if (session.outgoing) {
R.string.outgoing
} else {
R.string.incoming
})
}
dialogBinding.textIsContact.text = getString(if (contact == null) {
dialogBinding.fieldIsVerified.visibility = View.GONE
R.string.no
} else {
dialogBinding.textIsVerified.text = getString(if (contact.verified) {
R.string.yes
} else {
R.string.no
})
R.string.yes
})
AlertDialog.Builder(this)
.setTitle(sessionName)
.setView(dialogBinding.root)
.setPositiveButton(R.string.ok, null)
.show()
true true
} }
R.id.set_as_contact -> { R.id.set_as_contact -> {
@ -340,4 +311,39 @@ class ChatActivity : ServiceBoundActivity() {
} }
} }
} }
private fun showSessionInfo() {
val contact = airaService.contacts[sessionId]
val session = airaService.sessions[sessionId]
val publicKey = contact?.publicKey ?: session?.peerPublicKey
val dialogBinding = DialogInfoBinding.inflate(layoutInflater)
dialogBinding.textAvatar.setLetterFrom(sessionName)
dialogBinding.textFingerprint.text = StringUtils.beautifyFingerprint(generateFingerprint(publicKey!!))
if (session == null) {
dialogBinding.onlineFields.visibility = View.GONE
} else {
dialogBinding.textIp.text = session.ip
dialogBinding.textOutgoing.text = getString(if (session.outgoing) {
R.string.outgoing
} else {
R.string.incoming
})
}
dialogBinding.textIsContact.text = getString(if (contact == null) {
dialogBinding.fieldIsVerified.visibility = View.GONE
R.string.no
} else {
dialogBinding.textIsVerified.text = getString(if (contact.verified) {
R.string.yes
} else {
R.string.no
})
R.string.yes
})
AlertDialog.Builder(this)
.setTitle(sessionName)
.setView(dialogBinding.root)
.setPositiveButton(R.string.ok, null)
.show()
}
} }

View File

@ -82,14 +82,18 @@ class ChatAdapter(
internal class OutgoingMessageViewHolder(private val context: Context, itemView: View): MessageViewHolder(itemView) { internal class OutgoingMessageViewHolder(private val context: Context, itemView: View): MessageViewHolder(itemView) {
fun bind(chatItem: ChatItem) { fun bind(chatItem: ChatItem) {
configureBubble(context, bindMessage(chatItem), true) configureBubble(context, bindMessage(chatItem).apply {
setLinkTextColor(ContextCompat.getColor(context, R.color.outgoingTextLink))
}, true)
setPadding(true) setPadding(true)
} }
} }
internal class IncomingMessageViewHolder(private val context: Context, itemView: View): MessageViewHolder(itemView) { internal class IncomingMessageViewHolder(private val context: Context, itemView: View): MessageViewHolder(itemView) {
fun bind(chatItem: ChatItem) { fun bind(chatItem: ChatItem) {
configureBubble(context, bindMessage(chatItem), false) configureBubble(context, bindMessage(chatItem).apply {
setLinkTextColor(ContextCompat.getColor(context, R.color.incomingTextLink))
}, false)
setPadding(false) setPadding(false)
} }
} }

View File

@ -10,7 +10,6 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:textIsSelectable="true" android:textIsSelectable="true"
android:autoLink="all" android:autoLink="all"
android:textColorLink="@color/textLink"
android:textColor="@color/messageTextColor" android:textColor="@color/messageTextColor"
style="@style/Bubble"/> style="@style/Bubble"/>

View File

@ -2,12 +2,12 @@
<resources> <resources>
<color name="primary">#262626</color> <color name="primary">#262626</color>
<color name="secondary">#19a52c</color> <color name="secondary">#19a52c</color>
<color name="white">#FFFFFF</color>
<color name="backgroundColor">#111111</color> <color name="backgroundColor">#111111</color>
<color name="sessionBackground">#1A1A1A</color> <color name="sessionBackground">#1A1A1A</color>
<color name="bubbleBackground">@color/sessionBackground</color> <color name="bubbleBackground">@color/sessionBackground</color>
<color name="incomingBubbleBackground">@color/secondary</color> <color name="incomingBubbleBackground">@color/secondary</color>
<color name="textLink">#3845A3</color> <color name="outgoingTextLink">#d4866a</color>
<color name="incomingTextLink">#7d0839</color>
<color name="messageTextColor">#ffffff</color> <color name="messageTextColor">#ffffff</color>
<color name="itemSelected">#66666666</color> <color name="itemSelected">#66666666</color>
<color name="transparent">#00000000</color> <color name="transparent">#00000000</color>