2017-09-03 08:04:18 +02:00
|
|
|
package org.schabi.newpipe.fragments.list.playlist;
|
|
|
|
|
2022-01-16 17:08:13 +01:00
|
|
|
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
|
|
|
|
import static org.schabi.newpipe.ktx.ViewUtils.animate;
|
|
|
|
import static org.schabi.newpipe.ktx.ViewUtils.animateHideRecyclerViewAllowingScrolling;
|
|
|
|
|
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;
|
|
|
|
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;
|
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.annotation.Nullable;
|
2020-03-17 18:41:39 +01:00
|
|
|
import androidx.appcompat.content.res.AppCompatResources;
|
2020-03-31 19:20:15 +02:00
|
|
|
|
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;
|
2020-11-03 06:19:19 +01:00
|
|
|
import org.schabi.newpipe.databinding.PlaylistControlBinding;
|
|
|
|
import org.schabi.newpipe.databinding.PlaylistHeaderBinding;
|
2020-12-11 14:55:47 +01:00
|
|
|
import org.schabi.newpipe.error.ErrorInfo;
|
2021-12-01 09:43:24 +01:00
|
|
|
import org.schabi.newpipe.error.ErrorUtil;
|
2020-12-11 14:55:47 +01:00
|
|
|
import org.schabi.newpipe.error.UserAction;
|
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;
|
2020-03-17 18:41:39 +01:00
|
|
|
import org.schabi.newpipe.extractor.ServiceList;
|
2017-09-03 08:04:18 +02:00
|
|
|
import org.schabi.newpipe.extractor.playlist.PlaylistInfo;
|
2020-03-17 18:41:39 +01:00
|
|
|
import org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper;
|
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;
|
Add play next to long press menu & refactor enqueue methods (#6872)
* added mvp play next button in long press menu; new intent handling, new long press dialog entry, new dialog functions, new strings
* changed line length for checkstyle pass
* cleaned comments, moved strings
* Update app/src/main/res/values/strings.xml
to make long press entry more descriptive
Co-authored-by: opusforlife2 <53176348+opusforlife2@users.noreply.github.com>
* Update app/src/main/res/values/strings.xml
Co-authored-by: Stypox <stypox@pm.me>
* replace redundant nextOnVideoPlayer methods
Co-authored-by: Stypox <stypox@pm.me>
* add enqueueNextOnPlayer and enqueueOnPlayer without selectOnAppend and RESUME_PLAYBACK/ deprecate enqueueNextOn*Player and enqueueOn*Player methods
add getPlayerIntent, getPlayerEnqueueIntent and getPlayerEnqueueNextIntent without selectOnAppend and RESUME_PLAYBACK/ deprecate those with
add section comments
* removed deprecated methods
removed redundant methods
* removed deprecated methods
removed redundant methods
* replaced APPEND_ONLY, removed SELECT_ON_APPEND / replaced remaining enqueueOn*Player methods
* now works with playlists
* renamed dialog entry
* checking for >1 items in the queue using the PlayerHolder
* making enqueue*OnPlayer safe to call when no video is playing (defaulting to audio)
* corrected strings
* improve getQueueSize in PlayerHolder
* long press to enqueue only if queue isnt empty
* add Whitespace
Co-authored-by: Stypox <stypox@pm.me>
* clarify comments / add spaces
* PlayerType as parameter of the enqueueOnPlayer method
add Helper method
* using the helper function everywhere (except for the background and popup long-press actions (also on playlists, history, ...)), so basically nowhere
/ passing checkstyle
* assimilated the enqueue*OnPlayer methods
* removed redundant comment, variable
* simplify code line
Co-authored-by: Stypox <stypox@pm.me>
* move if
* replace workaround for isPlayerOpen()
Co-authored-by: Stypox <stypox@pm.me>
* replaced workarounds (getType), corrected static access with getInstance
* remove unused imports
* changed method call to original, new method doesnt exist yet.
* Use getter method instead of property access syntax.
* improve conditional for play next entry
Co-authored-by: Stypox <stypox@pm.me>
* show play next btn in feed fragment
Co-authored-by: Stypox <stypox@pm.me>
* add play next to local playlist and statistics fragment
Co-authored-by: Stypox <stypox@pm.me>
* formating
Co-authored-by: Stypox <stypox@pm.me>
* correcting logic
Co-authored-by: Stypox <stypox@pm.me>
* remove 2 year old unused string, formating
Co-authored-by: Stypox <stypox@pm.me>
* correct enqueue (next) conditionals, default to background if no player is open. Dont generally default to background play.
* remove player open checks from button long press enqueue actions
* improve log msg
* Rename next to enqueue_next
* Refactor kotlin
Co-authored-by: opusforlife2 <53176348+opusforlife2@users.noreply.github.com>
Co-authored-by: Stypox <stypox@pm.me>
2021-09-18 11:22:49 +02:00
|
|
|
import org.schabi.newpipe.player.MainPlayer.PlayerType;
|
2020-10-06 14:38:48 +02:00
|
|
|
import org.schabi.newpipe.player.helper.PlayerHolder;
|
2018-04-21 23:10:01 +02:00
|
|
|
import org.schabi.newpipe.player.playqueue.PlayQueue;
|
|
|
|
import org.schabi.newpipe.player.playqueue.PlaylistPlayQueue;
|
2017-09-03 08:04:18 +02:00
|
|
|
import org.schabi.newpipe.util.ExtractorHelper;
|
2020-03-20 20:57:56 +01:00
|
|
|
import org.schabi.newpipe.util.Localization;
|
2017-09-03 08:04:18 +02:00
|
|
|
import org.schabi.newpipe.util.NavigationHelper;
|
2022-01-16 17:08:13 +01:00
|
|
|
import org.schabi.newpipe.util.PicassoHelper;
|
2019-08-14 14:17:05 +02:00
|
|
|
import org.schabi.newpipe.util.StreamDialogEntry;
|
2022-01-16 17:08:13 +01:00
|
|
|
import org.schabi.newpipe.util.external_communication.KoreUtils;
|
|
|
|
import org.schabi.newpipe.util.external_communication.ShareUtils;
|
2017-09-03 08:04:18 +02:00
|
|
|
|
2018-03-18 16:37:49 +01:00
|
|
|
import java.util.ArrayList;
|
2020-10-06 14:38:48 +02:00
|
|
|
import java.util.Arrays;
|
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;
|
2022-01-16 17:08:13 +01:00
|
|
|
import java.util.function.Supplier;
|
2018-02-06 06:32:23 +01:00
|
|
|
|
2020-10-31 21:55:45 +01:00
|
|
|
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
|
|
|
|
import io.reactivex.rxjava3.core.Flowable;
|
|
|
|
import io.reactivex.rxjava3.core.Single;
|
|
|
|
import io.reactivex.rxjava3.disposables.CompositeDisposable;
|
|
|
|
import io.reactivex.rxjava3.disposables.Disposable;
|
2017-09-03 08:04:18 +02:00
|
|
|
|
|
|
|
public class PlaylistFragment extends BaseListInfoFragment<PlaylistInfo> {
|
2021-03-27 14:37:44 +01:00
|
|
|
|
|
|
|
private static final String PICASSO_PLAYLIST_TAG = "PICASSO_PLAYLIST_TAG";
|
|
|
|
|
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;
|
2021-03-27 14:37:44 +01:00
|
|
|
|
2017-09-03 08:04:18 +02:00
|
|
|
/*//////////////////////////////////////////////////////////////////////////
|
|
|
|
// Views
|
|
|
|
//////////////////////////////////////////////////////////////////////////*/
|
|
|
|
|
2020-11-03 06:19:19 +01:00
|
|
|
private PlaylistHeaderBinding headerBinding;
|
|
|
|
private PlaylistControlBinding playlistControlBinding;
|
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
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
public static PlaylistFragment getInstance(final int serviceId, final String url,
|
|
|
|
final String name) {
|
2020-08-16 10:24:58 +02:00
|
|
|
final 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;
|
|
|
|
}
|
|
|
|
|
2020-12-11 14:55:47 +01:00
|
|
|
public PlaylistFragment() {
|
|
|
|
super(UserAction.REQUESTED_PLAYLIST);
|
|
|
|
}
|
|
|
|
|
2017-09-03 08:04:18 +02:00
|
|
|
/*//////////////////////////////////////////////////////////////////////////
|
|
|
|
// LifeCycle
|
|
|
|
//////////////////////////////////////////////////////////////////////////*/
|
|
|
|
|
|
|
|
@Override
|
2020-03-31 19:20:15 +02:00
|
|
|
public void onCreate(final Bundle savedInstanceState) {
|
2018-02-06 06:32:23 +01:00
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
disposables = new CompositeDisposable();
|
2018-02-09 04:53:04 +01:00
|
|
|
isBookmarkButtonReady = new AtomicBoolean(false);
|
2020-03-31 19:20:15 +02:00
|
|
|
remotePlaylistManager = new RemotePlaylistManager(NewPipeDatabase
|
|
|
|
.getInstance(requireContext()));
|
2018-02-06 06:32:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-03-31 19:20:15 +02:00
|
|
|
public View onCreateView(@NonNull final LayoutInflater inflater,
|
|
|
|
@Nullable final ViewGroup container,
|
|
|
|
@Nullable final Bundle savedInstanceState) {
|
2017-09-03 08:04:18 +02:00
|
|
|
return inflater.inflate(R.layout.fragment_playlist, container, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*//////////////////////////////////////////////////////////////////////////
|
|
|
|
// Init
|
|
|
|
//////////////////////////////////////////////////////////////////////////*/
|
|
|
|
|
2020-11-03 06:19:19 +01:00
|
|
|
@Override
|
2022-01-16 17:08:13 +01:00
|
|
|
protected Supplier<View> getListHeaderSupplier() {
|
2020-11-03 06:19:19 +01:00
|
|
|
headerBinding = PlaylistHeaderBinding
|
|
|
|
.inflate(activity.getLayoutInflater(), itemsList, false);
|
|
|
|
playlistControlBinding = headerBinding.playlistControl;
|
2018-02-09 00:58:48 +01:00
|
|
|
|
2022-01-16 17:08:13 +01:00
|
|
|
return headerBinding::getRoot;
|
2017-09-03 08:04:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-03-31 19:20:15 +02:00
|
|
|
protected void initViews(final View rootView, final Bundle savedInstanceState) {
|
2017-09-03 08:04:18 +02:00
|
|
|
super.initViews(rootView, savedInstanceState);
|
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
infoListAdapter.setUseMiniVariant(true);
|
2017-09-03 08:04:18 +02:00
|
|
|
}
|
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
private PlayQueue getPlayQueueStartingAt(final StreamInfoItem infoItem) {
|
2019-08-14 14:17:05 +02:00
|
|
|
return getPlayQueue(Math.max(infoListAdapter.getItemsList().indexOf(infoItem), 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-03-31 19:20:15 +02:00
|
|
|
protected void showStreamDialog(final StreamInfoItem item) {
|
2019-08-14 14:17:05 +02:00
|
|
|
final Context context = getContext();
|
|
|
|
final Activity activity = getActivity();
|
2020-03-31 19:20:15 +02:00
|
|
|
if (context == null || context.getResources() == null || activity == null) {
|
|
|
|
return;
|
|
|
|
}
|
2019-08-14 14:17:05 +02:00
|
|
|
|
2020-10-06 14:38:48 +02:00
|
|
|
final ArrayList<StreamDialogEntry> entries = new ArrayList<>();
|
|
|
|
|
2022-01-27 17:11:16 +01:00
|
|
|
if (PlayerHolder.getInstance().isPlayQueueReady()) {
|
2020-10-06 17:22:12 +02:00
|
|
|
entries.add(StreamDialogEntry.enqueue);
|
Add play next to long press menu & refactor enqueue methods (#6872)
* added mvp play next button in long press menu; new intent handling, new long press dialog entry, new dialog functions, new strings
* changed line length for checkstyle pass
* cleaned comments, moved strings
* Update app/src/main/res/values/strings.xml
to make long press entry more descriptive
Co-authored-by: opusforlife2 <53176348+opusforlife2@users.noreply.github.com>
* Update app/src/main/res/values/strings.xml
Co-authored-by: Stypox <stypox@pm.me>
* replace redundant nextOnVideoPlayer methods
Co-authored-by: Stypox <stypox@pm.me>
* add enqueueNextOnPlayer and enqueueOnPlayer without selectOnAppend and RESUME_PLAYBACK/ deprecate enqueueNextOn*Player and enqueueOn*Player methods
add getPlayerIntent, getPlayerEnqueueIntent and getPlayerEnqueueNextIntent without selectOnAppend and RESUME_PLAYBACK/ deprecate those with
add section comments
* removed deprecated methods
removed redundant methods
* removed deprecated methods
removed redundant methods
* replaced APPEND_ONLY, removed SELECT_ON_APPEND / replaced remaining enqueueOn*Player methods
* now works with playlists
* renamed dialog entry
* checking for >1 items in the queue using the PlayerHolder
* making enqueue*OnPlayer safe to call when no video is playing (defaulting to audio)
* corrected strings
* improve getQueueSize in PlayerHolder
* long press to enqueue only if queue isnt empty
* add Whitespace
Co-authored-by: Stypox <stypox@pm.me>
* clarify comments / add spaces
* PlayerType as parameter of the enqueueOnPlayer method
add Helper method
* using the helper function everywhere (except for the background and popup long-press actions (also on playlists, history, ...)), so basically nowhere
/ passing checkstyle
* assimilated the enqueue*OnPlayer methods
* removed redundant comment, variable
* simplify code line
Co-authored-by: Stypox <stypox@pm.me>
* move if
* replace workaround for isPlayerOpen()
Co-authored-by: Stypox <stypox@pm.me>
* replaced workarounds (getType), corrected static access with getInstance
* remove unused imports
* changed method call to original, new method doesnt exist yet.
* Use getter method instead of property access syntax.
* improve conditional for play next entry
Co-authored-by: Stypox <stypox@pm.me>
* show play next btn in feed fragment
Co-authored-by: Stypox <stypox@pm.me>
* add play next to local playlist and statistics fragment
Co-authored-by: Stypox <stypox@pm.me>
* formating
Co-authored-by: Stypox <stypox@pm.me>
* correcting logic
Co-authored-by: Stypox <stypox@pm.me>
* remove 2 year old unused string, formating
Co-authored-by: Stypox <stypox@pm.me>
* correct enqueue (next) conditionals, default to background if no player is open. Dont generally default to background play.
* remove player open checks from button long press enqueue actions
* improve log msg
* Rename next to enqueue_next
* Refactor kotlin
Co-authored-by: opusforlife2 <53176348+opusforlife2@users.noreply.github.com>
Co-authored-by: Stypox <stypox@pm.me>
2021-09-18 11:22:49 +02:00
|
|
|
|
|
|
|
if (PlayerHolder.getInstance().getQueueSize() > 1) {
|
|
|
|
entries.add(StreamDialogEntry.enqueue_next);
|
|
|
|
}
|
2020-10-06 14:38:48 +02:00
|
|
|
}
|
Add play next to long press menu & refactor enqueue methods (#6872)
* added mvp play next button in long press menu; new intent handling, new long press dialog entry, new dialog functions, new strings
* changed line length for checkstyle pass
* cleaned comments, moved strings
* Update app/src/main/res/values/strings.xml
to make long press entry more descriptive
Co-authored-by: opusforlife2 <53176348+opusforlife2@users.noreply.github.com>
* Update app/src/main/res/values/strings.xml
Co-authored-by: Stypox <stypox@pm.me>
* replace redundant nextOnVideoPlayer methods
Co-authored-by: Stypox <stypox@pm.me>
* add enqueueNextOnPlayer and enqueueOnPlayer without selectOnAppend and RESUME_PLAYBACK/ deprecate enqueueNextOn*Player and enqueueOn*Player methods
add getPlayerIntent, getPlayerEnqueueIntent and getPlayerEnqueueNextIntent without selectOnAppend and RESUME_PLAYBACK/ deprecate those with
add section comments
* removed deprecated methods
removed redundant methods
* removed deprecated methods
removed redundant methods
* replaced APPEND_ONLY, removed SELECT_ON_APPEND / replaced remaining enqueueOn*Player methods
* now works with playlists
* renamed dialog entry
* checking for >1 items in the queue using the PlayerHolder
* making enqueue*OnPlayer safe to call when no video is playing (defaulting to audio)
* corrected strings
* improve getQueueSize in PlayerHolder
* long press to enqueue only if queue isnt empty
* add Whitespace
Co-authored-by: Stypox <stypox@pm.me>
* clarify comments / add spaces
* PlayerType as parameter of the enqueueOnPlayer method
add Helper method
* using the helper function everywhere (except for the background and popup long-press actions (also on playlists, history, ...)), so basically nowhere
/ passing checkstyle
* assimilated the enqueue*OnPlayer methods
* removed redundant comment, variable
* simplify code line
Co-authored-by: Stypox <stypox@pm.me>
* move if
* replace workaround for isPlayerOpen()
Co-authored-by: Stypox <stypox@pm.me>
* replaced workarounds (getType), corrected static access with getInstance
* remove unused imports
* changed method call to original, new method doesnt exist yet.
* Use getter method instead of property access syntax.
* improve conditional for play next entry
Co-authored-by: Stypox <stypox@pm.me>
* show play next btn in feed fragment
Co-authored-by: Stypox <stypox@pm.me>
* add play next to local playlist and statistics fragment
Co-authored-by: Stypox <stypox@pm.me>
* formating
Co-authored-by: Stypox <stypox@pm.me>
* correcting logic
Co-authored-by: Stypox <stypox@pm.me>
* remove 2 year old unused string, formating
Co-authored-by: Stypox <stypox@pm.me>
* correct enqueue (next) conditionals, default to background if no player is open. Dont generally default to background play.
* remove player open checks from button long press enqueue actions
* improve log msg
* Rename next to enqueue_next
* Refactor kotlin
Co-authored-by: opusforlife2 <53176348+opusforlife2@users.noreply.github.com>
Co-authored-by: Stypox <stypox@pm.me>
2021-09-18 11:22:49 +02:00
|
|
|
|
2019-08-14 14:17:05 +02:00
|
|
|
if (item.getStreamType() == StreamType.AUDIO_STREAM) {
|
2020-10-06 14:38:48 +02:00
|
|
|
entries.addAll(Arrays.asList(
|
2019-08-14 14:17:05 +02:00
|
|
|
StreamDialogEntry.start_here_on_background,
|
|
|
|
StreamDialogEntry.append_playlist,
|
2020-10-06 14:38:48 +02:00
|
|
|
StreamDialogEntry.share
|
|
|
|
));
|
|
|
|
} else {
|
|
|
|
entries.addAll(Arrays.asList(
|
2019-08-14 14:17:05 +02:00
|
|
|
StreamDialogEntry.start_here_on_background,
|
|
|
|
StreamDialogEntry.start_here_on_popup,
|
|
|
|
StreamDialogEntry.append_playlist,
|
2020-10-06 14:38:48 +02:00
|
|
|
StreamDialogEntry.share
|
|
|
|
));
|
2019-08-14 14:17:05 +02:00
|
|
|
}
|
2021-05-13 17:45:51 +02:00
|
|
|
entries.add(StreamDialogEntry.open_in_browser);
|
2021-03-26 13:28:11 +01:00
|
|
|
if (KoreUtils.shouldShowPlayWithKodi(context, item.getServiceId())) {
|
2020-12-30 23:40:21 +01:00
|
|
|
entries.add(StreamDialogEntry.play_with_kodi);
|
2020-12-30 03:17:36 +01:00
|
|
|
}
|
2021-05-15 18:20:27 +02:00
|
|
|
|
2021-09-24 05:39:47 +02:00
|
|
|
// show "mark as watched" only when watch history is enabled
|
2021-11-13 18:14:54 +01:00
|
|
|
if (StreamDialogEntry.shouldAddMarkAsWatched(item.getStreamType(), context)) {
|
2021-09-24 05:39:47 +02:00
|
|
|
entries.add(
|
|
|
|
StreamDialogEntry.mark_as_watched
|
|
|
|
);
|
|
|
|
}
|
2021-05-15 18:20:27 +02:00
|
|
|
if (!isNullOrEmpty(item.getUploaderUrl())) {
|
|
|
|
entries.add(StreamDialogEntry.show_channel_details);
|
|
|
|
}
|
|
|
|
|
2020-10-06 14:38:48 +02:00
|
|
|
StreamDialogEntry.setEnabledEntries(entries);
|
2019-08-14 14:17:05 +02:00
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
StreamDialogEntry.start_here_on_background.setCustomAction((fragment, infoItem) ->
|
|
|
|
NavigationHelper.playOnBackgroundPlayer(context,
|
|
|
|
getPlayQueueStartingAt(infoItem), true));
|
2019-08-14 14:17:05 +02:00
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
new InfoItemDialog(activity, item, StreamDialogEntry.getCommands(context),
|
|
|
|
(dialog, which) -> StreamDialogEntry.clickOn(which, this, item)).show();
|
2019-08-14 14:17:05 +02:00
|
|
|
}
|
|
|
|
|
2018-01-04 05:28:01 +01:00
|
|
|
@Override
|
2021-06-20 00:29:18 +02:00
|
|
|
public void onCreateOptionsMenu(@NonNull final Menu menu,
|
|
|
|
@NonNull final MenuInflater inflater) {
|
2020-03-31 19:20:15 +02: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() {
|
2020-11-03 06:19:19 +01:00
|
|
|
headerBinding = null;
|
|
|
|
playlistControlBinding = null;
|
|
|
|
|
2018-02-06 06:32:23 +01:00
|
|
|
super.onDestroyView();
|
2020-03-31 19:20:15 +02:00
|
|
|
if (isBookmarkButtonReady != null) {
|
|
|
|
isBookmarkButtonReady.set(false);
|
|
|
|
}
|
2018-02-09 04:53:04 +01:00
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
if (disposables != null) {
|
|
|
|
disposables.clear();
|
|
|
|
}
|
|
|
|
if (bookmarkReactor != null) {
|
|
|
|
bookmarkReactor.cancel();
|
|
|
|
}
|
2018-02-06 06:32:23 +01:00
|
|
|
|
|
|
|
bookmarkReactor = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onDestroy() {
|
|
|
|
super.onDestroy();
|
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
if (disposables != null) {
|
|
|
|
disposables.dispose();
|
|
|
|
}
|
2018-02-06 06:32:23 +01:00
|
|
|
|
|
|
|
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() {
|
2020-04-15 15:31:53 +02:00
|
|
|
return ExtractorHelper.getMorePlaylistItems(serviceId, url, currentNextPage);
|
2017-09-03 08:04:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-03-31 19:20:15 +02:00
|
|
|
protected Single<PlaylistInfo> loadResult(final 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
|
2020-03-31 19:20:15 +02:00
|
|
|
public boolean onOptionsItemSelected(final MenuItem item) {
|
2018-01-04 05:28:01 +01:00
|
|
|
switch (item.getItemId()) {
|
2020-02-22 10:36:10 +01:00
|
|
|
case R.id.action_settings:
|
|
|
|
NavigationHelper.openSettings(requireContext());
|
|
|
|
break;
|
2018-01-04 05:28:01 +01:00
|
|
|
case R.id.menu_item_openInBrowser:
|
2020-02-22 10:36:10 +01:00
|
|
|
ShareUtils.openUrlInBrowser(requireContext(), url);
|
2018-01-04 05:28:01 +01:00
|
|
|
break;
|
2018-01-29 08:01:06 +01:00
|
|
|
case R.id.menu_item_share:
|
2022-01-15 21:19:04 +01:00
|
|
|
if (currentInfo != null) {
|
|
|
|
ShareUtils.shareText(requireContext(), name, url,
|
|
|
|
currentInfo.getThumbnailUrl());
|
|
|
|
}
|
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();
|
2021-01-16 04:32:01 +01:00
|
|
|
animate(headerBinding.getRoot(), false, 200);
|
2021-01-15 11:26:09 +01:00
|
|
|
animateHideRecyclerViewAllowingScrolling(itemsList);
|
2017-09-03 08:04:18 +02:00
|
|
|
|
2021-03-27 14:37:44 +01:00
|
|
|
PicassoHelper.cancelTag(PICASSO_PLAYLIST_TAG);
|
2021-01-16 04:32:01 +01:00
|
|
|
animate(headerBinding.uploaderLayout, false, 200);
|
2017-09-03 08:04:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void handleResult(@NonNull final PlaylistInfo result) {
|
|
|
|
super.handleResult(result);
|
|
|
|
|
2021-01-16 04:32:01 +01:00
|
|
|
animate(headerBinding.getRoot(), true, 100);
|
|
|
|
animate(headerBinding.uploaderLayout, true, 300);
|
2020-11-03 06:19:19 +01:00
|
|
|
headerBinding.uploaderLayout.setOnClickListener(null);
|
2020-03-31 19:20:15 +02:00
|
|
|
// If we have an uploader put them into the UI
|
|
|
|
if (!TextUtils.isEmpty(result.getUploaderName())) {
|
2020-11-03 06:19:19 +01:00
|
|
|
headerBinding.uploaderName.setText(result.getUploaderName());
|
2017-12-08 15:05:08 +01:00
|
|
|
if (!TextUtils.isEmpty(result.getUploaderUrl())) {
|
2020-11-03 06:19:19 +01:00
|
|
|
headerBinding.uploaderLayout.setOnClickListener(v -> {
|
2018-07-08 17:46:21 +02:00
|
|
|
try {
|
2020-08-03 14:47:02 +02:00
|
|
|
NavigationHelper.openChannelFragment(getFM(), result.getServiceId(),
|
|
|
|
result.getUploaderUrl(), result.getUploaderName());
|
2020-08-16 10:24:58 +02:00
|
|
|
} catch (final Exception e) {
|
2021-12-01 09:43:24 +01:00
|
|
|
ErrorUtil.showUiErrorSnackbar(this, "Opening channel fragment", e);
|
2018-07-08 17:46:21 +02:00
|
|
|
}
|
|
|
|
});
|
2017-09-03 08:04:18 +02:00
|
|
|
}
|
2020-04-02 13:51:10 +02:00
|
|
|
} else { // Otherwise say we have no uploader
|
2020-11-03 06:19:19 +01:00
|
|
|
headerBinding.uploaderName.setText(R.string.playlist_no_uploader);
|
2017-09-03 08:04:18 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 06:19:19 +01:00
|
|
|
playlistControlBinding.getRoot().setVisibility(View.VISIBLE);
|
2017-11-12 09:16:51 +01:00
|
|
|
|
2020-03-17 18:41:39 +01:00
|
|
|
final String avatarUrl = result.getUploaderAvatarUrl();
|
|
|
|
if (result.getServiceId() == ServiceList.YouTube.getServiceId()
|
|
|
|
&& (YoutubeParsingHelper.isYoutubeMixId(result.getId())
|
|
|
|
|| YoutubeParsingHelper.isYoutubeMusicMixId(result.getId()))) {
|
|
|
|
// this is an auto-generated playlist (e.g. Youtube mix), so a radio is shown
|
2020-11-03 06:19:19 +01:00
|
|
|
headerBinding.uploaderAvatarView.setDisableCircularTransformation(true);
|
|
|
|
headerBinding.uploaderAvatarView.setBorderColor(
|
2020-03-17 18:41:39 +01:00
|
|
|
getResources().getColor(R.color.transparent_background_color));
|
2020-11-03 06:19:19 +01:00
|
|
|
headerBinding.uploaderAvatarView.setImageDrawable(
|
|
|
|
AppCompatResources.getDrawable(requireContext(),
|
2021-03-27 15:45:49 +01:00
|
|
|
R.drawable.ic_radio)
|
2020-11-03 06:19:19 +01:00
|
|
|
);
|
2020-03-17 18:41:39 +01:00
|
|
|
} else {
|
2021-03-27 14:37:44 +01:00
|
|
|
PicassoHelper.loadAvatar(avatarUrl).tag(PICASSO_PLAYLIST_TAG)
|
|
|
|
.into(headerBinding.uploaderAvatarView);
|
2020-03-17 18:41:39 +01:00
|
|
|
}
|
|
|
|
|
2020-11-03 06:19:19 +01:00
|
|
|
headerBinding.playlistStreamCount.setText(Localization
|
2020-03-20 20:57:56 +01:00
|
|
|
.localizeStreamCount(getContext(), result.getStreamCount()));
|
2017-09-03 08:04:18 +02:00
|
|
|
|
2017-12-08 15:05:08 +01:00
|
|
|
if (!result.getErrors().isEmpty()) {
|
2020-12-11 14:55:47 +01:00
|
|
|
showSnackBarError(new ErrorInfo(result.getErrors(), UserAction.REQUESTED_PLAYLIST,
|
|
|
|
result.getUrl(), result));
|
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());
|
|
|
|
|
2020-11-03 06:19:19 +01:00
|
|
|
playlistControlBinding.playlistCtrlPlayAllButton.setOnClickListener(view ->
|
2020-10-18 20:19:50 +02:00
|
|
|
NavigationHelper.playOnMainPlayer(activity, getPlayQueue()));
|
2020-11-03 06:19:19 +01:00
|
|
|
playlistControlBinding.playlistCtrlPlayPopupButton.setOnClickListener(view ->
|
2019-04-13 09:31:32 +02:00
|
|
|
NavigationHelper.playOnPopupPlayer(activity, getPlayQueue(), false));
|
2020-11-03 06:19:19 +01:00
|
|
|
playlistControlBinding.playlistCtrlPlayBgButton.setOnClickListener(view ->
|
2019-04-13 09:31:32 +02:00
|
|
|
NavigationHelper.playOnBackgroundPlayer(activity, getPlayQueue(), false));
|
2019-01-18 23:16:02 +01:00
|
|
|
|
2020-11-03 06:19:19 +01:00
|
|
|
playlistControlBinding.playlistCtrlPlayPopupButton.setOnLongClickListener(view -> {
|
Add play next to long press menu & refactor enqueue methods (#6872)
* added mvp play next button in long press menu; new intent handling, new long press dialog entry, new dialog functions, new strings
* changed line length for checkstyle pass
* cleaned comments, moved strings
* Update app/src/main/res/values/strings.xml
to make long press entry more descriptive
Co-authored-by: opusforlife2 <53176348+opusforlife2@users.noreply.github.com>
* Update app/src/main/res/values/strings.xml
Co-authored-by: Stypox <stypox@pm.me>
* replace redundant nextOnVideoPlayer methods
Co-authored-by: Stypox <stypox@pm.me>
* add enqueueNextOnPlayer and enqueueOnPlayer without selectOnAppend and RESUME_PLAYBACK/ deprecate enqueueNextOn*Player and enqueueOn*Player methods
add getPlayerIntent, getPlayerEnqueueIntent and getPlayerEnqueueNextIntent without selectOnAppend and RESUME_PLAYBACK/ deprecate those with
add section comments
* removed deprecated methods
removed redundant methods
* removed deprecated methods
removed redundant methods
* replaced APPEND_ONLY, removed SELECT_ON_APPEND / replaced remaining enqueueOn*Player methods
* now works with playlists
* renamed dialog entry
* checking for >1 items in the queue using the PlayerHolder
* making enqueue*OnPlayer safe to call when no video is playing (defaulting to audio)
* corrected strings
* improve getQueueSize in PlayerHolder
* long press to enqueue only if queue isnt empty
* add Whitespace
Co-authored-by: Stypox <stypox@pm.me>
* clarify comments / add spaces
* PlayerType as parameter of the enqueueOnPlayer method
add Helper method
* using the helper function everywhere (except for the background and popup long-press actions (also on playlists, history, ...)), so basically nowhere
/ passing checkstyle
* assimilated the enqueue*OnPlayer methods
* removed redundant comment, variable
* simplify code line
Co-authored-by: Stypox <stypox@pm.me>
* move if
* replace workaround for isPlayerOpen()
Co-authored-by: Stypox <stypox@pm.me>
* replaced workarounds (getType), corrected static access with getInstance
* remove unused imports
* changed method call to original, new method doesnt exist yet.
* Use getter method instead of property access syntax.
* improve conditional for play next entry
Co-authored-by: Stypox <stypox@pm.me>
* show play next btn in feed fragment
Co-authored-by: Stypox <stypox@pm.me>
* add play next to local playlist and statistics fragment
Co-authored-by: Stypox <stypox@pm.me>
* formating
Co-authored-by: Stypox <stypox@pm.me>
* correcting logic
Co-authored-by: Stypox <stypox@pm.me>
* remove 2 year old unused string, formating
Co-authored-by: Stypox <stypox@pm.me>
* correct enqueue (next) conditionals, default to background if no player is open. Dont generally default to background play.
* remove player open checks from button long press enqueue actions
* improve log msg
* Rename next to enqueue_next
* Refactor kotlin
Co-authored-by: opusforlife2 <53176348+opusforlife2@users.noreply.github.com>
Co-authored-by: Stypox <stypox@pm.me>
2021-09-18 11:22:49 +02:00
|
|
|
NavigationHelper.enqueueOnPlayer(activity, getPlayQueue(), PlayerType.POPUP);
|
2019-01-18 23:58:24 +01:00
|
|
|
return true;
|
|
|
|
});
|
|
|
|
|
2020-11-03 06:19:19 +01:00
|
|
|
playlistControlBinding.playlistCtrlPlayBgButton.setOnLongClickListener(view -> {
|
Add play next to long press menu & refactor enqueue methods (#6872)
* added mvp play next button in long press menu; new intent handling, new long press dialog entry, new dialog functions, new strings
* changed line length for checkstyle pass
* cleaned comments, moved strings
* Update app/src/main/res/values/strings.xml
to make long press entry more descriptive
Co-authored-by: opusforlife2 <53176348+opusforlife2@users.noreply.github.com>
* Update app/src/main/res/values/strings.xml
Co-authored-by: Stypox <stypox@pm.me>
* replace redundant nextOnVideoPlayer methods
Co-authored-by: Stypox <stypox@pm.me>
* add enqueueNextOnPlayer and enqueueOnPlayer without selectOnAppend and RESUME_PLAYBACK/ deprecate enqueueNextOn*Player and enqueueOn*Player methods
add getPlayerIntent, getPlayerEnqueueIntent and getPlayerEnqueueNextIntent without selectOnAppend and RESUME_PLAYBACK/ deprecate those with
add section comments
* removed deprecated methods
removed redundant methods
* removed deprecated methods
removed redundant methods
* replaced APPEND_ONLY, removed SELECT_ON_APPEND / replaced remaining enqueueOn*Player methods
* now works with playlists
* renamed dialog entry
* checking for >1 items in the queue using the PlayerHolder
* making enqueue*OnPlayer safe to call when no video is playing (defaulting to audio)
* corrected strings
* improve getQueueSize in PlayerHolder
* long press to enqueue only if queue isnt empty
* add Whitespace
Co-authored-by: Stypox <stypox@pm.me>
* clarify comments / add spaces
* PlayerType as parameter of the enqueueOnPlayer method
add Helper method
* using the helper function everywhere (except for the background and popup long-press actions (also on playlists, history, ...)), so basically nowhere
/ passing checkstyle
* assimilated the enqueue*OnPlayer methods
* removed redundant comment, variable
* simplify code line
Co-authored-by: Stypox <stypox@pm.me>
* move if
* replace workaround for isPlayerOpen()
Co-authored-by: Stypox <stypox@pm.me>
* replaced workarounds (getType), corrected static access with getInstance
* remove unused imports
* changed method call to original, new method doesnt exist yet.
* Use getter method instead of property access syntax.
* improve conditional for play next entry
Co-authored-by: Stypox <stypox@pm.me>
* show play next btn in feed fragment
Co-authored-by: Stypox <stypox@pm.me>
* add play next to local playlist and statistics fragment
Co-authored-by: Stypox <stypox@pm.me>
* formating
Co-authored-by: Stypox <stypox@pm.me>
* correcting logic
Co-authored-by: Stypox <stypox@pm.me>
* remove 2 year old unused string, formating
Co-authored-by: Stypox <stypox@pm.me>
* correct enqueue (next) conditionals, default to background if no player is open. Dont generally default to background play.
* remove player open checks from button long press enqueue actions
* improve log msg
* Rename next to enqueue_next
* Refactor kotlin
Co-authored-by: opusforlife2 <53176348+opusforlife2@users.noreply.github.com>
Co-authored-by: Stypox <stypox@pm.me>
2021-09-18 11:22:49 +02:00
|
|
|
NavigationHelper.enqueueOnPlayer(activity, getPlayQueue(), PlayerType.AUDIO);
|
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<>();
|
2020-08-16 10:24:58 +02:00
|
|
|
for (final InfoItem i : infoListAdapter.getItemsList()) {
|
2020-03-31 19:20:15 +02:00
|
|
|
if (i instanceof StreamInfoItem) {
|
2018-03-18 16:37:49 +01:00
|
|
|
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(),
|
2020-04-15 15:31:53 +02:00
|
|
|
currentInfo.getNextPage(),
|
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
|
|
|
|
|
|
|
/*//////////////////////////////////////////////////////////////////////////
|
|
|
|
// Utils
|
|
|
|
//////////////////////////////////////////////////////////////////////////*/
|
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
private Flowable<Integer> getUpdateProcessor(
|
|
|
|
@NonNull final List<PlaylistRemoteEntity> playlists,
|
|
|
|
@NonNull final PlaylistInfo result) {
|
2018-06-19 03:22:52 +02:00
|
|
|
final Flowable<Integer> noItemToUpdate = Flowable.just(/*noItemToUpdate=*/-1);
|
2020-03-31 19:20:15 +02:00
|
|
|
if (playlists.isEmpty()) {
|
|
|
|
return noItemToUpdate;
|
|
|
|
}
|
2018-06-19 03:22:52 +02:00
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
final PlaylistRemoteEntity playlistRemoteEntity = playlists.get(0);
|
|
|
|
if (playlistRemoteEntity.isIdenticalTo(result)) {
|
|
|
|
return noItemToUpdate;
|
|
|
|
}
|
2018-06-19 03:22:52 +02:00
|
|
|
|
|
|
|
return remotePlaylistManager.onUpdate(playlists.get(0).getUid(), result).toFlowable();
|
|
|
|
}
|
|
|
|
|
2018-02-06 06:32:23 +01:00
|
|
|
private Subscriber<List<PlaylistRemoteEntity>> getPlaylistBookmarkSubscriber() {
|
2022-01-15 23:55:19 +01:00
|
|
|
return new Subscriber<>() {
|
2018-02-06 06:32:23 +01:00
|
|
|
@Override
|
2020-03-31 19:20:15 +02:00
|
|
|
public void onSubscribe(final Subscription s) {
|
|
|
|
if (bookmarkReactor != null) {
|
|
|
|
bookmarkReactor.cancel();
|
|
|
|
}
|
2018-02-06 06:32:23 +01:00
|
|
|
bookmarkReactor = s;
|
|
|
|
bookmarkReactor.request(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-03-31 19:20:15 +02:00
|
|
|
public void onNext(final List<PlaylistRemoteEntity> playlist) {
|
2018-02-06 06:32:23 +01:00
|
|
|
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
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
if (bookmarkReactor != null) {
|
|
|
|
bookmarkReactor.request(1);
|
|
|
|
}
|
2018-02-06 06:32:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-12-11 14:55:47 +01:00
|
|
|
public void onError(final Throwable throwable) {
|
|
|
|
showError(new ErrorInfo(throwable, UserAction.REQUESTED_BOOKMARK,
|
|
|
|
"Get playlist bookmarks"));
|
2018-02-06 06:32:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-03-31 19:20:15 +02:00
|
|
|
public void onComplete() { }
|
2018-02-06 06:32:23 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-09-03 08:04:18 +02:00
|
|
|
@Override
|
2020-03-31 19:20:15 +02:00
|
|
|
public void setTitle(final String title) {
|
2017-09-03 08:04:18 +02:00
|
|
|
super.setTitle(title);
|
2021-03-28 22:25:51 +02:00
|
|
|
if (headerBinding != null) {
|
|
|
|
headerBinding.playlistTitleView.setText(title);
|
|
|
|
}
|
2017-09-03 08:04:18 +02:00
|
|
|
}
|
2018-02-06 06:32:23 +01:00
|
|
|
|
2018-02-09 04:53:04 +01:00
|
|
|
private void onBookmarkClicked() {
|
2020-03-31 19:20:15 +02:00
|
|
|
if (isBookmarkButtonReady == null || !isBookmarkButtonReady.get()
|
|
|
|
|| remotePlaylistManager == null) {
|
2018-02-09 04:53:04 +01:00
|
|
|
return;
|
2020-03-31 19:20:15 +02:00
|
|
|
}
|
2018-02-09 04:53:04 +01:00
|
|
|
|
|
|
|
final Disposable action;
|
|
|
|
|
|
|
|
if (currentInfo != null && playlistEntity == null) {
|
|
|
|
action = remotePlaylistManager.onBookmark(currentInfo)
|
|
|
|
.observeOn(AndroidSchedulers.mainThread())
|
2020-12-11 14:55:47 +01:00
|
|
|
.subscribe(ignored -> { /* Do nothing */ }, throwable ->
|
|
|
|
showError(new ErrorInfo(throwable, UserAction.REQUESTED_BOOKMARK,
|
|
|
|
"Adding playlist bookmark")));
|
2018-02-09 04:53:04 +01:00
|
|
|
} else if (playlistEntity != null) {
|
|
|
|
action = remotePlaylistManager.deletePlaylist(playlistEntity.getUid())
|
|
|
|
.observeOn(AndroidSchedulers.mainThread())
|
|
|
|
.doFinally(() -> playlistEntity = null)
|
2020-12-11 14:55:47 +01:00
|
|
|
.subscribe(ignored -> { /* Do nothing */ }, throwable ->
|
|
|
|
showError(new ErrorInfo(throwable, UserAction.REQUESTED_BOOKMARK,
|
|
|
|
"Deleting playlist bookmark")));
|
2018-02-09 04:53:04 +01:00
|
|
|
} else {
|
2020-10-31 21:55:45 +01:00
|
|
|
action = Disposable.empty();
|
2018-02-09 04:53:04 +01:00
|
|
|
}
|
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() {
|
2020-03-31 19:20:15 +02:00
|
|
|
if (playlistBookmarkButton == null || activity == null) {
|
|
|
|
return;
|
|
|
|
}
|
2018-02-06 06:32:23 +01:00
|
|
|
|
2021-03-27 15:45:49 +01:00
|
|
|
final int drawable = playlistEntity == null
|
|
|
|
? R.drawable.ic_playlist_add : R.drawable.ic_playlist_add_check;
|
2018-02-09 00:58:48 +01:00
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
final int titleRes = playlistEntity == null
|
|
|
|
? R.string.bookmark_playlist : R.string.unbookmark_playlist;
|
2018-02-09 00:58:48 +01:00
|
|
|
|
2021-03-27 15:45:49 +01:00
|
|
|
playlistBookmarkButton.setIcon(drawable);
|
2018-02-09 04:53:04 +01:00
|
|
|
playlistBookmarkButton.setTitle(titleRes);
|
2018-02-09 00:58:48 +01:00
|
|
|
}
|
2019-12-06 16:32:45 +01:00
|
|
|
}
|