Browse Source

fix lint/spotbug warnings

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
Marcel Hibbe 3 years ago
parent
commit
4f1a188a38

+ 49 - 41
app/src/main/java/com/nextcloud/talk/adapters/items/MentionAutocompleteItem.java

@@ -35,6 +35,7 @@ import com.nextcloud.talk.utils.ApiUtils;
 import com.nextcloud.talk.utils.DisplayUtils;
 
 import java.util.List;
+import java.util.Objects;
 import java.util.regex.Pattern;
 
 import androidx.core.content.ContextCompat;
@@ -50,14 +51,14 @@ public class MentionAutocompleteItem extends AbstractFlexibleItem<UserItem.UserI
 
     public static final String SOURCE_CALLS = "calls";
     public static final String SOURCE_GUESTS = "guests";
-    private String objectId;
-    private String displayName;
     private String source;
-    private String status;
-    private String statusIcon;
-    private String statusMessage;
-    private UserEntity currentUser;
-    private Context context;
+    private final String objectId;
+    private final String displayName;
+    private final String status;
+    private final String statusIcon;
+    private final String statusMessage;
+    private final UserEntity currentUser;
+    private final Context context;
 
     public MentionAutocompleteItem(
             Mention mention,
@@ -125,7 +126,7 @@ public class MentionAutocompleteItem extends AbstractFlexibleItem<UserItem.UserI
             FlexibleUtils.highlightText(holder.contactDisplayName,
                                         displayName,
                                         String.valueOf(adapter.getFilter(String.class)),
-                                        NextcloudTalkApplication.Companion.getSharedApplication()
+                                        Objects.requireNonNull(NextcloudTalkApplication.Companion.getSharedApplication())
                                             .getResources().getColor(R.color.colorPrimary));
             if (holder.contactMentionId != null) {
                 FlexibleUtils.highlightText(holder.contactMentionId,
@@ -142,7 +143,9 @@ public class MentionAutocompleteItem extends AbstractFlexibleItem<UserItem.UserI
         }
 
         if (SOURCE_CALLS.equals(source)) {
-            holder.participantAvatar.setImageResource(R.drawable.ic_circular_group);
+            if (holder.participantAvatar != null){
+                holder.participantAvatar.setImageResource(R.drawable.ic_circular_group);
+            }
         } else {
             String avatarId = objectId;
             String avatarUrl = ApiUtils.getUrlForAvatarWithName(currentUser.getBaseUrl(),
@@ -156,7 +159,10 @@ public class MentionAutocompleteItem extends AbstractFlexibleItem<UserItem.UserI
                     R.dimen.avatar_size_big);
             }
 
-            holder.participantAvatar.setController(null);
+            if(holder.participantAvatar != null){
+                holder.participantAvatar.setController(null);
+            }
+
             DraweeController draweeController = Fresco.newDraweeControllerBuilder()
                 .setOldController(holder.participantAvatar.getController())
                 .setAutoPlayAnimations(true)
@@ -165,43 +171,45 @@ public class MentionAutocompleteItem extends AbstractFlexibleItem<UserItem.UserI
             holder.participantAvatar.setController(draweeController);
         }
 
-        if (statusMessage != null) {
-            holder.statusMessage.setText(statusMessage);
-        } else {
-            holder.statusMessage.setText("");
-        }
-
-        if (statusIcon != null && !statusIcon.isEmpty()) {
-            holder.participantEmoji.setVisibility(View.VISIBLE);
-            holder.participantEmoji.setText(statusIcon);
-        } else {
-            holder.participantEmoji.setVisibility(View.GONE);
-            holder.participantEmoji.setText("");
-        }
+        if (holder.statusMessage != null && holder.participantEmoji != null && holder.participantOnlineStateImage != null) {
+            if (statusMessage != null) {
+                holder.statusMessage.setText(statusMessage);
+            } else {
+                holder.statusMessage.setText("");
+            }
 
-        if (status != null && status.equals(StatusType.DND.getString())) {
-            setOnlineStateIcon(holder, R.drawable.ic_user_status_dnd_with_border);
-            if (statusMessage == null || statusMessage.isEmpty()) {
-                holder.statusMessage.setText(R.string.dnd);
+            if (statusIcon != null && !statusIcon.isEmpty()) {
+                holder.participantEmoji.setVisibility(View.VISIBLE);
+                holder.participantEmoji.setText(statusIcon);
+            } else {
+                holder.participantEmoji.setVisibility(View.GONE);
+                holder.participantEmoji.setText("");
             }
-        } else if (status != null && status.equals(StatusType.AWAY.getString())) {
-            setOnlineStateIcon(holder, R.drawable.ic_user_status_away_with_border);
-            if (statusMessage == null || statusMessage.isEmpty()) {
-                holder.statusMessage.setText(R.string.away);
+
+            if (status != null && status.equals(StatusType.DND.getString())) {
+                holder.participantOnlineStateImage.setVisibility(View.VISIBLE);
+                holder.participantOnlineStateImage.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.ic_user_status_dnd_with_border));
+
+                if (statusMessage == null || statusMessage.isEmpty()) {
+                    holder.statusMessage.setText(R.string.dnd);
+                }
+            } else if (status != null && status.equals(StatusType.AWAY.getString())) {
+                holder.participantOnlineStateImage.setVisibility(View.VISIBLE);
+                holder.participantOnlineStateImage.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.ic_user_status_away_with_border));
+
+                if (statusMessage == null || statusMessage.isEmpty()) {
+                    holder.statusMessage.setText(R.string.away);
+                }
+            } else if (status != null && status.equals(StatusType.ONLINE.getString())) {
+                holder.participantOnlineStateImage.setVisibility(View.VISIBLE);
+                holder.participantOnlineStateImage.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.online_status_with_border));
+
+            } else {
+                holder.participantOnlineStateImage.setVisibility(View.GONE);
             }
-        } else if (status != null && status.equals(StatusType.ONLINE.getString())) {
-            setOnlineStateIcon(holder, R.drawable.online_status_with_border);
-        } else {
-            holder.participantOnlineStateImage.setVisibility(View.GONE);
         }
     }
 
-
-    private void setOnlineStateIcon(UserItem.UserItemViewHolder holder, int icon) {
-        holder.participantOnlineStateImage.setVisibility(View.VISIBLE);
-        holder.participantOnlineStateImage.setImageDrawable(ContextCompat.getDrawable(context, icon));
-    }
-
     @Override
     public boolean filter(String constraint) {
         return objectId != null &&

+ 6 - 7
app/src/main/java/com/nextcloud/talk/adapters/items/UserItem.java

@@ -145,17 +145,20 @@ public class UserItem extends AbstractFlexibleItem<UserItem.UserItemViewHolder>
             }
 
             if (participant.status != null && participant.status.equals(StatusType.DND.getString())) {
-                setOnlineStateIcon(holder, R.drawable.ic_user_status_dnd_with_border);
+                holder.participantOnlineStateImage.setImageDrawable(
+                    ContextCompat.getDrawable(context, 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);
+                holder.participantOnlineStateImage.setImageDrawable(
+                    ContextCompat.getDrawable(context, 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);
+                holder.participantOnlineStateImage.setImageDrawable(
+                    ContextCompat.getDrawable(context, R.drawable.online_status_with_border));
             } else {
                 holder.participantOnlineStateImage.setVisibility(View.GONE);
             }
@@ -289,10 +292,6 @@ public class UserItem extends AbstractFlexibleItem<UserItem.UserItemViewHolder>
         }
     }
 
-    private void setOnlineStateIcon(UserItem.UserItemViewHolder holder, int icon) {
-        holder.participantOnlineStateImage.setImageDrawable(ContextCompat.getDrawable(context, icon));
-    }
-
     @Override
     public boolean filter(String constraint) {
         return participant.getDisplayName() != null &&

+ 0 - 74
app/src/main/java/com/nextcloud/talk/models/json/status/predefined/PredefinedStatusOCS.java

@@ -1,74 +0,0 @@
-/*
- *
- *   Nextcloud Talk application
- *
- *   @author Tim Krüger
- *   Copyright (C) 2021 Tim Krüger <t@timkrueger.me>
- *
- *   This program is free software: you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation, either version 3 of the License, or
- *   at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-package com.nextcloud.talk.models.json.status.predefined;
-
-import com.bluelinelabs.logansquare.annotation.JsonField;
-import com.bluelinelabs.logansquare.annotation.JsonObject;
-import com.nextcloud.talk.models.json.autocomplete.AutocompleteUser;
-import com.nextcloud.talk.models.json.generic.GenericOCS;
-import com.nextcloud.talk.models.json.status.Status;
-
-import java.util.List;
-import java.util.Objects;
-
-import kotlin.jvm.JvmSuppressWildcards;
-
-@JsonObject
-public class PredefinedStatusOCS extends GenericOCS {
-    @JsonField(name = "data")
-    List<PredefinedStatus> data;
-
-    public List<PredefinedStatus> getData() {
-        return this.data;
-    }
-
-    public void setData(List<PredefinedStatus> data) {
-        this.data = data;
-    }
-
-    @Override
-    public boolean equals(Object o) {
-        if (this == o) {
-            return true;
-        }
-        if (o == null || getClass() != o.getClass()) {
-            return false;
-        }
-        if (!super.equals(o)) {
-            return false;
-        }
-        PredefinedStatusOCS that = (PredefinedStatusOCS) o;
-        return Objects.equals(data, that.data);
-    }
-
-    @Override
-    public int hashCode() {
-        return Objects.hash(super.hashCode(), data);
-    }
-
-    @Override
-    public String toString() {
-        return "PredefinedStatusOCS{" +
-            "data=" + data +
-            '}';
-    }
-
-}

+ 17 - 0
app/src/main/java/com/nextcloud/talk/models/json/status/predefined/PredefinedStatusOCS.kt

@@ -0,0 +1,17 @@
+package com.nextcloud.talk.models.json.status.predefined
+
+import android.os.Parcelable
+import com.bluelinelabs.logansquare.annotation.JsonField
+import com.bluelinelabs.logansquare.annotation.JsonObject
+import com.nextcloud.talk.models.json.generic.GenericOCS
+import kotlinx.android.parcel.Parcelize
+
+@Parcelize
+@JsonObject
+data class PredefinedStatusOCS(
+    @JsonField(name = ["data"])
+    var data: List<PredefinedStatus>?
+) : GenericOCS(), Parcelable {
+    // This constructor is added to work with the 'com.bluelinelabs.logansquare.annotation.JsonObject'
+    constructor() : this(null)
+}

+ 0 - 65
app/src/main/java/com/nextcloud/talk/models/json/status/predefined/PredefinedStatusOverall.java

@@ -1,65 +0,0 @@
-/*
- *
- *   Nextcloud Talk application
- *
- *   @author Tim Krüger
- *   Copyright (C) 2021 Tim Krüger <t@timkrueger.me>
- *
- *   This program is free software: you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation, either version 3 of the License, or
- *   at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-package com.nextcloud.talk.models.json.status.predefined;
-
-import com.bluelinelabs.logansquare.annotation.JsonField;
-import com.bluelinelabs.logansquare.annotation.JsonObject;
-import com.nextcloud.talk.models.json.status.StatusOCS;
-
-import java.util.Objects;
-
-@JsonObject
-public class PredefinedStatusOverall {
-    @JsonField(name = "ocs")
-    public PredefinedStatusOCS ocs;
-
-    public PredefinedStatusOCS getOcs() {
-        return this.ocs;
-    }
-
-    public void setOcs(PredefinedStatusOCS ocs) {
-        this.ocs = ocs;
-    }
-
-    @Override
-    public boolean equals(Object o) {
-        if (this == o) {
-            return true;
-        }
-        if (o == null || getClass() != o.getClass()) {
-            return false;
-        }
-        PredefinedStatusOverall that = (PredefinedStatusOverall) o;
-        return Objects.equals(ocs, that.ocs);
-    }
-
-    @Override
-    public int hashCode() {
-        return Objects.hash(ocs);
-    }
-
-    @Override
-    public String toString() {
-        return "PredefinedStatusOverall{" +
-            "ocs=" + ocs +
-            '}';
-    }
-}

+ 37 - 0
app/src/main/java/com/nextcloud/talk/models/json/status/predefined/PredefinedStatusOverall.kt

@@ -0,0 +1,37 @@
+/*
+ * Nextcloud Talk application
+ *
+ * @author Mario Danic
+ * @author Tim Krüger
+ * Copyright (C) 2022 Tim Krüger <t@timkrueger.me>
+ * Copyright (C) 2017-2018 Mario Danic <mario@lovelyhq.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package com.nextcloud.talk.models.json.status.predefined
+
+import android.os.Parcelable
+import com.bluelinelabs.logansquare.annotation.JsonField
+import com.bluelinelabs.logansquare.annotation.JsonObject
+import kotlinx.android.parcel.Parcelize
+
+@Parcelize
+@JsonObject
+data class PredefinedStatusOverall(
+    @JsonField(name = ["ocs"])
+    var ocs: PredefinedStatusOCS? = null
+) : Parcelable {
+    // This constructor is added to work with the 'com.bluelinelabs.logansquare.annotation.JsonObject'
+    constructor() : this(null)
+}

+ 1 - 1
app/src/main/java/com/nextcloud/talk/ui/dialog/SetStatusDialogFragment.kt

@@ -126,7 +126,7 @@ class SetStatusDialogFragment :
                                 .string(),
                             PredefinedStatusOverall::class.java
                         )
-                        predefinedStatusesList.addAll(predefinedStatusOverall.getOcs().data)
+                        predefinedStatusOverall.ocs?.data?.let { it1 -> predefinedStatusesList.addAll(it1) }
 
                         adapter.notifyDataSetChanged()
                     }