Search in sources :

Example 1 with FileDescriptorItem

use of com.frostwire.android.gui.adapters.menu.FileListAdapter.FileDescriptorItem 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)

Example 2 with FileDescriptorItem

use of com.frostwire.android.gui.adapters.menu.FileListAdapter.FileDescriptorItem in project frostwire by frostwire.

the class FileListAdapter method getListItemView.

private View getListItemView(int position, View view, ViewGroup parent) {
    view = super.getView(position, view, parent);
    final FileDescriptorItem item = getItem(position);
    if (item.fd.fileType == Constants.FILE_TYPE_AUDIO || item.fd.fileType == Constants.FILE_TYPE_RINGTONES) {
        initPlaybackStatusOverlayTouchFeedback(view, item);
    }
    ImageView thumbnailView = findView(view, R.id.view_my_files_thumbnail_list_item_browse_thumbnail_image_button);
    if (thumbnailView != null) {
        thumbnailView.setTag(item);
        thumbnailView.setOnClickListener(v -> {
            if (!selectAllMode) {
                if (getShowMenuOnClick()) {
                    if (showMenu(v)) {
                        return;
                    }
                }
                LOG.info("AbstractListAdapter.ViewOnClickListener.onClick()");
                onItemClicked(v);
            } else {
                onItemClicked(v);
            }
        });
    }
    return view;
}
Also used : ImageView(android.widget.ImageView) FileDescriptorItem(com.frostwire.android.gui.adapters.menu.FileListAdapter.FileDescriptorItem)

Example 3 with FileDescriptorItem

use of com.frostwire.android.gui.adapters.menu.FileListAdapter.FileDescriptorItem in project frostwire by frostwire.

the class FileListAdapter method deleteItem.

public void deleteItem(FileDescriptor fd) {
    FileDescriptorItem item = new FileDescriptorItem();
    item.fd = fd;
    super.deleteItem(item);
}
Also used : FileDescriptorItem(com.frostwire.android.gui.adapters.menu.FileListAdapter.FileDescriptorItem)

Example 4 with FileDescriptorItem

use of com.frostwire.android.gui.adapters.menu.FileListAdapter.FileDescriptorItem in project frostwire by frostwire.

the class FileListAdapter method checkSDStatus.

private void checkSDStatus() {
    Map<String, Boolean> sds = new HashMap<>();
    String privateSubPath = "Android" + File.separator + "data";
    File[] externalDirs = SystemUtils.getExternalFilesDirs(getContext());
    for (int i = 1; i < externalDirs.length; i++) {
        File path = externalDirs[i];
        String absolutePath = path.getAbsolutePath();
        boolean isSecondaryExternalStorageMounted = SystemUtils.isSecondaryExternalStorageMounted(path);
        sds.put(absolutePath, isSecondaryExternalStorageMounted);
        if (absolutePath.contains(privateSubPath)) {
            String prefix = absolutePath.substring(0, absolutePath.indexOf(privateSubPath) - 1);
            sds.put(prefix, isSecondaryExternalStorageMounted);
        }
    }
    if (sds.isEmpty()) {
        // yes, fast return (for now)
        return;
    }
    for (FileDescriptorItem item : getList()) {
        item.inSD = false;
        for (Entry<String, Boolean> e : sds.entrySet()) {
            if (item.fd.filePath.contains(e.getKey())) {
                item.inSD = true;
                item.mounted = e.getValue();
            }
        }
        item.exists = true;
    }
}
Also used : HashMap(java.util.HashMap) File(java.io.File) FileDescriptorItem(com.frostwire.android.gui.adapters.menu.FileListAdapter.FileDescriptorItem)

Example 5 with FileDescriptorItem

use of com.frostwire.android.gui.adapters.menu.FileListAdapter.FileDescriptorItem in project frostwire by frostwire.

the class FileListAdapter method getGridItemView.

private View getGridItemView(final int position, View view) {
    final FileDescriptorItem item = getItem(position);
    Context ctx = getContext();
    if (view == null && ctx != null) {
        // every list view item is wrapped in a generic container which has a hidden checkbox on the left hand side.
        view = View.inflate(ctx, R.layout.view_my_files_thumbnail_grid_item, null);
    }
    try {
        initCheckableGridImageView((RelativeLayout) view, item);
        // toggles checkbox mode.
        initTouchFeedback(view, item, v -> {
            // background image listener
            if (selectAllMode) {
                onItemClicked(v);
            } else {
                if (item.fd.fileType == Constants.FILE_TYPE_VIDEOS) {
                    LOG.info("getGridItemView() Background ImageView.onClick(), show the menu");
                    MenuAdapter menuAdapter = getMenuAdapter(v);
                    if (menuAdapter != null) {
                        new MenuBuilder(menuAdapter).show();
                    }
                } else {
                    localPlay(item.fd, v, position);
                }
            }
        }, this::onItemLongClicked, null);
        initPlaybackStatusOverlayTouchFeedback(view, item);
    } catch (Throwable e) {
        LOG.error("Fatal error getting view: " + e.getMessage(), e);
    }
    return view;
}
Also used : Context(android.content.Context) MenuAdapter(com.frostwire.android.gui.views.MenuAdapter) FileDescriptorItem(com.frostwire.android.gui.adapters.menu.FileListAdapter.FileDescriptorItem) MenuBuilder(com.frostwire.android.gui.views.MenuBuilder)

Aggregations

FileDescriptorItem (com.frostwire.android.gui.adapters.menu.FileListAdapter.FileDescriptorItem)6 Context (android.content.Context)2 FileDescriptor (com.frostwire.android.core.FileDescriptor)2 MenuAdapter (com.frostwire.android.gui.views.MenuAdapter)2 File (java.io.File)2 ArrayList (java.util.ArrayList)2 ImageView (android.widget.ImageView)1 MenuAction (com.frostwire.android.gui.views.MenuAction)1 MenuBuilder (com.frostwire.android.gui.views.MenuBuilder)1 HashMap (java.util.HashMap)1