Example #1
0
  // Create a download object for every chapter in the event and add them to the downloads queue
  public void onDownloadChaptersEvent(DownloadChaptersEvent event) {
    final Manga manga = event.getManga();
    final Source source = sourceManager.get(manga.source);

    for (Chapter chapter : event.getChapters()) {
      Download download = new Download(source, manga, chapter);

      if (!prepareDownload(download)) {
        queue.add(download);
        if (isRunning) downloadsQueueSubject.onNext(download);
      }
    }
  }
Example #2
0
  public boolean startDownloads() {
    if (queue.isEmpty()) return false;

    boolean hasPendingDownloads = false;
    if (downloadsSubscription == null) initializeSubscriptions();

    for (Download download : queue) {
      if (download.getStatus() != Download.DOWNLOADED) {
        if (download.getStatus() != Download.QUEUE) download.setStatus(Download.QUEUE);
        if (!hasPendingDownloads) hasPendingDownloads = true;
        downloadsQueueSubject.onNext(download);
      }
    }
    return hasPendingDownloads;
  }
Example #3
0
 private void checkDownloadIsSuccessful(final Download download) {
   int actualProgress = 0;
   int status = Download.DOWNLOADED;
   // If any page has an error, the download result will be error
   for (Page page : download.pages) {
     actualProgress += page.getProgress();
     if (page.getStatus() != Page.READY) status = Download.ERROR;
   }
   // Ensure that the chapter folder has all the images
   if (!isChapterDownloaded(download.directory, download.pages)) {
     status = Download.ERROR;
   }
   download.totalProgress = actualProgress;
   download.setStatus(status);
   // Delete successful downloads from queue after notifying
   if (status == Download.DOWNLOADED) {
     queue.remove(download);
   }
 }