Search in sources :

Example 11 with Playlist

use of com.frostwire.alexandria.Playlist in project frostwire by frostwire.

the class LibraryUtils method createNewPlaylist.

static void createNewPlaylist(final File[] files, final boolean starred) {
    final DialogFinishedListener listener = new DialogFinishedListener() {

        @Override
        public void onDialogCancelled() {
        }

        @Override
        public void onDialogOk(String playlistName) {
            if (StringUtils.isNullOrEmpty(playlistName, true)) {
                return;
            }
            if (playlistName.length() > 0) {
                GUIMediator.instance().setWindow(GUIMediator.Tabs.LIBRARY);
                final Playlist playlist = LibraryMediator.getLibrary().newPlaylist(playlistName, playlistName);
                playlist.save();
                GUIMediator.safeInvokeLater(new Runnable() {

                    @Override
                    public void run() {
                        LibraryMediator.instance().getLibraryPlaylists().addPlaylist(playlist);
                        LibraryMediator.instance().getLibraryPlaylists().markBeginImport(playlist);
                    }
                });
                Thread t = new Thread(new Runnable() {

                    public void run() {
                        try {
                            Set<File> ignore = TorrentUtil.getIgnorableFiles();
                            addToPlaylist(playlist, files, starred, ignore);
                            playlist.save();
                        } finally {
                            asyncAddToPlaylistFinalizer(playlist);
                        }
                    }
                }, "createNewPlaylist");
                t.setDaemon(true);
                t.start();
                UXStats.instance().log(UXAction.LIBRARY_PLAYLIST_CREATED);
            }
        }
    };
    GUIMediator.safeInvokeAndWait(new Runnable() {

        @Override
        public void run() {
            File[] mediaFiles = files;
            if (files.length == 1 && files[0].isDirectory()) {
                mediaFiles = FileUtils.getFilesRecursive(files[0], null);
            }
            FrostwireInputDialog.showInputDialog(GUIMediator.getAppFrame(), I18n.tr("Playlist name"), I18n.tr("Playlist name"), GUIMediator.getThemeImage("playlist"), suggestPlaylistName(mediaFiles), listener);
        }
    });
}
Also used : DialogFinishedListener(com.frostwire.gui.theme.DialogFinishedListener) Playlist(com.frostwire.alexandria.Playlist) Set(java.util.Set)

Example 12 with Playlist

use of com.frostwire.alexandria.Playlist in project frostwire by frostwire.

the class LibraryMediator method selectCurrentMedia.

public void selectCurrentMedia() {
    // Select current playlist.
    Playlist currentPlaylist = MediaPlayer.instance().getCurrentPlaylist();
    final MediaSource currentMedia = MediaPlayer.instance().getCurrentMedia();
    // If the current song is being played from a playlist.
    if (currentPlaylist != null && currentMedia != null && currentMedia.getPlaylistItem() != null) {
        if (currentPlaylist.getId() != LibraryDatabase.STARRED_PLAYLIST_ID) {
            // select the song once it's available on the right hand side
            getLibraryPlaylists().enqueueRunnable(new Runnable() {

                public void run() {
                    GUIMediator.safeInvokeLater(new Runnable() {

                        public void run() {
                            LibraryPlaylistsTableMediator.instance().setItemSelected(currentMedia.getPlaylistItem());
                        }
                    });
                }
            });
            // select the playlist
            getLibraryPlaylists().selectPlaylist(currentPlaylist);
        } else {
            LibraryExplorer libraryFiles = getLibraryExplorer();
            // select the song once it's available on the right hand side
            libraryFiles.enqueueRunnable(new Runnable() {

                public void run() {
                    GUIMediator.safeInvokeLater(new Runnable() {

                        public void run() {
                            LibraryPlaylistsTableMediator.instance().setItemSelected(currentMedia.getPlaylistItem());
                        }
                    });
                }
            });
            libraryFiles.selectStarred();
        }
    } else if (currentMedia != null && currentMedia.getFile() != null) {
        // selects the audio node at the top
        LibraryExplorer libraryFiles = getLibraryExplorer();
        // select the song once it's available on the right hand side
        libraryFiles.enqueueRunnable(new Runnable() {

            public void run() {
                GUIMediator.safeInvokeLater(new Runnable() {

                    public void run() {
                        LibraryFilesTableMediator.instance().setFileSelected(currentMedia.getFile());
                    }
                });
            }
        });
        libraryFiles.selectAudio();
    }
// Scroll to current song.
}
Also used : Playlist(com.frostwire.alexandria.Playlist) MediaSource(com.frostwire.gui.player.MediaSource)

Example 13 with Playlist

use of com.frostwire.alexandria.Playlist in project frostwire by frostwire.

the class LibraryPlaylists method setupModel.

private void setupModel() {
    model = new DefaultListModel<>();
    newPlaylistCell = new LibraryPlaylistsListCell(I18n.tr("New Playlist"), I18n.tr("Creates a new Playlist"), GUIMediator.getThemeImage("playlist_plus"), null, null);
    Library library = LibraryMediator.getLibrary();
    selectedPlaylistAction = new SelectedPlaylistActionListener();
    Playlist starredPlaylist = LibraryMediator.getLibrary().getStarredPlaylist();
    starredPlaylistCell = new LibraryPlaylistsListCell(I18n.tr("Starred"), I18n.tr("Show all starred items"), GUIMediator.getThemeImage("star_on"), starredPlaylist, selectedPlaylistAction);
    model.addElement(newPlaylistCell);
    model.addElement(starredPlaylistCell);
    for (Playlist playlist : library.getPlaylists()) {
        LibraryPlaylistsListCell cell = new LibraryPlaylistsListCell(null, null, GUIMediator.getThemeImage("playlist"), playlist, selectedPlaylistAction);
        model.addElement(cell);
    }
}
Also used : Playlist(com.frostwire.alexandria.Playlist) Library(com.frostwire.alexandria.Library)

Example 14 with Playlist

use of com.frostwire.alexandria.Playlist in project frostwire by frostwire.

the class LibraryPlaylists method refreshSelection.

void refreshSelection() {
    LibraryPlaylistsListCell cell = (LibraryPlaylistsListCell) list.getSelectedValue();
    if (cell == null) {
        // handle special case
        if (model.getSize() == 2 && MediaPlayer.instance().getCurrentPlaylist() == null) {
            list.setSelectedIndex(1);
        }
        return;
    }
    Playlist playlist = cell.getPlaylist();
    if (playlist != null) {
        if (playlist.getId() == LibraryDatabase.STARRED_PLAYLIST_ID) {
            playlist = LibraryMediator.getLibrary().getStarredPlaylist();
        } else {
            playlist.refresh();
        }
        LibraryMediator.instance().updateTableItems(playlist);
        LibraryMediator.instance().getLibrarySearch().setStatus("");
    }
    executePendingRunnables();
}
Also used : Playlist(com.frostwire.alexandria.Playlist)

Example 15 with Playlist

use of com.frostwire.alexandria.Playlist in project frostwire by frostwire.

the class LibraryPlaylists method actionStartRename.

private void actionStartRename() {
    cancelEdit();
    int index = list.getSelectedIndex();
    Playlist playlist = ((LibraryPlaylistsListCell) list.getSelectedValue()).getPlaylist();
    if (playlist != null && playlist.getId() == LibraryDatabase.STARRED_PLAYLIST_ID) {
        return;
    }
    if (index != -1) {
        startEdit(index);
    }
}
Also used : Playlist(com.frostwire.alexandria.Playlist)

Aggregations

Playlist (com.frostwire.alexandria.Playlist)18 Library (com.frostwire.alexandria.Library)4 PlaylistItem (com.frostwire.alexandria.PlaylistItem)3 DialogFinishedListener (com.frostwire.gui.theme.DialogFinishedListener)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 SkinMenu (com.frostwire.gui.theme.SkinMenu)2 SkinMenuItem (com.frostwire.gui.theme.SkinMenuItem)2 File (java.io.File)2 AddToPlaylistAction (com.frostwire.gui.bittorrent.BTDownloadActions.AddToPlaylistAction)1 CreateNewPlaylistAction (com.frostwire.gui.bittorrent.BTDownloadActions.CreateNewPlaylistAction)1 MediaSource (com.frostwire.gui.player.MediaSource)1 DataFlavor (java.awt.datatransfer.DataFlavor)1 Transferable (java.awt.datatransfer.Transferable)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1