mirror of
https://github.com/TeamNewPipe/NewPipe.git
synced 2024-11-22 02:53:09 +01: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 java.io.Serializable;
|
||||
import java.lang.ref.Reference;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@ -748,7 +749,7 @@ public class RouterActivity extends AppCompatActivity {
|
||||
*/
|
||||
private Optional<AppCompatActivity> getActivityContext() {
|
||||
return Optional.ofNullable(weakContext)
|
||||
.flatMap(context -> Optional.ofNullable(context.get()))
|
||||
.map(Reference::get)
|
||||
.filter(context -> !context.isFinishing());
|
||||
}
|
||||
|
||||
|
@ -1887,7 +1887,7 @@ public final class VideoDetailFragment
|
||||
setupBrightness();
|
||||
if (!isPlayerAndPlayerServiceAvailable()
|
||||
|| player.UIs().get(MainPlayerUi.class).isEmpty()
|
||||
|| getRoot().flatMap(v -> Optional.ofNullable(v.getParent())).isEmpty()) {
|
||||
|| getRoot().map(View::getParent).isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -62,8 +62,8 @@ public interface MediaItemTag {
|
||||
@NonNull
|
||||
static Optional<MediaItemTag> from(@Nullable final MediaItem mediaItem) {
|
||||
return Optional.ofNullable(mediaItem)
|
||||
.flatMap(item -> Optional.ofNullable(item.localConfiguration))
|
||||
.flatMap(localConfiguration -> Optional.ofNullable(localConfiguration.tag))
|
||||
.map(item -> item.localConfiguration)
|
||||
.map(localConfiguration -> localConfiguration.tag)
|
||||
.filter(MediaItemTag.class::isInstance)
|
||||
.map(MediaItemTag.class::cast);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user