From 7f1734b57c22e7f2c744c54ae01430e573bd0bfe Mon Sep 17 00:00:00 2001 From: adbenitez Date: Tue, 22 Apr 2025 22:53:47 +0200 Subject: [PATCH] fix linter warnings in ConversationListItem --- .../securesms/ConversationListItem.java | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/thoughtcrime/securesms/ConversationListItem.java b/src/main/java/org/thoughtcrime/securesms/ConversationListItem.java index 6859e13b8..360564c9e 100644 --- a/src/main/java/org/thoughtcrime/securesms/ConversationListItem.java +++ b/src/main/java/org/thoughtcrime/securesms/ConversationListItem.java @@ -64,11 +64,9 @@ public class ConversationListItem extends RelativeLayout private final static Typeface BOLD_TYPEFACE = Typeface.create("sans-serif-medium", Typeface.NORMAL); private final static Typeface LIGHT_TYPEFACE = Typeface.create("sans-serif", Typeface.NORMAL); - private DcLot dcSummary; private Set selectedThreads; private long chatId; private int msgId; - private GlideRequests glideRequests; private TextView subjectView; private FromTextView fromView; private TextView dateView; @@ -122,12 +120,10 @@ public class ConversationListItem extends RelativeLayout boolean batchMode, @Nullable String highlightSubstring) { - this.dcSummary = dcSummary; this.selectedThreads = selectedThreads; Recipient recipient = thread.getRecipient(); this.chatId = thread.getThreadId(); this.msgId = msgId; - this.glideRequests = glideRequests; int state = dcSummary.getState(); int unreadCount = thread.getUnreadCount(); @@ -163,7 +159,7 @@ public class ConversationListItem extends RelativeLayout this.avatar.setAvatar(glideRequests, recipient, false); DcContact contact = recipient.getDcContact(); - avatar.setSeenRecently(contact!=null? contact.wasSeenRecently() : false); + avatar.setSeenRecently(contact != null && contact.wasSeenRecently()); fromView.setCompoundDrawablesWithIntrinsicBounds( thread.isMuted()? R.drawable.ic_volume_off_grey600_18dp : 0, @@ -178,7 +174,6 @@ public class ConversationListItem extends RelativeLayout { this.selectedThreads = Collections.emptySet(); Recipient recipient = new Recipient(getContext(), contact); - this.glideRequests = glideRequests; fromView.setText(getHighlightedSpan(contact.getDisplayName(), highlightSubstring)); fromView.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0); @@ -203,7 +198,6 @@ public class ConversationListItem extends RelativeLayout DcContact sender = dcContext.getContact(messageResult.getFromId()); this.selectedThreads = Collections.emptySet(); Recipient recipient = new Recipient(getContext(), sender); - this.glideRequests = glideRequests; fromView.setText(recipient, true); fromView.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0); @@ -302,9 +296,9 @@ public class ConversationListItem extends RelativeLayout if (thread!=null && thread.getVisibility()==DcChat.DC_CHAT_VISIBILITY_PINNED) { bg = R.attr.pinned_list_item_background; } - TypedArray ta = getContext().obtainStyledAttributes(new int[] { bg }); - ViewUtil.setBackground(this, ta.getDrawable(0)); - ta.recycle(); + try (TypedArray ta = getContext().obtainStyledAttributes(new int[]{bg})) { + ViewUtil.setBackground(this, ta.getDrawable(0)); + } } private Spanned getHighlightedSpan(@Nullable String value, @@ -322,7 +316,10 @@ public class ConversationListItem extends RelativeLayout String normalizedValue = value.toLowerCase(Util.getLocale()); String normalizedTest = highlight.toLowerCase(Util.getLocale()); - List testTokens = Stream.of(normalizedTest.split(" ")).filter(s -> s.trim().length() > 0).toList(); + List testTokens; + try (Stream stream = Stream.of(normalizedTest.split(" "))) { + testTokens = stream.filter(s -> !s.trim().isEmpty()).toList(); + } Spannable spanned = new SpannableString(value); int searchStartIndex = 0;