Search in sources :

Example 1 with PieceIndexBitfield

use of com.frostwire.jlibtorrent.PieceIndexBitfield 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

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