mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2024-12-23 08:30:44 +00:00
Use Collection.removeIf() instead of using Iterator.remove() to remove elements conditionally.
This commit is contained in:
parent
abcacf8c74
commit
b0b0a75c87
@ -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,
|
||||||
|
@ -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);
|
||||||
|
@ -13,7 +13,7 @@ import java.io.IOException;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.Iterator;
|
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;
|
||||||
@ -564,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++;
|
||||||
|
Loading…
Reference in New Issue
Block a user