Răsfoiți Sursa

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>
Marcel Hibbe 3 ani în urmă
părinte
comite
4c07ccec11

+ 26 - 25
app/src/main/java/com/nextcloud/talk/adapters/items/UserItem.java

@@ -131,35 +131,36 @@ 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 (holder.statusMessage != null && holder.participantEmoji != null && holder.participantOnlineStateImage != null) {
+            if (participant.statusMessage != null) {
+                holder.statusMessage.setText(participant.statusMessage);
+            } else {
+                holder.statusMessage.setText("");
+            }
 
-        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 (participant.statusIcon != null && !participant.statusIcon.isEmpty()) {
+                holder.participantEmoji.setText(participant.statusIcon);
+            } else {
+                holder.participantEmoji.setVisibility(View.GONE);
             }
-        } 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);
+
+            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);
             }
-        } 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(
                 holder.contactDisplayName.getContext().getResources(),
@@ -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)

+ 2 - 2
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" />
 
     <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"

+ 5 - 5
app/src/main/res/layout/rv_item_conversation_info_participant.xml

@@ -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