mirror of
https://github.com/nextcloud/talk-android
synced 2025-07-11 06:44:09 +01:00
splitting up complex methods into smaller, easier to understand methods
Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
This commit is contained in:
parent
c9f230a10b
commit
eed209428e
@ -158,6 +158,26 @@ class MagicFirebaseMessagingService : FirebaseMessagingService() {
|
|||||||
base64DecodedSubject
|
base64DecodedSubject
|
||||||
)
|
)
|
||||||
if (signatureVerification!!.signatureValid) {
|
if (signatureVerification!!.signatureValid) {
|
||||||
|
decryptMessage(privateKey, base64DecodedSubject, subject, signature)
|
||||||
|
}
|
||||||
|
} catch (e1: NoSuchAlgorithmException) {
|
||||||
|
Log.d(NotificationWorker.TAG, "No proper algorithm to decrypt the message " + e1.localizedMessage)
|
||||||
|
} catch (e1: NoSuchPaddingException) {
|
||||||
|
Log.d(NotificationWorker.TAG, "No proper padding to decrypt the message " + e1.localizedMessage)
|
||||||
|
} catch (e1: InvalidKeyException) {
|
||||||
|
Log.d(NotificationWorker.TAG, "Invalid private key " + e1.localizedMessage)
|
||||||
|
}
|
||||||
|
} catch (exception: Exception) {
|
||||||
|
Log.d(NotificationWorker.TAG, "Something went very wrong " + exception.localizedMessage)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun decryptMessage(
|
||||||
|
privateKey: PrivateKey,
|
||||||
|
base64DecodedSubject: ByteArray?,
|
||||||
|
subject: String,
|
||||||
|
signature: String
|
||||||
|
) {
|
||||||
val cipher = Cipher.getInstance("RSA/None/PKCS1Padding")
|
val cipher = Cipher.getInstance("RSA/None/PKCS1Padding")
|
||||||
cipher.init(Cipher.DECRYPT_MODE, privateKey)
|
cipher.init(Cipher.DECRYPT_MODE, privateKey)
|
||||||
val decryptedSubject = cipher.doFinal(base64DecodedSubject)
|
val decryptedSubject = cipher.doFinal(base64DecodedSubject)
|
||||||
@ -237,17 +257,6 @@ class MagicFirebaseMessagingService : FirebaseMessagingService() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e1: NoSuchAlgorithmException) {
|
|
||||||
Log.d(NotificationWorker.TAG, "No proper algorithm to decrypt the message " + e1.localizedMessage)
|
|
||||||
} catch (e1: NoSuchPaddingException) {
|
|
||||||
Log.d(NotificationWorker.TAG, "No proper padding to decrypt the message " + e1.localizedMessage)
|
|
||||||
} catch (e1: InvalidKeyException) {
|
|
||||||
Log.d(NotificationWorker.TAG, "Invalid private key " + e1.localizedMessage)
|
|
||||||
}
|
|
||||||
} catch (exception: Exception) {
|
|
||||||
Log.d(NotificationWorker.TAG, "Something went very wrong " + exception.localizedMessage)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun checkIfCallIsActive(
|
private fun checkIfCallIsActive(
|
||||||
signatureVerification: SignatureVerification,
|
signatureVerification: SignatureVerification,
|
||||||
|
@ -153,6 +153,18 @@ class IncomingVoiceMessageViewHolder(incomingView: View, payload: Any) : Message
|
|||||||
showVoiceMessageLoading()
|
showVoiceMessageLoading()
|
||||||
WorkManager.getInstance(context!!).getWorkInfoByIdLiveData(workInfo.id)
|
WorkManager.getInstance(context!!).getWorkInfoByIdLiveData(workInfo.id)
|
||||||
.observeForever { info: WorkInfo? ->
|
.observeForever { info: WorkInfo? ->
|
||||||
|
showStatus(info)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e: ExecutionException) {
|
||||||
|
Log.e(TAG, "Error when checking if worker already exists", e)
|
||||||
|
} catch (e: InterruptedException) {
|
||||||
|
Log.e(TAG, "Error when checking if worker already exists", e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun showStatus(info: WorkInfo?) {
|
||||||
if (info != null) {
|
if (info != null) {
|
||||||
when (info.state) {
|
when (info.state) {
|
||||||
WorkInfo.State.RUNNING -> {
|
WorkInfo.State.RUNNING -> {
|
||||||
@ -172,14 +184,6 @@ class IncomingVoiceMessageViewHolder(incomingView: View, payload: Any) : Message
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (e: ExecutionException) {
|
|
||||||
Log.e(TAG, "Error when checking if worker already exists", e)
|
|
||||||
} catch (e: InterruptedException) {
|
|
||||||
Log.e(TAG, "Error when checking if worker already exists", e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun showPlayButton() {
|
private fun showPlayButton() {
|
||||||
binding.playPauseBtn.visibility = View.VISIBLE
|
binding.playPauseBtn.visibility = View.VISIBLE
|
||||||
@ -203,6 +207,18 @@ class IncomingVoiceMessageViewHolder(incomingView: View, payload: Any) : Message
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!message.isGrouped && !message.isOneToOneConversation) {
|
if (!message.isGrouped && !message.isOneToOneConversation) {
|
||||||
|
setAvatarOnMessage(message)
|
||||||
|
} else {
|
||||||
|
if (message.isOneToOneConversation) {
|
||||||
|
binding.messageUserAvatar.visibility = View.GONE
|
||||||
|
} else {
|
||||||
|
binding.messageUserAvatar.visibility = View.INVISIBLE
|
||||||
|
}
|
||||||
|
binding.messageAuthor.visibility = View.GONE
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun setAvatarOnMessage(message: ChatMessage) {
|
||||||
binding.messageUserAvatar.visibility = View.VISIBLE
|
binding.messageUserAvatar.visibility = View.VISIBLE
|
||||||
if (message.actorType == "guests") {
|
if (message.actorType == "guests") {
|
||||||
// do nothing, avatar is set
|
// do nothing, avatar is set
|
||||||
@ -228,14 +244,6 @@ class IncomingVoiceMessageViewHolder(incomingView: View, payload: Any) : Message
|
|||||||
binding.messageUserAvatar.visibility = View.VISIBLE
|
binding.messageUserAvatar.visibility = View.VISIBLE
|
||||||
binding.messageUserAvatar.setImageDrawable(drawable)
|
binding.messageUserAvatar.setImageDrawable(drawable)
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
if (message.isOneToOneConversation) {
|
|
||||||
binding.messageUserAvatar.visibility = View.GONE
|
|
||||||
} else {
|
|
||||||
binding.messageUserAvatar.visibility = View.INVISIBLE
|
|
||||||
}
|
|
||||||
binding.messageAuthor.visibility = View.GONE
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun colorizeMessageBubble(message: ChatMessage) {
|
private fun colorizeMessageBubble(message: ChatMessage) {
|
||||||
|
@ -26,6 +26,7 @@ package com.nextcloud.talk.adapters.messages
|
|||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
|
import android.content.res.Resources
|
||||||
import android.graphics.drawable.Drawable
|
import android.graphics.drawable.Drawable
|
||||||
import android.graphics.drawable.LayerDrawable
|
import android.graphics.drawable.LayerDrawable
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
@ -53,6 +54,7 @@ import com.nextcloud.talk.utils.DisplayUtils
|
|||||||
import com.nextcloud.talk.utils.TextMatchers
|
import com.nextcloud.talk.utils.TextMatchers
|
||||||
import com.nextcloud.talk.utils.preferences.AppPreferences
|
import com.nextcloud.talk.utils.preferences.AppPreferences
|
||||||
import com.stfalcon.chatkit.messages.MessageHolders
|
import com.stfalcon.chatkit.messages.MessageHolders
|
||||||
|
import java.util.HashMap
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
@AutoInjector(NextcloudTalkApplication::class)
|
@AutoInjector(NextcloudTalkApplication::class)
|
||||||
@ -72,17 +74,117 @@ class MagicIncomingTextMessageViewHolder(itemView: View, payload: Any) : Message
|
|||||||
override fun onBind(message: ChatMessage) {
|
override fun onBind(message: ChatMessage) {
|
||||||
super.onBind(message)
|
super.onBind(message)
|
||||||
sharedApplication!!.componentApplication.inject(this)
|
sharedApplication!!.componentApplication.inject(this)
|
||||||
val author: String = message.actorDisplayName
|
processAuthor(message)
|
||||||
if (!TextUtils.isEmpty(author)) {
|
|
||||||
binding.messageAuthor.text = author
|
if (!message.isGrouped && !message.isOneToOneConversation) {
|
||||||
|
showAvatarOnChatMessage(message)
|
||||||
|
} else {
|
||||||
|
if (message.isOneToOneConversation) {
|
||||||
|
binding.messageUserAvatar.visibility = View.GONE
|
||||||
|
} else {
|
||||||
|
binding.messageUserAvatar.visibility = View.INVISIBLE
|
||||||
|
}
|
||||||
|
binding.messageAuthor.visibility = View.GONE
|
||||||
|
}
|
||||||
|
|
||||||
|
val resources = itemView.resources
|
||||||
|
|
||||||
|
setBubbleOnChatMessage(message, resources)
|
||||||
|
|
||||||
|
itemView.isSelected = false
|
||||||
|
binding.messageTime.setTextColor(ResourcesCompat.getColor(resources, R.color.warm_grey_four, null))
|
||||||
|
|
||||||
|
var messageString: Spannable = SpannableString(message.text)
|
||||||
|
|
||||||
|
var textSize = context?.resources!!.getDimension(R.dimen.chat_text_size)
|
||||||
|
|
||||||
|
val messageParameters = message.messageParameters
|
||||||
|
if (messageParameters != null && messageParameters.size > 0) {
|
||||||
|
messageString = processMessageParameters(messageParameters, message, messageString)
|
||||||
|
} else if (TextMatchers.isMessageWithSingleEmoticonOnly(message.text)) {
|
||||||
|
textSize = (textSize * TEXT_SIZE_MULTIPLIER).toFloat()
|
||||||
|
itemView.isSelected = true
|
||||||
|
binding.messageAuthor.visibility = View.GONE
|
||||||
|
}
|
||||||
|
|
||||||
|
binding.messageText.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize)
|
||||||
|
binding.messageText.text = messageString
|
||||||
|
|
||||||
|
// parent message handling
|
||||||
|
if (!message.isDeleted && message.parentMessage != null) {
|
||||||
|
processParentMessage(message)
|
||||||
|
binding.messageQuote.quotedChatMessageView.visibility = View.VISIBLE
|
||||||
|
} else {
|
||||||
|
binding.messageQuote.quotedChatMessageView.visibility = View.GONE
|
||||||
|
}
|
||||||
|
|
||||||
|
itemView.setTag(MessageSwipeCallback.REPLYABLE_VIEW_TAG, message.isReplyable)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun processAuthor(message: ChatMessage) {
|
||||||
|
if (!TextUtils.isEmpty(message.actorDisplayName)) {
|
||||||
|
binding.messageAuthor.text = message.actorDisplayName
|
||||||
binding.messageUserAvatar.setOnClickListener {
|
binding.messageUserAvatar.setOnClickListener {
|
||||||
(payload as? ProfileBottomSheet)?.showFor(message.actorId, itemView.context)
|
(payload as? ProfileBottomSheet)?.showFor(message.actorId, itemView.context)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
binding.messageAuthor.setText(R.string.nc_nick_guest)
|
binding.messageAuthor.setText(R.string.nc_nick_guest)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!message.isGrouped && !message.isOneToOneConversation) {
|
private fun setBubbleOnChatMessage(
|
||||||
|
message: ChatMessage,
|
||||||
|
resources: Resources
|
||||||
|
) {
|
||||||
|
val bgBubbleColor = if (message.isDeleted) {
|
||||||
|
ResourcesCompat.getColor(resources, R.color.bg_message_list_incoming_bubble_deleted, null)
|
||||||
|
} else {
|
||||||
|
ResourcesCompat.getColor(resources, R.color.bg_message_list_incoming_bubble, null)
|
||||||
|
}
|
||||||
|
|
||||||
|
var bubbleResource = R.drawable.shape_incoming_message
|
||||||
|
|
||||||
|
if (message.isGrouped) {
|
||||||
|
bubbleResource = R.drawable.shape_grouped_incoming_message
|
||||||
|
}
|
||||||
|
|
||||||
|
val bubbleDrawable = DisplayUtils.getMessageSelector(
|
||||||
|
bgBubbleColor,
|
||||||
|
ResourcesCompat.getColor(resources, R.color.transparent, null),
|
||||||
|
bgBubbleColor, bubbleResource
|
||||||
|
)
|
||||||
|
ViewCompat.setBackground(bubble, bubbleDrawable)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun processParentMessage(message: ChatMessage) {
|
||||||
|
val parentChatMessage = message.parentMessage
|
||||||
|
parentChatMessage.activeUser = message.activeUser
|
||||||
|
parentChatMessage.imageUrl?.let {
|
||||||
|
binding.messageQuote.quotedMessageImage.visibility = View.VISIBLE
|
||||||
|
binding.messageQuote.quotedMessageImage.load(it) {
|
||||||
|
addHeader(
|
||||||
|
"Authorization",
|
||||||
|
ApiUtils.getCredentials(message.activeUser.username, message.activeUser.token)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} ?: run {
|
||||||
|
binding.messageQuote.quotedMessageImage.visibility = View.GONE
|
||||||
|
}
|
||||||
|
binding.messageQuote.quotedMessageAuthor.text = if (parentChatMessage.actorDisplayName.isNullOrEmpty())
|
||||||
|
context!!.getText(R.string.nc_nick_guest) else parentChatMessage.actorDisplayName
|
||||||
|
binding.messageQuote.quotedMessage.text = parentChatMessage.text
|
||||||
|
|
||||||
|
binding.messageQuote.quotedMessageAuthor
|
||||||
|
.setTextColor(ContextCompat.getColor(context!!, R.color.textColorMaxContrast))
|
||||||
|
|
||||||
|
if (parentChatMessage.actorId?.equals(message.activeUser.userId) == true) {
|
||||||
|
binding.messageQuote.quoteColoredView.setBackgroundResource(R.color.colorPrimary)
|
||||||
|
} else {
|
||||||
|
binding.messageQuote.quoteColoredView.setBackgroundResource(R.color.textColorMaxContrast)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun showAvatarOnChatMessage(message: ChatMessage) {
|
||||||
binding.messageUserAvatar.visibility = View.VISIBLE
|
binding.messageUserAvatar.visibility = View.VISIBLE
|
||||||
if (message.actorType == "guests") {
|
if (message.actorType == "guests") {
|
||||||
// do nothing, avatar is set
|
// do nothing, avatar is set
|
||||||
@ -110,46 +212,14 @@ class MagicIncomingTextMessageViewHolder(itemView: View, payload: Any) : Message
|
|||||||
binding.messageUserAvatar.visibility = View.VISIBLE
|
binding.messageUserAvatar.visibility = View.VISIBLE
|
||||||
binding.messageUserAvatar.setImageDrawable(drawable)
|
binding.messageUserAvatar.setImageDrawable(drawable)
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
if (message.isOneToOneConversation) {
|
|
||||||
binding.messageUserAvatar.visibility = View.GONE
|
|
||||||
} else {
|
|
||||||
binding.messageUserAvatar.visibility = View.INVISIBLE
|
|
||||||
}
|
|
||||||
binding.messageAuthor.visibility = View.GONE
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val resources = itemView.resources
|
private fun processMessageParameters(
|
||||||
|
messageParameters: HashMap<String, HashMap<String, String>>,
|
||||||
val bgBubbleColor = if (message.isDeleted) {
|
message: ChatMessage,
|
||||||
ResourcesCompat.getColor(resources, R.color.bg_message_list_incoming_bubble_deleted, null)
|
messageString: Spannable
|
||||||
} else {
|
): Spannable {
|
||||||
ResourcesCompat.getColor(resources, R.color.bg_message_list_incoming_bubble, null)
|
var messageStringInternal = messageString
|
||||||
}
|
|
||||||
|
|
||||||
var bubbleResource = R.drawable.shape_incoming_message
|
|
||||||
|
|
||||||
if (message.isGrouped) {
|
|
||||||
bubbleResource = R.drawable.shape_grouped_incoming_message
|
|
||||||
}
|
|
||||||
|
|
||||||
val bubbleDrawable = DisplayUtils.getMessageSelector(
|
|
||||||
bgBubbleColor,
|
|
||||||
ResourcesCompat.getColor(resources, R.color.transparent, null),
|
|
||||||
bgBubbleColor, bubbleResource
|
|
||||||
)
|
|
||||||
ViewCompat.setBackground(bubble, bubbleDrawable)
|
|
||||||
|
|
||||||
val messageParameters = message.messageParameters
|
|
||||||
|
|
||||||
itemView.isSelected = false
|
|
||||||
binding.messageTime.setTextColor(ResourcesCompat.getColor(resources, R.color.warm_grey_four, null))
|
|
||||||
|
|
||||||
var messageString: Spannable = SpannableString(message.text)
|
|
||||||
|
|
||||||
var textSize = context?.resources!!.getDimension(R.dimen.chat_text_size)
|
|
||||||
|
|
||||||
if (messageParameters != null && messageParameters.size > 0) {
|
|
||||||
for (key in messageParameters.keys) {
|
for (key in messageParameters.keys) {
|
||||||
val individualHashMap = message.messageParameters[key]
|
val individualHashMap = message.messageParameters[key]
|
||||||
if (individualHashMap != null) {
|
if (individualHashMap != null) {
|
||||||
@ -159,9 +229,9 @@ class MagicIncomingTextMessageViewHolder(itemView: View, payload: Any) : Message
|
|||||||
individualHashMap["type"] == "call"
|
individualHashMap["type"] == "call"
|
||||||
) {
|
) {
|
||||||
if (individualHashMap["id"] == message.activeUser!!.userId) {
|
if (individualHashMap["id"] == message.activeUser!!.userId) {
|
||||||
messageString = DisplayUtils.searchAndReplaceWithMentionSpan(
|
messageStringInternal = DisplayUtils.searchAndReplaceWithMentionSpan(
|
||||||
binding.messageText.context,
|
binding.messageText.context,
|
||||||
messageString,
|
messageStringInternal,
|
||||||
individualHashMap["id"]!!,
|
individualHashMap["id"]!!,
|
||||||
individualHashMap["name"]!!,
|
individualHashMap["name"]!!,
|
||||||
individualHashMap["type"]!!,
|
individualHashMap["type"]!!,
|
||||||
@ -169,9 +239,9 @@ class MagicIncomingTextMessageViewHolder(itemView: View, payload: Any) : Message
|
|||||||
R.xml.chip_you
|
R.xml.chip_you
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
messageString = DisplayUtils.searchAndReplaceWithMentionSpan(
|
messageStringInternal = DisplayUtils.searchAndReplaceWithMentionSpan(
|
||||||
binding.messageText.context,
|
binding.messageText.context,
|
||||||
messageString,
|
messageStringInternal,
|
||||||
individualHashMap["id"]!!,
|
individualHashMap["id"]!!,
|
||||||
individualHashMap["name"]!!,
|
individualHashMap["name"]!!,
|
||||||
individualHashMap["type"]!!,
|
individualHashMap["type"]!!,
|
||||||
@ -187,49 +257,7 @@ class MagicIncomingTextMessageViewHolder(itemView: View, payload: Any) : Message
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (TextMatchers.isMessageWithSingleEmoticonOnly(message.text)) {
|
return messageStringInternal
|
||||||
textSize = (textSize * TEXT_SIZE_MULTIPLIER).toFloat()
|
|
||||||
itemView.isSelected = true
|
|
||||||
binding.messageAuthor.visibility = View.GONE
|
|
||||||
}
|
|
||||||
|
|
||||||
binding.messageText.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize)
|
|
||||||
binding.messageText.text = messageString
|
|
||||||
|
|
||||||
// parent message handling
|
|
||||||
if (!message.isDeleted && message.parentMessage != null) {
|
|
||||||
val parentChatMessage = message.parentMessage
|
|
||||||
parentChatMessage.activeUser = message.activeUser
|
|
||||||
parentChatMessage.imageUrl?.let {
|
|
||||||
binding.messageQuote.quotedMessageImage.visibility = View.VISIBLE
|
|
||||||
binding.messageQuote.quotedMessageImage.load(it) {
|
|
||||||
addHeader(
|
|
||||||
"Authorization",
|
|
||||||
ApiUtils.getCredentials(message.activeUser.username, message.activeUser.token)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
} ?: run {
|
|
||||||
binding.messageQuote.quotedMessageImage.visibility = View.GONE
|
|
||||||
}
|
|
||||||
binding.messageQuote.quotedMessageAuthor.text = if (parentChatMessage.actorDisplayName.isNullOrEmpty())
|
|
||||||
context!!.getText(R.string.nc_nick_guest) else parentChatMessage.actorDisplayName
|
|
||||||
binding.messageQuote.quotedMessage.text = parentChatMessage.text
|
|
||||||
|
|
||||||
binding.messageQuote.quotedMessageAuthor
|
|
||||||
.setTextColor(ContextCompat.getColor(context!!, R.color.textColorMaxContrast))
|
|
||||||
|
|
||||||
if (parentChatMessage.actorId?.equals(message.activeUser.userId) == true) {
|
|
||||||
binding.messageQuote.quoteColoredView.setBackgroundResource(R.color.colorPrimary)
|
|
||||||
} else {
|
|
||||||
binding.messageQuote.quoteColoredView.setBackgroundResource(R.color.textColorMaxContrast)
|
|
||||||
}
|
|
||||||
|
|
||||||
binding.messageQuote.quotedChatMessageView.visibility = View.VISIBLE
|
|
||||||
} else {
|
|
||||||
binding.messageQuote.quotedChatMessageView.visibility = View.GONE
|
|
||||||
}
|
|
||||||
|
|
||||||
itemView.setTag(MessageSwipeCallback.REPLYABLE_VIEW_TAG, message.isReplyable)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
@ -72,30 +72,7 @@ class MagicOutcomingTextMessageViewHolder(itemView: View) : OutcomingTextMessage
|
|||||||
layoutParams.isWrapBefore = false
|
layoutParams.isWrapBefore = false
|
||||||
var textSize = context!!.resources.getDimension(R.dimen.chat_text_size)
|
var textSize = context!!.resources.getDimension(R.dimen.chat_text_size)
|
||||||
if (messageParameters != null && messageParameters.size > 0) {
|
if (messageParameters != null && messageParameters.size > 0) {
|
||||||
for (key in messageParameters.keys) {
|
messageString = processMessageParameters(messageParameters, message, messageString)
|
||||||
val individualHashMap: HashMap<String, String>? = message.messageParameters[key]
|
|
||||||
if (individualHashMap != null) {
|
|
||||||
if (individualHashMap["type"] == "user" ||
|
|
||||||
individualHashMap["type"] == "guest" ||
|
|
||||||
individualHashMap["type"] == "call"
|
|
||||||
) {
|
|
||||||
messageString = searchAndReplaceWithMentionSpan(
|
|
||||||
binding.messageText.context,
|
|
||||||
messageString,
|
|
||||||
individualHashMap["id"]!!,
|
|
||||||
individualHashMap["name"]!!,
|
|
||||||
individualHashMap["type"]!!,
|
|
||||||
message.activeUser,
|
|
||||||
R.xml.chip_others
|
|
||||||
)
|
|
||||||
} else if (individualHashMap["type"] == "file") {
|
|
||||||
realView.setOnClickListener { v: View? ->
|
|
||||||
val browserIntent = Intent(Intent.ACTION_VIEW, Uri.parse(individualHashMap["link"]))
|
|
||||||
context!!.startActivity(browserIntent)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (TextMatchers.isMessageWithSingleEmoticonOnly(message.text)) {
|
} else if (TextMatchers.isMessageWithSingleEmoticonOnly(message.text)) {
|
||||||
textSize = (textSize * TEXT_SIZE_MULTIPLIER).toFloat()
|
textSize = (textSize * TEXT_SIZE_MULTIPLIER).toFloat()
|
||||||
layoutParams.isWrapBefore = true
|
layoutParams.isWrapBefore = true
|
||||||
@ -104,59 +81,16 @@ class MagicOutcomingTextMessageViewHolder(itemView: View) : OutcomingTextMessage
|
|||||||
)
|
)
|
||||||
realView.isSelected = true
|
realView.isSelected = true
|
||||||
}
|
}
|
||||||
val resources = sharedApplication!!.resources
|
|
||||||
val bgBubbleColor = if (message.isDeleted) {
|
setBubbleOnChatMessage(message)
|
||||||
ResourcesCompat.getColor(resources, R.color.bg_message_list_outcoming_bubble_deleted, null)
|
|
||||||
} else {
|
|
||||||
ResourcesCompat.getColor(resources, R.color.bg_message_list_outcoming_bubble, null)
|
|
||||||
}
|
|
||||||
if (message.isGrouped) {
|
|
||||||
val bubbleDrawable = getMessageSelector(
|
|
||||||
bgBubbleColor,
|
|
||||||
ResourcesCompat.getColor(resources, R.color.transparent, null),
|
|
||||||
bgBubbleColor,
|
|
||||||
R.drawable.shape_grouped_outcoming_message
|
|
||||||
)
|
|
||||||
ViewCompat.setBackground(bubble, bubbleDrawable)
|
|
||||||
} else {
|
|
||||||
val bubbleDrawable = getMessageSelector(
|
|
||||||
bgBubbleColor,
|
|
||||||
ResourcesCompat.getColor(resources, R.color.transparent, null),
|
|
||||||
bgBubbleColor,
|
|
||||||
R.drawable.shape_outcoming_message
|
|
||||||
)
|
|
||||||
ViewCompat.setBackground(bubble, bubbleDrawable)
|
|
||||||
}
|
|
||||||
binding.messageText.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize)
|
binding.messageText.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize)
|
||||||
binding.messageTime.layoutParams = layoutParams
|
binding.messageTime.layoutParams = layoutParams
|
||||||
binding.messageText.text = messageString
|
binding.messageText.text = messageString
|
||||||
|
|
||||||
// parent message handling
|
// parent message handling
|
||||||
|
|
||||||
if (!message.isDeleted && message.parentMessage != null) {
|
if (!message.isDeleted && message.parentMessage != null) {
|
||||||
val parentChatMessage = message.parentMessage
|
processParentMessage(message)
|
||||||
parentChatMessage.activeUser = message.activeUser
|
|
||||||
parentChatMessage.imageUrl?.let {
|
|
||||||
binding.messageQuote.quotedMessageImage.visibility = View.VISIBLE
|
|
||||||
binding.messageQuote.quotedMessageImage.load(it) {
|
|
||||||
addHeader(
|
|
||||||
"Authorization",
|
|
||||||
ApiUtils.getCredentials(message.activeUser.username, message.activeUser.token)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
} ?: run {
|
|
||||||
binding.messageQuote.quotedMessageImage.visibility = View.GONE
|
|
||||||
}
|
|
||||||
binding.messageQuote.quotedMessageAuthor.text = parentChatMessage.actorDisplayName
|
|
||||||
?: context!!.getText(R.string.nc_nick_guest)
|
|
||||||
binding.messageQuote.quotedMessage.text = parentChatMessage.text
|
|
||||||
binding.messageQuote.quotedMessage.setTextColor(
|
|
||||||
ContextCompat.getColor(context!!, R.color.nc_outcoming_text_default)
|
|
||||||
)
|
|
||||||
binding.messageQuote.quotedMessageAuthor.setTextColor(ContextCompat.getColor(context!!, R.color.nc_grey))
|
|
||||||
|
|
||||||
binding.messageQuote.quoteColoredView.setBackgroundResource(R.color.white)
|
|
||||||
|
|
||||||
binding.messageQuote.quotedChatMessageView.visibility = View.VISIBLE
|
binding.messageQuote.quotedChatMessageView.visibility = View.VISIBLE
|
||||||
} else {
|
} else {
|
||||||
binding.messageQuote.quotedChatMessageView.visibility = View.GONE
|
binding.messageQuote.quotedChatMessageView.visibility = View.GONE
|
||||||
@ -186,6 +120,90 @@ class MagicOutcomingTextMessageViewHolder(itemView: View) : OutcomingTextMessage
|
|||||||
itemView.setTag(MessageSwipeCallback.REPLYABLE_VIEW_TAG, message.isReplyable)
|
itemView.setTag(MessageSwipeCallback.REPLYABLE_VIEW_TAG, message.isReplyable)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun processParentMessage(message: ChatMessage) {
|
||||||
|
val parentChatMessage = message.parentMessage
|
||||||
|
parentChatMessage.activeUser = message.activeUser
|
||||||
|
parentChatMessage.imageUrl?.let {
|
||||||
|
binding.messageQuote.quotedMessageImage.visibility = View.VISIBLE
|
||||||
|
binding.messageQuote.quotedMessageImage.load(it) {
|
||||||
|
addHeader(
|
||||||
|
"Authorization",
|
||||||
|
ApiUtils.getCredentials(message.activeUser.username, message.activeUser.token)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} ?: run {
|
||||||
|
binding.messageQuote.quotedMessageImage.visibility = View.GONE
|
||||||
|
}
|
||||||
|
binding.messageQuote.quotedMessageAuthor.text = parentChatMessage.actorDisplayName
|
||||||
|
?: context!!.getText(R.string.nc_nick_guest)
|
||||||
|
binding.messageQuote.quotedMessage.text = parentChatMessage.text
|
||||||
|
binding.messageQuote.quotedMessage.setTextColor(
|
||||||
|
ContextCompat.getColor(context!!, R.color.nc_outcoming_text_default)
|
||||||
|
)
|
||||||
|
binding.messageQuote.quotedMessageAuthor.setTextColor(ContextCompat.getColor(context!!, R.color.nc_grey))
|
||||||
|
|
||||||
|
binding.messageQuote.quoteColoredView.setBackgroundResource(R.color.white)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun setBubbleOnChatMessage(message: ChatMessage) {
|
||||||
|
val resources = sharedApplication!!.resources
|
||||||
|
val bgBubbleColor = if (message.isDeleted) {
|
||||||
|
ResourcesCompat.getColor(resources, R.color.bg_message_list_outcoming_bubble_deleted, null)
|
||||||
|
} else {
|
||||||
|
ResourcesCompat.getColor(resources, R.color.bg_message_list_outcoming_bubble, null)
|
||||||
|
}
|
||||||
|
if (message.isGrouped) {
|
||||||
|
val bubbleDrawable = getMessageSelector(
|
||||||
|
bgBubbleColor,
|
||||||
|
ResourcesCompat.getColor(resources, R.color.transparent, null),
|
||||||
|
bgBubbleColor,
|
||||||
|
R.drawable.shape_grouped_outcoming_message
|
||||||
|
)
|
||||||
|
ViewCompat.setBackground(bubble, bubbleDrawable)
|
||||||
|
} else {
|
||||||
|
val bubbleDrawable = getMessageSelector(
|
||||||
|
bgBubbleColor,
|
||||||
|
ResourcesCompat.getColor(resources, R.color.transparent, null),
|
||||||
|
bgBubbleColor,
|
||||||
|
R.drawable.shape_outcoming_message
|
||||||
|
)
|
||||||
|
ViewCompat.setBackground(bubble, bubbleDrawable)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun processMessageParameters(
|
||||||
|
messageParameters: HashMap<String, HashMap<String, String>>,
|
||||||
|
message: ChatMessage,
|
||||||
|
messageString: Spannable
|
||||||
|
): Spannable {
|
||||||
|
var messageString1 = messageString
|
||||||
|
for (key in messageParameters.keys) {
|
||||||
|
val individualHashMap: HashMap<String, String>? = message.messageParameters[key]
|
||||||
|
if (individualHashMap != null) {
|
||||||
|
if (individualHashMap["type"] == "user" ||
|
||||||
|
individualHashMap["type"] == "guest" ||
|
||||||
|
individualHashMap["type"] == "call"
|
||||||
|
) {
|
||||||
|
messageString1 = searchAndReplaceWithMentionSpan(
|
||||||
|
binding.messageText.context,
|
||||||
|
messageString1,
|
||||||
|
individualHashMap["id"]!!,
|
||||||
|
individualHashMap["name"]!!,
|
||||||
|
individualHashMap["type"]!!,
|
||||||
|
message.activeUser,
|
||||||
|
R.xml.chip_others
|
||||||
|
)
|
||||||
|
} else if (individualHashMap["type"] == "file") {
|
||||||
|
realView.setOnClickListener { v: View? ->
|
||||||
|
val browserIntent = Intent(Intent.ACTION_VIEW, Uri.parse(individualHashMap["link"]))
|
||||||
|
context!!.startActivity(browserIntent)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return messageString1
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val TEXT_SIZE_MULTIPLIER = 2.5
|
const val TEXT_SIZE_MULTIPLIER = 2.5
|
||||||
}
|
}
|
||||||
|
@ -87,36 +87,11 @@ class OutcomingVoiceMessageViewHolder(outcomingView: View) : MessageHolders
|
|||||||
updateDownloadState(message)
|
updateDownloadState(message)
|
||||||
binding.seekbar.max = message.voiceMessageDuration
|
binding.seekbar.max = message.voiceMessageDuration
|
||||||
|
|
||||||
if (message.isPlayingVoiceMessage) {
|
handleIsPlayingVoiceMessageState(message)
|
||||||
showPlayButton()
|
|
||||||
binding.playPauseBtn.icon = ContextCompat.getDrawable(
|
|
||||||
context!!,
|
|
||||||
R.drawable.ic_baseline_pause_voice_message_24
|
|
||||||
)
|
|
||||||
binding.seekbar.progress = message.voiceMessagePlayedSeconds
|
|
||||||
} else {
|
|
||||||
binding.playPauseBtn.visibility = View.VISIBLE
|
|
||||||
binding.playPauseBtn.icon = ContextCompat.getDrawable(
|
|
||||||
context!!,
|
|
||||||
R.drawable.ic_baseline_play_arrow_voice_message_24
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (message.isDownloadingVoiceMessage) {
|
handleIsDownloadingVoiceMessageState(message)
|
||||||
showVoiceMessageLoading()
|
|
||||||
} else {
|
|
||||||
binding.progressBar.visibility = View.GONE
|
|
||||||
}
|
|
||||||
|
|
||||||
if (message.resetVoiceMessage) {
|
handleResetVoiceMessageState(message)
|
||||||
binding.playPauseBtn.visibility = View.VISIBLE
|
|
||||||
binding.playPauseBtn.icon = ContextCompat.getDrawable(
|
|
||||||
context!!,
|
|
||||||
R.drawable.ic_baseline_play_arrow_voice_message_24
|
|
||||||
)
|
|
||||||
binding.seekbar.progress = SEEKBAR_START
|
|
||||||
message.resetVoiceMessage = false
|
|
||||||
}
|
|
||||||
|
|
||||||
binding.seekbar.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
|
binding.seekbar.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
|
||||||
override fun onStopTrackingTouch(seekBar: SeekBar) {
|
override fun onStopTrackingTouch(seekBar: SeekBar) {
|
||||||
@ -156,6 +131,43 @@ class OutcomingVoiceMessageViewHolder(outcomingView: View) : MessageHolders
|
|||||||
binding.checkMark.setContentDescription(readStatusContentDescriptionString)
|
binding.checkMark.setContentDescription(readStatusContentDescriptionString)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun handleResetVoiceMessageState(message: ChatMessage) {
|
||||||
|
if (message.resetVoiceMessage) {
|
||||||
|
binding.playPauseBtn.visibility = View.VISIBLE
|
||||||
|
binding.playPauseBtn.icon = ContextCompat.getDrawable(
|
||||||
|
context!!,
|
||||||
|
R.drawable.ic_baseline_play_arrow_voice_message_24
|
||||||
|
)
|
||||||
|
binding.seekbar.progress = SEEKBAR_START
|
||||||
|
message.resetVoiceMessage = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun handleIsDownloadingVoiceMessageState(message: ChatMessage) {
|
||||||
|
if (message.isDownloadingVoiceMessage) {
|
||||||
|
showVoiceMessageLoading()
|
||||||
|
} else {
|
||||||
|
binding.progressBar.visibility = View.GONE
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun handleIsPlayingVoiceMessageState(message: ChatMessage) {
|
||||||
|
if (message.isPlayingVoiceMessage) {
|
||||||
|
showPlayButton()
|
||||||
|
binding.playPauseBtn.icon = ContextCompat.getDrawable(
|
||||||
|
context!!,
|
||||||
|
R.drawable.ic_baseline_pause_voice_message_24
|
||||||
|
)
|
||||||
|
binding.seekbar.progress = message.voiceMessagePlayedSeconds
|
||||||
|
} else {
|
||||||
|
binding.playPauseBtn.visibility = View.VISIBLE
|
||||||
|
binding.playPauseBtn.icon = ContextCompat.getDrawable(
|
||||||
|
context!!,
|
||||||
|
R.drawable.ic_baseline_play_arrow_voice_message_24
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun updateDownloadState(message: ChatMessage) {
|
private fun updateDownloadState(message: ChatMessage) {
|
||||||
// check if download worker is already running
|
// check if download worker is already running
|
||||||
val fileId = message.getSelectedIndividualHashMap()["id"]
|
val fileId = message.getSelectedIndividualHashMap()["id"]
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
build:
|
build:
|
||||||
maxIssues: 108
|
maxIssues: 99
|
||||||
weights:
|
weights:
|
||||||
# complexity: 2
|
# complexity: 2
|
||||||
# LongParameterList: 1
|
# LongParameterList: 1
|
||||||
|
Loading…
Reference in New Issue
Block a user