A simple file downloader android library written in kotlin for modern android apps
Add the JitPack repository to you project level build.gradle file
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Add the dependency to your module build.gradle file
dependencies {
implementation 'com.github.Victor-El:DroidDownloader:v0.1.1-alpha.0'
}
Add the JitPack repository
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Add the dependency
<dependency>
<groupId>com.github.Victor-El</groupId>
<artifactId>DroidDownloader</artifactId>
<version>0.1.1-alpha.0</version>
</dependency>
val downloader: DroidDownloader = DefaultDroidDownloader.Builder()
.addConnectTimeOutMillis(5_000)
.addWriteTimeOutMillis(30_000)
.build()
suspend fun downloadFileAsync(
url: String,
path: String,
filename: String,
) {
val status = downloader.downloadFile(url, path, filename)
completedTasks.add(status)
withContext(Dispatchers.Main) {
when (status) {
is DownloadStatus.Success -> downloadFlow.emit(DownloadResult.Success(status.filePath))
is DownloadStatus.Failure.NetworkFailure -> downloadFlow.emit(DownloadResult.Error(status.message))
is DownloadStatus.Failure.DiskFailure -> downloadFlow.emit(DownloadResult.Error(status.message))
}
}
}
suspend fun downloadFileAsync(
url: String,
path: String,
filename: String,
authBearerToken: String,
) {
val status = downloader.downloadFileWithBearerAuth(url, path, filename, authBearerToken)
completedTasks.add(status)
withContext(Dispatchers.Main) {
when (status) {
is DownloadStatus.Success -> downloadFlow.emit(DownloadResult.Success(status.filePath))
is DownloadStatus.Failure.NetworkFailure -> downloadFlow.emit(DownloadResult.Error(status.message))
is DownloadStatus.Failure.DiskFailure -> downloadFlow.emit(DownloadResult.Error(status.message))
}
}
}
Elezua Victor
This project is licensed under the Apache MIT License - See: https://github.com/Victor-El/DroidDownloader/blob/master/LICENSE