use of com.frostwire.android.core.FileDescriptor in project frostwire by frostwire.
the class TransferListAdapter method populateCloudDownloadMenuActions.
private String populateCloudDownloadMenuActions(Object tag, List<MenuAction> items) {
Transfer download = (Transfer) tag;
String title = download.getDisplayName();
boolean errored = download.getState().name().contains("ERROR");
boolean finishedSuccessfully = !errored && download.isComplete() && isCloudDownload(tag);
if (finishedSuccessfully && Ref.alive(contextRef)) {
final List<FileDescriptor> files = Librarian.instance().getFiles(contextRef.get(), download.getSavePath().getAbsolutePath(), true);
boolean singleFile = files != null && files.size() == 1;
if (singleFile && !AndroidPlatform.saf(new File(files.get(0).filePath))) {
items.add(new SeedAction(contextRef.get(), files.get(0), download));
}
if (singleFile && files.get(0).fileType == Constants.FILE_TYPE_PICTURES) {
items.add(new OpenMenuAction(contextRef.get(), download.getDisplayName(), files.get(0)));
} else {
items.add(new OpenMenuAction(contextRef.get(), download.getDisplayName(), download.getSavePath().getAbsolutePath(), extractMime(download)));
}
}
if (Ref.alive(contextRef)) {
items.add(new CancelMenuAction(contextRef.get(), download, !finishedSuccessfully));
}
return title;
}
use of com.frostwire.android.core.FileDescriptor in project frostwire by frostwire.
the class Librarian method createEphemeralPlaylist.
public EphemeralPlaylist createEphemeralPlaylist(final Context context, FileDescriptor fd) {
List<FileDescriptor> fds = getFiles(context, Constants.FILE_TYPE_AUDIO, FilenameUtils.getPath(fd.filePath), false);
if (fds.size() == 0) {
// just in case
Log.w(TAG, "Logic error creating ephemeral playlist");
fds.add(fd);
}
EphemeralPlaylist playlist = new EphemeralPlaylist(fds);
playlist.setNextItem(new PlaylistItem(fd));
return playlist;
}
use of com.frostwire.android.core.FileDescriptor in project frostwire by frostwire.
the class MyFilesFragment method updateFiles.
private void updateFiles(Object[] data) {
if (data == null || data.length < 2 || data[1] == null) {
LOG.warn("Something wrong, data is null");
return;
}
try {
byte fileType = (Byte) data[0];
@SuppressWarnings("unchecked") List<FileDescriptor> items = (List<FileDescriptor>) data[1];
adapter = new FileListAdapter(getActivity(), items, fileType, selectAllModeOn) {
@Override
protected void onLocalPlay() {
if (adapter != null) {
saveListViewVisiblePosition(adapter.getFileType());
}
}
@Override
protected void onItemChecked(View v, boolean isChecked) {
super.onItemChecked(v, isChecked);
autoCheckUnCheckSelectAllCheckbox();
selectionModeCallback.onItemChecked(getActivity(), adapter.getCheckedCount());
}
@Override
protected boolean onItemLongClicked(View v) {
return onFileItemLongClicked(v);
}
@Override
protected void onItemClicked(View v) {
onFileItemClicked(v);
}
};
adapter.setCheckboxesVisibility(selectAllModeOn);
list.setNumColumns(adapter.getNumColumns());
restorePreviouslyChecked();
if (previousFilter != null) {
performFilter(previousFilter);
} else {
updateAdapter();
}
} catch (Throwable e) {
LOG.error("Error updating files in list", e);
}
}
use of com.frostwire.android.core.FileDescriptor in project frostwire by frostwire.
the class DeleteFileMenuAction method deleteFilesTask.
private static void deleteFilesTask(FileListAdapter fileListAdapter, List<FileDescriptor> files) {
byte fileType = fileListAdapter.getFileType();
Librarian.instance().deleteFiles(fileListAdapter.getContext(), fileType, new ArrayList<>(files));
int size = files.size();
for (int i = 0; i < size; i++) {
try {
FileDescriptor fd = files.get(i);
// only notifies if in main thread
fileListAdapter.deleteItem(fd);
} catch (Throwable ignored) {
}
}
}
use of com.frostwire.android.core.FileDescriptor in project frostwire by frostwire.
the class FileListAdapter method getMenuAdapter.
@Override
protected MenuAdapter getMenuAdapter(View view) {
Context context = getContext();
List<MenuAction> items = new ArrayList<>();
// due to long click generic handle
FileDescriptor fd = null;
if (view.getTag() instanceof FileDescriptorItem) {
FileDescriptorItem item = (FileDescriptorItem) view.getTag();
fd = item.fd;
} else if (view.getTag() instanceof FileDescriptor) {
fd = (FileDescriptor) view.getTag();
}
if (checkIfNotExists(fd)) {
notifyDataSetInvalidated();
return null;
}
List<FileDescriptor> checked = convertItems(getChecked());
boolean canOpenFile = fd.mime != null && (fd.mime.contains("audio") || fd.mime.contains("bittorrent") || fd.filePath != null);
int numChecked = checked.size();
boolean showSingleOptions = showSingleOptions(checked, fd);
if (showSingleOptions) {
if (!AndroidPlatform.saf(new File(fd.filePath)) && fd.fileType != Constants.FILE_TYPE_RINGTONES) {
items.add(new SeedAction(context, fd));
}
if (canOpenFile) {
items.add(new OpenMenuAction(context, fd, getViewPosition(view)));
}
items.add(new FileInformationAction(context, fd));
if ((fd.fileType == Constants.FILE_TYPE_AUDIO && numChecked <= 1) || fd.fileType == Constants.FILE_TYPE_RINGTONES) {
items.add(new SetAsRingtoneMenuAction(context, fd));
}
if (fd.fileType == Constants.FILE_TYPE_PICTURES && numChecked <= 1) {
items.add(new SetAsWallpaperMenuAction(context, fd));
}
if (fd.fileType != Constants.FILE_TYPE_APPLICATIONS && numChecked <= 1 && fd.fileType != Constants.FILE_TYPE_RINGTONES) {
items.add(new RenameFileMenuAction(context, this, fd));
}
if (fd.mime != null && fd.mime.equals(Constants.MIME_TYPE_BITTORRENT) && numChecked <= 1) {
items.add(new CopyMagnetMenuAction(context, R.drawable.contextmenu_icon_magnet, R.string.transfers_context_menu_copy_magnet, R.string.transfers_context_menu_copy_magnet_copied, fd.filePath));
items.add(new CopyMagnetMenuAction(context, R.drawable.contextmenu_icon_copy, R.string.transfers_context_menu_copy_infohash, R.string.transfers_context_menu_copy_infohash_copied, fd.filePath, false));
}
}
List<FileDescriptor> list = checked;
if (list.size() == 0) {
list = Collections.singletonList(fd);
}
if (fd.fileType == Constants.FILE_TYPE_AUDIO) {
items.add(new AddToPlaylistMenuAction(context, list));
}
if (fd.fileType != Constants.FILE_TYPE_APPLICATIONS && fd.fileType != Constants.FILE_TYPE_RINGTONES) {
items.add(new SendFileMenuAction(context, fd));
items.add(new DeleteFileMenuAction(context, this, list));
}
return new MenuAdapter(context, fd.title, items);
}
Aggregations