Skip to content

Commit

Permalink
style(detekt): Shorten methods
Browse files Browse the repository at this point in the history
Signed-off-by: Andy Scherzinger <[email protected]>
  • Loading branch information
AndyScherzinger committed Dec 13, 2024
1 parent 279bd8a commit f549870
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 65 deletions.
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 @@ -131,13 +131,32 @@ class OutcomingVoiceMessageViewHolder(outcomingView: View) :
}
})

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

voiceMessageInterface.registerMessageToObservePlaybackSpeedPreferences(message.user.id) { speed ->
binding.playbackSpeedControlBtn.setSpeed(speed)
}

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

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 @@ -151,21 +170,6 @@ class OutcomingVoiceMessageViewHolder(outcomingView: View) :
}

binding.checkMark.contentDescription = readStatusContentDescriptionString

voiceMessageInterface.registerMessageToObservePlaybackSpeedPreferences(message.user.id) { speed ->
binding.playbackSpeedControlBtn.setSpeed(speed)
}

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

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 @@ -3387,8 +3387,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 @@ -3418,6 +3416,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 @@ -3432,7 +3441,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 @@ -3442,6 +3451,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 @@ -3453,6 +3463,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
2 changes: 1 addition & 1 deletion detekt.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
# SPDX-License-Identifier: GPL-3.0-or-later
build:
maxIssues: 86
maxIssues: 83
weights:
# complexity: 2
# LongParameterList: 1
Expand Down

0 comments on commit f549870

Please sign in to comment.