Fix warning 1.5: 'Char.toInt(): Int' is deprecated

This commit is contained in:
Benoit Marty 2021-05-14 12:47:09 +02:00
parent 58a2fd8c77
commit 7a28be941c
3 changed files with 8 additions and 8 deletions

View file

@ -117,15 +117,15 @@ sealed class MatrixItem(
var first = dn[startIndex]
// LEFT-TO-RIGHT MARK
if (dn.length >= 2 && 0x200e == first.toInt()) {
if (dn.length >= 2 && 0x200e == first.code) {
startIndex++
first = dn[startIndex]
}
// check if its the start of a surrogate pair
if (first.toInt() in 0xD800..0xDBFF && dn.length > startIndex + 1) {
if (first.code in 0xD800..0xDBFF && dn.length > startIndex + 1) {
val second = dn[startIndex + 1]
if (second.toInt() in 0xDC00..0xDFFF) {
if (second.code in 0xDC00..0xDFFF) {
length++
}
}

View file

@ -42,13 +42,13 @@ fun CharSequence.splitEmoji(): List<CharSequence> {
while (index < length) {
val firstChar = get(index)
if (firstChar.toInt() == 0x200e) {
if (firstChar.code == 0x200e) {
// Left to right mark. What should I do with it?
} else if (firstChar.toInt() in 0xD800..0xDBFF && index + 1 < length) {
} else if (firstChar.code in 0xD800..0xDBFF && index + 1 < length) {
// We have the start of a surrogate pair
val secondChar = get(index + 1)
if (secondChar.toInt() in 0xDC00..0xDFFF) {
if (secondChar.code in 0xDC00..0xDFFF) {
// We have an emoji
result.add("$firstChar$secondChar")
index++

View file

@ -50,7 +50,7 @@ class MatrixItemColorProvider @Inject constructor(
fun getColorFromUserId(userId: String?): Int {
var hash = 0
userId?.toList()?.map { chr -> hash = (hash shl 5) - hash + chr.toInt() }
userId?.toList()?.map { chr -> hash = (hash shl 5) - hash + chr.code }
return when (abs(hash) % 8) {
1 -> R.color.riotx_username_2
@ -66,7 +66,7 @@ class MatrixItemColorProvider @Inject constructor(
@ColorRes
private fun getColorFromRoomId(roomId: String?): Int {
return when ((roomId?.toList()?.sumBy { it.toInt() } ?: 0) % 3) {
return when ((roomId?.toList()?.sumBy { it.code } ?: 0) % 3) {
1 -> R.color.riotx_avatar_fill_2
2 -> R.color.riotx_avatar_fill_3
else -> R.color.riotx_avatar_fill_1