2017-09-03 08:04:18 +02:00
|
|
|
package org.schabi.newpipe.fragments.list.playlist;
|
|
|
|
|
2019-08-14 14:17:05 +02:00
|
|
|
import android.app.Activity;
|
|
|
|
import android.content.Context;
|
2017-09-03 08:04:18 +02:00
|
|
|
import android.os.Bundle;
|
2019-10-04 14:59:08 +02:00
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.annotation.Nullable;
|
|
|
|
import androidx.appcompat.app.AppCompatActivity;
|
2017-09-03 08:04:18 +02:00
|
|
|
import android.text.TextUtils;
|
|
|
|
import android.util.Log;
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.Menu;
|
|
|
|
import android.view.MenuInflater;
|
2018-01-04 05:28:01 +01:00
|
|
|
import android.view.MenuItem;
|
2017-09-03 08:04:18 +02:00
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.widget.ImageView;
|
|
|
|
import android.widget.TextView;
|
|
|
|
|
2018-02-06 06:32:23 +01:00
|
|
|
import org.reactivestreams.Subscriber;
|
|
|
|
import org.reactivestreams.Subscription;
|
|
|
|
import org.schabi.newpipe.NewPipeDatabase;
|
2017-09-03 08:04:18 +02:00
|
|
|
import org.schabi.newpipe.R;
|
2018-02-06 06:32:23 +01:00
|
|
|
import org.schabi.newpipe.database.playlist.model.PlaylistRemoteEntity;
|
2018-03-18 16:37:49 +01:00
|
|
|
import org.schabi.newpipe.extractor.InfoItem;
|
2017-09-03 08:04:18 +02:00
|
|
|
import org.schabi.newpipe.extractor.ListExtractor;
|
|
|
|
import org.schabi.newpipe.extractor.NewPipe;
|
|
|
|
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
|
|
|
import org.schabi.newpipe.extractor.playlist.PlaylistInfo;
|
2017-11-11 23:47:34 +01:00
|
|
|
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
|
2019-08-14 14:17:05 +02:00
|
|
|
import org.schabi.newpipe.extractor.stream.StreamType;
|
2017-09-03 08:04:18 +02:00
|
|
|
import org.schabi.newpipe.fragments.list.BaseListInfoFragment;
|
2019-08-14 14:17:05 +02:00
|
|
|
import org.schabi.newpipe.info_list.InfoItemDialog;
|
2018-06-19 03:22:52 +02:00
|
|
|
import org.schabi.newpipe.local.playlist.RemotePlaylistManager;
|
2018-04-21 23:10:01 +02:00
|
|
|
import org.schabi.newpipe.player.playqueue.PlayQueue;
|
|
|
|
import org.schabi.newpipe.player.playqueue.PlaylistPlayQueue;
|
2018-07-08 17:46:21 +02:00
|
|
|
import org.schabi.newpipe.report.ErrorActivity;
|
2017-09-03 08:04:18 +02:00
|
|
|
import org.schabi.newpipe.report.UserAction;
|
|
|
|
import org.schabi.newpipe.util.ExtractorHelper;
|
2018-03-16 04:07:20 +01:00
|
|
|
import org.schabi.newpipe.util.ImageDisplayConstants;
|
2017-09-03 08:04:18 +02:00
|
|
|
import org.schabi.newpipe.util.NavigationHelper;
|
2019-04-06 20:17:04 +02:00
|
|
|
import org.schabi.newpipe.util.ShareUtils;
|
2019-08-14 14:17:05 +02:00
|
|
|
import org.schabi.newpipe.util.StreamDialogEntry;
|
2018-02-09 04:53:04 +01:00
|
|
|
import org.schabi.newpipe.util.ThemeHelper;
|
2017-09-03 08:04:18 +02:00
|
|
|
|
2018-03-18 16:37:49 +01:00
|
|
|
import java.util.ArrayList;
|
2018-02-06 06:32:23 +01:00
|
|
|
import java.util.List;
|
2018-02-09 04:53:04 +01:00
|
|
|
import java.util.concurrent.atomic.AtomicBoolean;
|
2018-02-06 06:32:23 +01:00
|
|
|
|
2018-06-19 03:22:52 +02:00
|
|
|
import io.reactivex.Flowable;
|
2017-09-03 08:04:18 +02:00
|
|
|
import io.reactivex.Single;
|
2018-02-06 06:32:23 +01:00
|
|
|
import io.reactivex.android.schedulers.AndroidSchedulers;
|
|
|
|
import io.reactivex.disposables.CompositeDisposable;
|
2018-02-09 03:48:36 +01:00
|
|
|
import io.reactivex.disposables.Disposable;
|
2018-02-09 04:53:04 +01:00
|
|
|
import io.reactivex.disposables.Disposables;
|
2017-09-03 08:04:18 +02:00
|
|
|
|
|
|
|
import static org.schabi.newpipe.util.AnimationUtils.animateView;
|
|
|
|
|
|
|
|
public class PlaylistFragment extends BaseListInfoFragment<PlaylistInfo> {
|
|
|
|
|
2018-02-06 06:32:23 +01:00
|
|
|
private CompositeDisposable disposables;
|
|
|
|
private Subscription bookmarkReactor;
|
2018-02-09 04:53:04 +01:00
|
|
|
private AtomicBoolean isBookmarkButtonReady;
|
2018-02-06 06:32:23 +01:00
|
|
|
|
|
|
|
private RemotePlaylistManager remotePlaylistManager;
|
|
|
|
private PlaylistRemoteEntity playlistEntity;
|
2017-09-03 08:04:18 +02:00
|
|
|
/*//////////////////////////////////////////////////////////////////////////
|
|
|
|
// Views
|
|
|
|
//////////////////////////////////////////////////////////////////////////*/
|
|
|
|
|
|
|
|
private View headerRootLayout;
|
|
|
|
private TextView headerTitleView;
|
|
|
|
private View headerUploaderLayout;
|
|
|
|
private TextView headerUploaderName;
|
|
|
|
private ImageView headerUploaderAvatar;
|
|
|
|
private TextView headerStreamCount;
|
2017-11-12 09:16:51 +01:00
|
|
|
private View playlistCtrl;
|
2017-09-03 08:04:18 +02:00
|
|
|
|
2017-11-12 09:16:51 +01:00
|
|
|
private View headerPlayAllButton;
|
|
|
|
private View headerPopupButton;
|
|
|
|
private View headerBackgroundButton;
|
2017-09-04 19:23:56 +02:00
|
|
|
|
2018-02-06 06:32:23 +01:00
|
|
|
private MenuItem playlistBookmarkButton;
|
2018-01-29 08:01:06 +01:00
|
|
|
|
2018-07-10 16:26:42 +02:00
|
|
|
public static PlaylistFragment getInstance(int serviceId, String url, String name) {
|
2017-09-03 08:04:18 +02:00
|
|
|
PlaylistFragment instance = new PlaylistFragment();
|
2018-07-10 16:26:42 +02:00
|
|
|
instance.setInitialData(serviceId, url, name);
|
2017-09-03 08:04:18 +02:00
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*//////////////////////////////////////////////////////////////////////////
|
|
|
|
// LifeCycle
|
|
|
|
//////////////////////////////////////////////////////////////////////////*/
|
|
|
|
|
|
|
|
@Override
|
2018-02-06 06:32:23 +01:00
|
|
|
public void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
disposables = new CompositeDisposable();
|
2018-02-09 04:53:04 +01:00
|
|
|
isBookmarkButtonReady = new AtomicBoolean(false);
|
2018-06-19 03:22:52 +02:00
|
|
|
remotePlaylistManager = new RemotePlaylistManager(NewPipeDatabase.getInstance(
|
|
|
|
requireContext()));
|
2018-02-06 06:32:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
|
|
|
|
@Nullable Bundle savedInstanceState) {
|
2017-09-03 08:04:18 +02:00
|
|
|
return inflater.inflate(R.layout.fragment_playlist, container, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*//////////////////////////////////////////////////////////////////////////
|
|
|
|
// Init
|
|
|
|
//////////////////////////////////////////////////////////////////////////*/
|
|
|
|
|
|
|
|
protected View getListHeader() {
|
|
|
|
headerRootLayout = activity.getLayoutInflater().inflate(R.layout.playlist_header, itemsList, false);
|
|
|
|
headerTitleView = headerRootLayout.findViewById(R.id.playlist_title_view);
|
|
|
|
headerUploaderLayout = headerRootLayout.findViewById(R.id.uploader_layout);
|
|
|
|
headerUploaderName = headerRootLayout.findViewById(R.id.uploader_name);
|
|
|
|
headerUploaderAvatar = headerRootLayout.findViewById(R.id.uploader_avatar_view);
|
|
|
|
headerStreamCount = headerRootLayout.findViewById(R.id.playlist_stream_count);
|
2017-11-12 09:16:51 +01:00
|
|
|
playlistCtrl = headerRootLayout.findViewById(R.id.playlist_control);
|
2017-09-06 02:48:48 +02:00
|
|
|
|
2017-11-12 09:16:51 +01:00
|
|
|
headerPlayAllButton = headerRootLayout.findViewById(R.id.playlist_ctrl_play_all_button);
|
|
|
|
headerPopupButton = headerRootLayout.findViewById(R.id.playlist_ctrl_play_popup_button);
|
|
|
|
headerBackgroundButton = headerRootLayout.findViewById(R.id.playlist_ctrl_play_bg_button);
|
2017-09-03 08:04:18 +02:00
|
|
|
|
2018-02-09 00:58:48 +01:00
|
|
|
|
2017-09-03 08:04:18 +02:00
|
|
|
return headerRootLayout;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void initViews(View rootView, Bundle savedInstanceState) {
|
|
|
|
super.initViews(rootView, savedInstanceState);
|
|
|
|
|
|
|
|
infoListAdapter.useMiniItemVariants(true);
|
|
|
|
}
|
|
|
|
|
2019-08-14 14:17:05 +02:00
|
|
|
private PlayQueue getPlayQueueStartingAt(StreamInfoItem infoItem) {
|
|
|
|
return getPlayQueue(Math.max(infoListAdapter.getItemsList().indexOf(infoItem), 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void showStreamDialog(StreamInfoItem item) {
|
|
|
|
final Context context = getContext();
|
|
|
|
final Activity activity = getActivity();
|
|
|
|
if (context == null || context.getResources() == null || activity == null) return;
|
|
|
|
|
|
|
|
if (item.getStreamType() == StreamType.AUDIO_STREAM) {
|
|
|
|
StreamDialogEntry.setEnabledEntries(
|
|
|
|
StreamDialogEntry.enqueue_on_background,
|
|
|
|
StreamDialogEntry.start_here_on_background,
|
|
|
|
StreamDialogEntry.append_playlist,
|
|
|
|
StreamDialogEntry.share);
|
|
|
|
} else {
|
|
|
|
StreamDialogEntry.setEnabledEntries(
|
|
|
|
StreamDialogEntry.enqueue_on_background,
|
|
|
|
StreamDialogEntry.enqueue_on_popup,
|
|
|
|
StreamDialogEntry.start_here_on_background,
|
|
|
|
StreamDialogEntry.start_here_on_popup,
|
|
|
|
StreamDialogEntry.append_playlist,
|
|
|
|
StreamDialogEntry.share);
|
|
|
|
|
|
|
|
StreamDialogEntry.start_here_on_popup.setCustomAction(
|
|
|
|
(fragment, infoItem) -> NavigationHelper.playOnPopupPlayer(context, getPlayQueueStartingAt(infoItem), true));
|
|
|
|
}
|
|
|
|
|
|
|
|
StreamDialogEntry.start_here_on_background.setCustomAction(
|
|
|
|
(fragment, infoItem) -> NavigationHelper.playOnBackgroundPlayer(context, getPlayQueueStartingAt(infoItem), true));
|
|
|
|
|
|
|
|
new InfoItemDialog(activity, item, StreamDialogEntry.getCommands(context), (dialog, which) ->
|
|
|
|
StreamDialogEntry.clickOn(which, this, item)).show();
|
|
|
|
}
|
|
|
|
|
2018-01-04 05:28:01 +01:00
|
|
|
@Override
|
|
|
|
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
2018-01-29 08:01:06 +01:00
|
|
|
if (DEBUG) Log.d(TAG, "onCreateOptionsMenu() called with: menu = [" + menu +
|
|
|
|
"], inflater = [" + inflater + "]");
|
2018-01-04 05:28:01 +01:00
|
|
|
super.onCreateOptionsMenu(menu, inflater);
|
|
|
|
inflater.inflate(R.menu.menu_playlist, menu);
|
2018-01-29 08:01:06 +01:00
|
|
|
|
2018-02-06 06:32:23 +01:00
|
|
|
playlistBookmarkButton = menu.findItem(R.id.menu_item_bookmark);
|
2018-02-09 04:53:04 +01:00
|
|
|
updateBookmarkButtons();
|
2018-02-06 06:32:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onDestroyView() {
|
|
|
|
super.onDestroyView();
|
2018-02-09 04:53:04 +01:00
|
|
|
if (isBookmarkButtonReady != null) isBookmarkButtonReady.set(false);
|
|
|
|
|
2018-02-06 06:32:23 +01:00
|
|
|
if (disposables != null) disposables.clear();
|
|
|
|
if (bookmarkReactor != null) bookmarkReactor.cancel();
|
|
|
|
|
|
|
|
bookmarkReactor = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onDestroy() {
|
|
|
|
super.onDestroy();
|
|
|
|
|
|
|
|
if (disposables != null) disposables.dispose();
|
|
|
|
|
|
|
|
disposables = null;
|
|
|
|
remotePlaylistManager = null;
|
|
|
|
playlistEntity = null;
|
2018-02-09 04:53:04 +01:00
|
|
|
isBookmarkButtonReady = null;
|
2018-01-04 05:28:01 +01:00
|
|
|
}
|
|
|
|
|
2017-09-03 08:04:18 +02:00
|
|
|
/*//////////////////////////////////////////////////////////////////////////
|
|
|
|
// Load and handle
|
|
|
|
//////////////////////////////////////////////////////////////////////////*/
|
|
|
|
|
|
|
|
@Override
|
2018-03-18 16:37:49 +01:00
|
|
|
protected Single<ListExtractor.InfoItemsPage> loadMoreItemsLogic() {
|
2018-07-10 16:26:42 +02:00
|
|
|
return ExtractorHelper.getMorePlaylistItems(serviceId, url, currentNextPageUrl);
|
2017-09-03 08:04:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected Single<PlaylistInfo> loadResult(boolean forceLoad) {
|
2018-07-10 16:26:42 +02:00
|
|
|
return ExtractorHelper.getPlaylistInfo(serviceId, url, forceLoad);
|
2017-09-03 08:04:18 +02:00
|
|
|
}
|
|
|
|
|
2018-01-04 05:28:01 +01:00
|
|
|
@Override
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
switch (item.getItemId()) {
|
|
|
|
case R.id.menu_item_openInBrowser:
|
2019-04-06 20:17:04 +02:00
|
|
|
ShareUtils.openUrlInBrowser(this.getContext(), url);
|
2018-01-04 05:28:01 +01:00
|
|
|
break;
|
2018-01-29 08:01:06 +01:00
|
|
|
case R.id.menu_item_share:
|
2019-04-06 20:17:04 +02:00
|
|
|
ShareUtils.shareUrl(this.getContext(), name, url);
|
2018-01-04 05:28:01 +01:00
|
|
|
break;
|
2018-02-06 06:32:23 +01:00
|
|
|
case R.id.menu_item_bookmark:
|
2018-02-09 04:53:04 +01:00
|
|
|
onBookmarkClicked();
|
2018-01-29 08:01:06 +01:00
|
|
|
break;
|
2018-01-04 05:28:01 +01:00
|
|
|
default:
|
|
|
|
return super.onOptionsItemSelected(item);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-09-03 08:04:18 +02:00
|
|
|
/*//////////////////////////////////////////////////////////////////////////
|
|
|
|
// Contract
|
|
|
|
//////////////////////////////////////////////////////////////////////////*/
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void showLoading() {
|
|
|
|
super.showLoading();
|
|
|
|
animateView(headerRootLayout, false, 200);
|
|
|
|
animateView(itemsList, false, 100);
|
|
|
|
|
|
|
|
imageLoader.cancelDisplayTask(headerUploaderAvatar);
|
|
|
|
animateView(headerUploaderLayout, false, 200);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void handleResult(@NonNull final PlaylistInfo result) {
|
|
|
|
super.handleResult(result);
|
|
|
|
|
|
|
|
animateView(headerRootLayout, true, 100);
|
|
|
|
animateView(headerUploaderLayout, true, 300);
|
|
|
|
headerUploaderLayout.setOnClickListener(null);
|
2019-10-15 16:40:51 +02:00
|
|
|
if (!TextUtils.isEmpty(result.getUploaderName())) { // If we have an uploader : Put them into the ui
|
2017-12-08 15:05:08 +01:00
|
|
|
headerUploaderName.setText(result.getUploaderName());
|
|
|
|
if (!TextUtils.isEmpty(result.getUploaderUrl())) {
|
2018-07-08 17:46:21 +02:00
|
|
|
headerUploaderLayout.setOnClickListener(v -> {
|
|
|
|
try {
|
2018-02-06 06:32:23 +01:00
|
|
|
NavigationHelper.openChannelFragment(getFragmentManager(),
|
2018-07-08 17:46:21 +02:00
|
|
|
result.getServiceId(),
|
2018-07-10 16:26:42 +02:00
|
|
|
result.getUploaderUrl(),
|
2018-07-08 17:46:21 +02:00
|
|
|
result.getUploaderName());
|
|
|
|
} catch (Exception e) {
|
|
|
|
ErrorActivity.reportUiError((AppCompatActivity) getActivity(), e);
|
|
|
|
}
|
|
|
|
});
|
2017-09-03 08:04:18 +02:00
|
|
|
}
|
2019-12-06 16:38:15 +01:00
|
|
|
} else { // Else : say we have no uploader
|
2019-10-15 20:49:24 +02:00
|
|
|
headerUploaderName.setText(R.string.playlist_no_uploader);
|
2017-09-03 08:04:18 +02:00
|
|
|
}
|
|
|
|
|
2017-11-12 09:16:51 +01:00
|
|
|
playlistCtrl.setVisibility(View.VISIBLE);
|
|
|
|
|
2018-03-16 04:07:20 +01:00
|
|
|
imageLoader.displayImage(result.getUploaderAvatarUrl(), headerUploaderAvatar,
|
|
|
|
ImageDisplayConstants.DISPLAY_AVATAR_OPTIONS);
|
2018-03-18 16:37:49 +01:00
|
|
|
headerStreamCount.setText(getResources().getQuantityString(R.plurals.videos,
|
|
|
|
(int) result.getStreamCount(), (int) result.getStreamCount()));
|
2017-09-03 08:04:18 +02:00
|
|
|
|
2017-12-08 15:05:08 +01:00
|
|
|
if (!result.getErrors().isEmpty()) {
|
|
|
|
showSnackBarError(result.getErrors(), UserAction.REQUESTED_PLAYLIST, NewPipe.getNameOfService(result.getServiceId()), result.getUrl(), 0);
|
2017-09-03 08:04:18 +02:00
|
|
|
}
|
2017-09-04 19:23:56 +02:00
|
|
|
|
2018-02-11 02:20:56 +01:00
|
|
|
remotePlaylistManager.getPlaylist(result)
|
2018-06-19 03:22:52 +02:00
|
|
|
.flatMap(lists -> getUpdateProcessor(lists, result), (lists, id) -> lists)
|
2018-02-11 02:20:56 +01:00
|
|
|
.onBackpressureLatest()
|
|
|
|
.observeOn(AndroidSchedulers.mainThread())
|
|
|
|
.subscribe(getPlaylistBookmarkSubscriber());
|
|
|
|
|
2018-02-06 06:32:23 +01:00
|
|
|
headerPlayAllButton.setOnClickListener(view ->
|
2019-04-13 09:31:32 +02:00
|
|
|
NavigationHelper.playOnMainPlayer(activity, getPlayQueue(), false));
|
2018-02-06 06:32:23 +01:00
|
|
|
headerPopupButton.setOnClickListener(view ->
|
2019-04-13 09:31:32 +02:00
|
|
|
NavigationHelper.playOnPopupPlayer(activity, getPlayQueue(), false));
|
2018-02-06 06:32:23 +01:00
|
|
|
headerBackgroundButton.setOnClickListener(view ->
|
2019-04-13 09:31:32 +02:00
|
|
|
NavigationHelper.playOnBackgroundPlayer(activity, getPlayQueue(), false));
|
2019-01-18 23:16:02 +01:00
|
|
|
|
2019-01-18 23:58:24 +01:00
|
|
|
headerPopupButton.setOnLongClickListener(view -> {
|
2019-04-13 09:31:32 +02:00
|
|
|
NavigationHelper.enqueueOnPopupPlayer(activity, getPlayQueue(), true);
|
2019-01-18 23:58:24 +01:00
|
|
|
return true;
|
|
|
|
});
|
|
|
|
|
|
|
|
headerBackgroundButton.setOnLongClickListener(view -> {
|
2019-04-13 09:31:32 +02:00
|
|
|
NavigationHelper.enqueueOnBackgroundPlayer(activity, getPlayQueue(), true);
|
2019-01-18 23:58:24 +01:00
|
|
|
return true;
|
2019-01-18 23:16:02 +01:00
|
|
|
});
|
2017-09-04 19:23:56 +02:00
|
|
|
}
|
|
|
|
|
2017-11-02 06:33:13 +01:00
|
|
|
private PlayQueue getPlayQueue() {
|
2017-11-11 23:47:34 +01:00
|
|
|
return getPlayQueue(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
private PlayQueue getPlayQueue(final int index) {
|
2018-03-18 16:37:49 +01:00
|
|
|
final List<StreamInfoItem> infoItems = new ArrayList<>();
|
|
|
|
for(InfoItem i : infoListAdapter.getItemsList()) {
|
|
|
|
if(i instanceof StreamInfoItem) {
|
|
|
|
infoItems.add((StreamInfoItem) i);
|
|
|
|
}
|
|
|
|
}
|
2017-11-02 07:38:18 +01:00
|
|
|
return new PlaylistPlayQueue(
|
2017-12-08 15:05:08 +01:00
|
|
|
currentInfo.getServiceId(),
|
|
|
|
currentInfo.getUrl(),
|
2018-02-24 22:57:25 +01:00
|
|
|
currentInfo.getNextPageUrl(),
|
2018-03-18 16:37:49 +01:00
|
|
|
infoItems,
|
2017-11-11 23:47:34 +01:00
|
|
|
index
|
2017-09-06 02:48:48 +02:00
|
|
|
);
|
|
|
|
}
|
2017-09-03 08:04:18 +02:00
|
|
|
|
|
|
|
@Override
|
2018-03-18 16:37:49 +01:00
|
|
|
public void handleNextItems(ListExtractor.InfoItemsPage result) {
|
2017-09-03 08:04:18 +02:00
|
|
|
super.handleNextItems(result);
|
|
|
|
|
2017-12-08 15:05:08 +01:00
|
|
|
if (!result.getErrors().isEmpty()) {
|
|
|
|
showSnackBarError(result.getErrors(), UserAction.REQUESTED_PLAYLIST, NewPipe.getNameOfService(serviceId)
|
2018-07-10 16:26:42 +02:00
|
|
|
, "Get next page of: " + url, 0);
|
2017-09-03 08:04:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*//////////////////////////////////////////////////////////////////////////
|
|
|
|
// OnError
|
|
|
|
//////////////////////////////////////////////////////////////////////////*/
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected boolean onError(Throwable exception) {
|
|
|
|
if (super.onError(exception)) return true;
|
|
|
|
|
|
|
|
int errorId = exception instanceof ExtractionException ? R.string.parsing_error : R.string.general_error;
|
2018-07-08 17:46:21 +02:00
|
|
|
onUnrecoverableError(exception,
|
|
|
|
UserAction.REQUESTED_PLAYLIST,
|
|
|
|
NewPipe.getNameOfService(serviceId),
|
2018-07-10 16:26:42 +02:00
|
|
|
url,
|
2018-07-08 17:46:21 +02:00
|
|
|
errorId);
|
2017-09-03 08:04:18 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*//////////////////////////////////////////////////////////////////////////
|
|
|
|
// Utils
|
|
|
|
//////////////////////////////////////////////////////////////////////////*/
|
|
|
|
|
2018-06-19 03:22:52 +02:00
|
|
|
private Flowable<Integer> getUpdateProcessor(@NonNull List<PlaylistRemoteEntity> playlists,
|
|
|
|
@NonNull PlaylistInfo result) {
|
|
|
|
final Flowable<Integer> noItemToUpdate = Flowable.just(/*noItemToUpdate=*/-1);
|
|
|
|
if (playlists.isEmpty()) return noItemToUpdate;
|
|
|
|
|
|
|
|
final PlaylistRemoteEntity playlistEntity = playlists.get(0);
|
|
|
|
if (playlistEntity.isIdenticalTo(result)) return noItemToUpdate;
|
|
|
|
|
|
|
|
return remotePlaylistManager.onUpdate(playlists.get(0).getUid(), result).toFlowable();
|
|
|
|
}
|
|
|
|
|
2018-02-06 06:32:23 +01:00
|
|
|
private Subscriber<List<PlaylistRemoteEntity>> getPlaylistBookmarkSubscriber() {
|
|
|
|
return new Subscriber<List<PlaylistRemoteEntity>>() {
|
|
|
|
@Override
|
|
|
|
public void onSubscribe(Subscription s) {
|
|
|
|
if (bookmarkReactor != null) bookmarkReactor.cancel();
|
|
|
|
bookmarkReactor = s;
|
|
|
|
bookmarkReactor.request(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onNext(List<PlaylistRemoteEntity> playlist) {
|
|
|
|
playlistEntity = playlist.isEmpty() ? null : playlist.get(0);
|
2018-02-09 04:53:04 +01:00
|
|
|
|
|
|
|
updateBookmarkButtons();
|
|
|
|
isBookmarkButtonReady.set(true);
|
2018-02-06 06:32:23 +01:00
|
|
|
|
|
|
|
if (bookmarkReactor != null) bookmarkReactor.request(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onError(Throwable t) {
|
|
|
|
PlaylistFragment.this.onError(t);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onComplete() {
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-09-03 08:04:18 +02:00
|
|
|
@Override
|
|
|
|
public void setTitle(String title) {
|
|
|
|
super.setTitle(title);
|
|
|
|
headerTitleView.setText(title);
|
|
|
|
}
|
2018-02-06 06:32:23 +01:00
|
|
|
|
2018-02-09 04:53:04 +01:00
|
|
|
private void onBookmarkClicked() {
|
|
|
|
if (isBookmarkButtonReady == null || !isBookmarkButtonReady.get() ||
|
|
|
|
remotePlaylistManager == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
final Disposable action;
|
|
|
|
|
|
|
|
if (currentInfo != null && playlistEntity == null) {
|
|
|
|
action = remotePlaylistManager.onBookmark(currentInfo)
|
|
|
|
.observeOn(AndroidSchedulers.mainThread())
|
|
|
|
.subscribe(ignored -> {/* Do nothing */}, this::onError);
|
|
|
|
} else if (playlistEntity != null) {
|
|
|
|
action = remotePlaylistManager.deletePlaylist(playlistEntity.getUid())
|
|
|
|
.observeOn(AndroidSchedulers.mainThread())
|
|
|
|
.doFinally(() -> playlistEntity = null)
|
|
|
|
.subscribe(ignored -> {/* Do nothing */}, this::onError);
|
|
|
|
} else {
|
|
|
|
action = Disposables.empty();
|
|
|
|
}
|
2018-02-06 06:32:23 +01:00
|
|
|
|
2018-02-09 04:53:04 +01:00
|
|
|
disposables.add(action);
|
2018-02-06 06:32:23 +01:00
|
|
|
}
|
|
|
|
|
2018-02-09 04:53:04 +01:00
|
|
|
private void updateBookmarkButtons() {
|
|
|
|
if (playlistBookmarkButton == null || activity == null) return;
|
2018-02-06 06:32:23 +01:00
|
|
|
|
2018-02-09 04:53:04 +01:00
|
|
|
final int iconAttr = playlistEntity == null ?
|
|
|
|
R.attr.ic_playlist_add : R.attr.ic_playlist_check;
|
2018-02-09 00:58:48 +01:00
|
|
|
|
2018-02-09 04:53:04 +01:00
|
|
|
final int titleRes = playlistEntity == null ?
|
|
|
|
R.string.bookmark_playlist : R.string.unbookmark_playlist;
|
2018-02-09 00:58:48 +01:00
|
|
|
|
2018-02-09 04:53:04 +01:00
|
|
|
playlistBookmarkButton.setIcon(ThemeHelper.resolveResourceIdFromAttr(activity, iconAttr));
|
|
|
|
playlistBookmarkButton.setTitle(titleRes);
|
2018-02-09 00:58:48 +01:00
|
|
|
}
|
2019-12-06 16:32:45 +01:00
|
|
|
}
|