Search in sources :

Example 1 with PlaylistStreamEntry

use of org.schabi.newpipe.database.playlist.PlaylistStreamEntry in project NewPipe by TeamNewPipe.

the class LocalPlaylistFragment method showStreamDialog.

/*//////////////////////////////////////////////////////////////////////////
    // Utils
    //////////////////////////////////////////////////////////////////////////*/
protected void showStreamDialog(final PlaylistStreamEntry item) {
    final Context context = getContext();
    final Activity activity = getActivity();
    if (context == null || context.getResources() == null || getActivity() == null)
        return;
    final StreamInfoItem infoItem = item.toStreamInfoItem();
    final String[] commands = new String[] { context.getResources().getString(R.string.enqueue_on_background), context.getResources().getString(R.string.enqueue_on_popup), context.getResources().getString(R.string.start_here_on_main), context.getResources().getString(R.string.start_here_on_background), context.getResources().getString(R.string.start_here_on_popup), context.getResources().getString(R.string.set_as_playlist_thumbnail), context.getResources().getString(R.string.delete) };
    final DialogInterface.OnClickListener actions = (dialogInterface, i) -> {
        final int index = Math.max(itemListAdapter.getItemsList().indexOf(item), 0);
        switch(i) {
            case 0:
                NavigationHelper.enqueueOnBackgroundPlayer(context, new SinglePlayQueue(infoItem));
                break;
            case 1:
                NavigationHelper.enqueueOnPopupPlayer(activity, new SinglePlayQueue(infoItem));
                break;
            case 2:
                NavigationHelper.playOnMainPlayer(context, getPlayQueue(index));
                break;
            case 3:
                NavigationHelper.playOnBackgroundPlayer(context, getPlayQueue(index));
                break;
            case 4:
                NavigationHelper.playOnPopupPlayer(activity, getPlayQueue(index));
                break;
            case 5:
                changeThumbnailUrl(item.thumbnailUrl);
                break;
            case 6:
                deleteItem(item);
                break;
            default:
                break;
        }
    };
    new InfoItemDialog(getActivity(), infoItem, commands, actions).show();
}
Also used : Context(android.content.Context) Context(android.content.Context) Bundle(android.os.Bundle) PlaylistStreamEntry(org.schabi.newpipe.database.playlist.PlaylistStreamEntry) NavigationHelper(org.schabi.newpipe.util.NavigationHelper) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) NonNull(android.support.annotation.NonNull) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) SinglePlayQueue(org.schabi.newpipe.playlist.SinglePlayQueue) ArrayList(java.util.ArrayList) Disposables(io.reactivex.disposables.Disposables) ItemTouchHelper(android.support.v7.widget.helper.ItemTouchHelper) Toast(android.widget.Toast) View(android.view.View) OnClickGesture(org.schabi.newpipe.util.OnClickGesture) State(icepick.State) AnimationUtils.animateView(org.schabi.newpipe.util.AnimationUtils.animateView) Subscriber(org.reactivestreams.Subscriber) R(org.schabi.newpipe.R) Log(android.util.Log) DialogInterface(android.content.DialogInterface) Parcelable(android.os.Parcelable) LayoutInflater(android.view.LayoutInflater) TextUtils(android.text.TextUtils) LocalItem(org.schabi.newpipe.database.LocalItem) UserAction(org.schabi.newpipe.report.UserAction) NewPipeDatabase(org.schabi.newpipe.NewPipeDatabase) ViewGroup(android.view.ViewGroup) LocalPlaylistManager(org.schabi.newpipe.fragments.local.LocalPlaylistManager) StreamInfoItem(org.schabi.newpipe.extractor.stream.StreamInfoItem) TimeUnit(java.util.concurrent.TimeUnit) RecyclerView(android.support.v7.widget.RecyclerView) List(java.util.List) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) AlertDialog(android.support.v7.app.AlertDialog) TextView(android.widget.TextView) PublishSubject(io.reactivex.subjects.PublishSubject) InfoItemDialog(org.schabi.newpipe.info_list.InfoItemDialog) Subscription(org.reactivestreams.Subscription) PlayQueue(org.schabi.newpipe.playlist.PlayQueue) Nullable(android.support.annotation.Nullable) Activity(android.app.Activity) Localization(org.schabi.newpipe.util.Localization) Collections(java.util.Collections) EditText(android.widget.EditText) StreamInfoItem(org.schabi.newpipe.extractor.stream.StreamInfoItem) InfoItemDialog(org.schabi.newpipe.info_list.InfoItemDialog) DialogInterface(android.content.DialogInterface) Activity(android.app.Activity) SinglePlayQueue(org.schabi.newpipe.playlist.SinglePlayQueue)

Example 2 with PlaylistStreamEntry

use of org.schabi.newpipe.database.playlist.PlaylistStreamEntry in project NewPipe by TeamNewPipe.

the class LocalPlaylistFragment method saveImmediate.

private void saveImmediate() {
    if (playlistManager == null || itemListAdapter == null)
        return;
    // List must be loaded and modified in order to save
    if (isLoadingComplete == null || isModified == null || !isLoadingComplete.get() || !isModified.get()) {
        Log.w(TAG, "Attempting to save playlist when local playlist " + "is not loaded or not modified: playlist id=[" + playlistId + "]");
        return;
    }
    final List<LocalItem> items = itemListAdapter.getItemsList();
    List<Long> streamIds = new ArrayList<>(items.size());
    for (final LocalItem item : items) {
        if (item instanceof PlaylistStreamEntry) {
            streamIds.add(((PlaylistStreamEntry) item).streamId);
        }
    }
    Log.d(TAG, "Updating playlist id=[" + playlistId + "] with [" + streamIds.size() + "] items");
    final Disposable disposable = playlistManager.updateJoin(playlistId, streamIds).observeOn(AndroidSchedulers.mainThread()).subscribe(() -> {
        if (isModified != null)
            isModified.set(false);
    }, this::onError);
    disposables.add(disposable);
}
Also used : CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) PlaylistStreamEntry(org.schabi.newpipe.database.playlist.PlaylistStreamEntry) ArrayList(java.util.ArrayList) LocalItem(org.schabi.newpipe.database.LocalItem)

Example 3 with PlaylistStreamEntry

use of org.schabi.newpipe.database.playlist.PlaylistStreamEntry in project NewPipe by TeamNewPipe.

the class LocalPlaylistFragment method initListeners.

@Override
protected void initListeners() {
    super.initListeners();
    headerTitleView.setOnClickListener(view -> createRenameDialog());
    itemTouchHelper = new ItemTouchHelper(getItemTouchCallback());
    itemTouchHelper.attachToRecyclerView(itemsList);
    itemListAdapter.setSelectedListener(new OnClickGesture<LocalItem>() {

        @Override
        public void selected(LocalItem selectedItem) {
            if (selectedItem instanceof PlaylistStreamEntry) {
                final PlaylistStreamEntry item = (PlaylistStreamEntry) selectedItem;
                NavigationHelper.openVideoDetailFragment(getFragmentManager(), item.serviceId, item.url, item.title);
            }
        }

        @Override
        public void held(LocalItem selectedItem) {
            if (selectedItem instanceof PlaylistStreamEntry) {
                showStreamDialog((PlaylistStreamEntry) selectedItem);
            }
        }

        @Override
        public void drag(LocalItem selectedItem, RecyclerView.ViewHolder viewHolder) {
            if (itemTouchHelper != null)
                itemTouchHelper.startDrag(viewHolder);
        }
    });
}
Also used : ItemTouchHelper(android.support.v7.widget.helper.ItemTouchHelper) PlaylistStreamEntry(org.schabi.newpipe.database.playlist.PlaylistStreamEntry) LocalItem(org.schabi.newpipe.database.LocalItem) RecyclerView(android.support.v7.widget.RecyclerView)

Example 4 with PlaylistStreamEntry

use of org.schabi.newpipe.database.playlist.PlaylistStreamEntry in project NewPipe by TeamNewPipe.

the class LocalPlaylistFragment method getPlayQueue.

private PlayQueue getPlayQueue(final int index) {
    if (itemListAdapter == null) {
        return new SinglePlayQueue(Collections.emptyList(), 0);
    }
    final List<LocalItem> infoItems = itemListAdapter.getItemsList();
    List<StreamInfoItem> streamInfoItems = new ArrayList<>(infoItems.size());
    for (final LocalItem item : infoItems) {
        if (item instanceof PlaylistStreamEntry) {
            streamInfoItems.add(((PlaylistStreamEntry) item).toStreamInfoItem());
        }
    }
    return new SinglePlayQueue(streamInfoItems, index);
}
Also used : StreamInfoItem(org.schabi.newpipe.extractor.stream.StreamInfoItem) PlaylistStreamEntry(org.schabi.newpipe.database.playlist.PlaylistStreamEntry) ArrayList(java.util.ArrayList) LocalItem(org.schabi.newpipe.database.LocalItem) SinglePlayQueue(org.schabi.newpipe.playlist.SinglePlayQueue)

Example 5 with PlaylistStreamEntry

use of org.schabi.newpipe.database.playlist.PlaylistStreamEntry in project NewPipe by TeamNewPipe.

the class LocalPlaylistStreamItemHolder method updateFromItem.

@Override
public void updateFromItem(final LocalItem localItem, final DateFormat dateFormat) {
    if (!(localItem instanceof PlaylistStreamEntry))
        return;
    final PlaylistStreamEntry item = (PlaylistStreamEntry) localItem;
    itemVideoTitleView.setText(item.title);
    itemAdditionalDetailsView.setText(Localization.concatenateStrings(item.uploader, NewPipe.getNameOfService(item.serviceId)));
    if (item.duration > 0) {
        itemDurationView.setText(Localization.getDurationString(item.duration));
        itemDurationView.setBackgroundColor(ContextCompat.getColor(itemBuilder.getContext(), R.color.duration_background_color));
        itemDurationView.setVisibility(View.VISIBLE);
    } else {
        itemDurationView.setVisibility(View.GONE);
    }
    // Default thumbnail is shown on error, while loading and if the url is empty
    itemBuilder.displayImage(item.thumbnailUrl, itemThumbnailView, ImageDisplayConstants.DISPLAY_THUMBNAIL_OPTIONS);
    itemView.setOnClickListener(view -> {
        if (itemBuilder.getOnItemSelectedListener() != null) {
            itemBuilder.getOnItemSelectedListener().selected(item);
        }
    });
    itemView.setLongClickable(true);
    itemView.setOnLongClickListener(view -> {
        if (itemBuilder.getOnItemSelectedListener() != null) {
            itemBuilder.getOnItemSelectedListener().held(item);
        }
        return true;
    });
    itemThumbnailView.setOnTouchListener(getOnTouchListener(item));
    itemHandleView.setOnTouchListener(getOnTouchListener(item));
}
Also used : PlaylistStreamEntry(org.schabi.newpipe.database.playlist.PlaylistStreamEntry)

Aggregations

PlaylistStreamEntry (org.schabi.newpipe.database.playlist.PlaylistStreamEntry)5 LocalItem (org.schabi.newpipe.database.LocalItem)4 ArrayList (java.util.ArrayList)3 RecyclerView (android.support.v7.widget.RecyclerView)2 ItemTouchHelper (android.support.v7.widget.helper.ItemTouchHelper)2 CompositeDisposable (io.reactivex.disposables.CompositeDisposable)2 Disposable (io.reactivex.disposables.Disposable)2 StreamInfoItem (org.schabi.newpipe.extractor.stream.StreamInfoItem)2 SinglePlayQueue (org.schabi.newpipe.playlist.SinglePlayQueue)2 Activity (android.app.Activity)1 Context (android.content.Context)1 DialogInterface (android.content.DialogInterface)1 Bundle (android.os.Bundle)1 Parcelable (android.os.Parcelable)1 NonNull (android.support.annotation.NonNull)1 Nullable (android.support.annotation.Nullable)1 AlertDialog (android.support.v7.app.AlertDialog)1 TextUtils (android.text.TextUtils)1 Log (android.util.Log)1 LayoutInflater (android.view.LayoutInflater)1