Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expandable player with unified UI #2907

Merged
merged 43 commits into from
Aug 1, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
c45514b
All players in one place
avently Dec 29, 2019
fc9b632
Optimizations and fixes of rare situations
avently Dec 31, 2019
bc2dc8d
First block of fixes for review
avently Dec 31, 2019
4519dd0
Second block of fixes for review
avently Jan 3, 2020
e063967
Third block of fixes for review
avently Jan 3, 2020
a2d5314
Fourth block of fixes for review
avently Jan 6, 2020
4c57893
New features and fixes
avently Jan 8, 2020
22bb129
Autoplay enhancement and new button at the top left corner
avently Jan 9, 2020
6fc9131
Changed default autoplay type to "Only on WiFi"
avently Jan 9, 2020
421b821
Fixes of VideoDetailFragment
avently Jan 10, 2020
0c394b1
Another fix of VideoDetailFragment
avently Jan 13, 2020
d1609cb
Enhancements to background playback and media button handling
avently Jan 15, 2020
92ff98d
New logic for handling global orientation
avently Jan 16, 2020
cc438fd
Player's elements positioning is better for tablet and in multiWindow…
avently Jan 17, 2020
26e487c
Hotfix
avently Jan 26, 2020
f334a27
Mini player, ExpandableSurfaceView with ZOOM support, popup
avently Feb 5, 2020
a47e6dd
AppBarLayout scrolling awesomeness, PlayQueue layout touches intercep…
avently Feb 12, 2020
6d7e376
Vertical videos in portrait & fullscreen, UI enhancements for tablets…
avently Feb 24, 2020
5c2ff9b
Better implementation of old code
avently Feb 28, 2020
d87e488
Fix for a ripple effect on a button
avently Feb 29, 2020
398cbe9
Better backstack, better tablet support, switching players confirmati…
avently Mar 10, 2020
a7fbe05
Changes for review
avently Jun 27, 2020
b2164ce
Marked many (too many) variables as final
avently Jul 12, 2020
d2aaa6f
Merged the latest changes
avently Jul 13, 2020
bff2387
Small fixes of issues
avently Jul 13, 2020
d8f7db4
Made checkStyle happy
avently Jul 14, 2020
08412d6
Mini player slide to botom fix, buttons size fix
avently Jul 14, 2020
787b136
NonNull instead of NotNull annotations
avently Jul 14, 2020
d196f8b
New icons
avently Jul 15, 2020
06e70ab
Merged the latest changes
avently Jul 20, 2020
c7ccf9b
AndroidTvUtils -> DeviceUtils
avently Jul 20, 2020
77cd318
Removed unused line
avently Jul 20, 2020
3ecbbea
Better TV support, icons, activity_main refactoring
avently Jul 21, 2020
7aa8a5c
Fixed a situation when background playback could use a video stream i…
avently Jul 21, 2020
91a0257
Fixes for Android API <21
avently Jul 22, 2020
7c79d42
Quality selector for external playback and better fullscreen mode for…
avently Jul 23, 2020
08db1d5
Android TV: ability to select all buttons in the main player, as well…
avently Jul 25, 2020
ec8b000
Merged the latest code
avently Jul 25, 2020
f2e4b69
Another part of UI improvements for Android TV
avently Jul 25, 2020
5293d17
Removed unused files, translations, styles, settings key
avently Jul 25, 2020
68ed738
Renamed files
avently Jul 25, 2020
8562fbd
Merge branch 'dev'
avently Jul 28, 2020
e41218c
Disable starting player service via media button when there is nothin…
avently Jul 28, 2020
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
8 changes: 8 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@
</intent-filter>
</service>

<service
android:name=".player.MainPlayer"
android:exported="false">
<intent-filter>
<action android:name="android.intent.action.MEDIA_BUTTON" />
</intent-filter>
</service>

<activity
android:name=".player.BackgroundPlayerActivity"
android:launchMode="singleTask"
Expand Down
65 changes: 34 additions & 31 deletions app/src/main/java/org/schabi/newpipe/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,16 @@

package org.schabi.newpipe;

import android.content.Intent;
import android.content.SharedPreferences;
import android.content.*;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Spinner;
import android.widget.TextView;
import android.view.*;
import android.widget.*;

import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBar;
Expand All @@ -53,6 +41,7 @@
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;

import com.google.android.material.bottomsheet.BottomSheetBehavior;
import com.google.android.material.navigation.NavigationView;

import org.schabi.newpipe.extractor.NewPipe;
Expand All @@ -64,16 +53,10 @@
import org.schabi.newpipe.fragments.MainFragment;
import org.schabi.newpipe.fragments.detail.VideoDetailFragment;
import org.schabi.newpipe.fragments.list.search.SearchFragment;
import org.schabi.newpipe.player.VideoPlayer;
import org.schabi.newpipe.player.playqueue.PlayQueue;
import org.schabi.newpipe.report.ErrorActivity;
import org.schabi.newpipe.util.Constants;
import org.schabi.newpipe.util.KioskTranslator;
import org.schabi.newpipe.util.NavigationHelper;
import org.schabi.newpipe.util.PeertubeHelper;
import org.schabi.newpipe.util.PermissionHelper;
import org.schabi.newpipe.util.ServiceHelper;
import org.schabi.newpipe.util.StateSaver;
import org.schabi.newpipe.util.TLSSocketFactoryCompat;
import org.schabi.newpipe.util.ThemeHelper;
import org.schabi.newpipe.util.*;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -470,12 +453,25 @@ protected void onNewIntent(Intent intent) {
public void onBackPressed() {
if (DEBUG) Log.d(TAG, "onBackPressed() called");

Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.fragment_holder);
// If current fragment implements BackPressable (i.e. can/wanna handle back press) delegate the back press to it
if (fragment instanceof BackPressable) {
if (((BackPressable) fragment).onBackPressed()) return;
}
FrameLayout bottomSheetLayout = findViewById(R.id.fragment_player_holder);
BottomSheetBehavior bottomSheetBehavior = BottomSheetBehavior.from(bottomSheetLayout);

if (bottomSheetBehavior.getState() == BottomSheetBehavior.STATE_HIDDEN || bottomSheetBehavior.getState() == BottomSheetBehavior.STATE_COLLAPSED) {
avently marked this conversation as resolved.
Show resolved Hide resolved
Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.fragment_holder);
// If current fragment implements BackPressable (i.e. can/wanna handle back press) delegate the back press to it
if (fragment instanceof BackPressable) {
if (((BackPressable) fragment).onBackPressed()) return;
}

} else {
Fragment fragmentPlayer = getSupportFragmentManager().findFragmentById(R.id.fragment_player_holder);
// If current fragment implements BackPressable (i.e. can/wanna handle back press) delegate the back press to it
if (fragmentPlayer instanceof BackPressable) {
if (!((BackPressable) fragmentPlayer).onBackPressed())
bottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
return;
}
}

if (getSupportFragmentManager().getBackStackEntryCount() == 1) {
finish();
Expand All @@ -494,7 +490,7 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis
NavigationHelper.openDownloads(this);
break;
case PermissionHelper.DOWNLOAD_DIALOG_REQUEST_CODE:
Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.fragment_holder);
Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.fragment_player_holder);
if (fragment instanceof VideoDetailFragment) {
((VideoDetailFragment) fragment).openDownloadDialog();
}
Expand Down Expand Up @@ -595,6 +591,11 @@ private void initFragments() {
if (DEBUG) Log.d(TAG, "initFragments() called");
StateSaver.clearStateFiles();
if (getIntent() != null && getIntent().hasExtra(Constants.KEY_LINK_TYPE)) {
// When user watch a video inside popup and then tries to open the video in main player while the app is closed
// he will see a blank fragment on place of kiosk. Let's open it first
if (getSupportFragmentManager().getBackStackEntryCount() == 0)
NavigationHelper.openMainFragment(getSupportFragmentManager());

handleIntent(getIntent());
} else NavigationHelper.gotoMainFragment(getSupportFragmentManager());
}
Expand Down Expand Up @@ -643,7 +644,9 @@ private void handleIntent(Intent intent) {
switch (((StreamingService.LinkType) intent.getSerializableExtra(Constants.KEY_LINK_TYPE))) {
case STREAM:
boolean autoPlay = intent.getBooleanExtra(VideoDetailFragment.AUTO_PLAY, false);
NavigationHelper.openVideoDetailFragment(getSupportFragmentManager(), serviceId, url, title, autoPlay);
final String intentCacheKey = intent.getStringExtra(VideoPlayer.PLAY_QUEUE_KEY);
final PlayQueue playQueue = intentCacheKey != null ? SerializedCache.getInstance().take(intentCacheKey, PlayQueue.class) : null;
NavigationHelper.openVideoDetailFragment(getSupportFragmentManager(), serviceId, url, title, autoPlay, playQueue);
break;
case CHANNEL:
NavigationHelper.openChannelFragment(getSupportFragmentManager(),
Expand Down
15 changes: 13 additions & 2 deletions app/src/main/java/org/schabi/newpipe/RouterActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.schabi.newpipe.extractor.playlist.PlaylistInfo;
import org.schabi.newpipe.extractor.stream.StreamInfo;
import org.schabi.newpipe.extractor.stream.VideoStream;
import org.schabi.newpipe.fragments.detail.VideoDetailFragment;
import org.schabi.newpipe.player.playqueue.ChannelPlayQueue;
import org.schabi.newpipe.player.playqueue.PlayQueue;
import org.schabi.newpipe.player.playqueue.PlaylistPlayQueue;
Expand Down Expand Up @@ -581,7 +582,7 @@ public Consumer<Info> getResultHandler(Choice choice) {
playQueue = new SinglePlayQueue((StreamInfo) info);

if (playerChoice.equals(videoPlayerKey)) {
NavigationHelper.playOnMainPlayer(this, playQueue, true);
openMainPlayer(playQueue, choice);
} else if (playerChoice.equals(backgroundPlayerKey)) {
NavigationHelper.enqueueOnBackgroundPlayer(this, playQueue, true);
} else if (playerChoice.equals(popupPlayerKey)) {
Expand All @@ -594,7 +595,7 @@ public Consumer<Info> getResultHandler(Choice choice) {
playQueue = info instanceof ChannelInfo ? new ChannelPlayQueue((ChannelInfo) info) : new PlaylistPlayQueue((PlaylistInfo) info);

if (playerChoice.equals(videoPlayerKey)) {
NavigationHelper.playOnMainPlayer(this, playQueue, true);
openMainPlayer(playQueue, choice);
} else if (playerChoice.equals(backgroundPlayerKey)) {
NavigationHelper.playOnBackgroundPlayer(this, playQueue, true);
} else if (playerChoice.equals(popupPlayerKey)) {
Expand All @@ -604,6 +605,16 @@ public Consumer<Info> getResultHandler(Choice choice) {
};
}

private void openMainPlayer(PlayQueue playQueue, Choice choice) {
avently marked this conversation as resolved.
Show resolved Hide resolved
Intent intent = NavigationHelper.getPlayerIntent(this, MainActivity.class, playQueue, true);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra(Constants.KEY_LINK_TYPE, choice.linkType);
intent.putExtra(Constants.KEY_URL, choice.url);
intent.putExtra(Constants.KEY_TITLE, "");
intent.putExtra(VideoDetailFragment.AUTO_PLAY, true);
this.startActivity(intent);
}

@Override
public void onDestroy() {
super.onDestroy();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
package org.schabi.newpipe.fragments.detail;

import org.schabi.newpipe.player.playqueue.PlayQueue;

import java.io.Serializable;

class StackItem implements Serializable {
private final int serviceId;
private String title;
private final String url;
private final PlayQueue playQueue;

StackItem(int serviceId, String url, String title) {
StackItem(int serviceId, String url, String title, PlayQueue playQueue) {
this.serviceId = serviceId;
this.url = url;
this.title = title;
this.playQueue = playQueue;
}

public void setTitle(String title) {
Expand All @@ -29,6 +33,8 @@ public String getUrl() {
return url;
}

public PlayQueue getPlayQueue() { return playQueue; }

@Override
public String toString() {
return getServiceId() + ":" + getUrl() + " > " + getTitle();
Expand Down
Loading