diff --git a/app/build.gradle b/app/build.gradle index f45722de8..cfda114c2 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -65,6 +65,9 @@ android { } compileOptions { + // Flag to enable support for the new language APIs + coreLibraryDesugaringEnabled true + sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 encoding 'utf-8' @@ -144,6 +147,8 @@ afterEvaluate { } dependencies { + coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.0.10' + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" implementation "frankiesardo:icepick:${icepickVersion}" diff --git a/app/src/main/java/org/schabi/newpipe/about/LicenseFragment.java b/app/src/main/java/org/schabi/newpipe/about/LicenseFragment.java index e869dbb14..a6e64616d 100644 --- a/app/src/main/java/org/schabi/newpipe/about/LicenseFragment.java +++ b/app/src/main/java/org/schabi/newpipe/about/LicenseFragment.java @@ -19,6 +19,7 @@ import org.schabi.newpipe.util.ShareUtils; import java.io.Serializable; import java.util.Arrays; +import java.util.Comparator; /** * Fragment containing the software licenses. @@ -64,7 +65,7 @@ public class LicenseFragment extends Fragment { } } // Sort components by name - Arrays.sort(softwareComponents, (o1, o2) -> o1.getName().compareTo(o2.getName())); + Arrays.sort(softwareComponents, Comparator.comparing(SoftwareComponent::getName)); } @Nullable 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 3ce95631c..43dbd89ea 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 @@ -5,6 +5,7 @@ import org.schabi.newpipe.database.playlist.model.PlaylistRemoteEntity; import java.util.ArrayList; import java.util.Collections; +import java.util.Comparator; import java.util.List; public interface PlaylistLocalItem extends LocalItem { @@ -18,15 +19,8 @@ public interface PlaylistLocalItem extends LocalItem { items.addAll(localPlaylists); items.addAll(remotePlaylists); - Collections.sort(items, (left, right) -> { - final String on1 = left.getOrderingName(); - final String on2 = right.getOrderingName(); - if (on1 == null) { - return on2 == null ? 0 : 1; - } else { - return on2 == null ? -1 : on1.compareToIgnoreCase(on2); - } - }); + Collections.sort(items, Comparator.comparing(PlaylistLocalItem::getOrderingName, + Comparator.nullsLast(String.CASE_INSENSITIVE_ORDER))); return items; } diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java index 8902834e4..58e28df49 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java @@ -50,7 +50,6 @@ import org.schabi.newpipe.util.ShareUtils; import org.schabi.newpipe.util.ThemeHelper; import java.util.ArrayList; -import java.util.Iterator; import java.util.List; import java.util.concurrent.TimeUnit; @@ -495,13 +494,12 @@ public class ChannelFragment extends BaseListInfoFragment // 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 - for (Iterator it = errors.iterator(); it.hasNext();) { - final Throwable throwable = it.next(); + errors.removeIf(throwable -> { if (throwable instanceof ContentNotSupportedException) { showContentNotSupported(); - it.remove(); } - } + return throwable instanceof ContentNotSupportedException; + }); if (!errors.isEmpty()) { showSnackBarError(errors, UserAction.REQUESTED_CHANNEL, diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/search/SearchFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/search/SearchFragment.java index c402565fd..1e54176d4 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/search/SearchFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/search/SearchFragment.java @@ -61,7 +61,6 @@ import org.schabi.newpipe.util.ServiceHelper; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Queue; @@ -758,16 +757,9 @@ public class SearchFragment extends BaseListFragment iterator = networkResult.iterator(); - while (iterator.hasNext() && localResult.size() > 0) { - final SuggestionItem next = iterator.next(); - for (final SuggestionItem item : localResult) { - if (item.query.equals(next.query)) { - iterator.remove(); - break; - } - } - } + networkResult.removeIf(networkItem -> + localResult.stream().anyMatch(localItem -> + localItem.query.equals(networkItem.query))); if (networkResult.size() > 0) { result.addAll(networkResult); diff --git a/app/src/main/java/org/schabi/newpipe/local/history/StatisticsPlaylistFragment.java b/app/src/main/java/org/schabi/newpipe/local/history/StatisticsPlaylistFragment.java index 48a0e3430..b4398d873 100644 --- a/app/src/main/java/org/schabi/newpipe/local/history/StatisticsPlaylistFragment.java +++ b/app/src/main/java/org/schabi/newpipe/local/history/StatisticsPlaylistFragment.java @@ -43,6 +43,7 @@ import org.schabi.newpipe.util.ThemeHelper; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; +import java.util.Comparator; import java.util.List; import icepick.State; @@ -68,18 +69,19 @@ public class StatisticsPlaylistFragment private HistoryRecordManager recordManager; private List processResult(final List results) { + final Comparator comparator; switch (sortMode) { case LAST_PLAYED: - Collections.sort(results, (left, right) -> - right.getLatestAccessDate().compareTo(left.getLatestAccessDate())); - return results; + comparator = Comparator.comparing(StreamStatisticsEntry::getLatestAccessDate); + break; case MOST_PLAYED: - Collections.sort(results, (left, right) -> - Long.compare(right.getWatchCount(), left.getWatchCount())); - return results; + comparator = Comparator.comparingLong(StreamStatisticsEntry::getWatchCount); + break; default: return null; } + Collections.sort(results, comparator.reversed()); + return results; } /////////////////////////////////////////////////////////////////////////// diff --git a/app/src/main/java/org/schabi/newpipe/util/ListHelper.java b/app/src/main/java/org/schabi/newpipe/util/ListHelper.java index e26c00fb2..0c840f8c3 100644 --- a/app/src/main/java/org/schabi/newpipe/util/ListHelper.java +++ b/app/src/main/java/org/schabi/newpipe/util/ListHelper.java @@ -18,6 +18,7 @@ import org.schabi.newpipe.extractor.stream.VideoStream; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; +import java.util.Comparator; import java.util.HashMap; import java.util.List; @@ -265,10 +266,8 @@ public final class ListHelper { */ private static void sortStreamList(final List videoStreams, final boolean ascendingOrder) { - Collections.sort(videoStreams, (o1, o2) -> { - final int result = compareVideoStreamResolution(o1, o2); - return result == 0 ? 0 : (ascendingOrder ? result : -result); - }); + final Comparator comparator = ListHelper::compareVideoStreamResolution; + Collections.sort(videoStreams, ascendingOrder ? comparator : comparator.reversed()); } /** diff --git a/app/src/main/java/us/shandian/giga/get/Mission.java b/app/src/main/java/us/shandian/giga/get/Mission.java index 8e814a2af..ff1319884 100644 --- a/app/src/main/java/us/shandian/giga/get/Mission.java +++ b/app/src/main/java/us/shandian/giga/get/Mission.java @@ -35,6 +35,10 @@ public abstract class Mission implements Serializable { */ public StoredFileHelper storage; + public long getTimestamp() { + return timestamp; + } + /** * Delete the downloaded file * diff --git a/app/src/main/java/us/shandian/giga/service/DownloadManager.java b/app/src/main/java/us/shandian/giga/service/DownloadManager.java index 994c6ee63..dc4d5701b 100644 --- a/app/src/main/java/us/shandian/giga/service/DownloadManager.java +++ b/app/src/main/java/us/shandian/giga/service/DownloadManager.java @@ -12,7 +12,8 @@ import java.io.File; import java.io.IOException; import java.util.ArrayList; 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.FinishedMission; @@ -198,7 +199,7 @@ public class DownloadManager { } 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) { ArrayList pending = new ArrayList<>(mMissionsPending); ArrayList finished = new ArrayList<>(mMissionsFinished); - ArrayList remove = new ArrayList<>(hidden); + List remove = new ArrayList<>(hidden); // hide missions (if required) - Iterator iterator = remove.iterator(); - while (iterator.hasNext()) { - Mission mission = iterator.next(); - if (pending.remove(mission) || finished.remove(mission)) iterator.remove(); - } + remove.removeIf(mission -> pending.remove(mission) || finished.remove(mission)); int fakeTotal = pending.size(); if (fakeTotal > 0) fakeTotal++; diff --git a/build.gradle b/build.gradle index f15900bc6..de8691749 100644 --- a/build.gradle +++ b/build.gradle @@ -7,7 +7,7 @@ buildscript { google() } 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" // NOTE: Do not place your application dependencies here; they belong diff --git a/checkstyle-suppressions.xml b/checkstyle-suppressions.xml index 70a2afe73..43ee99958 100644 --- a/checkstyle-suppressions.xml +++ b/checkstyle-suppressions.xml @@ -13,7 +13,7 @@ + lines="281,313"/>