From 4c07ccec11f4fe70ae53ff7917d4da0ff513585b Mon Sep 17 00:00:00 2001 From: Marcel Hibbe Date: Wed, 23 Feb 2022 14:21:22 +0100 Subject: [PATCH] fix NPE when opening Contacts view. because UserItem is used for ContactsController and ConversationInfoController it differs between two different xml designs in method getLayoutRes() because of this there need to be checks which xml element exists or not. These are added with this commit. In the long term UserItem should not use two different xml designs. This might also be a problem for view binding?! Signed-off-by: Marcel Hibbe --- .../talk/adapters/items/UserItem.java | 55 ++++++++++--------- app/src/main/res/layout/rv_item_contact.xml | 4 +- .../rv_item_conversation_info_participant.xml | 10 ++-- 3 files changed, 35 insertions(+), 34 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/adapters/items/UserItem.java b/app/src/main/java/com/nextcloud/talk/adapters/items/UserItem.java index 84c6219c7..ef22694c2 100644 --- a/app/src/main/java/com/nextcloud/talk/adapters/items/UserItem.java +++ b/app/src/main/java/com/nextcloud/talk/adapters/items/UserItem.java @@ -131,34 +131,35 @@ public class UserItem extends AbstractFlexibleItem } } - if (participant.statusMessage != null) { - holder.statusMessage.setText(participant.statusMessage); - } else { - holder.statusMessage.setText(""); - } - - if (participant.statusIcon != null && !participant.statusIcon.isEmpty()) { - holder.participantEmoji.setText(participant.statusIcon); - } else { - holder.participantEmoji.setVisibility(View.GONE); - } - - if (participant.status != null && participant.status.equals(StatusType.DND.getString())) { - setOnlineStateIcon(holder, R.drawable.ic_user_status_dnd_with_border); - if (participant.statusMessage == null || participant.statusMessage.isEmpty()) { - holder.statusMessage.setText(R.string.dnd); + if (holder.statusMessage != null && holder.participantEmoji != null && holder.participantOnlineStateImage != null) { + if (participant.statusMessage != null) { + holder.statusMessage.setText(participant.statusMessage); + } else { + holder.statusMessage.setText(""); } - } else if (participant.status != null && participant.status.equals(StatusType.AWAY.getString())) { - setOnlineStateIcon(holder, R.drawable.ic_user_status_away_with_border); - if (participant.statusMessage == null || participant.statusMessage.isEmpty()) { - holder.statusMessage.setText(R.string.away); - } - } else if (participant.status != null && participant.status.equals(StatusType.ONLINE.getString())) { - setOnlineStateIcon(holder, R.drawable.online_status_with_border); - } else { - holder.participantOnlineStateImage.setVisibility(View.GONE); - } + if (participant.statusIcon != null && !participant.statusIcon.isEmpty()) { + holder.participantEmoji.setText(participant.statusIcon); + } else { + holder.participantEmoji.setVisibility(View.GONE); + } + + if (participant.status != null && participant.status.equals(StatusType.DND.getString())) { + setOnlineStateIcon(holder, R.drawable.ic_user_status_dnd_with_border); + if (participant.statusMessage == null || participant.statusMessage.isEmpty()) { + holder.statusMessage.setText(R.string.dnd); + } + } else if (participant.status != null && participant.status.equals(StatusType.AWAY.getString())) { + setOnlineStateIcon(holder, R.drawable.ic_user_status_away_with_border); + if (participant.statusMessage == null || participant.statusMessage.isEmpty()) { + holder.statusMessage.setText(R.string.away); + } + } else if (participant.status != null && participant.status.equals(StatusType.ONLINE.getString())) { + setOnlineStateIcon(holder, R.drawable.online_status_with_border); + } else { + holder.participantOnlineStateImage.setVisibility(View.GONE); + } + } if (!isOnline) { holder.contactDisplayName.setTextColor(ResourcesCompat.getColor( @@ -314,7 +315,7 @@ public class UserItem extends AbstractFlexibleItem @BindView(R.id.name_text) public EmojiTextView contactDisplayName; @Nullable - @BindView(R.id.conversation_info_participant_avatar) + @BindView(R.id.avatar_drawee_view) public SimpleDraweeView participantAvatar; @Nullable @BindView(R.id.secondary_text) diff --git a/app/src/main/res/layout/rv_item_contact.xml b/app/src/main/res/layout/rv_item_contact.xml index 57d6e6894..7bcefd7e7 100644 --- a/app/src/main/res/layout/rv_item_contact.xml +++ b/app/src/main/res/layout/rv_item_contact.xml @@ -48,7 +48,7 @@ android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_toStartOf="@id/checkedImageView" - android:layout_toEndOf="@id/simple_drawee_view" + android:layout_toEndOf="@id/avatar_drawee_view" android:ellipsize="end" android:lines="1" android:textAlignment="viewStart" @@ -56,7 +56,7 @@ tools:text="Jane Doe" /> + app:layout_constraintBottom_toBottomOf="@+id/avatar_drawee_view" + app:layout_constraintEnd_toEndOf="@+id/avatar_drawee_view" />