Merge pull request #3817 from Isira-Seneviratne/Use_Java_8_APIs

Use Java 8 APIs.
This commit is contained in:
Tobias Groza 2020-11-01 16:30:50 +01:00 committed by GitHub
commit e97d0b9a69
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 40 additions and 48 deletions

View file

@ -65,6 +65,9 @@ android {
} }
compileOptions { compileOptions {
// Flag to enable support for the new language APIs
coreLibraryDesugaringEnabled true
sourceCompatibility JavaVersion.VERSION_1_8 sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8
encoding 'utf-8' encoding 'utf-8'
@ -144,6 +147,8 @@ afterEvaluate {
} }
dependencies { dependencies {
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.0.10'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
implementation "frankiesardo:icepick:${icepickVersion}" implementation "frankiesardo:icepick:${icepickVersion}"

View file

@ -19,6 +19,7 @@ import org.schabi.newpipe.util.ShareUtils;
import java.io.Serializable; import java.io.Serializable;
import java.util.Arrays; import java.util.Arrays;
import java.util.Comparator;
/** /**
* Fragment containing the software licenses. * Fragment containing the software licenses.
@ -64,7 +65,7 @@ public class LicenseFragment extends Fragment {
} }
} }
// Sort components by name // Sort components by name
Arrays.sort(softwareComponents, (o1, o2) -> o1.getName().compareTo(o2.getName())); Arrays.sort(softwareComponents, Comparator.comparing(SoftwareComponent::getName));
} }
@Nullable @Nullable

View file

@ -5,6 +5,7 @@ import org.schabi.newpipe.database.playlist.model.PlaylistRemoteEntity;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator;
import java.util.List; import java.util.List;
public interface PlaylistLocalItem extends LocalItem { public interface PlaylistLocalItem extends LocalItem {
@ -18,15 +19,8 @@ public interface PlaylistLocalItem extends LocalItem {
items.addAll(localPlaylists); items.addAll(localPlaylists);
items.addAll(remotePlaylists); items.addAll(remotePlaylists);
Collections.sort(items, (left, right) -> { Collections.sort(items, Comparator.comparing(PlaylistLocalItem::getOrderingName,
final String on1 = left.getOrderingName(); Comparator.nullsLast(String.CASE_INSENSITIVE_ORDER)));
final String on2 = right.getOrderingName();
if (on1 == null) {
return on2 == null ? 0 : 1;
} else {
return on2 == null ? -1 : on1.compareToIgnoreCase(on2);
}
});
return items; return items;
} }

View file

@ -50,7 +50,6 @@ import org.schabi.newpipe.util.ShareUtils;
import org.schabi.newpipe.util.ThemeHelper; import org.schabi.newpipe.util.ThemeHelper;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -495,13 +494,12 @@ public class ChannelFragment extends BaseListInfoFragment<ChannelInfo>
// handling ContentNotSupportedException not to show the error but an appropriate string // handling ContentNotSupportedException not to show the error but an appropriate string
// so that crashes won't be sent uselessly and the user will understand what happened // so that crashes won't be sent uselessly and the user will understand what happened
for (Iterator<Throwable> it = errors.iterator(); it.hasNext();) { errors.removeIf(throwable -> {
final Throwable throwable = it.next();
if (throwable instanceof ContentNotSupportedException) { if (throwable instanceof ContentNotSupportedException) {
showContentNotSupported(); showContentNotSupported();
it.remove();
}
} }
return throwable instanceof ContentNotSupportedException;
});
if (!errors.isEmpty()) { if (!errors.isEmpty()) {
showSnackBarError(errors, UserAction.REQUESTED_CHANNEL, showSnackBarError(errors, UserAction.REQUESTED_CHANNEL,

View file

@ -61,7 +61,6 @@ import org.schabi.newpipe.util.ServiceHelper;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Queue; import java.util.Queue;
@ -758,16 +757,9 @@ public class SearchFragment extends BaseListFragment<SearchInfo, ListExtractor.I
} }
// Remove duplicates // Remove duplicates
final Iterator<SuggestionItem> iterator = networkResult.iterator(); networkResult.removeIf(networkItem ->
while (iterator.hasNext() && localResult.size() > 0) { localResult.stream().anyMatch(localItem ->
final SuggestionItem next = iterator.next(); localItem.query.equals(networkItem.query)));
for (final SuggestionItem item : localResult) {
if (item.query.equals(next.query)) {
iterator.remove();
break;
}
}
}
if (networkResult.size() > 0) { if (networkResult.size() > 0) {
result.addAll(networkResult); result.addAll(networkResult);

View file

@ -43,6 +43,7 @@ import org.schabi.newpipe.util.ThemeHelper;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator;
import java.util.List; import java.util.List;
import icepick.State; import icepick.State;
@ -68,18 +69,19 @@ public class StatisticsPlaylistFragment
private HistoryRecordManager recordManager; private HistoryRecordManager recordManager;
private List<StreamStatisticsEntry> processResult(final List<StreamStatisticsEntry> results) { private List<StreamStatisticsEntry> processResult(final List<StreamStatisticsEntry> results) {
final Comparator<StreamStatisticsEntry> comparator;
switch (sortMode) { switch (sortMode) {
case LAST_PLAYED: case LAST_PLAYED:
Collections.sort(results, (left, right) -> comparator = Comparator.comparing(StreamStatisticsEntry::getLatestAccessDate);
right.getLatestAccessDate().compareTo(left.getLatestAccessDate())); break;
return results;
case MOST_PLAYED: case MOST_PLAYED:
Collections.sort(results, (left, right) -> comparator = Comparator.comparingLong(StreamStatisticsEntry::getWatchCount);
Long.compare(right.getWatchCount(), left.getWatchCount())); break;
return results;
default: default:
return null; return null;
} }
Collections.sort(results, comparator.reversed());
return results;
} }
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////

View file

@ -18,6 +18,7 @@ import org.schabi.newpipe.extractor.stream.VideoStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -265,10 +266,8 @@ public final class ListHelper {
*/ */
private static void sortStreamList(final List<VideoStream> videoStreams, private static void sortStreamList(final List<VideoStream> videoStreams,
final boolean ascendingOrder) { final boolean ascendingOrder) {
Collections.sort(videoStreams, (o1, o2) -> { final Comparator<VideoStream> comparator = ListHelper::compareVideoStreamResolution;
final int result = compareVideoStreamResolution(o1, o2); Collections.sort(videoStreams, ascendingOrder ? comparator : comparator.reversed());
return result == 0 ? 0 : (ascendingOrder ? result : -result);
});
} }
/** /**

View file

@ -35,6 +35,10 @@ public abstract class Mission implements Serializable {
*/ */
public StoredFileHelper storage; public StoredFileHelper storage;
public long getTimestamp() {
return timestamp;
}
/** /**
* Delete the downloaded file * Delete the downloaded file
* *

View file

@ -12,7 +12,8 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Iterator; import java.util.Comparator;
import java.util.List;
import us.shandian.giga.get.DownloadMission; import us.shandian.giga.get.DownloadMission;
import us.shandian.giga.get.FinishedMission; import us.shandian.giga.get.FinishedMission;
@ -198,7 +199,7 @@ public class DownloadManager {
} }
if (mMissionsPending.size() > 1) if (mMissionsPending.size() > 1)
Collections.sort(mMissionsPending, (mission1, mission2) -> Long.compare(mission1.timestamp, mission2.timestamp)); Collections.sort(mMissionsPending, Comparator.comparingLong(Mission::getTimestamp));
} }
/** /**
@ -563,14 +564,10 @@ public class DownloadManager {
synchronized (DownloadManager.this) { synchronized (DownloadManager.this) {
ArrayList<Mission> pending = new ArrayList<>(mMissionsPending); ArrayList<Mission> pending = new ArrayList<>(mMissionsPending);
ArrayList<Mission> finished = new ArrayList<>(mMissionsFinished); ArrayList<Mission> finished = new ArrayList<>(mMissionsFinished);
ArrayList<Mission> remove = new ArrayList<>(hidden); List<Mission> remove = new ArrayList<>(hidden);
// hide missions (if required) // hide missions (if required)
Iterator<Mission> iterator = remove.iterator(); remove.removeIf(mission -> pending.remove(mission) || finished.remove(mission));
while (iterator.hasNext()) {
Mission mission = iterator.next();
if (pending.remove(mission) || finished.remove(mission)) iterator.remove();
}
int fakeTotal = pending.size(); int fakeTotal = pending.size();
if (fakeTotal > 0) fakeTotal++; if (fakeTotal > 0) fakeTotal++;

View file

@ -7,7 +7,7 @@ buildscript {
google() google()
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:3.6.3' classpath 'com.android.tools.build:gradle:4.1.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong // NOTE: Do not place your application dependencies here; they belong

View file

@ -13,7 +13,7 @@
<suppress checks="FinalParameters" <suppress checks="FinalParameters"
files="ListHelper.java" files="ListHelper.java"
lines="282,314"/> lines="281,313"/>
<!-- org.schabi.newpipe.streams --> <!-- org.schabi.newpipe.streams -->
<suppress checks="LineLength" <suppress checks="LineLength"

View file

@ -1,6 +1,6 @@
#Fri May 01 19:39:41 CEST 2020 #Sat Oct 17 06:10:46 IST 2020
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip