mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2024-12-23 00:20:32 +00:00
Actually there is no need to use flatMap
`null` values returned in the lambda are converted to empty `Optional`s in the `map` method: https://developer.android.com/reference/java/util/Optional#map(java.util.function.Function%3C?%20super%20T,%20?%20extends%20U%3E)
This commit is contained in:
parent
eed44b3231
commit
ad605e2c5a
@ -87,6 +87,7 @@ import org.schabi.newpipe.util.urlfinder.UrlFinder;
|
|||||||
import org.schabi.newpipe.views.FocusOverlayView;
|
import org.schabi.newpipe.views.FocusOverlayView;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.lang.ref.Reference;
|
||||||
import java.lang.ref.WeakReference;
|
import java.lang.ref.WeakReference;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@ -748,7 +749,7 @@ public class RouterActivity extends AppCompatActivity {
|
|||||||
*/
|
*/
|
||||||
private Optional<AppCompatActivity> getActivityContext() {
|
private Optional<AppCompatActivity> getActivityContext() {
|
||||||
return Optional.ofNullable(weakContext)
|
return Optional.ofNullable(weakContext)
|
||||||
.flatMap(context -> Optional.ofNullable(context.get()))
|
.map(Reference::get)
|
||||||
.filter(context -> !context.isFinishing());
|
.filter(context -> !context.isFinishing());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1887,7 +1887,7 @@ public final class VideoDetailFragment
|
|||||||
setupBrightness();
|
setupBrightness();
|
||||||
if (!isPlayerAndPlayerServiceAvailable()
|
if (!isPlayerAndPlayerServiceAvailable()
|
||||||
|| player.UIs().get(MainPlayerUi.class).isEmpty()
|
|| player.UIs().get(MainPlayerUi.class).isEmpty()
|
||||||
|| getRoot().flatMap(v -> Optional.ofNullable(v.getParent())).isEmpty()) {
|
|| getRoot().map(View::getParent).isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,8 +62,8 @@ public interface MediaItemTag {
|
|||||||
@NonNull
|
@NonNull
|
||||||
static Optional<MediaItemTag> from(@Nullable final MediaItem mediaItem) {
|
static Optional<MediaItemTag> from(@Nullable final MediaItem mediaItem) {
|
||||||
return Optional.ofNullable(mediaItem)
|
return Optional.ofNullable(mediaItem)
|
||||||
.flatMap(item -> Optional.ofNullable(item.localConfiguration))
|
.map(item -> item.localConfiguration)
|
||||||
.flatMap(localConfiguration -> Optional.ofNullable(localConfiguration.tag))
|
.map(localConfiguration -> localConfiguration.tag)
|
||||||
.filter(MediaItemTag.class::isInstance)
|
.filter(MediaItemTag.class::isInstance)
|
||||||
.map(MediaItemTag.class::cast);
|
.map(MediaItemTag.class::cast);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user