Search in sources :

Example 1 with Transfer

use of com.frostwire.transfers.Transfer 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 Transfer

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

the class TransfersFragment method updateMenuItemVisibility.

private void updateMenuItemVisibility(Menu menu) {
    TransferManager tm = TransferManager.instance();
    boolean bittorrentDisconnected = tm.isBittorrentDisconnected();
    final List<Transfer> transfers = tm.getTransfers();
    if (transfers != null && transfers.size() > 0) {
        if (someTransfersComplete(transfers)) {
            menu.findItem(R.id.fragment_transfers_menu_clear_all).setVisible(true);
        }
        if (!bittorrentDisconnected) {
            if (someTransfersActive(transfers)) {
                menu.findItem(R.id.fragment_transfers_menu_pause_stop_all).setVisible(true);
            }
        }
        // Preferences > Connectivity is disconnected.
        if (someTransfersInactive(transfers)) {
            menu.findItem(R.id.fragment_transfers_menu_resume_all).setVisible(true);
        }
        if (!someTransfersSeeding(transfers) && someTransfersComplete(transfers)) {
            menu.findItem(R.id.fragment_transfers_menu_seed_all).setVisible(true);
        }
        if (someTransfersSeeding(transfers) && someTransfersComplete(transfers)) {
            menu.findItem(R.id.fragment_transfers_menu_seed_all).setVisible(true);
            menu.findItem(R.id.fragment_transfers_menu_stop_seeding_all).setVisible(true);
        }
        if (someTransfersSeeding(transfers)) {
            menu.findItem(R.id.fragment_transfers_menu_stop_seeding_all).setVisible(true);
        }
    }
}
Also used : TransferManager(com.frostwire.android.gui.transfers.TransferManager) Transfer(com.frostwire.transfers.Transfer)

Example 3 with Transfer

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

the class TransferManager method stopHttpTransfers.

/**
 * Stops all HttpDownloads (Cloud and Wi-Fi)
 */
public void stopHttpTransfers() {
    List<Transfer> transfers = new ArrayList<>();
    transfers.addAll(httpDownloads);
    for (Transfer t : transfers) {
        if (t != null && !t.isComplete() && t.isDownloading()) {
            t.remove(false);
        }
    }
}
Also used : Transfer(com.frostwire.transfers.Transfer) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

Example 4 with Transfer

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

the class TransferManager method getDownloadsBandwidth.

public long getDownloadsBandwidth() {
    if (BTEngine.ctx == null) {
        // too early
        return 0;
    }
    long torrentDownloadsBandwidth = BTEngine.getInstance().downloadRate();
    long peerDownloadsBandwidth = 0;
    for (Transfer d : httpDownloads) {
        peerDownloadsBandwidth += d.getDownloadSpeed();
    }
    return torrentDownloadsBandwidth + peerDownloadsBandwidth;
}
Also used : Transfer(com.frostwire.transfers.Transfer)

Example 5 with Transfer

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

the class TransfersFragment method setupAdapter.

private void setupAdapter(Context context) {
    if (context == null) {
        return;
    }
    List<Transfer> transfers = filter(TransferManager.instance().getTransfers(), selectedStatus);
    Collections.sort(transfers, transferComparator);
    adapter = new TransferListAdapter(context, transfers);
    list.setLayoutManager(recyclerViewLayoutManager);
    list.setAdapter(adapter);
}
Also used : TransferListAdapter(com.frostwire.android.gui.adapters.TransferListAdapter) Transfer(com.frostwire.transfers.Transfer)

Aggregations

Transfer (com.frostwire.transfers.Transfer)8 File (java.io.File)3 CancelMenuAction (com.frostwire.android.gui.adapters.menu.CancelMenuAction)2 OpenMenuAction (com.frostwire.android.gui.adapters.menu.OpenMenuAction)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 FileDescriptor (com.frostwire.android.core.FileDescriptor)1 TransferListAdapter (com.frostwire.android.gui.adapters.TransferListAdapter)1 CopyToClipboardMenuAction (com.frostwire.android.gui.adapters.menu.CopyToClipboardMenuAction)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 TransferDetailsMenuAction (com.frostwire.android.gui.adapters.menu.TransferDetailsMenuAction)1 TransferManager (com.frostwire.android.gui.transfers.TransferManager)1 UIBittorrentDownload (com.frostwire.android.gui.transfers.UIBittorrentDownload)1 MenuAction (com.frostwire.android.gui.views.MenuAction)1 MenuAdapter (com.frostwire.android.gui.views.MenuAdapter)1 BittorrentDownload (com.frostwire.transfers.BittorrentDownload)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1