Skip to content

Commit

Permalink
Must check in the callback :)
Browse files Browse the repository at this point in the history
  • Loading branch information
harshad1 committed Jan 7, 2025
1 parent 2f6cfcb commit 342d83a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -353,9 +353,9 @@ public static void showMultiChoiceDialogWithSearchFilterUI(final Activity activi
final boolean isMultiSelOk = dopt.positionCallback != null && dopt.isMultiSelectEnabled;
final boolean isPlainDialog = dopt.callback != null && (dopt.data == null || dopt.data.isEmpty());
if (isSearchOk || isMultiSelOk || isPlainDialog) {
final boolean selectionChanged = !GsCollectionUtils.setEquals(dopt.preSelected, listAdapter._selectedItems);
dialogBuilder.setPositiveButton(dopt.okButtonText, (dialogInterface, i) -> {
final String searchText = dopt.isSearchEnabled ? searchEditText.getText().toString() : null;
final boolean selectionChanged = !GsCollectionUtils.setEquals(dopt.preSelected, listAdapter._selectedItems);
if (dopt.positionCallback != null && (selectionChanged || dopt.callback == null)) {
dopt.positionCallback.callback(new ArrayList<>(listAdapter._selectedItems));
} else if (dopt.callback != null && !TextUtils.isEmpty(searchText)) {
Expand Down
10 changes: 2 additions & 8 deletions app/src/main/java/net/gsantner/opoc/util/GsCollectionUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,8 @@ public static <T> Set<T> setDiff(final Collection<T> a, final Collection<T> b) {
/**
* Check if 2 collections have the same elements
*/
public static <T> boolean setEquals(Collection<T> a, Collection<T> b) {
a = a != null ? a : Collections.emptySet();
b = b != null ? b : Collections.emptySet();

a = a instanceof Set ? a : new HashSet<>(a);
b = b instanceof Set ? b : new HashSet<>(b);

return a.equals(b);
public static <T> boolean setEquals(final Collection<T> a, final Collection<T> b) {
return (a == b) || (a != null && b != null && a.size() == b.size() && a.containsAll(b));
}

/**
Expand Down

0 comments on commit 342d83a

Please sign in to comment.