Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
133 changes: 91 additions & 42 deletions app/src/main/java/org/schabi/newpipe/player/VideoPlayerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
import org.schabi.newpipe.util.KoreUtil;
import org.schabi.newpipe.util.ListHelper;
import org.schabi.newpipe.util.NavigationHelper;
import org.schabi.newpipe.util.PermissionHelper;
import org.schabi.newpipe.util.ShareUtils;

import java.util.List;
Expand Down Expand Up @@ -159,12 +160,8 @@ public class VideoPlayerImpl extends VideoPlayer
private ImageButton queueButton;
private ImageButton repeatButton;
private ImageButton shuffleButton;
private ImageButton playWithKodi;
private ImageButton openInBrowser;
private ImageButton fullscreenButton;
private ImageButton playerCloseButton;
private ImageButton screenRotationButton;
private ImageButton muteButton;

private ImageButton playPauseButton;
private ImageButton playPreviousButton;
Expand All @@ -181,7 +178,13 @@ public class VideoPlayerImpl extends VideoPlayer
private MainPlayer.PlayerType playerType = MainPlayer.PlayerType.VIDEO;

private ImageButton moreOptionsButton;
private ImageButton playWithKodi;
private ImageButton openInBrowser;
private ImageButton shareButton;
private ImageButton muteButton;
private ImageButton switchPopupButton;
private ImageButton switchBackgroundButton;
private ImageButton switchMainButton;

private View primaryControls;
private View secondaryControls;
Expand Down Expand Up @@ -290,12 +293,8 @@ public void initViews(final View view) {
this.queueButton = view.findViewById(R.id.queueButton);
this.repeatButton = view.findViewById(R.id.repeatButton);
this.shuffleButton = view.findViewById(R.id.shuffleButton);
this.playWithKodi = view.findViewById(R.id.playWithKodi);
this.openInBrowser = view.findViewById(R.id.openInBrowser);
this.fullscreenButton = view.findViewById(R.id.fullScreenButton);
this.screenRotationButton = view.findViewById(R.id.screenRotationButton);
this.playerCloseButton = view.findViewById(R.id.playerCloseButton);
this.muteButton = view.findViewById(R.id.switchMute);

this.playPauseButton = view.findViewById(R.id.playPauseButton);
this.playPreviousButton = view.findViewById(R.id.playPreviousButton);
Expand All @@ -304,7 +303,13 @@ public void initViews(final View view) {
this.moreOptionsButton = view.findViewById(R.id.moreOptionsButton);
this.primaryControls = view.findViewById(R.id.primaryControls);
this.secondaryControls = view.findViewById(R.id.secondaryControls);
this.playWithKodi = view.findViewById(R.id.playWithKodi);
this.openInBrowser = view.findViewById(R.id.openInBrowser);
this.shareButton = view.findViewById(R.id.share);
this.muteButton = view.findViewById(R.id.switchMute);
this.switchPopupButton = view.findViewById(R.id.switchPopup);
this.switchBackgroundButton = view.findViewById(R.id.switchBackground);
this.switchMainButton = view.findViewById(R.id.switchMain);

this.queueLayout = view.findViewById(R.id.playQueuePanel);
this.itemsListCloseButton = view.findViewById(R.id.playQueueClose);
Expand Down Expand Up @@ -346,42 +351,50 @@ protected void setupSubtitleView(final @NonNull SubtitleView view,
*/
private void setupElementsVisibility() {
if (popupPlayerSelected()) {
fullscreenButton.setVisibility(View.VISIBLE);
screenRotationButton.setVisibility(View.GONE);
getResizeView().setVisibility(View.GONE);
getRootView().findViewById(R.id.metadataView).setVisibility(View.GONE);
queueButton.setVisibility(View.GONE);
moreOptionsButton.setVisibility(View.GONE);
getTopControlsRoot().setOrientation(LinearLayout.HORIZONTAL);
primaryControls.getLayoutParams().width = LinearLayout.LayoutParams.WRAP_CONTENT;
secondaryControls.setAlpha(1.0f);
secondaryControls.setVisibility(View.VISIBLE);
secondaryControls.setTranslationY(0);
shareButton.setVisibility(View.GONE);

moreOptionsButton.setVisibility(View.GONE);
playWithKodi.setVisibility(View.GONE);
openInBrowser.setVisibility(View.GONE);
shareButton.setVisibility(View.GONE);
muteButton.setVisibility(View.GONE);
switchPopupButton.setVisibility(View.GONE);
switchBackgroundButton.setVisibility(View.GONE);
switchMainButton.setVisibility(View.VISIBLE);

playerCloseButton.setVisibility(View.GONE);
getTopControlsRoot().bringToFront();
getTopControlsRoot().setClickable(false);
getTopControlsRoot().setFocusable(false);
getBottomControlsRoot().bringToFront();
onQueueClosed();
} else {
fullscreenButton.setVisibility(View.GONE);
setupScreenRotationButton();
getResizeView().setVisibility(View.VISIBLE);
getRootView().findViewById(R.id.metadataView).setVisibility(View.VISIBLE);
moreOptionsButton.setVisibility(View.VISIBLE);
getTopControlsRoot().setOrientation(LinearLayout.VERTICAL);
primaryControls.getLayoutParams().width = LinearLayout.LayoutParams.MATCH_PARENT;
secondaryControls.setVisibility(View.INVISIBLE);

moreOptionsButton.setVisibility(View.VISIBLE);
moreOptionsButton.setImageDrawable(AppCompatResources.getDrawable(service,
R.drawable.ic_expand_more_white_24dp));
shareButton.setVisibility(View.VISIBLE);
showHideKodiButton();
openInBrowser.setVisibility(View.VISIBLE);
shareButton.setVisibility(View.VISIBLE);
muteButton.setVisibility(View.VISIBLE);
switchPopupButton.setVisibility(isFullscreen ? View.VISIBLE : View.GONE);
switchBackgroundButton.setVisibility(isFullscreen ? View.VISIBLE : View.GONE);
switchMainButton.setVisibility(View.GONE);

playerCloseButton.setVisibility(isFullscreen ? View.GONE : View.VISIBLE);
// Top controls have a large minHeight which is allows to drag the player
// down in fullscreen mode (just larger area to make easy to locate by finger)
Expand Down Expand Up @@ -459,13 +472,15 @@ public void initListeners() {

moreOptionsButton.setOnClickListener(this);
moreOptionsButton.setOnLongClickListener(this);
shareButton.setOnClickListener(this);
fullscreenButton.setOnClickListener(this);
screenRotationButton.setOnClickListener(this);
playWithKodi.setOnClickListener(this);
openInBrowser.setOnClickListener(this);
playerCloseButton.setOnClickListener(this);
shareButton.setOnClickListener(this);
muteButton.setOnClickListener(this);
switchPopupButton.setOnClickListener(this);
switchBackgroundButton.setOnClickListener(this);
switchMainButton.setOnClickListener(this);
screenRotationButton.setOnClickListener(this);
playerCloseButton.setOnClickListener(this);

settingsContentObserver = new ContentObserver(new Handler()) {
@Override
Expand Down Expand Up @@ -732,30 +747,56 @@ public void toggleFullscreen() {
}

isFullscreen = !isFullscreen;
if (!isFullscreen) {
// Apply window insets because Android will not do it when orientation changes
// from landscape to portrait (open vertical video to reproduce)
getControlsRoot().setPadding(0, 0, 0, 0);
} else {
if (isFullscreen) {
// Android needs tens milliseconds to send new insets but a user is able to see
// how controls changes it's position from `0` to `nav bar height` padding.
// So just hide the controls to hide this visual inconsistency
hideControls(0, 0);
} else {
// Apply window insets because Android will not do it when orientation changes
// from landscape to portrait (open vertical video to reproduce)
getControlsRoot().setPadding(0, 0, 0, 0);
}
fragmentListener.onFullscreenStateChanged(isFullscreen());
fragmentListener.onFullscreenStateChanged(isFullscreen);

if (!isFullscreen()) {
titleTextView.setVisibility(View.GONE);
channelTextView.setVisibility(View.GONE);
playerCloseButton.setVisibility(videoPlayerSelected() ? View.VISIBLE : View.GONE);
} else {
if (isFullscreen) {
titleTextView.setVisibility(View.VISIBLE);
channelTextView.setVisibility(View.VISIBLE);
playerCloseButton.setVisibility(View.GONE);
switchPopupButton.setVisibility(View.VISIBLE);
switchBackgroundButton.setVisibility(View.VISIBLE);
} else {
titleTextView.setVisibility(View.GONE);
channelTextView.setVisibility(View.GONE);
playerCloseButton.setVisibility(videoPlayerSelected() ? View.VISIBLE : View.GONE);
switchPopupButton.setVisibility(View.GONE);
switchBackgroundButton.setVisibility(View.GONE);
}
setupScreenRotationButton();
}

public void switchToPopup() {
if (PermissionHelper.isPopupEnabled(context)) {
if (service.isLandscape() && globalScreenOrientationLocked(service)) {
fragmentListener.onScreenRotationButtonClicked();
}

setRecovery();
NavigationHelper.playOnPopupPlayer(context, playQueue, isPlaying());
} else {
PermissionHelper.showPopupEnablementToast(context);
}
}

public void switchToBackground() {
if (service.isLandscape() && globalScreenOrientationLocked(service)) {
fragmentListener.onScreenRotationButtonClicked();
}

setRecovery();
NavigationHelper.playOnBackgroundPlayer(context, playQueue, isPlaying());
}

public void switchFromPopupToMain() {
if (DEBUG) {
Log.d(TAG, "switchFromPopupToMain() called");
Expand Down Expand Up @@ -790,6 +831,17 @@ public void switchFromPopupToMain() {
context.startActivity(intent);
}

private void onRotateScreen() {
// Only if it's not a vertical video or vertical video but in landscape with locked
// orientation a screen orientation can be changed automatically
if (!isVerticalVideo
|| (service.isLandscape() && globalScreenOrientationLocked(service))) {
fragmentListener.onScreenRotationButtonClicked();
} else {
toggleFullscreen();
}
}

@Override
public void onClick(final View v) {
super.onClick(v);
Expand All @@ -810,25 +862,22 @@ public void onClick(final View v) {
return;
} else if (v.getId() == moreOptionsButton.getId()) {
onMoreOptionsClicked();
} else if (v.getId() == shareButton.getId()) {
onShareClicked();
} else if (v.getId() == playWithKodi.getId()) {
onPlayWithKodiClicked();
} else if (v.getId() == openInBrowser.getId()) {
onOpenInBrowserClicked();
} else if (v.getId() == fullscreenButton.getId()) {
switchFromPopupToMain();
} else if (v.getId() == screenRotationButton.getId()) {
// Only if it's not a vertical video or vertical video but in landscape with locked
// orientation a screen orientation can be changed automatically
if (!isVerticalVideo
|| (service.isLandscape() && globalScreenOrientationLocked(service))) {
fragmentListener.onScreenRotationButtonClicked();
} else {
toggleFullscreen();
}
} else if (v.getId() == shareButton.getId()) {
onShareClicked();
} else if (v.getId() == muteButton.getId()) {
onMuteUnmuteButtonClicked();
} else if (v.getId() == switchPopupButton.getId()) {
switchToPopup();
} else if (v.getId() == switchBackgroundButton.getId()) {
switchToBackground();
} else if (v.getId() == switchMainButton.getId()) {
switchFromPopupToMain();
} else if (v.getId() == screenRotationButton.getId()) {
onRotateScreen();
} else if (v.getId() == playerCloseButton.getId()) {
service.sendBroadcast(new Intent(VideoDetailFragment.ACTION_HIDE_MAIN_PLAYER));
}
Expand Down
56 changes: 39 additions & 17 deletions app/src/main/res/layout-large-land/player.xml
Original file line number Diff line number Diff line change
Expand Up @@ -259,71 +259,93 @@
<androidx.appcompat.widget.AppCompatImageButton
android:id="@+id/playWithKodi"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:layout_height="37dp"
android:padding="@dimen/player_main_buttons_padding"
android:layout_marginEnd="8dp"
android:clickable="true"
android:focusable="true"
android:scaleType="fitXY"
app:srcCompat="@drawable/ic_cast_white_24dp"
android:background="?attr/selectableItemBackground"
android:contentDescription="@string/play_with_kodi_title"
tools:ignore="RtlHardcoded"/>
android:contentDescription="@string/play_with_kodi_title"/>

<androidx.appcompat.widget.AppCompatImageButton
android:id="@+id/openInBrowser"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:layout_height="37dp"
android:padding="@dimen/player_main_buttons_padding"
android:layout_marginEnd="8dp"
android:clickable="true"
android:focusable="true"
android:scaleType="fitXY"
app:srcCompat="@drawable/ic_language_white_24dp"
android:background="?attr/selectableItemBackground"
android:contentDescription="@string/open_in_browser"
tools:ignore="RtlHardcoded"/>
android:contentDescription="@string/open_in_browser"/>

<androidx.appcompat.widget.AppCompatImageButton
android:id="@+id/share"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:layout_height="37dp"
android:padding="@dimen/player_main_buttons_padding"
android:layout_marginEnd="8dp"
android:clickable="true"
android:focusable="true"
android:scaleType="fitXY"
app:srcCompat="@drawable/ic_share_white_24dp"
android:background="?attr/selectableItemBackground"
android:contentDescription="@string/share"
tools:ignore="RtlHardcoded"/>
android:contentDescription="@string/share"/>

<androidx.appcompat.widget.AppCompatImageButton
android:id="@+id/switchMute"
android:layout_width="wrap_content"
android:layout_height="37dp"
android:layout_marginEnd="8dp"
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:contentDescription="@string/mute"
android:focusable="true"
android:padding="@dimen/player_main_buttons_padding"
android:scaleType="fitXY"
app:srcCompat="@drawable/ic_volume_off_white_24dp"/>

<androidx.appcompat.widget.AppCompatImageButton
android:id="@+id/switchPopup"
android:layout_width="wrap_content"
android:layout_height="37dp"
android:layout_marginEnd="8dp"
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:contentDescription="@string/popup_player"
android:focusable="true"
android:padding="@dimen/player_main_buttons_padding"
android:scaleType="fitXY"
app:srcCompat="@drawable/ic_volume_off_white_24dp"
app:srcCompat="@drawable/ic_picture_in_picture_white_24dp"/>

<androidx.appcompat.widget.AppCompatImageButton
android:id="@+id/switchBackground"
android:layout_width="wrap_content"
android:layout_height="37dp"
android:background="?attr/selectableItemBackground"
android:contentDescription="@string/mute"
tools:ignore="RtlHardcoded" />
android:clickable="true"
android:contentDescription="@string/background_player"
android:focusable="true"
android:padding="@dimen/player_main_buttons_padding"
android:scaleType="fitXY"
app:srcCompat="@drawable/ic_headset_white_24dp"/>

<androidx.appcompat.widget.AppCompatImageButton
android:id="@+id/fullScreenButton"
android:id="@+id/switchMain"
android:layout_width="40dp"
android:layout_height="40dp"
android:padding="@dimen/player_main_buttons_padding"
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:contentDescription="@string/switch_to_main"
android:focusable="true"
android:padding="@dimen/player_main_buttons_padding"
android:scaleType="fitCenter"
app:srcCompat="@drawable/ic_fullscreen_white_24dp"
tools:ignore="ContentDescription,RtlHardcoded"
android:visibility="gone"
tools:visibility="visible"/>
app:srcCompat="@drawable/ic_fullscreen_white_24dp"
tools:visibility="visible" />

</LinearLayout>

Expand Down
Loading