mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2025-01-11 01:40:59 +00:00
Some refactorings after review comments
This commit is contained in:
parent
3692858a3d
commit
61c1da144e
@ -1311,11 +1311,12 @@ public final class VideoDetailFragment
|
|||||||
setHeightThumbnail();
|
setHeightThumbnail();
|
||||||
|
|
||||||
// Prevent from re-adding a view multiple times
|
// Prevent from re-adding a view multiple times
|
||||||
new Handler().post(() -> player.UIs().get(MainPlayerUi.class).ifPresent(playerUi -> {
|
new Handler(Looper.getMainLooper()).post(() ->
|
||||||
playerUi.removeViewFromParent();
|
player.UIs().get(MainPlayerUi.class).ifPresent(playerUi -> {
|
||||||
binding.playerPlaceholder.addView(playerUi.getBinding().getRoot());
|
playerUi.removeViewFromParent();
|
||||||
playerUi.setupVideoSurfaceIfNeeded();
|
binding.playerPlaceholder.addView(playerUi.getBinding().getRoot());
|
||||||
}));
|
playerUi.setupVideoSurfaceIfNeeded();
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void removeVideoPlayerView() {
|
private void removeVideoPlayerView() {
|
||||||
|
@ -168,7 +168,7 @@ public abstract class PlaylistDialog extends DialogFragment implements StateSave
|
|||||||
|
|
||||||
final List<StreamEntity> streamEntities = Stream.of(player.getPlayQueue())
|
final List<StreamEntity> streamEntities = Stream.of(player.getPlayQueue())
|
||||||
.filter(Objects::nonNull)
|
.filter(Objects::nonNull)
|
||||||
.flatMap(playQueue -> Objects.requireNonNull(playQueue).getStreams().stream())
|
.flatMap(playQueue -> playQueue.getStreams().stream())
|
||||||
.map(StreamEntity::new)
|
.map(StreamEntity::new)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
if (streamEntities.isEmpty()) {
|
if (streamEntities.isEmpty()) {
|
||||||
|
@ -33,8 +33,6 @@ import org.schabi.newpipe.util.ThemeHelper;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* One service for all players.
|
* One service for all players.
|
||||||
*
|
|
||||||
* @author mauriciocolli
|
|
||||||
*/
|
*/
|
||||||
public final class PlayerService extends Service {
|
public final class PlayerService extends Service {
|
||||||
private static final String TAG = PlayerService.class.getSimpleName();
|
private static final String TAG = PlayerService.class.getSimpleName();
|
||||||
@ -72,14 +70,16 @@ public final class PlayerService extends Service {
|
|||||||
+ "], flags = [" + flags + "], startId = [" + startId + "]");
|
+ "], flags = [" + flags + "], startId = [" + startId + "]");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Intent.ACTION_MEDIA_BUTTON.equals(intent.getAction())
|
if (Intent.ACTION_MEDIA_BUTTON.equals(intent.getAction())
|
||||||
|| player.getPlayQueue() != null) {
|
&& player.getPlayQueue() == null) {
|
||||||
// ^ no need to process media button's action if player is not working
|
// No need to process media button's actions if the player is not working, otherwise the
|
||||||
|
// player service would strangely start with nothing to play
|
||||||
|
return START_NOT_STICKY;
|
||||||
|
}
|
||||||
|
|
||||||
player.handleIntent(intent);
|
player.handleIntent(intent);
|
||||||
if (player.getMediaSessionManager() != null) {
|
if (player.getMediaSessionManager() != null) {
|
||||||
player.getMediaSessionManager().handleMediaButtonIntent(intent);
|
player.getMediaSessionManager().handleMediaButtonIntent(intent);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return START_NOT_STICKY;
|
return START_NOT_STICKY;
|
||||||
@ -97,11 +97,6 @@ public final class PlayerService extends Service {
|
|||||||
// We can't just pause the player here because it will make transition
|
// We can't just pause the player here because it will make transition
|
||||||
// from one stream to a new stream not smooth
|
// from one stream to a new stream not smooth
|
||||||
player.smoothStopForImmediateReusing();
|
player.smoothStopForImmediateReusing();
|
||||||
|
|
||||||
// Notification shows information about old stream but if a user selects
|
|
||||||
// a stream from backStack it's not actual anymore
|
|
||||||
// So we should hide the notification at all.
|
|
||||||
// When autoplay enabled such notification flashing is annoying so skip this case
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,6 +75,11 @@ import java.util.Optional;
|
|||||||
public final class MainPlayerUi extends VideoPlayerUi implements View.OnLayoutChangeListener {
|
public final class MainPlayerUi extends VideoPlayerUi implements View.OnLayoutChangeListener {
|
||||||
private static final String TAG = MainPlayerUi.class.getSimpleName();
|
private static final String TAG = MainPlayerUi.class.getSimpleName();
|
||||||
|
|
||||||
|
// see the Javadoc of calculateMaxEndScreenThumbnailHeight for information
|
||||||
|
private static final int DETAIL_ROOT_MINIMUM_HEIGHT = 85; // dp
|
||||||
|
private static final int DETAIL_TITLE_TEXT_SIZE_TV = 16; // sp
|
||||||
|
private static final int DETAIL_TITLE_TEXT_SIZE_TABLET = 15; // sp
|
||||||
|
|
||||||
private boolean isFullscreen = false;
|
private boolean isFullscreen = false;
|
||||||
private boolean isVerticalVideo = false;
|
private boolean isVerticalVideo = false;
|
||||||
private boolean fragmentIsVisible = false;
|
private boolean fragmentIsVisible = false;
|
||||||
@ -262,13 +267,8 @@ public final class MainPlayerUi extends VideoPlayerUi implements View.OnLayoutCh
|
|||||||
binding.topControls.setClickable(true);
|
binding.topControls.setClickable(true);
|
||||||
binding.topControls.setFocusable(true);
|
binding.topControls.setFocusable(true);
|
||||||
|
|
||||||
if (isFullscreen) {
|
binding.titleTextView.setVisibility(isFullscreen ? View.VISIBLE : View.GONE);
|
||||||
binding.titleTextView.setVisibility(View.VISIBLE);
|
binding.channelTextView.setVisibility(isFullscreen ? View.VISIBLE : View.GONE);
|
||||||
binding.channelTextView.setVisibility(View.VISIBLE);
|
|
||||||
} else {
|
|
||||||
binding.titleTextView.setVisibility(View.GONE);
|
|
||||||
binding.channelTextView.setVisibility(View.GONE);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -450,13 +450,12 @@ public final class MainPlayerUi extends VideoPlayerUi implements View.OnLayoutCh
|
|||||||
* The calculating follows these rules:
|
* The calculating follows these rules:
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li>
|
* <li>
|
||||||
* Show at least stream title and content creator on TVs and tablets
|
* Show at least stream title and content creator on TVs and tablets when in landscape
|
||||||
* when in landscape (always the case for TVs) and not in fullscreen mode.
|
* (always the case for TVs) and not in fullscreen mode. This requires to have at least
|
||||||
* This requires to have at least <code>85dp</code> free space for {@link R.id.detail_root}
|
* {@link #DETAIL_ROOT_MINIMUM_HEIGHT} free space for {@link R.id.detail_root} and
|
||||||
* and additional space for the stream title text size
|
* additional space for the stream title text size ({@link R.id.detail_title_root_layout}).
|
||||||
* ({@link R.id.detail_title_root_layout}).
|
* The text size is {@link #DETAIL_TITLE_TEXT_SIZE_TABLET} on tablets and
|
||||||
* The text size is <code>15sp</code> on tablets and <code>16sp</code> on TVs,
|
* {@link #DETAIL_TITLE_TEXT_SIZE_TV} on TVs, see {@link R.id.titleTextView}.
|
||||||
* see {@link R.id.titleTextView}.
|
|
||||||
* </li>
|
* </li>
|
||||||
* <li>
|
* <li>
|
||||||
* Otherwise, the max thumbnail height is the screen height.
|
* Otherwise, the max thumbnail height is the screen height.
|
||||||
@ -472,12 +471,12 @@ public final class MainPlayerUi extends VideoPlayerUi implements View.OnLayoutCh
|
|||||||
final int screenHeight = context.getResources().getDisplayMetrics().heightPixels;
|
final int screenHeight = context.getResources().getDisplayMetrics().heightPixels;
|
||||||
|
|
||||||
if (DeviceUtils.isTv(context) && !isFullscreen()) {
|
if (DeviceUtils.isTv(context) && !isFullscreen()) {
|
||||||
final int videoInfoHeight =
|
final int videoInfoHeight = DeviceUtils.dpToPx(DETAIL_ROOT_MINIMUM_HEIGHT, context)
|
||||||
DeviceUtils.dpToPx(85, context) + DeviceUtils.spToPx(16, context);
|
+ DeviceUtils.spToPx(DETAIL_TITLE_TEXT_SIZE_TV, context);
|
||||||
return Math.min(bitmap.getHeight(), screenHeight - videoInfoHeight);
|
return Math.min(bitmap.getHeight(), screenHeight - videoInfoHeight);
|
||||||
} else if (DeviceUtils.isTablet(context) && isLandscape() && !isFullscreen()) {
|
} else if (DeviceUtils.isTablet(context) && isLandscape() && !isFullscreen()) {
|
||||||
final int videoInfoHeight =
|
final int videoInfoHeight = DeviceUtils.dpToPx(DETAIL_ROOT_MINIMUM_HEIGHT, context)
|
||||||
DeviceUtils.dpToPx(85, context) + DeviceUtils.spToPx(15, context);
|
+ DeviceUtils.spToPx(DETAIL_TITLE_TEXT_SIZE_TABLET, context);
|
||||||
return Math.min(bitmap.getHeight(), screenHeight - videoInfoHeight);
|
return Math.min(bitmap.getHeight(), screenHeight - videoInfoHeight);
|
||||||
} else { // fullscreen player: max height is the device height
|
} else { // fullscreen player: max height is the device height
|
||||||
return Math.min(bitmap.getHeight(), screenHeight);
|
return Math.min(bitmap.getHeight(), screenHeight);
|
||||||
@ -933,15 +932,9 @@ public final class MainPlayerUi extends VideoPlayerUi implements View.OnLayoutCh
|
|||||||
}
|
}
|
||||||
fragmentListener.onFullscreenStateChanged(isFullscreen);
|
fragmentListener.onFullscreenStateChanged(isFullscreen);
|
||||||
|
|
||||||
if (isFullscreen) {
|
binding.titleTextView.setVisibility(isFullscreen ? View.VISIBLE : View.GONE);
|
||||||
binding.titleTextView.setVisibility(View.VISIBLE);
|
binding.channelTextView.setVisibility(isFullscreen ? View.VISIBLE : View.GONE);
|
||||||
binding.channelTextView.setVisibility(View.VISIBLE);
|
binding.playerCloseButton.setVisibility(isFullscreen ? View.GONE : View.VISIBLE);
|
||||||
binding.playerCloseButton.setVisibility(View.GONE);
|
|
||||||
} else {
|
|
||||||
binding.titleTextView.setVisibility(View.GONE);
|
|
||||||
binding.channelTextView.setVisibility(View.GONE);
|
|
||||||
binding.playerCloseButton.setVisibility(View.VISIBLE);
|
|
||||||
}
|
|
||||||
setupScreenRotationButton();
|
setupScreenRotationButton();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package org.schabi.newpipe.player.ui;
|
package org.schabi.newpipe.player.ui;
|
||||||
|
|
||||||
import static com.google.android.exoplayer2.Player.REPEAT_MODE_ALL;
|
import static com.google.android.exoplayer2.Player.REPEAT_MODE_ALL;
|
||||||
import static com.google.android.exoplayer2.Player.REPEAT_MODE_OFF;
|
|
||||||
import static com.google.android.exoplayer2.Player.REPEAT_MODE_ONE;
|
import static com.google.android.exoplayer2.Player.REPEAT_MODE_ONE;
|
||||||
import static org.schabi.newpipe.MainActivity.DEBUG;
|
import static org.schabi.newpipe.MainActivity.DEBUG;
|
||||||
import static org.schabi.newpipe.ktx.ViewUtils.animate;
|
import static org.schabi.newpipe.ktx.ViewUtils.animate;
|
||||||
@ -912,18 +911,12 @@ public abstract class VideoPlayerUi extends PlayerUi
|
|||||||
public void onRepeatModeChanged(@RepeatMode final int repeatMode) {
|
public void onRepeatModeChanged(@RepeatMode final int repeatMode) {
|
||||||
super.onRepeatModeChanged(repeatMode);
|
super.onRepeatModeChanged(repeatMode);
|
||||||
|
|
||||||
switch (repeatMode) {
|
if (repeatMode == REPEAT_MODE_ALL) {
|
||||||
case REPEAT_MODE_OFF:
|
binding.repeatButton.setImageResource(R.drawable.exo_controls_repeat_all);
|
||||||
binding.repeatButton.setImageResource(R.drawable.exo_controls_repeat_off);
|
} else if (repeatMode == REPEAT_MODE_ONE) {
|
||||||
break;
|
binding.repeatButton.setImageResource(R.drawable.exo_controls_repeat_one);
|
||||||
case REPEAT_MODE_ONE:
|
} else /* repeatMode == REPEAT_MODE_OFF */ {
|
||||||
binding.repeatButton.setImageResource(R.drawable.exo_controls_repeat_one);
|
binding.repeatButton.setImageResource(R.drawable.exo_controls_repeat_off);
|
||||||
break;
|
|
||||||
case REPEAT_MODE_ALL:
|
|
||||||
binding.repeatButton.setImageResource(R.drawable.exo_controls_repeat_all);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break; // unreachable
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user