Skip to content
Snippets Groups Projects
Commit 11584579 authored by Pierre Nicolas's avatar Pierre Nicolas :joy:
Browse files

Add sequence break with previous interaction when current is a reply

Change-Id: Ic514492571b4bea54372147e512ccb7284049c1a
parent fae192eb
No related branches found
No related tags found
No related merge requests found
...@@ -1138,42 +1138,65 @@ class ConversationAdapter( ...@@ -1138,42 +1138,65 @@ class ConversationAdapter(
mInteractions[position + 1] mInteractions[position + 1]
else null else null
/**
* Returns a SequenceType object which tell what type is the Interaction.
*
* @param i index of the interaction to analyse from interactions array.
* @param isTimeShown meta data of the interaction telling if the time is shown.
* @return the SequenceType of the analyzed interaction.
*/
private fun getMsgSequencing(i: Int, isTimeShown: Boolean): SequenceType { private fun getMsgSequencing(i: Int, isTimeShown: Boolean): SequenceType {
val msg = mInteractions[i] val msg = mInteractions[i]
// Manage specific interaction which are always single (ex : emoji).
if (isAlwaysSingleMsg(msg)) { if (isAlwaysSingleMsg(msg)) {
return SequenceType.SINGLE return SequenceType.SINGLE
} }
// If there is only one interaction in the conversation
// OR if this is the first interaction.
if (mInteractions.size == 1 || i == 0) { if (mInteractions.size == 1 || i == 0) {
// If this interaction is the last.
if (mInteractions.size == i + 1) { if (mInteractions.size == i + 1) {
return SequenceType.SINGLE return SequenceType.SINGLE
} }
// Get the next interaction and if exists check if sequence break needed.
val nextMsg = getNextMessageFromPosition(i) val nextMsg = getNextMessageFromPosition(i)
if (nextMsg != null) { if (nextMsg != null) {
return if (isSeqBreak(msg, nextMsg) || hasPermanentTimeString(nextMsg, i + 1)) { return if (isSeqBreak(msg, nextMsg)
|| hasPermanentTimeString(nextMsg, i + 1)
) {
SequenceType.SINGLE SequenceType.SINGLE
} else { } else {
SequenceType.FIRST SequenceType.FIRST
} }
} }
} else if (mInteractions.size == i + 1) { } else if (mInteractions.size == i + 1) { // If this is the last interaction.
// Get the previous interaction and if exists check if sequence break needed.
val prevMsg = getPreviousMessageFromPosition(i) val prevMsg = getPreviousMessageFromPosition(i)
if (prevMsg != null) { if (prevMsg != null) {
return if (isSeqBreak(msg, prevMsg) || isTimeShown) { return if (isSeqBreak(prevMsg, msg) || isTimeShown) {
SequenceType.SINGLE SequenceType.SINGLE
} else { } else {
SequenceType.LAST SequenceType.LAST
} }
} }
} }
// If not the first, nor the last and if there is not only one interaction.
// Get the next and previous interactions and if exists check if sequence break needed.
val prevMsg = getPreviousMessageFromPosition(i) val prevMsg = getPreviousMessageFromPosition(i)
val nextMsg = getNextMessageFromPosition(i) val nextMsg = getNextMessageFromPosition(i)
if (prevMsg != null && nextMsg != null) { if (prevMsg != null && nextMsg != null) {
val nextMsgHasTime = hasPermanentTimeString(nextMsg, i + 1) val nextMsgHasTime = hasPermanentTimeString(nextMsg, i + 1)
return if ((isSeqBreak(msg, prevMsg) || isTimeShown) && !(isSeqBreak(msg, nextMsg) || nextMsgHasTime)) { return if ((isSeqBreak(prevMsg, msg) || isTimeShown)
&& !(isSeqBreak(msg, nextMsg) || nextMsgHasTime)
) {
SequenceType.FIRST SequenceType.FIRST
} else if (!isSeqBreak(msg, prevMsg) && !isTimeShown && isSeqBreak(msg, nextMsg)) { } else if (!isSeqBreak(prevMsg, msg) && !isTimeShown && isSeqBreak(msg, nextMsg)) {
SequenceType.LAST SequenceType.LAST
} else if (!isSeqBreak(msg, prevMsg) && !isTimeShown && !isSeqBreak(msg, nextMsg)) { } else if (!isSeqBreak(prevMsg, msg) && !isTimeShown && !isSeqBreak(msg, nextMsg)) {
if (nextMsgHasTime) SequenceType.LAST else SequenceType.MIDDLE if (nextMsgHasTime) SequenceType.LAST else SequenceType.MIDDLE
} else { } else {
SequenceType.SINGLE SequenceType.SINGLE
...@@ -1253,8 +1276,20 @@ class ConversationAdapter( ...@@ -1253,8 +1276,20 @@ class ConversationAdapter(
params.bottomMargin = targetSize params.bottomMargin = targetSize
} }
/**
* Tells if a break should be added in the sequence.
* The first interaction must be before the second interaction.
*
* @param first first interaction
* @param second second interaction
* @return True if a sequence break is needed. Else false.
*/
private fun isSeqBreak(first: Interaction, second: Interaction): Boolean = private fun isSeqBreak(first: Interaction, second: Interaction): Boolean =
StringUtils.isOnlyEmoji(first.body) != StringUtils.isOnlyEmoji(second.body) || first.isIncoming != second.isIncoming || first.type !== Interaction.InteractionType.TEXT || second.type !== Interaction.InteractionType.TEXT StringUtils.isOnlyEmoji(first.body) != StringUtils.isOnlyEmoji(second.body)
|| first.isIncoming != second.isIncoming
|| first.type !== Interaction.InteractionType.TEXT
|| second.type !== Interaction.InteractionType.TEXT
|| second.replyTo != null
private fun isAlwaysSingleMsg(msg: Interaction): Boolean = private fun isAlwaysSingleMsg(msg: Interaction): Boolean =
(msg.type !== Interaction.InteractionType.TEXT (msg.type !== Interaction.InteractionType.TEXT
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment