Search in sources :

Example 1 with Downloader

use of de.danoeh.antennapod.core.service.download.Downloader in project AntennaPod by AntennaPod.

the class PostDownloaderTask method run.

@Override
public void run() {
    List<Downloader> runningDownloads = new ArrayList<>();
    for (Downloader downloader : downloads) {
        if (!downloader.cancelled) {
            runningDownloads.add(downloader);
        }
    }
    List<Downloader> list = Collections.unmodifiableList(runningDownloads);
    EventBus.getDefault().postSticky(DownloadEvent.refresh(list));
}
Also used : ArrayList(java.util.ArrayList) Downloader(de.danoeh.antennapod.core.service.download.Downloader)

Example 2 with Downloader

use of de.danoeh.antennapod.core.service.download.Downloader in project AntennaPod by AntennaPod.

the class HttpDownloaderTest method testDeleteOnFailShouldNotDelete.

@Test
public void testDeleteOnFailShouldNotDelete() throws IOException {
    String filename = "testDeleteOnFailShouldDelete";
    File dest = new File(destDir, filename);
    dest.delete();
    assertTrue(dest.createNewFile());
    Downloader downloader = download(url404, filename, false, false, null, null, false);
    assertTrue(new File(downloader.getDownloadRequest().getDestination()).exists());
}
Also used : Downloader(de.danoeh.antennapod.core.service.download.Downloader) HttpDownloader(de.danoeh.antennapod.core.service.download.HttpDownloader) File(java.io.File) FeedFile(de.danoeh.antennapod.model.feed.FeedFile) Test(org.junit.Test) LargeTest(androidx.test.filters.LargeTest)

Example 3 with Downloader

use of de.danoeh.antennapod.core.service.download.Downloader in project AntennaPod by AntennaPod.

the class HttpDownloaderTest method testAuthenticationShouldFail.

@Test
public void testAuthenticationShouldFail() {
    Downloader downloader = download(urlAuth, "testAuthSuccess", false, true, "user", "Wrong passwd", true);
    assertEquals(DownloadError.ERROR_UNAUTHORIZED, downloader.getResult().getReason());
}
Also used : Downloader(de.danoeh.antennapod.core.service.download.Downloader) HttpDownloader(de.danoeh.antennapod.core.service.download.HttpDownloader) Test(org.junit.Test) LargeTest(androidx.test.filters.LargeTest)

Example 4 with Downloader

use of de.danoeh.antennapod.core.service.download.Downloader in project AntennaPod by AntennaPod.

the class HttpDownloaderTest method download.

private Downloader download(String url, String title, boolean expectedResult, boolean deleteExisting, String username, String password, boolean deleteOnFail) {
    FeedFile feedFile = setupFeedFile(url, title, deleteExisting);
    DownloadRequest request = new DownloadRequest(feedFile.getFile_url(), url, title, 0, feedFile.getTypeAsInt(), username, password, deleteOnFail, null, false);
    Downloader downloader = new HttpDownloader(request);
    downloader.call();
    DownloadStatus status = downloader.getResult();
    assertNotNull(status);
    assertEquals(expectedResult, status.isSuccessful());
    assertTrue(status.isDone());
    // the file should not exist if the download has failed and deleteExisting was true
    assertTrue(!deleteExisting || new File(feedFile.getFile_url()).exists() == expectedResult);
    return downloader;
}
Also used : HttpDownloader(de.danoeh.antennapod.core.service.download.HttpDownloader) DownloadStatus(de.danoeh.antennapod.core.service.download.DownloadStatus) FeedFile(de.danoeh.antennapod.model.feed.FeedFile) DownloadRequest(de.danoeh.antennapod.core.service.download.DownloadRequest) Downloader(de.danoeh.antennapod.core.service.download.Downloader) HttpDownloader(de.danoeh.antennapod.core.service.download.HttpDownloader) File(java.io.File) FeedFile(de.danoeh.antennapod.model.feed.FeedFile)

Example 5 with Downloader

use of de.danoeh.antennapod.core.service.download.Downloader in project AntennaPod by AntennaPod.

the class HttpDownloaderTest method testDeleteOnFailShouldDelete.

@Test
public void testDeleteOnFailShouldDelete() {
    Downloader downloader = download(url404, "testDeleteOnFailShouldDelete", false, true, null, null, true);
    assertFalse(new File(downloader.getDownloadRequest().getDestination()).exists());
}
Also used : Downloader(de.danoeh.antennapod.core.service.download.Downloader) HttpDownloader(de.danoeh.antennapod.core.service.download.HttpDownloader) File(java.io.File) FeedFile(de.danoeh.antennapod.model.feed.FeedFile) Test(org.junit.Test) LargeTest(androidx.test.filters.LargeTest)

Aggregations

Downloader (de.danoeh.antennapod.core.service.download.Downloader)11 HttpDownloader (de.danoeh.antennapod.core.service.download.HttpDownloader)6 DownloadRequest (de.danoeh.antennapod.core.service.download.DownloadRequest)5 DownloadStatus (de.danoeh.antennapod.core.service.download.DownloadStatus)5 LargeTest (androidx.test.filters.LargeTest)4 File (java.io.File)4 FeedFile (de.danoeh.antennapod.model.feed.FeedFile)3 Test (org.junit.Test)3 Dialog (android.app.Dialog)2 Context (android.content.Context)2 Bundle (android.os.Bundle)2 Log (android.util.Log)2 MenuItem (android.view.MenuItem)2 View (android.view.View)2 TextView (android.widget.TextView)2 NonNull (androidx.annotation.NonNull)2 Nullable (androidx.annotation.Nullable)2 AlertDialog (androidx.appcompat.app.AlertDialog)2 Snackbar (com.google.android.material.snackbar.Snackbar)2 R (de.danoeh.antennapod.R)2