fix lint/spotbug warnings

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
Marcel Hibbe 2022-02-23 14:49:14 +01:00
parent 4c07ccec11
commit 4f1a188a38
No known key found for this signature in database
GPG Key ID: C793F8B59F43CE7B
7 changed files with 111 additions and 189 deletions

View File

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

View File

@ -145,17 +145,20 @@ public class UserItem extends AbstractFlexibleItem<UserItem.UserItemViewHolder>
} }
if (participant.status != null && participant.status.equals(StatusType.DND.getString())) { 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()) { if (participant.statusMessage == null || participant.statusMessage.isEmpty()) {
holder.statusMessage.setText(R.string.dnd); holder.statusMessage.setText(R.string.dnd);
} }
} else if (participant.status != null && participant.status.equals(StatusType.AWAY.getString())) { } 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()) { if (participant.statusMessage == null || participant.statusMessage.isEmpty()) {
holder.statusMessage.setText(R.string.away); holder.statusMessage.setText(R.string.away);
} }
} else if (participant.status != null && participant.status.equals(StatusType.ONLINE.getString())) { } 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 { } else {
holder.participantOnlineStateImage.setVisibility(View.GONE); 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 @Override
public boolean filter(String constraint) { public boolean filter(String constraint) {
return participant.getDisplayName() != null && return participant.getDisplayName() != null &&

View File

@ -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 +
'}';
}
}

View File

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

View File

@ -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 +
'}';
}
}

View File

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

View File

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