Search in sources :

Example 1 with CancelMenuAction

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

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

the class TransferListAdapter method populateBittorrentDownloadMenuActions.

private String populateBittorrentDownloadMenuActions(BittorrentDownload bittorrentDownload, List<MenuAction> items) {
    String title;
    title = bittorrentDownload.getDisplayName();
    // If it's a torrent download with a single file, we should be able to open it.
    if (bittorrentDownload.isComplete() && bittorrentDownload.getItems().size() > 0) {
        TransferItem transferItem = bittorrentDownload.getItems().get(0);
        String path = transferItem.getFile().getAbsolutePath();
        String mimeType = UIUtils.getMimeType(path);
        items.add(new OpenMenuAction(contextRef.get(), path, mimeType));
    }
    if (!bittorrentDownload.isComplete() && !bittorrentDownload.isSeeding()) {
        if (!bittorrentDownload.isPaused()) {
            items.add(new PauseDownloadMenuAction(contextRef.get(), bittorrentDownload));
        } else {
            boolean wifiIsUp = NetworkManager.instance().isDataWIFIUp();
            boolean bittorrentOnMobileData = !ConfigurationManager.instance().getBoolean(Constants.PREF_KEY_NETWORK_USE_WIFI_ONLY);
            if (wifiIsUp || bittorrentOnMobileData) {
                if (!bittorrentDownload.isComplete()) {
                    items.add(new ResumeDownloadMenuAction(contextRef.get(), bittorrentDownload, R.string.resume_torrent_menu_action));
                }
            }
        }
    }
    if (bittorrentDownload.getState() == TransferState.FINISHED) {
        items.add(new SeedAction(contextRef.get(), bittorrentDownload));
    }
    if (bittorrentDownload.getState() == TransferState.SEEDING) {
        items.add(new StopSeedingAction(contextRef.get(), bittorrentDownload));
    }
    items.add(new CancelMenuAction(contextRef.get(), bittorrentDownload, !bittorrentDownload.isComplete()));
    items.add(new CopyToClipboardMenuAction(contextRef.get(), R.drawable.contextmenu_icon_magnet, R.string.transfers_context_menu_copy_magnet, R.string.transfers_context_menu_copy_magnet_copied, bittorrentDownload.magnetUri() + BTEngine.getInstance().magnetPeers()));
    items.add(new CopyToClipboardMenuAction(contextRef.get(), R.drawable.contextmenu_icon_copy, R.string.transfers_context_menu_copy_infohash, R.string.transfers_context_menu_copy_infohash_copied, bittorrentDownload.getInfoHash()));
    if (bittorrentDownload.isComplete()) {
        // Remove Torrent and Data action.
        items.add(new CancelMenuAction(contextRef.get(), bittorrentDownload, true, true));
    }
    if (bittorrentDownload instanceof UIBittorrentDownload) {
        UIBittorrentDownload uidl = (UIBittorrentDownload) bittorrentDownload;
        if (uidl.hasPaymentOptions()) {
            PaymentOptions po = uidl.getPaymentOptions();
            if (po.bitcoin != null) {
                items.add(new SendBitcoinTipAction(contextRef.get(), po.bitcoin));
            }
            if (po.paypalUrl != null) {
                items.add(new SendFiatTipAction(contextRef.get(), po.paypalUrl));
            }
            if (po.bitcoin != null) {
                items.add(new SendBitcoinTipAction(contextRef.get(), po.bitcoin));
            }
        }
        if (bittorrentDownload.getInfoHash() != null && !"".equals(bittorrentDownload.getInfoHash())) {
            items.add(new TransferDetailsMenuAction(contextRef.get(), R.string.show_torrent_details, bittorrentDownload.getInfoHash()));
        }
    }
    return title;
}
Also used : CopyToClipboardMenuAction(com.frostwire.android.gui.adapters.menu.CopyToClipboardMenuAction) UIBittorrentDownload(com.frostwire.android.gui.transfers.UIBittorrentDownload) PaymentOptions(com.frostwire.bittorrent.PaymentOptions) SeedAction(com.frostwire.android.gui.adapters.menu.SeedAction) CancelMenuAction(com.frostwire.android.gui.adapters.menu.CancelMenuAction) TransferDetailsMenuAction(com.frostwire.android.gui.adapters.menu.TransferDetailsMenuAction) SendFiatTipAction(com.frostwire.android.gui.adapters.menu.SendFiatTipAction) OpenMenuAction(com.frostwire.android.gui.adapters.menu.OpenMenuAction) PauseDownloadMenuAction(com.frostwire.android.gui.adapters.menu.PauseDownloadMenuAction) SendBitcoinTipAction(com.frostwire.android.gui.adapters.menu.SendBitcoinTipAction) ResumeDownloadMenuAction(com.frostwire.android.gui.adapters.menu.ResumeDownloadMenuAction) TransferItem(com.frostwire.transfers.TransferItem) StopSeedingAction(com.frostwire.android.gui.adapters.menu.StopSeedingAction)

Example 3 with CancelMenuAction

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

the class TransferDetailFragment method onOptionsItemSelected.

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    Activity activity = getActivity();
    int itemId = item.getItemId();
    PaymentOptions paymentOptions = uiBittorrentDownload.getPaymentOptions();
    switch(itemId) {
        // TODO: Add a force re-announce action
        case R.id.fragment_transfer_detail_menu_delete:
            // TODO: add an action listener and pass to dialog
            new CancelMenuAction(activity, uiBittorrentDownload, true, true).onClick(activity);
            break;
        case R.id.fragment_transfer_detail_menu_pause_resume_seed:
            if (isPausable()) {
                new PauseDownloadMenuAction(activity, uiBittorrentDownload).onClick(activity);
            } else if (isSeedable()) {
                new SeedAction(activity, uiBittorrentDownload).onClick(activity);
            } else if (isResumable()) {
                new ResumeDownloadMenuAction(activity, uiBittorrentDownload, R.string.resume_torrent_menu_action).onClick(activity);
            }
            updatePauseResumeSeedMenuAction();
            break;
        case R.id.fragment_transfer_detail_menu_clear:
            new CancelMenuAction(activity, uiBittorrentDownload, false, false).onClick(activity);
            break;
        case R.id.fragment_transfer_detail_menu_copy_magnet:
            new CopyToClipboardMenuAction(activity, R.drawable.contextmenu_icon_magnet, R.string.transfers_context_menu_copy_magnet, R.string.transfers_context_menu_copy_magnet_copied, uiBittorrentDownload.magnetUri() + BTEngine.getInstance().magnetPeers()).onClick(activity);
            break;
        case R.id.fragment_transfer_detail_menu_copy_infohash:
            new CopyToClipboardMenuAction(activity, R.drawable.contextmenu_icon_copy, R.string.transfers_context_menu_copy_infohash, R.string.transfers_context_menu_copy_infohash_copied, uiBittorrentDownload.getInfoHash()).onClick(activity);
            break;
        case R.id.fragment_transfer_detail_menu_donate_fiat:
            new SendFiatTipAction(activity, paymentOptions.paypalUrl).onClick(activity);
            break;
        case R.id.fragment_transfer_detail_menu_donate_bitcoin:
            new SendBitcoinTipAction(activity, paymentOptions.bitcoin).onClick(activity);
            break;
    }
    return super.onOptionsItemSelected(item);
}
Also used : CancelMenuAction(com.frostwire.android.gui.adapters.menu.CancelMenuAction) CopyToClipboardMenuAction(com.frostwire.android.gui.adapters.menu.CopyToClipboardMenuAction) SendFiatTipAction(com.frostwire.android.gui.adapters.menu.SendFiatTipAction) Activity(android.app.Activity) PauseDownloadMenuAction(com.frostwire.android.gui.adapters.menu.PauseDownloadMenuAction) SendBitcoinTipAction(com.frostwire.android.gui.adapters.menu.SendBitcoinTipAction) PaymentOptions(com.frostwire.bittorrent.PaymentOptions) ResumeDownloadMenuAction(com.frostwire.android.gui.adapters.menu.ResumeDownloadMenuAction) SeedAction(com.frostwire.android.gui.adapters.menu.SeedAction)

Aggregations

CancelMenuAction (com.frostwire.android.gui.adapters.menu.CancelMenuAction)3 SeedAction (com.frostwire.android.gui.adapters.menu.SeedAction)3 CopyToClipboardMenuAction (com.frostwire.android.gui.adapters.menu.CopyToClipboardMenuAction)2 OpenMenuAction (com.frostwire.android.gui.adapters.menu.OpenMenuAction)2 PauseDownloadMenuAction (com.frostwire.android.gui.adapters.menu.PauseDownloadMenuAction)2 ResumeDownloadMenuAction (com.frostwire.android.gui.adapters.menu.ResumeDownloadMenuAction)2 SendBitcoinTipAction (com.frostwire.android.gui.adapters.menu.SendBitcoinTipAction)2 SendFiatTipAction (com.frostwire.android.gui.adapters.menu.SendFiatTipAction)2 PaymentOptions (com.frostwire.bittorrent.PaymentOptions)2 Activity (android.app.Activity)1 FileDescriptor (com.frostwire.android.core.FileDescriptor)1 StopSeedingAction (com.frostwire.android.gui.adapters.menu.StopSeedingAction)1 TransferDetailsMenuAction (com.frostwire.android.gui.adapters.menu.TransferDetailsMenuAction)1 UIBittorrentDownload (com.frostwire.android.gui.transfers.UIBittorrentDownload)1 Transfer (com.frostwire.transfers.Transfer)1 TransferItem (com.frostwire.transfers.TransferItem)1 File (java.io.File)1