Fix spotbugs

Signed-off-by: Álvaro Brey <alvaro.brey@nextcloud.com>
This commit is contained in:
Álvaro Brey 2022-05-30 15:43:12 +02:00
parent 1f00f426c7
commit 232334efac
No known key found for this signature in database
GPG key ID: 2585783189A62105
2 changed files with 23 additions and 16 deletions

View file

@ -67,6 +67,8 @@ import eu.davidea.viewholders.FlexibleViewHolder;
public class ConversationItem extends AbstractFlexibleItem<ConversationItem.ConversationItemViewHolder> implements
ISectionable<ConversationItem.ConversationItemViewHolder, GenericTextHeaderItem>, IFilterable<String> {
public static final int VIEW_TYPE = R.layout.rv_item_conversation_with_last_message;
private static final float STATUS_SIZE_IN_DP = 9f;
private final Conversation conversation;
@ -75,6 +77,7 @@ public class ConversationItem extends AbstractFlexibleItem<ConversationItem.Conv
private GenericTextHeaderItem header;
private final Status status;
public ConversationItem(Conversation conversation, UserEntity userEntity, Context activityContext, Status status) {
this.conversation = conversation;
this.userEntity = userEntity;
@ -114,6 +117,11 @@ public class ConversationItem extends AbstractFlexibleItem<ConversationItem.Conv
return R.layout.rv_item_conversation_with_last_message;
}
@Override
public int getItemViewType() {
return VIEW_TYPE;
}
@Override
public ConversationItemViewHolder createViewHolder(View view, FlexibleAdapter<IFlexible> adapter) {
return new ConversationItemViewHolder(view, adapter);

View file

@ -956,31 +956,30 @@ public class ConversationsListController extends BaseController implements Flexi
@Override
public boolean onItemClick(View view, int position) {
final AbstractFlexibleItem item = adapter.getItem(position);
if (item instanceof ConversationItem) {
showConversation(((ConversationItem) Objects.requireNonNull(item)).getModel());
} else if (item instanceof MessageResultItem) {
MessageResultItem messageItem = (MessageResultItem) item;
String conversationToken = messageItem.getMessageEntry().getConversationToken();
selectedMessageId = messageItem.getMessageEntry().getMessageId();
showConversationByToken(conversationToken);
} else if (item instanceof LoadMoreResultsItem) {
loadMoreMessages();
if (item != null) {
final int viewType = item.getItemViewType();
if (viewType == MessageResultItem.VIEW_TYPE) {
MessageResultItem messageItem = (MessageResultItem) item;
String conversationToken = messageItem.getMessageEntry().getConversationToken();
selectedMessageId = messageItem.getMessageEntry().getMessageId();
showConversationByToken(conversationToken);
} else if (viewType == LoadMoreResultsItem.VIEW_TYPE) {
loadMoreMessages();
} else if (viewType == ConversationItem.VIEW_TYPE) {
showConversation(((ConversationItem) Objects.requireNonNull(item)).getModel());
}
}
return true;
}
private void showConversationByToken(String conversationToken) {
Conversation conversation = null;
for (AbstractFlexibleItem absItem : conversationItems) {
ConversationItem conversationItem = ((ConversationItem) absItem);
if (conversationItem.getModel().getToken().equals(conversationToken)) {
conversation = conversationItem.getModel();
final Conversation conversation = conversationItem.getModel();
showConversation(conversation);
}
}
if (conversation != null) {
showConversation(conversation);
}
}
private void showConversation(@Nullable final Conversation conversation) {
@ -1390,7 +1389,7 @@ public class ConversationsListController extends BaseController implements Flexi
clearMessageSearchResults();
final List<SearchMessageEntry> entries = results.getMessages();
if (entries.size() > 0) {
List<AbstractFlexibleItem> adapterItems = new ArrayList<>();
List<AbstractFlexibleItem> adapterItems = new ArrayList<>(entries.size() + 1);
for (int i = 0; i < entries.size(); i++) {
final boolean showHeader = i == 0;
adapterItems.add(new MessageResultItem(context, currentUser, entries.get(i), showHeader));