-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/develop' into feature/upgrade-pe…
…rsonal-team-api-android
- Loading branch information
Showing
42 changed files
with
946 additions
and
287 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
app/src/main/kotlin/com/wire/android/ui/common/textfield/MentionDeletionHandler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Wire | ||
* Copyright (C) 2024 Wire Swiss GmbH | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see http://www.gnu.org/licenses/. | ||
*/ | ||
package com.wire.android.ui.common.textfield | ||
|
||
import androidx.compose.ui.text.TextRange | ||
|
||
object MentionDeletionHandler { | ||
@Suppress("ReturnCount") | ||
fun handle( | ||
oldText: String, | ||
newText: String, | ||
oldSelection: TextRange, | ||
mentions: List<String> | ||
): String { | ||
if (oldText == newText) { | ||
// No change in text, only cursor movement, return as is | ||
return oldText | ||
} | ||
for (mention in mentions) { | ||
// Find the start position of the mention in the text | ||
val mentionStart = oldText.indexOf(mention) | ||
|
||
if (mentionStart == -1) continue | ||
|
||
val mentionEnd = mentionStart + mention.length | ||
|
||
// Check if the selection (i.e., user's cursor position) is inside the mention's range | ||
if (oldSelection.start in mentionStart + 1..mentionEnd || oldSelection.end in mentionStart + 1..mentionEnd) { | ||
// If the user is deleting inside the mention, remove the entire mention | ||
return oldText.removeRange(mentionStart, mentionEnd) | ||
} | ||
} | ||
return newText | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
app/src/main/kotlin/com/wire/android/ui/common/textfield/MentionVisualTransformation.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Wire | ||
* Copyright (C) 2024 Wire Swiss GmbH | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see http://www.gnu.org/licenses/. | ||
*/ | ||
package com.wire.android.ui.common.textfield | ||
|
||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.text.AnnotatedString | ||
import androidx.compose.ui.text.SpanStyle | ||
import androidx.compose.ui.text.buildAnnotatedString | ||
import androidx.compose.ui.text.font.FontWeight | ||
import androidx.compose.ui.text.input.OffsetMapping | ||
import androidx.compose.ui.text.input.TransformedText | ||
import androidx.compose.ui.text.input.VisualTransformation | ||
import androidx.compose.ui.text.withStyle | ||
import com.wire.android.ui.home.conversations.model.UIMention | ||
|
||
class MentionVisualTransformation( | ||
val color: Color, | ||
val mentions: List<UIMention> | ||
) : VisualTransformation { | ||
override fun filter(text: AnnotatedString): TransformedText { | ||
val styledText = buildAnnotatedString { | ||
var lastIndex = 0 | ||
text.takeIf { it.isNotEmpty() }?.let { | ||
mentions.forEach { mention -> | ||
// Append the text before the mention | ||
append(text.subSequence(lastIndex, mention.start)) | ||
// Apply the style to the mention | ||
withStyle(style = SpanStyle(color = color, fontWeight = FontWeight.Bold)) { | ||
append(text.subSequence(mention.start, mention.start + mention.length)) | ||
} | ||
lastIndex = mention.start + mention.length | ||
} | ||
} | ||
// Append the remaining text after the last mention | ||
append(text.subSequence(lastIndex, text.length)) | ||
} | ||
return TransformedText( | ||
text = styledText, | ||
offsetMapping = object : OffsetMapping { | ||
override fun originalToTransformed(offset: Int): Int = offset | ||
override fun transformedToOriginal(offset: Int): Int = offset | ||
} | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.