Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable-20.1] detekt improvements #4547

Merged
merged 10 commits into from
Dec 16, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,8 @@ class OutcomingTextMessageViewHolder(itemView: View) :
itemView
)

val messageParameters = message.messageParameters
if (
(messageParameters == null || messageParameters.size <= 0) &&
(message.messageParameters == null || message.messageParameters!!.size <= 0) &&
TextMatchers.isMessageWithSingleEmoticonOnly(message.text)
) {
textSize = (textSize * TEXT_SIZE_MULTIPLIER).toFloat()
Expand Down Expand Up @@ -115,13 +114,29 @@ class OutcomingTextMessageViewHolder(itemView: View) :
binding.messageQuote.quotedChatMessageView.visibility = View.GONE
}

val readStatusDrawableInt = when (message.readStatus) {
setReadStatus(message.readStatus)

itemView.setTag(R.string.replyable_message_view_tag, message.replyable)

Reaction().showReactions(
message,
::clickOnReaction,
::longClickOnReaction,
binding.reactions,
context,
true,
viewThemeUtils
)
}

private fun setReadStatus(readStatus: Enum<ReadStatus>) {
val readStatusDrawableInt = when (readStatus) {
ReadStatus.READ -> R.drawable.ic_check_all
ReadStatus.SENT -> R.drawable.ic_check
else -> null
}

val readStatusContentDescriptionString = when (message.readStatus) {
val readStatusContentDescriptionString = when (readStatus) {
ReadStatus.READ -> context.resources?.getString(R.string.nc_message_read)
ReadStatus.SENT -> context.resources?.getString(R.string.nc_message_sent)
else -> null
Expand All @@ -135,18 +150,6 @@ class OutcomingTextMessageViewHolder(itemView: View) :
}

binding.checkMark.contentDescription = readStatusContentDescriptionString

itemView.setTag(R.string.replyable_message_view_tag, message.replyable)

Reaction().showReactions(
message,
::clickOnReaction,
::longClickOnReaction,
binding.reactions,
context,
true,
viewThemeUtils
)
}

private fun longClickOnReaction(chatMessage: ChatMessage) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,27 @@ class OutcomingVoiceMessageViewHolder(outcomingView: View) :
}
})

val readStatusDrawableInt = when (message.readStatus) {
setReadStatus(message.readStatus)

Reaction().showReactions(
message,
::clickOnReaction,
::longClickOnReaction,
binding.reactions,
binding.messageTime.context,
true,
viewThemeUtils
)
}

private fun setReadStatus(readStatus: Enum<ReadStatus>) {
val readStatusDrawableInt = when (readStatus) {
ReadStatus.READ -> R.drawable.ic_check_all
ReadStatus.SENT -> R.drawable.ic_check
else -> null
}

val readStatusContentDescriptionString = when (message.readStatus) {
val readStatusContentDescriptionString = when (readStatus) {
ReadStatus.READ -> context?.resources?.getString(R.string.nc_message_read)
ReadStatus.SENT -> context?.resources?.getString(R.string.nc_message_sent)
else -> null
Expand All @@ -148,16 +162,6 @@ class OutcomingVoiceMessageViewHolder(outcomingView: View) :
}

binding.checkMark.contentDescription = readStatusContentDescriptionString

Reaction().showReactions(
message,
::clickOnReaction,
::longClickOnReaction,
binding.reactions,
binding.messageTime.context,
true,
viewThemeUtils
)
}

private fun longClickOnReaction(chatMessage: ChatMessage) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,34 +85,7 @@ class SystemMessageViewHolder(itemView: View) : MessageHolders.IncomingTextMessa
binding.systemMessageLayout.visibility = View.VISIBLE
binding.similarMessagesHint.visibility = View.GONE
if (message.expandableParent) {
binding.expandCollapseIcon.visibility = View.VISIBLE

if (!message.isExpanded) {
val similarMessages = String.format(
sharedApplication!!.resources.getString(R.string.see_similar_system_messages),
message.expandableChildrenAmount
)

binding.messageText.text = messageString
binding.similarMessagesHint.visibility = View.VISIBLE
binding.similarMessagesHint.text = similarMessages

binding.expandCollapseIcon.setImageDrawable(
ContextCompat.getDrawable(context!!, R.drawable.baseline_unfold_more_24)
)
binding.systemMessageLayout.setOnClickListener { systemMessageInterface.expandSystemMessage(message) }
binding.messageText.setOnClickListener { systemMessageInterface.expandSystemMessage(message) }
} else {
binding.messageText.text = messageString
binding.similarMessagesHint.visibility = View.GONE
binding.similarMessagesHint.text = ""

binding.expandCollapseIcon.setImageDrawable(
ContextCompat.getDrawable(context!!, R.drawable.baseline_unfold_less_24)
)
binding.systemMessageLayout.setOnClickListener { systemMessageInterface.collapseSystemMessages() }
binding.messageText.setOnClickListener { systemMessageInterface.collapseSystemMessages() }
}
processExpandableParent(message, messageString)
} else if (message.hiddenByCollapse) {
binding.systemMessageLayout.visibility = View.GONE
} else {
Expand All @@ -131,6 +104,38 @@ class SystemMessageViewHolder(itemView: View) : MessageHolders.IncomingTextMessa
itemView.setTag(R.string.replyable_message_view_tag, message.replyable)
}

@SuppressLint("SetTextI18n", "StringFormatInvalid")
private fun processExpandableParent(message: ChatMessage, messageString: Spannable) {
binding.expandCollapseIcon.visibility = View.VISIBLE

if (!message.isExpanded) {
val similarMessages = String.format(
sharedApplication!!.resources.getString(R.string.see_similar_system_messages),
message.expandableChildrenAmount
)

binding.messageText.text = messageString
binding.similarMessagesHint.visibility = View.VISIBLE
binding.similarMessagesHint.text = similarMessages

binding.expandCollapseIcon.setImageDrawable(
ContextCompat.getDrawable(context!!, R.drawable.baseline_unfold_more_24)
)
binding.systemMessageLayout.setOnClickListener { systemMessageInterface.expandSystemMessage(message) }
binding.messageText.setOnClickListener { systemMessageInterface.expandSystemMessage(message) }
} else {
binding.messageText.text = messageString
binding.similarMessagesHint.visibility = View.GONE
binding.similarMessagesHint.text = ""

binding.expandCollapseIcon.setImageDrawable(
ContextCompat.getDrawable(context!!, R.drawable.baseline_unfold_less_24)
)
binding.systemMessageLayout.setOnClickListener { systemMessageInterface.collapseSystemMessages() }
binding.messageText.setOnClickListener { systemMessageInterface.collapseSystemMessages() }
}
}

fun assignSystemMessageInterface(systemMessageInterface: SystemMessageInterface) {
this.systemMessageInterface = systemMessageInterface
}
Expand Down
17 changes: 14 additions & 3 deletions app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3335,8 +3335,6 @@ class ChatActivity :
}

fun shareToNotes(message: ChatMessage, roomToken: String) {
val apiVersion = ApiUtils.getChatApiVersion(spreedCapabilities, intArrayOf(1))
val type = message.getCalculateMessageType()
var shareUri: Uri? = null
val data: HashMap<String?, String?>?
var metaData: String = ""
Expand Down Expand Up @@ -3366,6 +3364,17 @@ class ChatActivity :
"\"longitude\":\"$lon\",\"name\":\"$name\"}"
}

shareToNotes(shareUri, roomToken, message, objectId, metaData)
}

private fun shareToNotes(
shareUri: Uri?,
roomToken: String,
message: ChatMessage,
objectId: String,
metaData: String
) {
val type = message.getCalculateMessageType()
when (type) {
ChatMessage.MessageType.VOICE_MESSAGE -> {
uploadFile(shareUri.toString(), true, token = roomToken)
Expand All @@ -3380,7 +3389,7 @@ class ChatActivity :
uploadFile(shareUri.toString(), false, caption!!, roomToken)
Snackbar.make(binding.root, R.string.nc_message_sent, Snackbar.LENGTH_SHORT).show()
} catch (e: java.lang.Exception) {
Log.w(TAG, "File corresponding to the uri does not exist " + shareUri.toString())
Log.w(TAG, "File corresponding to the uri does not exist $shareUri")
downloadFileToCache(message, false) {
uploadFile(shareUri.toString(), false, caption!!, roomToken)
Snackbar.make(binding.root, R.string.nc_message_sent, Snackbar.LENGTH_SHORT).show()
Expand All @@ -3390,6 +3399,7 @@ class ChatActivity :
}

ChatMessage.MessageType.SINGLE_NC_GEOLOCATION_MESSAGE -> {
val apiVersion = ApiUtils.getChatApiVersion(spreedCapabilities, intArrayOf(1))
chatViewModel.shareLocationToNotes(
credentials!!,
ApiUtils.getUrlToSendLocation(apiVersion, conversationUser!!.baseUrl!!, roomToken),
Expand All @@ -3401,6 +3411,7 @@ class ChatActivity :
}

ChatMessage.MessageType.REGULAR_TEXT_MESSAGE -> {
val apiVersion = ApiUtils.getChatApiVersion(spreedCapabilities, intArrayOf(1))
chatViewModel.shareToNotes(
credentials!!,
ApiUtils.getUrlForChat(apiVersion, conversationUser!!.baseUrl!!, roomToken),
Expand Down
28 changes: 8 additions & 20 deletions app/src/main/java/com/nextcloud/talk/chat/MessageInputFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class MessageInputFragment : Fragment() {
private var mentionAutocomplete: Autocomplete<*>? = null
private var xcounter = 0f
private var ycounter = 0f
private var isCollapsed = false
private var collapsed = false

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand Down Expand Up @@ -219,11 +219,7 @@ class MessageInputFragment : Fragment() {
binding.fragmentCallStarted.callAuthorChipSecondary.text = message.actorDisplayName
val user = userManager.currentUser.blockingGet()
val url: String = if (message.actorType == "guests" || message.actorType == "guest") {
ApiUtils.getUrlForGuestAvatar(
user!!.baseUrl!!,
message.actorDisplayName,
true
)
ApiUtils.getUrlForGuestAvatar(user!!.baseUrl!!, message.actorDisplayName, true)
} else {
ApiUtils.getUrlForAvatar(user!!.baseUrl!!, message.actorId, false)
}
Expand Down Expand Up @@ -456,20 +452,12 @@ class MessageInputFragment : Fragment() {
}

binding.fragmentCallStarted.callStartedCloseBtn.setOnClickListener {
isCollapsed = !isCollapsed
if (isCollapsed) {
binding.fragmentCallStarted.callAuthorLayout.visibility = View.GONE
binding.fragmentCallStarted.callBtnLayout.visibility = View.GONE
binding.fragmentCallStarted.callAuthorChipSecondary.visibility = View.VISIBLE
binding.fragmentCallStarted.callStartedSecondaryText.visibility = View.VISIBLE
} else {
binding.fragmentCallStarted.callAuthorLayout.visibility = View.VISIBLE
binding.fragmentCallStarted.callBtnLayout.visibility = View.VISIBLE
binding.fragmentCallStarted.callAuthorChipSecondary.visibility = View.GONE
binding.fragmentCallStarted.callStartedSecondaryText.visibility = View.GONE
}

setDropDown(isCollapsed)
collapsed = !collapsed
binding.fragmentCallStarted.callAuthorLayout.visibility = if (collapsed) View.GONE else View.VISIBLE
binding.fragmentCallStarted.callBtnLayout.visibility = if (collapsed) View.GONE else View.VISIBLE
binding.fragmentCallStarted.callAuthorChipSecondary.visibility = if (collapsed) View.VISIBLE else View.GONE
binding.fragmentCallStarted.callStartedSecondaryText.visibility = if (collapsed) View.VISIBLE else View.GONE
setDropDown(collapsed)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -506,55 +506,68 @@ class OfflineFirstChatRepository @Inject constructor(
}

if (result.second.isNotEmpty()) {
val chatMessagesJson = result.second
chatMessagesFromSync = updateMessagesData(
result.second,
blockContainingQueriedMessage,
lookIntoFuture,
hasHistory
)
} else {
Log.d(TAG, "no data is updated...")
}

handleUpdateMessages(chatMessagesJson)
return chatMessagesFromSync
}

chatMessagesFromSync = chatMessagesJson.map {
it.asEntity(currentUser.id!!)
}
private suspend fun OfflineFirstChatRepository.updateMessagesData(
chatMessagesJson: List<ChatMessageJson>,
blockContainingQueriedMessage: ChatBlockEntity?,
lookIntoFuture: Boolean,
hasHistory: Boolean
): List<ChatMessageEntity> {
handleUpdateMessages(chatMessagesJson)

chatDao.upsertChatMessages(chatMessagesFromSync)
val chatMessagesFromSyncToProcess = chatMessagesJson.map {
it.asEntity(currentUser.id!!)
}

val oldestIdFromSync = chatMessagesFromSync.minByOrNull { it.id }!!.id
val newestIdFromSync = chatMessagesFromSync.maxByOrNull { it.id }!!.id
Log.d(TAG, "oldestIdFromSync: $oldestIdFromSync")
Log.d(TAG, "newestIdFromSync: $newestIdFromSync")
chatDao.upsertChatMessages(chatMessagesFromSyncToProcess)

var oldestMessageIdForNewChatBlock = oldestIdFromSync
var newestMessageIdForNewChatBlock = newestIdFromSync
val oldestIdFromSync = chatMessagesFromSyncToProcess.minByOrNull { it.id }!!.id
val newestIdFromSync = chatMessagesFromSyncToProcess.maxByOrNull { it.id }!!.id
Log.d(TAG, "oldestIdFromSync: $oldestIdFromSync")
Log.d(TAG, "newestIdFromSync: $newestIdFromSync")

if (blockContainingQueriedMessage != null) {
if (lookIntoFuture) {
val oldestMessageIdFromBlockOfQueriedMessage = blockContainingQueriedMessage.oldestMessageId
Log.d(TAG, "oldestMessageIdFromBlockOfQueriedMessage: $oldestMessageIdFromBlockOfQueriedMessage")
oldestMessageIdForNewChatBlock = oldestMessageIdFromBlockOfQueriedMessage
} else {
val newestMessageIdFromBlockOfQueriedMessage = blockContainingQueriedMessage.newestMessageId
Log.d(TAG, "newestMessageIdFromBlockOfQueriedMessage: $newestMessageIdFromBlockOfQueriedMessage")
newestMessageIdForNewChatBlock = newestMessageIdFromBlockOfQueriedMessage
}
}
var oldestMessageIdForNewChatBlock = oldestIdFromSync
var newestMessageIdForNewChatBlock = newestIdFromSync

Log.d(TAG, "oldestMessageIdForNewChatBlock: $oldestMessageIdForNewChatBlock")
Log.d(TAG, "newestMessageIdForNewChatBlock: $newestMessageIdForNewChatBlock")
if (blockContainingQueriedMessage != null) {
if (lookIntoFuture) {
val oldestMessageIdFromBlockOfQueriedMessage = blockContainingQueriedMessage.oldestMessageId
Log.d(TAG, "oldestMessageIdFromBlockOfQueriedMessage: $oldestMessageIdFromBlockOfQueriedMessage")
oldestMessageIdForNewChatBlock = oldestMessageIdFromBlockOfQueriedMessage
} else {
val newestMessageIdFromBlockOfQueriedMessage = blockContainingQueriedMessage.newestMessageId
Log.d(TAG, "newestMessageIdFromBlockOfQueriedMessage: $newestMessageIdFromBlockOfQueriedMessage")
newestMessageIdForNewChatBlock = newestMessageIdFromBlockOfQueriedMessage
}
}

val newChatBlock = ChatBlockEntity(
internalConversationId = internalConversationId,
accountId = conversationModel.accountId,
token = conversationModel.token,
oldestMessageId = oldestMessageIdForNewChatBlock,
newestMessageId = newestMessageIdForNewChatBlock,
hasHistory = hasHistory
)
chatBlocksDao.upsertChatBlock(newChatBlock)
Log.d(TAG, "oldestMessageIdForNewChatBlock: $oldestMessageIdForNewChatBlock")
Log.d(TAG, "newestMessageIdForNewChatBlock: $newestMessageIdForNewChatBlock")

updateBlocks(newChatBlock)
} else {
Log.d(TAG, "no data is updated...")
}
val newChatBlock = ChatBlockEntity(
internalConversationId = internalConversationId,
accountId = conversationModel.accountId,
token = conversationModel.token,
oldestMessageId = oldestMessageIdForNewChatBlock,
newestMessageId = newestMessageIdForNewChatBlock,
hasHistory = hasHistory
)
chatBlocksDao.upsertChatBlock(newChatBlock)

return chatMessagesFromSync
updateBlocks(newChatBlock)
return chatMessagesFromSyncToProcess
}

private suspend fun handleUpdateMessages(messagesJson: List<ChatMessageJson>) {
Expand Down
Loading
Loading