-Enable background and popup playlists.

This commit is contained in:
John Zhen M 2017-09-05 17:48:48 -07:00 committed by John Zhen Mo
parent 7e5940c4e9
commit 7e51695afa
10 changed files with 192 additions and 125 deletions

View file

@ -724,7 +724,7 @@ public class VideoDetailFragment extends BaseStateFragment<StreamInfo> implement
.getBoolean(activity.getString(R.string.use_external_audio_player_key), false);
if (!useExternalAudioPlayer && android.os.Build.VERSION.SDK_INT >= 16) {
openNormalBackgroundPlayer(audioStream);
openNormalBackgroundPlayer();
} else {
openExternalBackgroundPlayer(audioStream);
}
@ -763,8 +763,8 @@ public class VideoDetailFragment extends BaseStateFragment<StreamInfo> implement
}
private void openNormalBackgroundPlayer(AudioStream audioStream) {
activity.startService(NavigationHelper.getOpenBackgroundPlayerIntent(activity, currentInfo, audioStream));
private void openNormalBackgroundPlayer() {
activity.startService(NavigationHelper.getOpenBackgroundPlayerIntent(activity, currentInfo));
Toast.makeText(activity, R.string.background_player_playing_toast, Toast.LENGTH_SHORT).show();
}

View file

@ -21,7 +21,9 @@ import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.playlist.PlaylistInfo;
import org.schabi.newpipe.fragments.list.BaseListInfoFragment;
import org.schabi.newpipe.player.BackgroundPlayer;
import org.schabi.newpipe.player.MainVideoPlayer;
import org.schabi.newpipe.player.PopupVideoPlayer;
import org.schabi.newpipe.report.UserAction;
import org.schabi.newpipe.util.ExtractorHelper;
import org.schabi.newpipe.util.NavigationHelper;
@ -44,6 +46,8 @@ public class PlaylistFragment extends BaseListInfoFragment<PlaylistInfo> {
private TextView headerStreamCount;
private Button headerPlayAllButton;
private Button headerPopupButton;
private Button headerBackgroundButton;
public static PlaylistFragment getInstance(int serviceId, String url, String name) {
PlaylistFragment instance = new PlaylistFragment();
@ -71,7 +75,10 @@ public class PlaylistFragment extends BaseListInfoFragment<PlaylistInfo> {
headerUploaderName = headerRootLayout.findViewById(R.id.uploader_name);
headerUploaderAvatar = headerRootLayout.findViewById(R.id.uploader_avatar_view);
headerStreamCount = headerRootLayout.findViewById(R.id.playlist_stream_count);
headerPlayAllButton = headerRootLayout.findViewById(R.id.playlist_play_all_button);
headerPopupButton = headerRootLayout.findViewById(R.id.playlist_play_popup_button);
headerBackgroundButton = headerRootLayout.findViewById(R.id.playlist_play_bg_button);
return headerRootLayout;
}
@ -138,7 +145,7 @@ public class PlaylistFragment extends BaseListInfoFragment<PlaylistInfo> {
}
imageLoader.displayImage(result.uploader_avatar_url, headerUploaderAvatar, DISPLAY_AVATAR_OPTIONS);
headerStreamCount.setText(getResources().getQuantityString(R.plurals.videos, (int) result.stream_count));
headerStreamCount.setText(getResources().getQuantityString(R.plurals.videos, (int) result.stream_count, (int) result.stream_count));
if (!result.errors.isEmpty()) {
showSnackBarError(result.errors, UserAction.REQUESTED_PLAYLIST, NewPipe.getNameOfService(result.service_id), result.url, 0);
@ -147,15 +154,28 @@ public class PlaylistFragment extends BaseListInfoFragment<PlaylistInfo> {
headerPlayAllButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
final Intent intent = NavigationHelper.getExternalPlaylistIntent(
activity, MainVideoPlayer.class, currentInfo, infoListAdapter.getItemsList(), 0
);
startActivity(intent);
startActivity(buildPlaylistIntent(MainVideoPlayer.class));
}
});
headerPopupButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
activity.startService(buildPlaylistIntent(PopupVideoPlayer.class));
}
});
headerBackgroundButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
activity.startService(buildPlaylistIntent(BackgroundPlayer.class));
}
});
}
private Intent buildPlaylistIntent(final Class targetClazz) {
return NavigationHelper.getExternalPlaylistIntent(
activity, targetClazz, currentInfo, infoListAdapter.getItemsList(), 0
);
}
@Override
public void handleNextItems(ListExtractor.NextItemsResult result) {