Search in sources :

Example 1 with MenuBuilder

use of com.frostwire.android.gui.views.MenuBuilder 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)

Example 2 with MenuBuilder

use of com.frostwire.android.gui.views.MenuBuilder in project frostwire by frostwire.

the class FileListAdapter method localPlay.

private void localPlay(FileDescriptor fd, View view, int position) {
    if (fd == null) {
        return;
    }
    onLocalPlay();
    Context ctx = getContext();
    if (fd.mime != null && fd.mime.contains("audio")) {
        if (fd.equals(Engine.instance().getMediaPlayer().getCurrentFD(getContext()))) {
            Engine.instance().getMediaPlayer().stop();
        } else {
            try {
                UIUtils.playEphemeralPlaylist(ctx, fd);
                UXStats.instance().log(UXAction.LIBRARY_PLAY_AUDIO_FROM_FILE);
            } catch (RuntimeException re) {
                re.printStackTrace();
                UIUtils.showShortMessage(ctx, R.string.media_player_failed);
            }
        }
        notifyDataSetChanged();
    } else {
        if (fd.filePath != null && fd.mime != null) {
            // special treatment of ringtones
            if (fd.fileType == Constants.FILE_TYPE_RINGTONES) {
                playRingtone(fd);
            } else if (fd.fileType == Constants.FILE_TYPE_PICTURES && ctx instanceof MainActivity) {
                Intent intent = new Intent(ctx, ImageViewerActivity.class);
                intent.putExtra(ImageViewerFragment.EXTRA_FILE_DESCRIPTOR_BUNDLE, fd.toBundle());
                intent.putExtra(ImageViewerFragment.EXTRA_ADAPTER_FILE_OFFSET, position);
                ctx.startActivity(intent);
            } else if ("application/x-bittorrent".equals(fd.mime)) {
                // torrents are often DOCUMENT typed
                TransferManager.instance().downloadTorrent(UIUtils.getFileUri(ctx, fd.filePath, false).toString());
                UIUtils.showTransfersOnDownloadStart(ctx);
            } else {
                UIUtils.openFile(ctx, fd.filePath, fd.mime, true);
            }
        } else {
            // it will automatically remove the 'Open' entry.
            MenuAdapter menuAdapter = getMenuAdapter(view);
            if (menuAdapter != null) {
                new MenuBuilder(menuAdapter).show();
                UIUtils.showShortMessage(ctx, R.string.cant_open_file);
            }
        }
    }
}
Also used : Context(android.content.Context) ImageViewerActivity(com.frostwire.android.gui.activities.ImageViewerActivity) MenuAdapter(com.frostwire.android.gui.views.MenuAdapter) Intent(android.content.Intent) MainActivity(com.frostwire.android.gui.activities.MainActivity) MenuBuilder(com.frostwire.android.gui.views.MenuBuilder)

Example 3 with MenuBuilder

use of com.frostwire.android.gui.views.MenuBuilder in project frostwire by frostwire.

the class AddToPlaylistMenuAction method onClick.

@Override
public void onClick(Context context) {
    MenuBuilder menuBuilder = new MenuBuilder(new MenuAdapter(getContext(), R.string.add_to_playlist, getMenuActions()));
    menuBuilder.show();
}
Also used : MenuAdapter(com.frostwire.android.gui.views.MenuAdapter) MenuBuilder(com.frostwire.android.gui.views.MenuBuilder)

Aggregations

MenuAdapter (com.frostwire.android.gui.views.MenuAdapter)3 MenuBuilder (com.frostwire.android.gui.views.MenuBuilder)3 Context (android.content.Context)2 Intent (android.content.Intent)1 ImageViewerActivity (com.frostwire.android.gui.activities.ImageViewerActivity)1 MainActivity (com.frostwire.android.gui.activities.MainActivity)1 FileDescriptorItem (com.frostwire.android.gui.adapters.menu.FileListAdapter.FileDescriptorItem)1