From 4f1a188a38b5cf9ada09b1d1ae444ac1285c1edf Mon Sep 17 00:00:00 2001 From: Marcel Hibbe Date: Wed, 23 Feb 2022 14:49:14 +0100 Subject: [PATCH] fix lint/spotbug warnings Signed-off-by: Marcel Hibbe --- .../items/MentionAutocompleteItem.java | 92 ++++++++++--------- .../talk/adapters/items/UserItem.java | 13 ++- .../predefined/PredefinedStatusOCS.java | 74 --------------- .../status/predefined/PredefinedStatusOCS.kt | 17 ++++ .../predefined/PredefinedStatusOverall.java | 65 ------------- .../predefined/PredefinedStatusOverall.kt | 37 ++++++++ .../talk/ui/dialog/SetStatusDialogFragment.kt | 2 +- 7 files changed, 111 insertions(+), 189 deletions(-) delete mode 100644 app/src/main/java/com/nextcloud/talk/models/json/status/predefined/PredefinedStatusOCS.java create mode 100644 app/src/main/java/com/nextcloud/talk/models/json/status/predefined/PredefinedStatusOCS.kt delete mode 100644 app/src/main/java/com/nextcloud/talk/models/json/status/predefined/PredefinedStatusOverall.java create mode 100644 app/src/main/java/com/nextcloud/talk/models/json/status/predefined/PredefinedStatusOverall.kt diff --git a/app/src/main/java/com/nextcloud/talk/adapters/items/MentionAutocompleteItem.java b/app/src/main/java/com/nextcloud/talk/adapters/items/MentionAutocompleteItem.java index dbe3f3a8e..fd107682e 100644 --- a/app/src/main/java/com/nextcloud/talk/adapters/items/MentionAutocompleteItem.java +++ b/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 } 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 } } - 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 && diff --git a/app/src/main/java/com/nextcloud/talk/models/json/status/predefined/PredefinedStatusOCS.java b/app/src/main/java/com/nextcloud/talk/models/json/status/predefined/PredefinedStatusOCS.java deleted file mode 100644 index e3447b013..000000000 --- a/app/src/main/java/com/nextcloud/talk/models/json/status/predefined/PredefinedStatusOCS.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * - * Nextcloud Talk application - * - * @author Tim Krüger - * Copyright (C) 2021 Tim Krüger - * - * 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 . - */ -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 data; - - public List getData() { - return this.data; - } - - public void setData(List 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 + - '}'; - } - -} diff --git a/app/src/main/java/com/nextcloud/talk/models/json/status/predefined/PredefinedStatusOCS.kt b/app/src/main/java/com/nextcloud/talk/models/json/status/predefined/PredefinedStatusOCS.kt new file mode 100644 index 000000000..53164cd65 --- /dev/null +++ b/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? +) : GenericOCS(), Parcelable { + // This constructor is added to work with the 'com.bluelinelabs.logansquare.annotation.JsonObject' + constructor() : this(null) +} \ No newline at end of file diff --git a/app/src/main/java/com/nextcloud/talk/models/json/status/predefined/PredefinedStatusOverall.java b/app/src/main/java/com/nextcloud/talk/models/json/status/predefined/PredefinedStatusOverall.java deleted file mode 100644 index a9ccf8089..000000000 --- a/app/src/main/java/com/nextcloud/talk/models/json/status/predefined/PredefinedStatusOverall.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * - * Nextcloud Talk application - * - * @author Tim Krüger - * Copyright (C) 2021 Tim Krüger - * - * 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 . - */ -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 + - '}'; - } -} diff --git a/app/src/main/java/com/nextcloud/talk/models/json/status/predefined/PredefinedStatusOverall.kt b/app/src/main/java/com/nextcloud/talk/models/json/status/predefined/PredefinedStatusOverall.kt new file mode 100644 index 000000000..030bd4926 --- /dev/null +++ b/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 + * Copyright (C) 2017-2018 Mario Danic + * + * 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 . + */ +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) +} diff --git a/app/src/main/java/com/nextcloud/talk/ui/dialog/SetStatusDialogFragment.kt b/app/src/main/java/com/nextcloud/talk/ui/dialog/SetStatusDialogFragment.kt index 63f8264d0..837b2b993 100644 --- a/app/src/main/java/com/nextcloud/talk/ui/dialog/SetStatusDialogFragment.kt +++ b/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() }