From 46226c4efc802b0bb458963a58a3119c83cda880 Mon Sep 17 00:00:00 2001 From: ganfra Date: Tue, 26 Feb 2019 15:04:43 +0100 Subject: [PATCH] Avatar : skip '@' when name is userId --- .../core/extensions/CharSequence.kt | 22 ------------------- .../features/home/AvatarRenderer.kt | 7 ++++-- 2 files changed, 5 insertions(+), 24 deletions(-) delete mode 100644 app/src/main/java/im/vector/riotredesign/core/extensions/CharSequence.kt diff --git a/app/src/main/java/im/vector/riotredesign/core/extensions/CharSequence.kt b/app/src/main/java/im/vector/riotredesign/core/extensions/CharSequence.kt deleted file mode 100644 index b16c110a93..0000000000 --- a/app/src/main/java/im/vector/riotredesign/core/extensions/CharSequence.kt +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2019 New Vector Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package im.vector.riotredesign.core.extensions - - -fun CharSequence.firstCharAsString(): String { - return if (isNotEmpty()) this[0].toString() else "" -} \ No newline at end of file diff --git a/app/src/main/java/im/vector/riotredesign/features/home/AvatarRenderer.kt b/app/src/main/java/im/vector/riotredesign/features/home/AvatarRenderer.kt index 5e66ddba27..ae21e6b916 100644 --- a/app/src/main/java/im/vector/riotredesign/features/home/AvatarRenderer.kt +++ b/app/src/main/java/im/vector/riotredesign/features/home/AvatarRenderer.kt @@ -21,10 +21,10 @@ import androidx.core.content.ContextCompat import com.amulyakhare.textdrawable.TextDrawable import com.bumptech.glide.request.RequestOptions import im.vector.matrix.android.api.Matrix +import im.vector.matrix.android.api.MatrixPatterns import im.vector.matrix.android.api.session.room.model.RoomMember import im.vector.matrix.android.api.session.room.model.RoomSummary import im.vector.riotredesign.R -import im.vector.riotredesign.core.extensions.firstCharAsString import im.vector.riotredesign.core.glide.GlideApp object AvatarRenderer { @@ -43,7 +43,10 @@ object AvatarRenderer { } val resolvedUrl = Matrix.getInstance().currentSession.contentUrlResolver().resolveFullSize(avatarUrl) val avatarColor = ContextCompat.getColor(imageView.context, R.color.pale_teal) - val fallbackDrawable = TextDrawable.builder().buildRound(name.firstCharAsString().toUpperCase(), avatarColor) + val isNameUserId = MatrixPatterns.isUserId(name) + val firstLetterIndex = if (isNameUserId) 1 else 0 + val firstLetter = name[firstLetterIndex].toString().toUpperCase() + val fallbackDrawable = TextDrawable.builder().buildRound(firstLetter, avatarColor) GlideApp .with(imageView)