Search in sources :

Example 1 with StreamStatisticsEntry

use of org.schabi.newpipe.database.stream.StreamStatisticsEntry in project NewPipe by TeamNewPipe.

the class StatisticsPlaylistFragment method showStreamDialog.

/*//////////////////////////////////////////////////////////////////////////
    // Utils
    //////////////////////////////////////////////////////////////////////////*/
private void showStreamDialog(final StreamStatisticsEntry 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) };
    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;
            default:
                break;
        }
    };
    new InfoItemDialog(getActivity(), infoItem, commands, actions).show();
}
Also used : Context(android.content.Context) Context(android.content.Context) StreamStatisticsEntry(org.schabi.newpipe.database.stream.StreamStatisticsEntry) Bundle(android.os.Bundle) NavigationHelper(org.schabi.newpipe.util.NavigationHelper) NonNull(android.support.annotation.NonNull) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) SinglePlayQueue(org.schabi.newpipe.playlist.SinglePlayQueue) ArrayList(java.util.ArrayList) HistoryRecordManager(org.schabi.newpipe.history.HistoryRecordManager) View(android.view.View) OnClickGesture(org.schabi.newpipe.util.OnClickGesture) State(icepick.State) Subscriber(org.reactivestreams.Subscriber) R(org.schabi.newpipe.R) DialogInterface(android.content.DialogInterface) Parcelable(android.os.Parcelable) LayoutInflater(android.view.LayoutInflater) LocalItem(org.schabi.newpipe.database.LocalItem) UserAction(org.schabi.newpipe.report.UserAction) ViewGroup(android.view.ViewGroup) StreamInfoItem(org.schabi.newpipe.extractor.stream.StreamInfoItem) List(java.util.List) 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) Collections(java.util.Collections) 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 StreamStatisticsEntry

use of org.schabi.newpipe.database.stream.StreamStatisticsEntry in project NewPipe by TeamNewPipe.

the class LocalStatisticStreamItemHolder method updateFromItem.

@Override
public void updateFromItem(final LocalItem localItem, final DateFormat dateFormat) {
    if (!(localItem instanceof StreamStatisticsEntry))
        return;
    final StreamStatisticsEntry item = (StreamStatisticsEntry) localItem;
    itemVideoTitleView.setText(item.title);
    itemUploaderView.setText(item.uploader);
    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);
    }
    itemAdditionalDetails.setText(getStreamInfoDetailLine(item, dateFormat));
    // 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;
    });
}
Also used : StreamStatisticsEntry(org.schabi.newpipe.database.stream.StreamStatisticsEntry)

Example 3 with StreamStatisticsEntry

use of org.schabi.newpipe.database.stream.StreamStatisticsEntry in project NewPipe by TeamNewPipe.

the class StatisticsPlaylistFragment 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 StreamStatisticsEntry) {
            streamInfoItems.add(((StreamStatisticsEntry) item).toStreamInfoItem());
        }
    }
    return new SinglePlayQueue(streamInfoItems, index);
}
Also used : StreamInfoItem(org.schabi.newpipe.extractor.stream.StreamInfoItem) StreamStatisticsEntry(org.schabi.newpipe.database.stream.StreamStatisticsEntry) ArrayList(java.util.ArrayList) LocalItem(org.schabi.newpipe.database.LocalItem) SinglePlayQueue(org.schabi.newpipe.playlist.SinglePlayQueue)

Aggregations

StreamStatisticsEntry (org.schabi.newpipe.database.stream.StreamStatisticsEntry)3 ArrayList (java.util.ArrayList)2 LocalItem (org.schabi.newpipe.database.LocalItem)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 LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 State (icepick.State)1 AndroidSchedulers (io.reactivex.android.schedulers.AndroidSchedulers)1 Collections (java.util.Collections)1 List (java.util.List)1 Subscriber (org.reactivestreams.Subscriber)1