Skip to content

Commit 9680e33

Browse files
Merge pull request #1690 from session-foundation/fix/avatar-badges
Fix/avatar badges
2 parents e075acd + f7984ed commit 9680e33

File tree

9 files changed

+41
-49
lines changed

9 files changed

+41
-49
lines changed
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
package org.thoughtcrime.securesms.conversation.v2.input_bar.mentions
22

3-
import android.view.View
43
import network.loki.messenger.databinding.ViewMentionCandidateV2Binding
54
import org.thoughtcrime.securesms.conversation.v2.mention.MentionViewModel
65
import org.thoughtcrime.securesms.ui.components.Avatar
76
import org.thoughtcrime.securesms.ui.setThemedContent
87
import org.thoughtcrime.securesms.ui.theme.LocalDimensions
8+
import org.thoughtcrime.securesms.util.AvatarBadge
99

1010
fun ViewMentionCandidateV2Binding.update(candidate: MentionViewModel.Candidate) {
1111
mentionCandidateNameTextView.text = candidate.nameHighlighted
1212
profilePictureView.setThemedContent {
1313
Avatar(
1414
size = LocalDimensions.current.iconMediumAvatar,
1515
data = candidate.member.avatarData,
16+
badge = if (candidate.member.showAdminCrown) AvatarBadge.Admin else AvatarBadge.None
1617
)
1718
}
18-
19-
moderatorIconImageView.visibility = if (candidate.member.showAdminCrown) View.VISIBLE else View.GONE
2019
}

app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/VisibleMessageView.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ import org.thoughtcrime.securesms.ui.theme.LocalColors
6161
import org.thoughtcrime.securesms.ui.theme.LocalDimensions
6262
import org.thoughtcrime.securesms.ui.theme.LocalType
6363
import org.thoughtcrime.securesms.ui.theme.bold
64+
import org.thoughtcrime.securesms.util.AvatarBadge
6465
import org.thoughtcrime.securesms.util.AvatarUtils
6566
import org.thoughtcrime.securesms.util.DateUtils
6667
import org.thoughtcrime.securesms.util.disableClipping
@@ -176,7 +177,6 @@ class VisibleMessageView : FrameLayout {
176177
val isStartOfMessageCluster = isStartOfMessageCluster(message, previous, isGroupThread)
177178
val isEndOfMessageCluster = isEndOfMessageCluster(message, next, isGroupThread)
178179
// Show profile picture and sender name if this is a group thread AND the message is incoming
179-
binding.moderatorIconImageView.isVisible = false
180180
binding.profilePictureView.visibility = when {
181181
threadRecipient.isGroupOrCommunityRecipient && !message.isOutgoing && isEndOfMessageCluster -> View.VISIBLE
182182
threadRecipient.isGroupOrCommunityRecipient -> View.INVISIBLE
@@ -200,22 +200,22 @@ class VisibleMessageView : FrameLayout {
200200

201201
if (isGroupThread && !message.isOutgoing) {
202202
if (isEndOfMessageCluster) {
203+
val showProBadge = if (sender.address is Address.WithAccountId) {
204+
(threadRecipient.data as? RecipientData.GroupLike)
205+
?.shouldShowAdminCrown(sender.address.accountId) == true
206+
} else {
207+
false
208+
}
203209
binding.profilePictureView.setThemedContent {
204210
Avatar(
205211
size = LocalDimensions.current.iconMediumAvatar,
206212
data = avatarUtils.getUIDataFromRecipient(sender),
213+
badge = if(showProBadge) AvatarBadge.Admin else AvatarBadge.None,
207214
modifier = Modifier.clickable {
208215
delegate?.showUserProfileModal(message.recipient)
209216
}
210217
)
211218
}
212-
213-
binding.moderatorIconImageView.isVisible = if (sender.address is Address.WithAccountId) {
214-
(threadRecipient.data as? RecipientData.GroupLike)
215-
?.shouldShowAdminCrown(sender.address.accountId) == true
216-
} else {
217-
false
218-
}
219219
}
220220
}
221221
if(!message.isOutgoing && (isStartOfMessageCluster && isGroupThread)){

app/src/main/java/org/thoughtcrime/securesms/ui/ProComponents.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ import org.thoughtcrime.securesms.ui.theme.LocalType
8080
import org.thoughtcrime.securesms.ui.theme.PreviewTheme
8181
import org.thoughtcrime.securesms.ui.theme.SessionColorsParameterProvider
8282
import org.thoughtcrime.securesms.ui.theme.ThemeColors
83+
import org.thoughtcrime.securesms.util.AvatarBadge
8384
import org.thoughtcrime.securesms.util.AvatarUIData
8485

8586

@@ -750,7 +751,7 @@ fun AvatarQrWidget(
750751
label = "corner_radius"
751752
)
752753

753-
// Scale animations for content
754+
// Scale animations for content (used when going from QR back to avatar)
754755
val avatarScale by animateFloatAsState(
755756
targetValue = if (showQR) 0.8f else 1f,
756757
animationSpec = animationSpecFast,
@@ -835,7 +836,6 @@ fun AvatarQrWidget(
835836
}
836837
Avatar(
837838
modifier = avatarModifier
838-
.size(animatedSize)
839839
.graphicsLayer(
840840
alpha = avatarAlpha,
841841
scaleX = avatarScale,
@@ -844,7 +844,7 @@ fun AvatarQrWidget(
844844
,
845845
size = animatedSize,
846846
maxSizeLoad = LocalDimensions.current.iconXXLargeAvatar,
847-
data = avatarUIData
847+
data = avatarUIData,
848848
)
849849

850850
// QR with scale and alpha

app/src/main/java/org/thoughtcrime/securesms/ui/components/Avatar.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import androidx.compose.ui.tooling.preview.Preview
3131
import androidx.compose.ui.tooling.preview.PreviewParameter
3232
import androidx.compose.ui.unit.Dp
3333
import androidx.compose.ui.unit.dp
34+
import androidx.compose.ui.unit.max
3435
import androidx.compose.ui.unit.sp
3536
import coil3.compose.AsyncImagePainter
3637
import coil3.compose.SubcomposeAsyncImage
@@ -55,6 +56,7 @@ import org.thoughtcrime.securesms.util.AvatarUIData
5556
import org.thoughtcrime.securesms.util.AvatarUIElement
5657
import org.thoughtcrime.securesms.util.avatarOptions
5758

59+
private val MIN_BADGE_SIZE = 12.dp
5860

5961
@Composable
6062
fun BaseAvatar(
@@ -105,8 +107,8 @@ fun BaseAvatar(
105107
Box(
106108
modifier = Modifier
107109
.align(Alignment.BottomEnd)
108-
.offset(1.dp, 1.dp) // Used to make up for transparent padding in icon.
109-
.size(size * 0.4f)
110+
.offset(x = 1.dp, y = 1.dp)
111+
.size(max(size * 0.4f, MIN_BADGE_SIZE))
110112
) {
111113
badge()
112114
}

app/src/main/java/org/thoughtcrime/securesms/util/AvatarUtils.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ data class AvatarUIElement(
231231

232232
sealed class AvatarBadge(@DrawableRes val icon: Int){
233233
data object None: AvatarBadge(0)
234-
data object Admin: AvatarBadge(R.drawable.ic_crown_custom_enlarged)
234+
data object Admin: AvatarBadge(R.drawable.ic_crown_custom_enlarged_no_padding)
235235
data class Custom(@DrawableRes val iconRes: Int): AvatarBadge(iconRes)
236236
}
237237

app/src/main/java/org/thoughtcrime/securesms/util/FilenameUtils.kt

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,18 @@ object FilenameUtils {
9292
val projection = arrayOf(OpenableColumns.DISPLAY_NAME)
9393
val contentRes = context.contentResolver
9494
if (contentRes != null) {
95-
val cursor = contentRes.query(uri, projection, null, null, null)
96-
cursor?.use {
97-
if (it.moveToFirst()) {
98-
val nameIndex = it.getColumnIndexOrThrow(OpenableColumns.DISPLAY_NAME)
99-
extractedFilename = it.getString(nameIndex)
95+
try {
96+
val cursor = contentRes.query(uri, projection, null, null, null)
97+
cursor?.use {
98+
if (it.moveToFirst()) {
99+
val nameIndex = it.getColumnIndex(OpenableColumns.DISPLAY_NAME)
100+
if (nameIndex != -1) {
101+
extractedFilename = it.getString(nameIndex)
102+
}
103+
}
100104
}
105+
} catch (e: Exception) {
106+
Log.w(TAG, "Unable to query display name for uri: $uri", e)
101107
}
102108
}
103109
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="38dp"
3+
android:height="38dp"
4+
android:viewportWidth="38"
5+
android:viewportHeight="38">
6+
<path
7+
android:pathData="M19,19m-19,0a19,19 0,1 1,38 0a19,19 0,1 1,-38 0"
8+
android:fillColor="?crownBg"/>
9+
<path
10+
android:pathData="M27.092,28.268C27.745,28.268 28.274,28.798 28.274,29.45C28.274,30.103 27.745,30.632 27.092,30.632H10.543C9.891,30.632 9.361,30.103 9.361,29.45C9.361,28.798 9.891,28.268 10.543,28.268H27.092ZM18.936,7.005C19.173,7.02 19.404,7.084 19.616,7.19L19.72,7.247L19.82,7.311C20.015,7.445 20.182,7.617 20.31,7.816L20.371,7.919L20.381,7.938L23.864,14.549L28.903,10.232L28.926,10.213C29.217,9.976 29.576,9.837 29.951,9.817L30.091,9.816C30.371,9.823 30.645,9.896 30.891,10.03L31.012,10.102L31.127,10.183C31.348,10.354 31.527,10.574 31.646,10.827L31.702,10.956L31.746,11.089C31.838,11.402 31.843,11.736 31.756,12.053L31.754,12.058L28.405,24.169C28.268,24.664 27.973,25.102 27.566,25.415C27.158,25.728 26.659,25.9 26.145,25.904H11.493C10.979,25.901 10.479,25.729 10.071,25.416C9.663,25.103 9.367,24.665 9.23,24.169L5.882,12.06L5.88,12.054C5.782,11.692 5.801,11.307 5.935,10.957L5.99,10.829C6.13,10.534 6.349,10.282 6.624,10.103L6.745,10.031C6.991,9.897 7.265,9.824 7.545,9.817L7.685,9.818L7.825,9.831C8.148,9.874 8.455,10.007 8.71,10.214C8.717,10.22 8.726,10.226 8.734,10.233L13.771,14.549L17.254,7.938L17.264,7.919C17.417,7.641 17.642,7.409 17.916,7.247L18.02,7.19C18.267,7.066 18.54,7 18.818,7L18.936,7.005Z"
11+
android:fillColor="?crown"/>
12+
</vector>

app/src/main/res/layout/view_mention_candidate_v2.xml

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,6 @@
2525
app:layout_constraintTop_toTopOf="parent"
2626
app:layout_constraintStart_toStartOf="parent"/>
2727

28-
<ImageView
29-
android:id="@+id/moderatorIconImageView"
30-
android:layout_width="16dp"
31-
android:layout_height="16dp"
32-
android:src="@drawable/ic_crown_custom_enlarged"
33-
android:layout_marginEnd="-1dp"
34-
android:layout_marginBottom="-1dp"
35-
android:layout_alignParentEnd="true"
36-
android:layout_alignParentBottom="true"
37-
app:layout_constraintBottom_toBottomOf="@+id/profilePictureView"
38-
app:layout_constraintEnd_toEndOf="@+id/profilePictureView"
39-
android:contentDescription="@string/AccessibilityId_contactMentions"/>
40-
4128
</androidx.constraintlayout.widget.ConstraintLayout>
4229

4330
<TextView

app/src/main/res/layout/view_visible_message.xml

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,6 @@
4545
app:layout_constraintStart_toStartOf="parent"
4646
tools:visibility="visible" />
4747

48-
<ImageView
49-
android:id="@+id/moderatorIconImageView"
50-
android:layout_width="16dp"
51-
android:layout_height="16dp"
52-
android:src="@drawable/ic_crown_custom_enlarged"
53-
android:layout_marginEnd="-1dp"
54-
android:layout_marginBottom="-1dp"
55-
android:layout_alignParentEnd="true"
56-
android:layout_alignParentBottom="true"
57-
android:visibility="gone"
58-
app:layout_constraintBottom_toBottomOf="@+id/profilePictureView"
59-
app:layout_constraintEnd_toEndOf="@+id/profilePictureView"
60-
tools:visibility="visible"/>
61-
6248
<androidx.compose.ui.platform.ComposeView
6349
android:id="@+id/senderName"
6450
android:layout_width="0dp"

0 commit comments

Comments
 (0)