diff options
author | desperateCoder <echotodevnull@gmail.com> | 2021-01-04 16:53:49 +0300 |
---|---|---|
committer | desperateCoder <echotodevnull@gmail.com> | 2021-01-04 16:53:49 +0300 |
commit | 3ce91091519e74c27e00b7906a7629c338878a35 (patch) | |
tree | 435d32bf4748b033afe15a2c7c0981d5d02390e1 /app | |
parent | 7bb8bc0f595784c5e037b5852bd2bd5b518e3808 (diff) |
#597 filter widget: more stable sort?
Diffstat (limited to 'app')
-rw-r--r-- | app/src/main/java/it/niedermann/nextcloud/deck/ui/widget/upcoming/UpcomingWidgetFactory.java | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/widget/upcoming/UpcomingWidgetFactory.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/widget/upcoming/UpcomingWidgetFactory.java index 6a161fbdd..af02fa077 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/widget/upcoming/UpcomingWidgetFactory.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/widget/upcoming/UpcomingWidgetFactory.java @@ -16,11 +16,14 @@ import java.time.LocalDate; import java.time.ZoneId; import java.util.ArrayList; import java.util.Collections; +import java.util.Comparator; import java.util.List; import java.util.NoSuchElementException; +import java.util.stream.Collectors; import it.niedermann.nextcloud.deck.DeckLog; import it.niedermann.nextcloud.deck.R; +import it.niedermann.nextcloud.deck.model.Card; import it.niedermann.nextcloud.deck.model.full.FullCard; import it.niedermann.nextcloud.deck.model.widget.filter.dto.FilterWidgetCard; import it.niedermann.nextcloud.deck.persistence.sync.SyncManager; @@ -53,15 +56,14 @@ public class UpcomingWidgetFactory implements RemoteViewsService.RemoteViewsFact final List<FilterWidgetCard> response = syncManager.getCardsForFilterWidget(appWidgetId); DeckLog.verbose(UpcomingWidgetFactory.class.getSimpleName() + " with id " + appWidgetId + " fetched " + response.size() + " cards from the database."); data.clear(); - Collections.sort(response, (card1, card2) -> { - if (card1 == null || card1.getCard() == null || card1.getCard().getCard().getDueDate() == null) { - return 1; - } - if (card2 == null || card2.getCard() == null || card2.getCard().getCard().getDueDate() == null) { - return -1; - } - return card1.getCard().getCard().getDueDate().compareTo(card2.getCard().getCard().getDueDate()); - }); + Comparator<Card> comparator = Comparator.comparing(Card::getDueDate); + Collections.sort( + response.stream() + .map((filterWidgetCard -> filterWidgetCard == null ? null : filterWidgetCard.getCard())) + .map(fullCard -> fullCard == null ? null : fullCard.getCard()) + .collect(Collectors.toList()), + comparator + ); EUpcomingDueType lastDueType = null; for (FilterWidgetCard filterWidgetCard : response) { final EUpcomingDueType nextDueType = getDueType(filterWidgetCard.getCard().getCard().getDueDate()); |