Search in sources :

Example 1 with LocalItem

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

the class BookmarkFragment method initListeners.

@Override
protected void initListeners() {
    super.initListeners();
    itemListAdapter.setSelectedListener(new OnClickGesture<LocalItem>() {

        @Override
        public void selected(LocalItem selectedItem) {
            // Requires the parent fragment to find holder for fragment replacement
            if (getParentFragment() == null)
                return;
            final FragmentManager fragmentManager = getParentFragment().getFragmentManager();
            if (selectedItem instanceof PlaylistMetadataEntry) {
                final PlaylistMetadataEntry entry = ((PlaylistMetadataEntry) selectedItem);
                NavigationHelper.openLocalPlaylistFragment(fragmentManager, entry.uid, entry.name);
            } else if (selectedItem instanceof PlaylistRemoteEntity) {
                final PlaylistRemoteEntity entry = ((PlaylistRemoteEntity) selectedItem);
                NavigationHelper.openPlaylistFragment(fragmentManager, entry.getServiceId(), entry.getUrl(), entry.getName());
            }
        }

        @Override
        public void held(LocalItem selectedItem) {
            if (selectedItem instanceof PlaylistMetadataEntry) {
                showLocalDeleteDialog((PlaylistMetadataEntry) selectedItem);
            } else if (selectedItem instanceof PlaylistRemoteEntity) {
                showRemoteDeleteDialog((PlaylistRemoteEntity) selectedItem);
            }
        }
    });
    lastPlayedButton.setOnClickListener(view -> {
        if (getParentFragment() != null) {
            NavigationHelper.openLastPlayedFragment(getParentFragment().getFragmentManager());
        }
    });
    mostPlayedButton.setOnClickListener(view -> {
        if (getParentFragment() != null) {
            NavigationHelper.openMostPlayedFragment(getParentFragment().getFragmentManager());
        }
    });
}
Also used : FragmentManager(android.support.v4.app.FragmentManager) PlaylistLocalItem(org.schabi.newpipe.database.playlist.PlaylistLocalItem) LocalItem(org.schabi.newpipe.database.LocalItem) PlaylistRemoteEntity(org.schabi.newpipe.database.playlist.model.PlaylistRemoteEntity) PlaylistMetadataEntry(org.schabi.newpipe.database.playlist.PlaylistMetadataEntry)

Example 2 with LocalItem

use of org.schabi.newpipe.database.LocalItem 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 LocalItem

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

the class PlaylistAppendDialog method onViewCreated.

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    final LocalPlaylistManager playlistManager = new LocalPlaylistManager(NewPipeDatabase.getInstance(getContext()));
    playlistAdapter = new LocalItemListAdapter(getActivity());
    playlistAdapter.setSelectedListener(new OnClickGesture<LocalItem>() {

        @Override
        public void selected(LocalItem selectedItem) {
            if (!(selectedItem instanceof PlaylistMetadataEntry) || getStreams() == null)
                return;
            onPlaylistSelected(playlistManager, (PlaylistMetadataEntry) selectedItem, getStreams());
        }
    });
    playlistRecyclerView = view.findViewById(R.id.playlist_list);
    playlistRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
    playlistRecyclerView.setAdapter(playlistAdapter);
    final View newPlaylistButton = view.findViewById(R.id.newPlaylist);
    newPlaylistButton.setOnClickListener(ignored -> openCreatePlaylistDialog());
    playlistReactor = playlistManager.getPlaylists().observeOn(AndroidSchedulers.mainThread()).subscribe(this::onPlaylistsReceived);
}
Also used : LocalItemListAdapter(org.schabi.newpipe.fragments.local.LocalItemListAdapter) LocalItem(org.schabi.newpipe.database.LocalItem) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) LocalPlaylistManager(org.schabi.newpipe.fragments.local.LocalPlaylistManager) PlaylistMetadataEntry(org.schabi.newpipe.database.playlist.PlaylistMetadataEntry)

Example 4 with LocalItem

use of org.schabi.newpipe.database.LocalItem 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 5 with LocalItem

use of org.schabi.newpipe.database.LocalItem 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)

Aggregations

LocalItem (org.schabi.newpipe.database.LocalItem)6 ArrayList (java.util.ArrayList)3 PlaylistStreamEntry (org.schabi.newpipe.database.playlist.PlaylistStreamEntry)3 RecyclerView (android.support.v7.widget.RecyclerView)2 PlaylistMetadataEntry (org.schabi.newpipe.database.playlist.PlaylistMetadataEntry)2 StreamInfoItem (org.schabi.newpipe.extractor.stream.StreamInfoItem)2 SinglePlayQueue (org.schabi.newpipe.playlist.SinglePlayQueue)2 FragmentManager (android.support.v4.app.FragmentManager)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 ItemTouchHelper (android.support.v7.widget.helper.ItemTouchHelper)1 View (android.view.View)1 CompositeDisposable (io.reactivex.disposables.CompositeDisposable)1 Disposable (io.reactivex.disposables.Disposable)1 PlaylistLocalItem (org.schabi.newpipe.database.playlist.PlaylistLocalItem)1 PlaylistRemoteEntity (org.schabi.newpipe.database.playlist.model.PlaylistRemoteEntity)1 StreamStatisticsEntry (org.schabi.newpipe.database.stream.StreamStatisticsEntry)1 LocalItemListAdapter (org.schabi.newpipe.fragments.local.LocalItemListAdapter)1 LocalPlaylistManager (org.schabi.newpipe.fragments.local.LocalPlaylistManager)1