Use stream sorting.
This commit is contained in:
parent
b7a44560f5
commit
f1de353b74
2 changed files with 9 additions and 15 deletions
|
@ -3,10 +3,10 @@ package org.schabi.newpipe.database.playlist;
|
||||||
import org.schabi.newpipe.database.LocalItem;
|
import org.schabi.newpipe.database.LocalItem;
|
||||||
import org.schabi.newpipe.database.playlist.model.PlaylistRemoteEntity;
|
import org.schabi.newpipe.database.playlist.model.PlaylistRemoteEntity;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
public interface PlaylistLocalItem extends LocalItem {
|
public interface PlaylistLocalItem extends LocalItem {
|
||||||
String getOrderingName();
|
String getOrderingName();
|
||||||
|
@ -14,14 +14,9 @@ public interface PlaylistLocalItem extends LocalItem {
|
||||||
static List<PlaylistLocalItem> merge(
|
static List<PlaylistLocalItem> merge(
|
||||||
final List<PlaylistMetadataEntry> localPlaylists,
|
final List<PlaylistMetadataEntry> localPlaylists,
|
||||||
final List<PlaylistRemoteEntity> remotePlaylists) {
|
final List<PlaylistRemoteEntity> remotePlaylists) {
|
||||||
final List<PlaylistLocalItem> items = new ArrayList<>(
|
return Stream.concat(localPlaylists.stream(), remotePlaylists.stream())
|
||||||
localPlaylists.size() + remotePlaylists.size());
|
.sorted(Comparator.comparing(PlaylistLocalItem::getOrderingName,
|
||||||
items.addAll(localPlaylists);
|
Comparator.nullsLast(String.CASE_INSENSITIVE_ORDER)))
|
||||||
items.addAll(remotePlaylists);
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
Collections.sort(items, Comparator.comparing(PlaylistLocalItem::getOrderingName,
|
|
||||||
Comparator.nullsLast(String.CASE_INSENSITIVE_ORDER)));
|
|
||||||
|
|
||||||
return items;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.ShareUtils;
|
||||||
import org.schabi.newpipe.util.external_communication.TextLinkifier;
|
import org.schabi.newpipe.util.external_communication.TextLinkifier;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import icepick.State;
|
import icepick.State;
|
||||||
import io.reactivex.rxjava3.disposables.CompositeDisposable;
|
import io.reactivex.rxjava3.disposables.CompositeDisposable;
|
||||||
|
@ -209,8 +208,8 @@ public class DescriptionFragment extends BaseFragment {
|
||||||
final ItemMetadataTagsBinding itemBinding
|
final ItemMetadataTagsBinding itemBinding
|
||||||
= ItemMetadataTagsBinding.inflate(inflater, layout, false);
|
= ItemMetadataTagsBinding.inflate(inflater, layout, false);
|
||||||
|
|
||||||
final List<String> tags = new ArrayList<>(streamInfo.getTags());
|
final List<String> tags = streamInfo.getTags().stream().sorted()
|
||||||
Collections.sort(tags);
|
.collect(Collectors.toList());
|
||||||
for (final String tag : tags) {
|
for (final String tag : tags) {
|
||||||
final Chip chip = (Chip) inflater.inflate(R.layout.chip,
|
final Chip chip = (Chip) inflater.inflate(R.layout.chip,
|
||||||
itemBinding.metadataTagsChips, false);
|
itemBinding.metadataTagsChips, false);
|
||||||
|
|
Loading…
Reference in a new issue