Search in sources :

Example 1 with FileDescriptor

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;
}
Also used : CancelMenuAction(com.frostwire.android.gui.adapters.menu.CancelMenuAction) Transfer(com.frostwire.transfers.Transfer) OpenMenuAction(com.frostwire.android.gui.adapters.menu.OpenMenuAction) File(java.io.File) FileDescriptor(com.frostwire.android.core.FileDescriptor) SeedAction(com.frostwire.android.gui.adapters.menu.SeedAction)

Example 2 with FileDescriptor

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;
}
Also used : EphemeralPlaylist(com.frostwire.android.core.player.EphemeralPlaylist) FileDescriptor(com.frostwire.android.core.FileDescriptor) PlaylistItem(com.frostwire.android.core.player.PlaylistItem)

Example 3 with FileDescriptor

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);
    }
}
Also used : FileListAdapter(com.frostwire.android.gui.adapters.menu.FileListAdapter) List(java.util.List) ArrayList(java.util.ArrayList) GridView(android.widget.GridView) SearchView(android.support.v7.widget.SearchView) View(android.view.View) TextView(android.widget.TextView) FileDescriptor(com.frostwire.android.core.FileDescriptor)

Example 4 with FileDescriptor

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) {
        }
    }
}
Also used : FileDescriptor(com.frostwire.android.core.FileDescriptor)

Example 5 with FileDescriptor

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);
}
Also used : Context(android.content.Context) ArrayList(java.util.ArrayList) MenuAdapter(com.frostwire.android.gui.views.MenuAdapter) FileDescriptorItem(com.frostwire.android.gui.adapters.menu.FileListAdapter.FileDescriptorItem) FileDescriptor(com.frostwire.android.core.FileDescriptor) MenuAction(com.frostwire.android.gui.views.MenuAction) File(java.io.File)

Aggregations

FileDescriptor (com.frostwire.android.core.FileDescriptor)15 ArrayList (java.util.ArrayList)6 File (java.io.File)4 ContentResolver (android.content.ContentResolver)3 TextView (android.widget.TextView)3 Point (android.graphics.Point)2 Bundle (android.os.Bundle)2 ImageButton (android.widget.ImageButton)2 TableFetcher (com.frostwire.android.core.providers.TableFetcher)2 Librarian (com.frostwire.android.gui.Librarian)2 FileDescriptorItem (com.frostwire.android.gui.adapters.menu.FileListAdapter.FileDescriptorItem)2 MediaPlaybackStatusOverlayView (com.frostwire.android.gui.views.MediaPlaybackStatusOverlayView)2 Activity (android.app.Activity)1 Context (android.content.Context)1 Intent (android.content.Intent)1 Cursor (android.database.Cursor)1 Uri (android.net.Uri)1 SearchView (android.support.v7.widget.SearchView)1 View (android.view.View)1 GridView (android.widget.GridView)1