Search in sources :

Example 1 with TorrentStatus

use of com.frostwire.jlibtorrent.TorrentStatus in project frostwire by frostwire.

the class TransferDetailTrackersFragment method updateComponents.

@Override
protected void updateComponents() {
    if (uiBittorrentDownload == null) {
        return;
    }
    if (adapter != null) {
        adapter.notifyDataSetChanged();
    }
    TorrentStatus status = uiBittorrentDownload.getDl().getTorrentHandle().status();
    boolean announcingToDht = status.announcingToDht();
    boolean announcingToLSD = status.announcingToLsd();
    dhtStatus.setText(announcingToDht ? R.string.working : R.string.disabled);
    lsdStatus.setText(announcingToLSD ? R.string.working : R.string.disabled);
}
Also used : TorrentStatus(com.frostwire.jlibtorrent.TorrentStatus)

Example 2 with TorrentStatus

use of com.frostwire.jlibtorrent.TorrentStatus in project frostwire by frostwire.

the class BTDownload method getProgress.

@Override
public int getProgress() {
    if (th == null || !th.isValid()) {
        return 0;
    }
    TorrentStatus ts = th.status();
    if (ts == null) {
        // this can't never happens
        return 0;
    }
    float fp = ts.progress();
    TorrentStatus.State state = ts.state();
    if (Float.compare(fp, 1f) == 0 && state != TorrentStatus.State.CHECKING_FILES) {
        return 100;
    }
    int p = (int) (fp * 100);
    if (p > 0 && state != TorrentStatus.State.CHECKING_FILES) {
        return Math.min(p, 100);
    }
    return 0;
}
Also used : TorrentStatus(com.frostwire.jlibtorrent.TorrentStatus)

Example 3 with TorrentStatus

use of com.frostwire.jlibtorrent.TorrentStatus in project frostwire by frostwire.

the class BTDownload method getState.

public TransferState getState() {
    if (!engine.isRunning()) {
        return TransferState.STOPPED;
    }
    if (engine.isPaused()) {
        return TransferState.PAUSED;
    }
    if (!th.isValid()) {
        return TransferState.ERROR;
    }
    final TorrentStatus status = th.status();
    final boolean isPaused = isPaused(status);
    if (isPaused && status.isFinished()) {
        return TransferState.FINISHED;
    }
    if (isPaused && !status.isFinished()) {
        return TransferState.PAUSED;
    }
    if (!isPaused && status.isFinished()) {
        // see the docs of isFinished
        return TransferState.SEEDING;
    }
    final TorrentStatus.State state = status.state();
    switch(state) {
        case CHECKING_FILES:
            return TransferState.CHECKING;
        case DOWNLOADING_METADATA:
            return TransferState.DOWNLOADING_METADATA;
        case DOWNLOADING:
            return TransferState.DOWNLOADING;
        case FINISHED:
            return TransferState.FINISHED;
        case SEEDING:
            return TransferState.SEEDING;
        case ALLOCATING:
            return TransferState.ALLOCATING;
        case CHECKING_RESUME_DATA:
            return TransferState.CHECKING;
        case UNKNOWN:
            return TransferState.UNKNOWN;
        default:
            return TransferState.UNKNOWN;
    }
}
Also used : TorrentStatus(com.frostwire.jlibtorrent.TorrentStatus)

Example 4 with TorrentStatus

use of com.frostwire.jlibtorrent.TorrentStatus in project frostwire by frostwire.

the class BTDownload method getETA.

public long getETA() {
    if (!th.isValid()) {
        return 0;
    }
    TorrentInfo ti = th.torrentFile();
    if (ti == null) {
        return 0;
    }
    TorrentStatus status = th.status();
    long left = ti.totalSize() - status.totalDone();
    long rate = status.downloadPayloadRate();
    if (left <= 0) {
        return 0;
    }
    if (rate <= 0) {
        return -1;
    }
    return left / rate;
}
Also used : TorrentStatus(com.frostwire.jlibtorrent.TorrentStatus) TorrentInfo(com.frostwire.jlibtorrent.TorrentInfo)

Example 5 with TorrentStatus

use of com.frostwire.jlibtorrent.TorrentStatus in project frostwire by frostwire.

the class TransferDetailPiecesFragment method updateComponents.

@Override
protected void updateComponents() {
    if (uiBittorrentDownload == null) {
        return;
    }
    ensureTorrentHandleAsync();
    if (torrentHandle == null) {
        return;
    }
    TorrentStatus status = torrentHandle.status(TorrentHandle.QUERY_PIECES);
    TorrentInfo torrentInfo = torrentHandle.torrentFile();
    if (pieceSizeString == null) {
        pieceSizeString = UIUtils.getBytesInHuman(torrentInfo.pieceSize(0));
    }
    if (totalPieces == -1) {
        totalPieces = torrentInfo.numPieces();
        piecesNumberTextView.setText(String.valueOf(totalPieces));
        // progressBar.setVisibility(View.VISIBLE);
        hexHiveView.setVisibility(View.GONE);
    }
    PieceIndexBitfield pieces = status.pieces();
    long piecesCount = pieces.count();
    if (isAdded()) {
        // I do this color look-up only once and pass it down to the view holder
        // otherwise it has to be done thousands of times.
        pieceSizeTextView.setText(pieceSizeString);
        hexDataAdapter = new PieceAdapter(totalPieces, pieces);
        hexHiveView.setVisibility(View.VISIBLE);
    }
    if (hexDataAdapter != null) {
        if (piecesCount >= 0) {
            hexDataAdapter.updateData(pieces);
        }
        // noinspection unchecked
        hexHiveView.updateData(hexDataAdapter);
        piecesNumberTextView.setText(piecesCount + "/" + totalPieces);
    }
}
Also used : TorrentStatus(com.frostwire.jlibtorrent.TorrentStatus) PieceIndexBitfield(com.frostwire.jlibtorrent.PieceIndexBitfield) TorrentInfo(com.frostwire.jlibtorrent.TorrentInfo)

Aggregations

TorrentStatus (com.frostwire.jlibtorrent.TorrentStatus)5 TorrentInfo (com.frostwire.jlibtorrent.TorrentInfo)2 PieceIndexBitfield (com.frostwire.jlibtorrent.PieceIndexBitfield)1