From f1de353b74f10e6834bf3e2ea33cd784b31a0654 Mon Sep 17 00:00:00 2001 From: Isira Seneviratne Date: Sat, 16 Jul 2022 08:34:04 +0530 Subject: [PATCH 1/2] Use stream sorting. --- .../database/playlist/PlaylistLocalItem.java | 17 ++++++----------- .../fragments/detail/DescriptionFragment.java | 7 +++---- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/database/playlist/PlaylistLocalItem.java b/app/src/main/java/org/schabi/newpipe/database/playlist/PlaylistLocalItem.java index 43dbd89ea..695f9ec5a 100644 --- a/app/src/main/java/org/schabi/newpipe/database/playlist/PlaylistLocalItem.java +++ b/app/src/main/java/org/schabi/newpipe/database/playlist/PlaylistLocalItem.java @@ -3,10 +3,10 @@ package org.schabi.newpipe.database.playlist; import org.schabi.newpipe.database.LocalItem; import org.schabi.newpipe.database.playlist.model.PlaylistRemoteEntity; -import java.util.ArrayList; -import java.util.Collections; import java.util.Comparator; import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; public interface PlaylistLocalItem extends LocalItem { String getOrderingName(); @@ -14,14 +14,9 @@ public interface PlaylistLocalItem extends LocalItem { static List merge( final List localPlaylists, final List remotePlaylists) { - final List items = new ArrayList<>( - localPlaylists.size() + remotePlaylists.size()); - items.addAll(localPlaylists); - items.addAll(remotePlaylists); - - Collections.sort(items, Comparator.comparing(PlaylistLocalItem::getOrderingName, - Comparator.nullsLast(String.CASE_INSENSITIVE_ORDER))); - - return items; + return Stream.concat(localPlaylists.stream(), remotePlaylists.stream()) + .sorted(Comparator.comparing(PlaylistLocalItem::getOrderingName, + Comparator.nullsLast(String.CASE_INSENSITIVE_ORDER))) + .collect(Collectors.toList()); } } diff --git a/app/src/main/java/org/schabi/newpipe/fragments/detail/DescriptionFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/detail/DescriptionFragment.java index d57ddb02d..362388314 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/detail/DescriptionFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/detail/DescriptionFragment.java @@ -26,9 +26,8 @@ import org.schabi.newpipe.util.NavigationHelper; import org.schabi.newpipe.util.external_communication.ShareUtils; import org.schabi.newpipe.util.external_communication.TextLinkifier; -import java.util.ArrayList; -import java.util.Collections; import java.util.List; +import java.util.stream.Collectors; import icepick.State; import io.reactivex.rxjava3.disposables.CompositeDisposable; @@ -209,8 +208,8 @@ public class DescriptionFragment extends BaseFragment { final ItemMetadataTagsBinding itemBinding = ItemMetadataTagsBinding.inflate(inflater, layout, false); - final List tags = new ArrayList<>(streamInfo.getTags()); - Collections.sort(tags); + final List tags = streamInfo.getTags().stream().sorted() + .collect(Collectors.toList()); for (final String tag : tags) { final Chip chip = (Chip) inflater.inflate(R.layout.chip, itemBinding.metadataTagsChips, false); From e77224444051323fe506b350ebd4df5546ca4de2 Mon Sep 17 00:00:00 2001 From: Isira Seneviratne <31027858+Isira-Seneviratne@users.noreply.github.com> Date: Tue, 19 Jul 2022 05:10:51 +0530 Subject: [PATCH 2/2] Update app/src/main/java/org/schabi/newpipe/fragments/detail/DescriptionFragment.java Co-authored-by: Stypox --- .../newpipe/fragments/detail/DescriptionFragment.java | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/fragments/detail/DescriptionFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/detail/DescriptionFragment.java index 362388314..ab4883768 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/detail/DescriptionFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/detail/DescriptionFragment.java @@ -26,9 +26,6 @@ import org.schabi.newpipe.util.NavigationHelper; import org.schabi.newpipe.util.external_communication.ShareUtils; import org.schabi.newpipe.util.external_communication.TextLinkifier; -import java.util.List; -import java.util.stream.Collectors; - import icepick.State; import io.reactivex.rxjava3.disposables.CompositeDisposable; @@ -208,16 +205,14 @@ public class DescriptionFragment extends BaseFragment { final ItemMetadataTagsBinding itemBinding = ItemMetadataTagsBinding.inflate(inflater, layout, false); - final List tags = streamInfo.getTags().stream().sorted() - .collect(Collectors.toList()); - for (final String tag : tags) { + streamInfo.getTags().stream().sorted().forEach(tag -> { final Chip chip = (Chip) inflater.inflate(R.layout.chip, itemBinding.metadataTagsChips, false); chip.setText(tag); chip.setOnClickListener(this::onTagClick); chip.setOnLongClickListener(this::onTagLongClick); itemBinding.metadataTagsChips.addView(chip); - } + }); layout.addView(itemBinding.getRoot()); }