private void handleCoreDownloader() { File possibleTorrentFile = null; possibleTorrentFile = downloader.getSaveFile(); String fileExtension = FileUtils.getFileExtension(possibleTorrentFile); if ("torrent".equalsIgnoreCase(fileExtension)) { try { shareTorrentFile(possibleTorrentFile); downloadManager.downloadTorrent(possibleTorrentFile, null, false); downloadItems.remove(getDownloadItem(downloader)); } catch (DownloadException e) { final File torrentFile = possibleTorrentFile; activityCallback.handleDownloadException( new DownloadAction() { @Override public void download(File saveDirectory, boolean overwrite) throws DownloadException { downloadManager.downloadTorrent(torrentFile, saveDirectory, overwrite); downloadItems.remove(getDownloadItem(downloader)); } @Override public void downloadCanceled(DownloadException ignored) { // nothing to do } }, e, false); } } }
@Inject public TorrentDownloadListener( DownloadManager downloadManager, ActivityCallback activityCallback, @GnutellaFiles FileCollection gnutellaFileList, TorrentManager torrentManager, @Assisted List<DownloadItem> downloadItems, @Assisted Downloader downloader) { this.downloader = Objects.nonNull(downloader, "downloader"); this.downloadManager = Objects.nonNull(downloadManager, "downloadManager"); this.torrentManager = Objects.nonNull(torrentManager, "torrentManager"); this.gnutellaFileList = Objects.nonNull(gnutellaFileList, "gnutellaFileList"); this.activityCallback = Objects.nonNull(activityCallback, "activityCallback"); this.downloadItems = Objects.nonNull(downloadItems, "downloadItems"); if (downloader.getState() == DownloadState.COMPLETE) { if (downloader instanceof CoreDownloader) { handleEvent(new DownloadStateEvent((CoreDownloader) downloader, DownloadState.COMPLETE)); } } }
DownloadItem getDownloadItem(Downloader downloader) { DownloadItem item = (DownloadItem) downloader.getAttribute(DownloadItem.DOWNLOAD_ITEM); return item; }