From 3ac1b18d3d39c0fb83e760e6c4937bce404dd75f Mon Sep 17 00:00:00 2001 From: Andy Scherzinger Date: Thu, 7 Nov 2024 15:42:58 +0100 Subject: [PATCH] fix(spotbugs): Improve spotbugs scoring Signed-off-by: Andy Scherzinger --- .../talk/call/CallParticipantList.java | 2 +- .../MentionAutocompletePresenter.java | 45 ++++++++++--------- .../dialog/ChooseAccountDialogFragment.java | 6 +-- 3 files changed, 29 insertions(+), 24 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/call/CallParticipantList.java b/app/src/main/java/com/nextcloud/talk/call/CallParticipantList.java index 4a1c7370b..4b3727aa4 100644 --- a/app/src/main/java/com/nextcloud/talk/call/CallParticipantList.java +++ b/app/src/main/java/com/nextcloud/talk/call/CallParticipantList.java @@ -86,8 +86,8 @@ public class CallParticipantList { callParticipants.remove(callParticipant.getSessionId()); // No need to copy it, as it will be no longer used. callParticipant.setInCall(Participant.InCallFlags.DISCONNECTED); - left.add(callParticipant); } + left.addAll(knownCallParticipantsNotFound); if (!joined.isEmpty() || !updated.isEmpty() || !left.isEmpty()) { callParticipantListNotifier.notifyChanged(joined, updated, left, unchanged); diff --git a/app/src/main/java/com/nextcloud/talk/presenters/MentionAutocompletePresenter.java b/app/src/main/java/com/nextcloud/talk/presenters/MentionAutocompletePresenter.java index 9ec1f67e3..5d5f20699 100644 --- a/app/src/main/java/com/nextcloud/talk/presenters/MentionAutocompletePresenter.java +++ b/app/src/main/java/com/nextcloud/talk/presenters/MentionAutocompletePresenter.java @@ -126,28 +126,33 @@ public class MentionAutocompletePresenter extends RecyclerViewPresenter @Override public void onNext(@NonNull MentionOverall mentionOverall) { - List mentionsList = mentionOverall.getOcs().getData(); + if (mentionOverall.getOcs() != null) { + List mentionsList = mentionOverall.getOcs().getData(); - if (mentionsList.size() == 0) { - adapter.clear(); - } else { - List internalAbstractFlexibleItemList = - new ArrayList<>(mentionsList.size()); - for (Mention mention : mentionsList) { - internalAbstractFlexibleItemList.add( - new MentionAutocompleteItem( - mention, - currentUser, - context, - roomToken, - viewThemeUtils)); + if (mentionsList != null) { + + if (mentionsList.isEmpty()) { + adapter.clear(); + } else { + List internalAbstractFlexibleItemList = + new ArrayList<>(mentionsList.size()); + for (Mention mention : mentionsList) { + internalAbstractFlexibleItemList.add( + new MentionAutocompleteItem( + mention, + currentUser, + context, + roomToken, + viewThemeUtils)); + } + + if (adapter.getItemCount() != 0) { + adapter.clear(); + } + + adapter.updateDataSet(internalAbstractFlexibleItemList); + } } - - if (adapter.getItemCount() != 0) { - adapter.clear(); - } - - adapter.updateDataSet(internalAbstractFlexibleItemList); } } diff --git a/app/src/main/java/com/nextcloud/talk/ui/dialog/ChooseAccountDialogFragment.java b/app/src/main/java/com/nextcloud/talk/ui/dialog/ChooseAccountDialogFragment.java index 8e5382147..729fa5181 100644 --- a/app/src/main/java/com/nextcloud/talk/ui/dialog/ChooseAccountDialogFragment.java +++ b/app/src/main/java/com/nextcloud/talk/ui/dialog/ChooseAccountDialogFragment.java @@ -109,7 +109,7 @@ public class ChooseAccountDialogFragment extends DialogFragment { themeViews(); setupCurrentUser(user); - setupListeners(user); + setupListeners(); setupAdapter(); prepareViews(); } @@ -220,7 +220,7 @@ public class ChooseAccountDialogFragment extends DialogFragment { adapter.updateDataSet(userItems, false); } - private void setupListeners(User user) { + private void setupListeners() { // Creating listeners for quick-actions binding.currentAccount.getRoot().setOnClickListener(v -> dismiss()); @@ -240,7 +240,7 @@ public class ChooseAccountDialogFragment extends DialogFragment { binding.setStatus.setOnClickListener(v -> { dismiss(); - if (status != null) { + if (status != null && getActivity() != null) { SetStatusDialogFragment setStatusDialog = SetStatusDialogFragment.newInstance(status); setStatusDialog.show(getActivity().getSupportFragmentManager(), "fragment_set_status"); } else {