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 <dev@mhibbe.de>
This commit is contained in:
Marcel Hibbe 2022-02-23 14:21:22 +01:00
parent 7820bc7c51
commit 4c07ccec11
No known key found for this signature in database
GPG Key ID: C793F8B59F43CE7B
3 changed files with 35 additions and 34 deletions

View File

@ -131,34 +131,35 @@ public class UserItem extends AbstractFlexibleItem<UserItem.UserItemViewHolder>
}
}
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<UserItem.UserItemViewHolder>
@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)

View File

@ -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" />
<com.facebook.drawee.view.SimpleDraweeView
android:id="@+id/simple_drawee_view"
android:id="@+id/avatar_drawee_view"
android:layout_width="@dimen/avatar_size"
android:layout_height="@dimen/avatar_size"
android:layout_centerVertical="true"

View File

@ -29,7 +29,7 @@
<com.facebook.drawee.view.SimpleDraweeView
android:id="@+id/conversation_info_participant_avatar"
android:id="@+id/avatar_drawee_view"
android:layout_width="@dimen/small_item_height"
android:layout_height="@dimen/small_item_height"
android:layout_marginStart="@dimen/standard_margin"
@ -56,8 +56,8 @@
android:layout_height="16dp"
android:contentDescription="@null"
android:src="@drawable/online_status"
app:layout_constraintBottom_toBottomOf="@+id/conversation_info_participant_avatar"
app:layout_constraintEnd_toEndOf="@+id/conversation_info_participant_avatar" />
app:layout_constraintBottom_toBottomOf="@+id/avatar_drawee_view"
app:layout_constraintEnd_toEndOf="@+id/avatar_drawee_view" />
<androidx.emoji.widget.EmojiTextView
@ -70,8 +70,8 @@
android:textAlignment="viewStart"
android:textAppearance="?android:attr/textAppearanceListItem"
android:textColor="@color/conversation_item_header"
app:layout_constraintStart_toEndOf="@id/conversation_info_participant_avatar"
app:layout_constraintTop_toTopOf="@+id/conversation_info_participant_avatar"
app:layout_constraintStart_toEndOf="@id/avatar_drawee_view"
app:layout_constraintTop_toTopOf="@+id/avatar_drawee_view"
tools:text="Jane Doe" />
<androidx.emoji.widget.EmojiTextView