use of com.frostwire.alexandria.PlaylistItem in project frostwire by frostwire.
the class LibraryPlaylistsTransferHandler method importData.
@Override
public boolean importData(TransferSupport support) {
if (!canImport(support)) {
return false;
}
DropLocation location = support.getDropLocation();
int index = list.locationToIndex(location.getDropPoint());
if (index != -1) {
// depending on the mouse position detect which playlist item the drop was done
Playlist playlist = getTargetPlaylist(location, index);
if (playlist == null) {
if (createNewPlaylist(support)) {
return false;
}
} else {
try {
Transferable transferable = support.getTransferable();
final DataFlavor[] dataFlavors = transferable.getTransferDataFlavors();
if (DNDUtils.contains(dataFlavors, LibraryPlaylistsTableTransferable.ITEM_ARRAY)) {
PlaylistItem[] playlistItems = LibraryUtils.convertToPlaylistItems((LibraryPlaylistsTableTransferable.PlaylistItemContainer) transferable.getTransferData(LibraryPlaylistsTableTransferable.ITEM_ARRAY));
LibraryUtils.asyncAddToPlaylist(playlist, playlistItems);
} else {
File[] files = DNDUtils.getFiles(support.getTransferable());
if (files.length == 1 && files[0].getAbsolutePath().endsWith(".m3u")) {
LibraryUtils.asyncAddToPlaylist(playlist, files[0]);
} else {
// importing a regular file
LibraryUtils.asyncAddToPlaylist(playlist, files);
}
}
} catch (Throwable e) {
return false;
}
}
} else {
return false;
}
return false;
}
use of com.frostwire.alexandria.PlaylistItem in project frostwire by frostwire.
the class LibraryUtils method convertToPlaylistItems.
static PlaylistItem[] convertToPlaylistItems(LibraryPlaylistsTableTransferable.Item[] items) {
List<PlaylistItem> playlistItems = new ArrayList<>(items.length);
for (LibraryPlaylistsTableTransferable.Item item : items) {
PlaylistItem playlistItem = new PlaylistItem(null, item.id, item.filePath, item.fileName, item.fileSize, item.fileExtension, item.trackTitle, item.trackDurationInSecs, item.trackArtist, item.trackAlbum, item.coverArtPath, item.trackBitrate, item.trackComment, item.trackGenre, item.trackNumber, item.trackYear, item.starred);
playlistItems.add(playlistItem);
}
return playlistItems.toArray(new PlaylistItem[0]);
}
use of com.frostwire.alexandria.PlaylistItem in project frostwire by frostwire.
the class LibraryUtils method movePlaylistItemsToIndex.
static void movePlaylistItemsToIndex(Playlist playlist, int[] selectedIndexes, int index) {
List<PlaylistItem> items = playlist.getItems();
int targetIndex = index;
// first, order items in list correctly
for (int i = 0; i < selectedIndexes.length; i++) {
int sourceIndex = selectedIndexes[i];
if (sourceIndex != targetIndex) {
items.add(targetIndex, items.get(sourceIndex));
items.remove(sourceIndex < targetIndex ? sourceIndex : sourceIndex + 1);
// adjust remaining selected indexes if insertion point is greater than their location
for (int j = i + 1; j < selectedIndexes.length; j++) {
if (targetIndex > selectedIndexes[j]) {
selectedIndexes[j]--;
}
}
// update insertion point
if (sourceIndex > targetIndex) {
targetIndex++;
}
}
}
// second, generate new indexes based list order
for (int i = 0; i < items.size(); i++) {
PlaylistItem item = items.get(i);
// set index (1-based)
item.setSortIndexByTrackNumber(i + 1);
item.save();
}
// initiate UI refresh
GUIMediator.safeInvokeLater(new Runnable() {
public void run() {
LibraryMediator.instance().getLibraryPlaylists().refreshSelection();
}
});
}
use of com.frostwire.alexandria.PlaylistItem in project frostwire by frostwire.
the class LibraryUtils method getPlaylistDurationInDDHHMMSS.
static String getPlaylistDurationInDDHHMMSS(Playlist playlist) {
List<PlaylistItem> items = playlist.getItems();
float totalSecs = 0;
for (PlaylistItem item : items) {
totalSecs += item.getTrackDurationInSecs();
}
return getSecondsInDDHHMMSS((int) totalSecs);
}
use of com.frostwire.alexandria.PlaylistItem in project frostwire by frostwire.
the class LibraryUtils method addPlaylistItem.
private static void addPlaylistItem(Playlist playlist, File file, boolean starred, int index) {
try {
LibraryMediator.instance().getLibrarySearch().pushStatus(I18n.tr("Importing") + " " + file.getName());
TagsData mt = new TagsReader(file).parse();
PlaylistItem item = playlist.newItem(file.getAbsolutePath(), file.getName(), file.length(), FilenameUtils.getExtension(file.getName()), mt.getTitle(), mt.getDuration(), mt.getArtist(), mt.getAlbum(), // TODO: cover art path
"", mt.getBitrate(), mt.getComment(), mt.getGenre(), mt.getTrack(), mt.getYear(), starred || playlist.isStarred());
List<PlaylistItem> items = playlist.getItems();
if (index != -1 && index < items.size()) {
// insert item
items.add(index, item);
// update all sort indexes from insertion point onwards
for (int i = index; i < items.size(); i++) {
PlaylistItem curItem = items.get(i);
curItem.setSortIndexByTrackNumber(i + 1);
curItem.save();
}
} else {
items.add(item);
// fall back index would be it being the last track.
item.setSortIndexByTrackNumber(items.size());
item.save(item.isStarred());
}
if (isPlaylistSelected(playlist)) {
// refresh UI
LibraryMediator.instance().getLibraryPlaylists().refreshSelection();
}
} finally {
LibraryMediator.instance().getLibrarySearch().revertStatus();
}
}
Aggregations