Skip to content

An extension of "PRDownloader" by "MindOrks" having a DownloaderQueue to control downloads properly. A file downloader library for Android with pause and resume support

License

Notifications You must be signed in to change notification settings

arefbhrn/EPRDownloader

Repository files navigation

EPRDownloader

An extension of "PRDownloader" by "Mindorks" having a DownloaderQueue to control downloads properly

A file downloader library for Android with pause and resume support

License

Demo

Overview of EPRDownloader library

  • EPRDownloader can be used to download any type of files like image, video, pdf, apk and etc.
  • Supports pause and resume while downloading a file.
  • Supports large file download.
  • Simple interface to make download request.
  • We can check if the status of downloading with the given download Id.
  • EPRDownloader gives callbacks for everything like onProgress, onCancel, onStart, onError and etc while downloading a file. (Resetable anytime)
  • Supports proper request canceling.
  • Many requests can be made in parallel.
  • All types of customization are possible.
  • -> Has a Request Queue to handle download requests properly.

Using EPRDownloader Library in your Android application

Add this in your build.gradle

implementation 'com.github.arefbhrn:EPRDownloader:1.0.1'

Do not forget to add internet permission in manifest if already not present

<uses-permission android:name="android.permission.INTERNET" />

Then initialize it in onCreate() Method of application class :

EPRDownloader.initialize(getApplicationContext());

Initializing it with some customization

// Enabling database for resume support even after the application is killed:
EPRDownloaderConfig config = EPRDownloaderConfig.newBuilder()
                .setDatabaseEnabled(true)
                .build();
EPRDownloader.initialize(getApplicationContext(), config);

// Setting timeout globally for the download network requests:
EPRDownloaderConfig config = EPRDownloaderConfig.newBuilder()
                .setReadTimeout(30_000)
                .setConnectTimeout(30_000)
                .build();
EPRDownloader.initialize(getApplicationContext(), config);

Make a download request

DownloadRequest download = EPRDownloader.download(ur, folderName + "/", fileName).build()
        .addOnStartOrResumeListener(new OnStartOrResumeListener() {
            @Override
            public void onStartOrResume() {

            }
        })
        .addOnPauseListener(new OnPauseListener() {
            @Override
            public void onPause() {

            }
        })
        .addOnCancelListener(new OnCancelListener() {
            @Override
            public void onCancel() {

            }
        })
        .addOnProgressListener(new OnProgressListener() {
            @Override
            public void onProgress(Progress progress) {

            }
        })
        .addOnDownloadListener(new OnDownloadListener() {
            @Override
            public void onDownloadComplete() {

            }

            @Override
            public void onError(Error error) {

            }
        });
download.start();

Pause a download request

EPRDownloader.pause(downloadId);

Resume a download request

EPRDownloader.resume(downloadId);

Cancel a download request

// Cancel with the download id
EPRDownloader.cancel(downloadId);
// The tag can be set to any request and then can be used to cancel the request
EPRDownloader.cancel(TAG);
// Cancel all the requests
EPRDownloader.cancelAll();

Generate ID of a download request

int downloadId = Utils.getUniqueId(url, folderName + "/", fileName);

Or if download object is already defined:

int downloadId = download.getDownloadId();

Status of a download request

Status status = EPRDownloader.getStatus(downloadId);

Clean up resumed files if database enabled

// Method to clean up temporary resumed files which is older than the given day
EPRDownloader.cleanUp(days);

Using DownloaderQueue

DownloaderQueue.setRunningLimit(3); // set maximum number of concurrent downloads
int downloadId = Utils.getUniqueId(url, folderName + "/", fileName);
DownloadRequest download = DownloaderQueue.get(downloadId);

Other downloads in this FIFO queue will wait until they can meet conditions to start.

Add to DownloaderQueue

DownloaderQueue.add(download);

Get download from DownloaderQueue (not remove it)

download = DownloaderQueue.get(downloadId);

Remove download from DownloaderQueue

DownloaderQueue.remove(downloadId);

If this library helps you in anyway, show your love ❤️ by putting a ⭐ on this project ✌️

License

This project is licensed under the Apache 2.0 License - see the LICENSE.md file for details

About

An extension of "PRDownloader" by "MindOrks" having a DownloaderQueue to control downloads properly. A file downloader library for Android with pause and resume support

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages