Skip to content

Commit dfcfb60

Browse files
committed
Rebased and added fullscreen button
- commits based on dev branch - readded fullscreenButton to PopupPlayer that was removed in one of a previous commits
1 parent 0d3bbff commit dfcfb60

File tree

7 files changed

+61
-38
lines changed

7 files changed

+61
-38
lines changed

app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java

+7-6
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
import org.schabi.newpipe.history.HistoryListener;
7575
import org.schabi.newpipe.info_list.InfoItemBuilder;
7676
import org.schabi.newpipe.info_list.InfoItemDialog;
77+
import org.schabi.newpipe.player.BasePlayer;
7778
import org.schabi.newpipe.player.MainVideoPlayer;
7879
import org.schabi.newpipe.player.PopupVideoPlayer;
7980
import org.schabi.newpipe.player.VideoPlayer;
@@ -238,7 +239,7 @@ public void onServiceConnected(ComponentName name, IBinder service) {
238239
if(mVideoPlayer.getView().getParent() == null)
239240
viewHolder.addView(mVideoPlayer.getView());
240241
// If the player is already attached to other instance of VideoDetailFragment just reattach it to the current instance
241-
else if(getView().findViewById(R.layout.activity_main_player) == null) {
242+
else if(getView().findViewById(R.id.aspectRatioLayout) == null) {
242243
removeVideoPlayerView();
243244
viewHolder.addView(mVideoPlayer.getView());
244245
hideMainVideoPlayer();
@@ -413,7 +414,7 @@ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, Strin
413414
else {
414415
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
415416
}
416-
if(mVideoPlayer != null) mVideoPlayer.checkAutorotation();
417+
if(mVideoPlayer != null && player != null) player.checkAutorotation();
417418
}
418419
}
419420

@@ -1068,11 +1069,11 @@ private void openPopupPlayer(final boolean append) {
10681069
}
10691070

10701071
if (append) {
1071-
NavigationHelper.enqueueOnPopupPlayer(activity, itemQueue);
1072+
NavigationHelper.enqueueOnPopupPlayer(activity, new SinglePlayQueue(currentInfo));
10721073
} else {
10731074
Toast.makeText(activity, R.string.popup_playing_toast, Toast.LENGTH_SHORT).show();
10741075
final Intent intent = NavigationHelper.getPlayerIntent(
1075-
activity, PopupVideoPlayer.class, itemQueue, getSelectedVideoStream().resolution
1076+
activity, PopupVideoPlayer.class, playQueue, getSelectedVideoStream().resolution
10761077
);
10771078
activity.startService(intent);
10781079
}
@@ -1101,9 +1102,9 @@ private void openNormalBackgroundPlayer(final boolean append) {
11011102
playQueue.setRecovery(0, mVideoPlayer.getPlaybackPosition());
11021103
}
11031104
if (append) {
1104-
NavigationHelper.enqueueOnBackgroundPlayer(activity, itemQueue);
1105+
NavigationHelper.enqueueOnBackgroundPlayer(activity, new SinglePlayQueue(currentInfo));
11051106
} else {
1106-
NavigationHelper.playOnBackgroundPlayer(activity, itemQueue);
1107+
NavigationHelper.playOnBackgroundPlayer(activity, playQueue);
11071108
}
11081109
}
11091110

app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ public void onClick(DialogInterface dialogInterface, int i) {
176176
NavigationHelper.enqueueOnPopupPlayer(context, new SinglePlayQueue(item));
177177
break;
178178
case 2:
179-
NavigationHelper.playOnMainPlayer(context, getPlayQueue(index));
179+
NavigationHelper.playOnMainPlayer(getFragmentManager(), getPlayQueue(index));
180180
break;
181181
case 3:
182182
NavigationHelper.playOnBackgroundPlayer(context, getPlayQueue(index));
@@ -463,7 +463,7 @@ public void handleResult(@NonNull ChannelInfo result) {
463463
headerPlayAllButton.setOnClickListener(new View.OnClickListener() {
464464
@Override
465465
public void onClick(View view) {
466-
NavigationHelper.playOnMainPlayer(activity, getPlayQueue());
466+
NavigationHelper.playOnMainPlayer(getFragmentManager(), getPlayQueue());
467467
}
468468
});
469469
headerPopupButton.setOnClickListener(new View.OnClickListener() {

app/src/main/java/org/schabi/newpipe/fragments/list/playlist/PlaylistFragment.java

+2-13
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@
2727
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
2828
import org.schabi.newpipe.fragments.list.BaseListInfoFragment;
2929
import org.schabi.newpipe.info_list.InfoItemDialog;
30-
import org.schabi.newpipe.player.BackgroundPlayer;
31-
import org.schabi.newpipe.player.PopupVideoPlayer;
32-
import org.schabi.newpipe.playlist.ExternalPlayQueue;
3330
import org.schabi.newpipe.playlist.PlayQueue;
3431
import org.schabi.newpipe.playlist.PlaylistPlayQueue;
3532
import org.schabi.newpipe.playlist.SinglePlayQueue;
@@ -134,7 +131,7 @@ public void onClick(DialogInterface dialogInterface, int i) {
134131
NavigationHelper.enqueueOnPopupPlayer(context, new SinglePlayQueue(item));
135132
break;
136133
case 2:
137-
NavigationHelper.playOnMainPlayer(context, getPlayQueue(index));
134+
NavigationHelper.playOnMainPlayer(getFragmentManager(), getPlayQueue(index));
138135
break;
139136
case 3:
140137
NavigationHelper.playOnBackgroundPlayer(context, getPlayQueue(index));
@@ -209,15 +206,7 @@ public void onClick(View v) {
209206
headerPlayAllButton.setOnClickListener(new View.OnClickListener() {
210207
@Override
211208
public void onClick(View view) {
212-
final PlayQueue playQueue = new ExternalPlayQueue(
213-
currentInfo.service_id,
214-
currentInfo.url,
215-
currentInfo.next_streams_url,
216-
infoListAdapter.getItemsList(),
217-
0
218-
);
219-
InfoItem firstStream = infoListAdapter.getItemsList().get(0);
220-
NavigationHelper.openVideoDetailFragment(getFragmentManager(), firstStream.service_id, firstStream.url, firstStream.name, false, playQueue);
209+
NavigationHelper.playOnMainPlayer(getFragmentManager(), getPlayQueue());
221210
}
222211
});
223212
headerPopupButton.setOnClickListener(new View.OnClickListener() {

app/src/main/java/org/schabi/newpipe/player/MainVideoPlayer.java

+22-11
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ public class MainVideoPlayer extends Service {
9898

9999
private VideoPlayerImpl playerImpl;
100100
public boolean isFullscreen = false;
101-
private ImageButton screenRotationButton;
102101

103102
private PlayerEventListener fragmentListener;
104103
private final IBinder mBinder = new MainVideoPlayer.LocalBinder();
@@ -165,9 +164,6 @@ private void createView() {
165164
playerImpl = new VideoPlayerImpl(this);
166165
playerImpl.setStartedFromNewPipe(true);
167166
playerImpl.setup(layout);
168-
169-
screenRotationButton = layout.findViewById(R.id.screenRotationButton);
170-
checkAutorotation();
171167
}
172168

173169
public void stop() {
@@ -229,11 +225,6 @@ public void loadVideo(StreamInfo info, PlayQueue queue, String videoResolution,
229225
getView().findViewById(R.id.surfaceView).setVisibility(View.GONE);
230226
}
231227

232-
public void checkAutorotation() {
233-
boolean autorotationEnabled = PreferenceManager.getDefaultSharedPreferences(this).getBoolean(this.getString(R.string.use_video_autorotation_key), false);
234-
screenRotationButton.setVisibility(autorotationEnabled? View.GONE : View.VISIBLE);
235-
}
236-
237228
private void toggleOrientation() {
238229
Activity parent = playerImpl.getParentActivity();
239230
if(parent == null) return;
@@ -354,6 +345,7 @@ public class VideoPlayerImpl extends VideoPlayer {
354345
private ImageButton queueButton;
355346
private ImageButton repeatButton;
356347
private ImageButton shuffleButton;
348+
private ImageButton screenRotationButton;
357349

358350
private ImageButton playPauseButton;
359351
private ImageButton playPreviousButton;
@@ -393,7 +385,7 @@ public void initViews(View rootView) {
393385
this.queueButton = rootView.findViewById(R.id.queueButton);
394386
this.repeatButton = rootView.findViewById(R.id.repeatButton);
395387
this.shuffleButton = rootView.findViewById(R.id.shuffleButton);
396-
388+
this.screenRotationButton = rootView.findViewById(R.id.screenRotationButton);
397389
this.playPauseButton = rootView.findViewById(R.id.playPauseButton);
398390
this.playPreviousButton = rootView.findViewById(R.id.playPreviousButton);
399391
this.playNextButton = rootView.findViewById(R.id.playNextButton);
@@ -403,6 +395,7 @@ public void initViews(View rootView) {
403395

404396
titleTextView.setSelected(true);
405397
channelTextView.setSelected(true);
398+
checkAutorotation();
406399

407400
getRootView().setKeepScreenOn(true);
408401
}
@@ -423,6 +416,7 @@ public void initListeners() {
423416
playPauseButton.setOnClickListener(this);
424417
playPreviousButton.setOnClickListener(this);
425418
playNextButton.setOnClickListener(this);
419+
screenRotationButton.setOnClickListener(this);
426420
moreOptionsButton.setOnClickListener(this);
427421
}
428422

@@ -528,7 +522,6 @@ public void onPlayBackgroundButtonClicked() {
528522

529523
((View) getControlAnimationView().getParent()).setVisibility(View.GONE);
530524
destroy();
531-
finish();
532525
}
533526

534527

@@ -544,6 +537,9 @@ public void onClick(View v) {
544537
} else if (v.getId() == playNextButton.getId()) {
545538
onPlayNext();
546539

540+
} else if (v.getId() == screenRotationButton.getId()) {
541+
onScreenRotationClicked();
542+
547543
} else if (v.getId() == queueButton.getId()) {
548544
onQueueClicked();
549545
return;
@@ -800,6 +796,16 @@ public void onBroadcastReceived(Intent intent) {
800796
}
801797
resetNotification();
802798
}
799+
/*@Override
800+
public void onConfigurationChanged(Configuration newConfig) {
801+
super.onConfigurationChanged(newConfig);
802+
803+
if (playerImpl.isSomePopupMenuVisible()) {
804+
playerImpl.moreOptionsPopupMenu.dismiss();
805+
playerImpl.getQualityPopupMenu().dismiss();
806+
playerImpl.getPlaybackSpeedPopupMenu().dismiss();
807+
}
808+
}*/
803809

804810
/*//////////////////////////////////////////////////////////////////////////
805811
// Utils
@@ -894,6 +900,11 @@ private void updatePlaybackButtons() {
894900
setShuffleButton(shuffleButton, playQueue.isShuffled());
895901
}
896902

903+
public void checkAutorotation() {
904+
boolean autorotationEnabled = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getBoolean(getApplication().getString(R.string.use_video_autorotation_key), false);
905+
screenRotationButton.setVisibility(autorotationEnabled? View.GONE : View.VISIBLE);
906+
}
907+
897908
private void buildMoreOptionsMenu() {
898909
if (moreOptionsPopupMenu == null) return;
899910
moreOptionsPopupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

app/src/main/java/org/schabi/newpipe/player/VideoPlayer.java

+8-1
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ public abstract class VideoPlayer extends BasePlayer implements SimpleExoPlayer.
124124

125125
private View topControlsRoot;
126126
private TextView qualityTextView;
127+
private ImageButton fullScreenButton;
127128

128129
private ValueAnimator controlViewAnimator;
129130
private Handler controlsVisibilityHandler = new Handler();
@@ -165,6 +166,7 @@ public void initViews(View rootView) {
165166
this.bottomControlsRoot = rootView.findViewById(R.id.bottomControls);
166167
this.topControlsRoot = rootView.findViewById(R.id.topControls);
167168
this.qualityTextView = rootView.findViewById(R.id.qualityTextView);
169+
this.fullScreenButton = rootView.findViewById(R.id.fullScreenButton);
168170

169171
//this.aspectRatioFrameLayout.setAspectRatio(16.0f / 9.0f);
170172

@@ -185,6 +187,7 @@ public void initListeners() {
185187
playbackSeekBar.setOnSeekBarChangeListener(this);
186188
playbackSpeedTextView.setOnClickListener(this);
187189
qualityTextView.setOnClickListener(this);
190+
fullScreenButton.setOnClickListener(this);
188191
}
189192

190193
@Override
@@ -452,7 +455,9 @@ public void onFastForward() {
452455
@Override
453456
public void onClick(View v) {
454457
if (DEBUG) Log.d(TAG, "onClick() called with: v = [" + v + "]");
455-
if (v.getId() == qualityTextView.getId()) {
458+
if (v.getId() == fullScreenButton.getId()) {
459+
onFullScreenButtonClicked();
460+
} else if (v.getId() == qualityTextView.getId()) {
456461
onQualitySelectorClicked();
457462
} else if (v.getId() == playbackSpeedTextView.getId()) {
458463
onPlaybackSpeedClicked();
@@ -750,6 +755,8 @@ public TextView getQualityTextView() {
750755
return qualityTextView;
751756
}
752757

758+
public ImageButton getFullScreenButton() { return fullScreenButton; }
759+
753760
public PopupMenu getQualityPopupMenu() {
754761
return qualityPopupMenu;
755762
}

app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@
3232
import org.schabi.newpipe.player.BackgroundPlayer;
3333
import org.schabi.newpipe.player.BackgroundPlayerActivity;
3434
import org.schabi.newpipe.player.BasePlayer;
35-
import org.schabi.newpipe.player.MainVideoPlayer;
3635
import org.schabi.newpipe.player.PopupVideoPlayer;
3736
import org.schabi.newpipe.player.PopupVideoPlayerActivity;
3837
import org.schabi.newpipe.player.VideoPlayer;
3938
import org.schabi.newpipe.playlist.PlayQueue;
39+
import org.schabi.newpipe.playlist.PlayQueueItem;
4040
import org.schabi.newpipe.settings.SettingsActivity;
4141

4242
@SuppressWarnings({"unused", "WeakerAccess"})
@@ -83,8 +83,9 @@ public static Intent getPlayerIntent(final Context context,
8383
.putExtra(BasePlayer.PLAYBACK_PITCH, playbackPitch);
8484
}
8585

86-
public static void playOnMainPlayer(final Context context, final PlayQueue queue) {
87-
context.startActivity(getPlayerIntent(context, MainVideoPlayer.class, queue));
86+
public static void playOnMainPlayer(final FragmentManager fragmentManager, final PlayQueue queue) {
87+
PlayQueueItem firstStream = queue.getItem(0);
88+
NavigationHelper.openVideoDetailFragment(fragmentManager, firstStream.getServiceId(), firstStream.getUrl(), firstStream.getTitle(), false, queue);
8889
}
8990

9091
public static void playOnPopupPlayer(final Context context, final PlayQueue queue) {

app/src/main/res/layout/activity_main_player.xml

+16-2
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@
209209
android:layout_width="wrap_content"
210210
android:layout_height="wrap_content"
211211
android:layout_marginRight="2dp"
212-
android:layout_toLeftOf="@+id/queueButton"
212+
android:layout_toLeftOf="@+id/screenRotationButton"
213213
android:gravity="center"
214214
android:minHeight="35dp"
215215
android:minWidth="40dp"
@@ -240,7 +240,7 @@
240240
android:layout_height="35dp"
241241
android:layout_marginLeft="2dp"
242242
android:layout_marginRight="2dp"
243-
android:layout_toLeftOf="@+id/moreOptionsButton"
243+
android:layout_toLeftOf="@+id/fullScreenButton"
244244
android:background="#00ffffff"
245245
android:clickable="true"
246246
android:focusable="true"
@@ -250,6 +250,19 @@
250250
tools:ignore="ContentDescription,RtlHardcoded"
251251
android:visibility="gone" />
252252

253+
<ImageButton
254+
android:id="@+id/fullScreenButton"
255+
android:layout_width="35dp"
256+
android:layout_height="35dp"
257+
android:layout_alignParentRight="true"
258+
android:layout_marginLeft="4dp"
259+
android:background="#00ffffff"
260+
android:clickable="true"
261+
android:focusable="true"
262+
android:scaleType="fitXY"
263+
android:src="@drawable/ic_fullscreen_exit_white"
264+
tools:ignore="ContentDescription,RtlHardcoded"/>
265+
253266
<ImageButton
254267
android:id="@+id/moreOptionsButton"
255268
android:layout_width="wrap_content"
@@ -262,6 +275,7 @@
262275
android:focusable="true"
263276
android:scaleType="fitXY"
264277
android:src="?attr/options"
278+
android:visibility="gone"
265279
tools:ignore="ContentDescription,RtlHardcoded"/>
266280

267281
</RelativeLayout>

0 commit comments

Comments
 (0)