use of com.frostwire.bittorrent.BTDownload in project frostwire by frostwire.
the class TransferManager method loadTorrentsTask.
private void loadTorrentsTask() {
bittorrentDownloadsList.clear();
bittorrentDownloadsMap.clear();
final BTEngine btEngine = BTEngine.getInstance();
btEngine.setListener(new BTEngineAdapter() {
@Override
public void downloadAdded(BTEngine engine, BTDownload dl) {
String name = dl.getName();
if (name != null && name.contains("fetch_magnet")) {
return;
}
File savePath = dl.getSavePath();
if (savePath != null && savePath.toString().contains("fetch_magnet")) {
return;
}
UIBittorrentDownload uiBittorrentDownload = new UIBittorrentDownload(TransferManager.this, dl);
bittorrentDownloadsList.add(uiBittorrentDownload);
bittorrentDownloadsMap.put(dl.getInfoHash(), uiBittorrentDownload);
}
@Override
public void downloadUpdate(BTEngine engine, BTDownload dl) {
try {
BittorrentDownload bittorrentDownload = bittorrentDownloadsMap.get(dl.getInfoHash());
if (bittorrentDownload instanceof UIBittorrentDownload) {
UIBittorrentDownload bt = (UIBittorrentDownload) bittorrentDownload;
bt.updateUI(dl);
}
} catch (Throwable e) {
LOG.error("Error updating bittorrent download", e);
}
}
});
btEngine.restoreDownloads();
}
use of com.frostwire.bittorrent.BTDownload in project frostwire by frostwire.
the class TransferDetailDetailsFragment method updateComponents.
@Override
protected void updateComponents() {
if (uiBittorrentDownload != null) {
// ensureComponentsReferenced();
BTDownload btDL = uiBittorrentDownload.getDl();
if (onCopyToClipboardListener == null) {
onCopyToClipboardListener = new CopyToClipboardOnClickListener(uiBittorrentDownload);
}
// static data for this download is done only once
if ("".equals(storagePath.getText())) {
storagePath.setText(uiBittorrentDownload.getSavePath().getAbsolutePath());
}
if ("".equals(totalSize.getText())) {
totalSize.setText(UIUtils.getBytesInHuman(uiBittorrentDownload.getSize()));
}
if ("".equals(numberOfFiles.getText())) {
List<TransferItem> items = uiBittorrentDownload.getItems();
int fileCount = items == null ? 0 : items.size();
numberOfFiles.setText(fileCount + "");
}
if ("".equals(hash.getText())) {
hash.setText(uiBittorrentDownload.getInfoHash());
hash.setOnClickListener(onCopyToClipboardListener);
hashCopyButton.setOnClickListener(onCopyToClipboardListener);
}
if ("".equals(magnet.getText())) {
magnet.setText(uiBittorrentDownload.magnetUri());
magnet.setOnClickListener(onCopyToClipboardListener);
magnetCopyButton.setOnClickListener(onCopyToClipboardListener);
}
if ("".equals(createdOn.getText())) {
createdOn.setText(DateUtils.formatDateTime(getActivity(), uiBittorrentDownload.getCreated().getTime(), DateUtils.FORMAT_ABBREV_MONTH | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_YEAR));
}
if ("".equals(comment.getText())) {
TorrentInfo torrentInfo = uiBittorrentDownload.getDl().getTorrentHandle().torrentFile();
String torrentComment = torrentInfo.comment();
if (torrentComment != null && !"".equals(torrentComment)) {
comment.setText(torrentComment);
} else {
comment.setText(" ");
View view = findView(comment.getRootView(), R.id.fragment_transfer_detail_details_comment_container);
view.setVisibility(View.GONE);
}
}
if (onSequentialDownloadCheckboxCheckedListener == null) {
onSequentialDownloadCheckboxCheckedListener = new SequentialDownloadCheckboxCheckedListener(uiBittorrentDownload);
}
sequentialDownloadCheckBox.setOnCheckedChangeListener(null);
sequentialDownloadCheckBox.setChecked(btDL.isSequentialDownload());
sequentialDownloadCheckBox.setOnCheckedChangeListener(onSequentialDownloadCheckboxCheckedListener);
if (onRateLimitClickListener == null) {
onRateLimitClickListener = new OnSpeedLimitClickListener(uiBittorrentDownload, this, getFragmentManager());
downloadSpeedLimit.setOnClickListener(onRateLimitClickListener);
downloadSpeedLimitArrow.setOnClickListener(onRateLimitClickListener);
uploadSpeedLimit.setOnClickListener(onRateLimitClickListener);
uploadSpeedLimitArrow.setOnClickListener(onRateLimitClickListener);
}
int downloadRateLimit = btDL.getDownloadRateLimit();
int uploadRateLimit = btDL.getUploadRateLimit();
if (downloadRateLimit > 0) {
downloadSpeedLimit.setText(UIUtils.getBytesInHuman(downloadRateLimit) + "/s");
} else if (downloadRateLimit == DOWNLOAD_UNLIMITED_VALUE || downloadRateLimit == -1) {
downloadSpeedLimit.setText(R.string.unlimited);
}
if (uploadRateLimit > 0) {
uploadSpeedLimit.setText(UIUtils.getBytesInHuman(uploadRateLimit) + "/s");
} else if (uploadRateLimit == UPLOAD_UNLIMITED_VALUE || uploadRateLimit == -1) {
uploadSpeedLimit.setText(R.string.unlimited);
}
}
}
use of com.frostwire.bittorrent.BTDownload in project frostwire by frostwire.
the class DownloadManagerImpl method loadSavedDownloadsAndScheduleWriting.
public void loadSavedDownloadsAndScheduleWriting() {
try {
BTEngine engine = BTEngine.getInstance();
engine.setListener(new BTEngineAdapter() {
@Override
public void downloadAdded(BTEngine engine, BTDownload dl) {
if (engine == null || dl == null) {
return;
}
String name = dl.getName();
if (name == null || name.contains("fetch_magnet:")) {
return;
}
File savePath = dl.getSavePath();
if (savePath != null && savePath.toString().contains("fetch_magnet")) {
return;
}
// don't add frostwire update downloads to the download manager.
if (savePath != null) {
final File parentFile = savePath.getParentFile();
if (parentFile != null) {
if (parentFile.getAbsolutePath().equals(UpdateSettings.UPDATES_DIR.getAbsolutePath())) {
LOG.info("Update download, not adding to transfer manager: " + savePath);
return;
}
} else if (savePath.getAbsolutePath().equals(UpdateSettings.UPDATES_DIR.getAbsolutePath())) {
// save path must have been a root folder, like D:\, so no parent file.
LOG.info("Update download, not adding to transfer manager: " + savePath);
return;
}
}
addDownload(dl);
}
@Override
public void downloadUpdate(BTEngine engine, BTDownload dl) {
updateDownload(dl);
}
});
engine.restoreDownloads();
} catch (Throwable e) {
LOG.error("General error loading saved downloads", e);
}
}
Aggregations