Skip to content

Commit

Permalink
Merge pull request #4544 from nextcloud/style/noid/detekt-improvements
Browse files Browse the repository at this point in the history
detekt improvements
  • Loading branch information
AndyScherzinger authored Dec 13, 2024
2 parents 19c5b14 + d2778b2 commit a73099d
Show file tree
Hide file tree
Showing 17 changed files with 479 additions and 484 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
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 @@ -457,20 +453,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
Loading

0 comments on commit a73099d

Please sign in to comment.