Search in sources :

Example 1 with TransferItem

use of com.frostwire.transfers.TransferItem 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 2 with TransferItem

use of com.frostwire.transfers.TransferItem in project frostwire by frostwire.

the class Transfers method getSkippedFiles.

public static Set<File> getSkippedFiles(BTDownload dl) {
    Set<File> set = new HashSet<>();
    List<TransferItem> items = dl.getItems();
    for (TransferItem item : items) {
        try {
            if (item.isSkipped()) {
                set.add(item.getFile());
            }
        } catch (Throwable e) {
            LOG.error("Error getting file information", e);
        }
    }
    return set;
}
Also used : File(java.io.File) TransferItem(com.frostwire.transfers.TransferItem) HashSet(java.util.HashSet)

Example 3 with TransferItem

use of com.frostwire.transfers.TransferItem in project frostwire by frostwire.

the class UIBittorrentDownload method deleteFilesFromContentResolver.

private void deleteFilesFromContentResolver(Context context, boolean deleteTorrent) {
    final List<TransferItem> items = getItems();
    final ContentResolver cr = context.getContentResolver();
    Librarian librarian = Librarian.instance();
    if (librarian == null) {
        return;
    }
    for (TransferItem item : items) {
        final List<FileDescriptor> fileDescriptors = librarian.getFiles(context, item.getFile().getAbsolutePath(), true);
        for (FileDescriptor fd : fileDescriptors) {
            File file = new File(fd.filePath);
            if (file.isFile()) {
                try {
                    TableFetcher fetcher = TableFetchers.getFetcher(fd.fileType);
                    if (fetcher != null) {
                        cr.delete(fetcher.getContentUri(), MediaStore.MediaColumns._ID + " = " + fd.id, null);
                    }
                } catch (Throwable e) {
                    LOG.error("Failed to delete file from media store. (" + fd.filePath + ")", e);
                }
            }
        }
    }
    if (deleteTorrent) {
        File torrent = dl.getTorrentFile();
        if (torrent != null) {
            final List<FileDescriptor> fds = librarian.getFiles(context, Constants.FILE_TYPE_TORRENTS, torrent.getAbsolutePath(), true);
            librarian.deleteFiles(context, Constants.FILE_TYPE_TORRENTS, fds);
        }
    }
}
Also used : TableFetcher(com.frostwire.android.core.providers.TableFetcher) Librarian(com.frostwire.android.gui.Librarian) TransferItem(com.frostwire.transfers.TransferItem) File(java.io.File) FileDescriptor(com.frostwire.android.core.FileDescriptor) ContentResolver(android.content.ContentResolver)

Example 4 with TransferItem

use of com.frostwire.transfers.TransferItem in project frostwire by frostwire.

the class BittorrentDownload method calculateSize.

private long calculateSize(BTDownload dl) {
    long size = dl.getSize();
    boolean partial = dl.isPartial();
    if (partial) {
        List<TransferItem> items = dl.getItems();
        long totalSize = 0;
        for (TransferItem item : items) {
            if (!item.isSkipped()) {
                totalSize += item.getSize();
            }
        }
        if (totalSize > 0) {
            size = totalSize;
        }
    }
    return size;
}
Also used : TransferItem(com.frostwire.transfers.TransferItem)

Example 5 with TransferItem

use of com.frostwire.transfers.TransferItem in project frostwire by frostwire.

the class TorrentUtil method getDownloadManager.

public static BittorrentDownload getDownloadManager(File f) {
    List<BTDownload> downloads = BTDownloadMediator.instance().getDownloads();
    for (BTDownload d : downloads) {
        if (d instanceof BittorrentDownload) {
            BittorrentDownload bt = (BittorrentDownload) d;
            com.frostwire.bittorrent.BTDownload dl = bt.getDl();
            List<TransferItem> items = dl.getItems();
            for (TransferItem item : items) {
                if (f.equals(item.getFile())) {
                    return bt;
                }
            }
        }
    }
    return null;
}
Also used : TransferItem(com.frostwire.transfers.TransferItem)

Aggregations

TransferItem (com.frostwire.transfers.TransferItem)7 TorrentInfo (com.frostwire.jlibtorrent.TorrentInfo)2 File (java.io.File)2 ContentResolver (android.content.ContentResolver)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 FileDescriptor (com.frostwire.android.core.FileDescriptor)1 TableFetcher (com.frostwire.android.core.providers.TableFetcher)1 Librarian (com.frostwire.android.gui.Librarian)1 CancelMenuAction (com.frostwire.android.gui.adapters.menu.CancelMenuAction)1 CopyToClipboardMenuAction (com.frostwire.android.gui.adapters.menu.CopyToClipboardMenuAction)1 OpenMenuAction (com.frostwire.android.gui.adapters.menu.OpenMenuAction)1 PauseDownloadMenuAction (com.frostwire.android.gui.adapters.menu.PauseDownloadMenuAction)1 ResumeDownloadMenuAction (com.frostwire.android.gui.adapters.menu.ResumeDownloadMenuAction)1 SeedAction (com.frostwire.android.gui.adapters.menu.SeedAction)1 SendBitcoinTipAction (com.frostwire.android.gui.adapters.menu.SendBitcoinTipAction)1 SendFiatTipAction (com.frostwire.android.gui.adapters.menu.SendFiatTipAction)1 StopSeedingAction (com.frostwire.android.gui.adapters.menu.StopSeedingAction)1 TransferDetailsMenuAction (com.frostwire.android.gui.adapters.menu.TransferDetailsMenuAction)1