mirror of
https://github.com/oxen-io/session-android.git
synced 2025-02-17 15:18:26 +00:00
Insert mentions
This commit is contained in:
parent
6140be6e56
commit
0ac0cba448
@ -302,11 +302,9 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
|
|||||||
// 36 DP is the exact height of the typing indicator view. It's also exactly 18 * 2, and 18 is the large message
|
// 36 DP is the exact height of the typing indicator view. It's also exactly 18 * 2, and 18 is the large message
|
||||||
// corner radius. This makes 36 DP look "correct" in the context of other messages on the screen.
|
// corner radius. This makes 36 DP look "correct" in the context of other messages on the screen.
|
||||||
val typingIndicatorHeight = if (typingIndicatorViewContainer.isVisible) toPx(36, resources) else 0
|
val typingIndicatorHeight = if (typingIndicatorViewContainer.isVisible) toPx(36, resources) else 0
|
||||||
// We * don't * want to move the recycler view up when showing the mention candidates view
|
|
||||||
val additionalContentContainerHeight = if (isShowingMentionCandidatesView) 0 else additionalContentContainer.height
|
|
||||||
// Recycler view
|
// Recycler view
|
||||||
val recyclerViewLayoutParams = conversationRecyclerView.layoutParams as RelativeLayout.LayoutParams
|
val recyclerViewLayoutParams = conversationRecyclerView.layoutParams as RelativeLayout.LayoutParams
|
||||||
recyclerViewLayoutParams.bottomMargin = newValue + additionalContentContainerHeight + typingIndicatorHeight
|
recyclerViewLayoutParams.bottomMargin = newValue + typingIndicatorHeight
|
||||||
conversationRecyclerView.layoutParams = recyclerViewLayoutParams
|
conversationRecyclerView.layoutParams = recyclerViewLayoutParams
|
||||||
// Additional content container
|
// Additional content container
|
||||||
val additionalContentContainerLayoutParams = additionalContentContainer.layoutParams as RelativeLayout.LayoutParams
|
val additionalContentContainerLayoutParams = additionalContentContainer.layoutParams as RelativeLayout.LayoutParams
|
||||||
@ -331,22 +329,28 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun showOrHideMentionCandidatesIfNeeded(text: CharSequence) {
|
private fun showOrHideMentionCandidatesIfNeeded(text: CharSequence) {
|
||||||
val isBackspace = (text.length < previousText.length)
|
if (text.length < previousText.length) {
|
||||||
if (isBackspace) {
|
|
||||||
currentMentionStartIndex = -1
|
currentMentionStartIndex = -1
|
||||||
hideMentionCandidates()
|
hideMentionCandidates()
|
||||||
val mentionsToRemove = mentions.filter { !text.contains(it.displayName) }
|
val mentionsToRemove = mentions.filter { !text.contains(it.displayName) }
|
||||||
mentions.removeAll(mentionsToRemove)
|
mentions.removeAll(mentionsToRemove)
|
||||||
}
|
}
|
||||||
if (text.isNotEmpty()) {
|
if (text.isNotEmpty()) {
|
||||||
if (currentMentionStartIndex > text.length) { resetMentions() } // Should never occur
|
|
||||||
val lastCharIndex = text.lastIndex
|
val lastCharIndex = text.lastIndex
|
||||||
val lastChar = text[lastCharIndex]
|
val lastChar = text[lastCharIndex]
|
||||||
val secondToLastChar = if (lastCharIndex > 0) text[lastCharIndex - 1] else ' '
|
// Check if there is whitespace before the '@' or the '@' is the first character
|
||||||
if (lastChar == '@' && Character.isWhitespace(secondToLastChar)) {
|
|
||||||
|
val isCharacterBeforeLastWhiteSpaceOrStartOfLine: Boolean
|
||||||
|
if (text.length == 1) {
|
||||||
|
isCharacterBeforeLastWhiteSpaceOrStartOfLine = true // Start of line
|
||||||
|
} else {
|
||||||
|
val charBeforeLast = text[lastCharIndex - 1]
|
||||||
|
isCharacterBeforeLastWhiteSpaceOrStartOfLine = Character.isWhitespace(charBeforeLast)
|
||||||
|
}
|
||||||
|
if (lastChar == '@' && isCharacterBeforeLastWhiteSpaceOrStartOfLine) {
|
||||||
currentMentionStartIndex = lastCharIndex
|
currentMentionStartIndex = lastCharIndex
|
||||||
showOrUpdateMentionCandidatesIfNeeded()
|
showOrUpdateMentionCandidatesIfNeeded()
|
||||||
} else if (Character.isWhitespace(lastChar)) {
|
} else if (Character.isWhitespace(lastChar) || lastChar == '@') { // the lastCharacter == "@" is to check for @@
|
||||||
currentMentionStartIndex = -1
|
currentMentionStartIndex = -1
|
||||||
hideMentionCandidates()
|
hideMentionCandidates()
|
||||||
} else if (currentMentionStartIndex != -1) {
|
} else if (currentMentionStartIndex != -1) {
|
||||||
@ -362,6 +366,7 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
|
|||||||
additionalContentContainer.removeAllViews()
|
additionalContentContainer.removeAllViews()
|
||||||
val view = MentionCandidatesView(this)
|
val view = MentionCandidatesView(this)
|
||||||
view.glide = glide
|
view.glide = glide
|
||||||
|
view.onCandidateSelected = { handleMentionSelected(it) }
|
||||||
additionalContentContainer.addView(view)
|
additionalContentContainer.addView(view)
|
||||||
val candidates = MentionsManager.getMentionCandidates(query, threadID, thread.isOpenGroupRecipient)
|
val candidates = MentionsManager.getMentionCandidates(query, threadID, thread.isOpenGroupRecipient)
|
||||||
this.mentionCandidatesView = view
|
this.mentionCandidatesView = view
|
||||||
@ -617,6 +622,18 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
|
|||||||
// TODO: Implement
|
// TODO: Implement
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun handleMentionSelected(mention: Mention) {
|
||||||
|
if (currentMentionStartIndex == -1) { return }
|
||||||
|
mentions.add(mention)
|
||||||
|
val previousText = inputBar.text
|
||||||
|
val newText = previousText.substring(0, currentMentionStartIndex) + "@" + mention.displayName + " "
|
||||||
|
inputBar.text = newText
|
||||||
|
inputBar.inputBarEditText.setSelection(newText.length)
|
||||||
|
currentMentionStartIndex = -1
|
||||||
|
hideMentionCandidates()
|
||||||
|
this.previousText = newText
|
||||||
|
}
|
||||||
|
|
||||||
override fun send() {
|
override fun send() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user