Android library for downloading, saving/caching and retrieving any type of files ( image, video, pdf, apk etc ) easily.
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
dependencies {
implementation 'com.github.kk121:File-Loader:1.2'
}
<dependency>
<groupId>com.github.kk121</groupId>
<artifactId>File-Loader</artifactId>
<version>1.2</version>
</dependency>
FileLoader.with(this)
.load("https://upload.wikimedia.org/wikipedia/commons/3/3c/Enrique_Simonet_-_Marina_veneciana_6MB.jpg",false) //2nd parameter is optioal, pass true to force load from network
.fromDirectory("test4", FileLoader.DIR_INTERNAL)
.asFile(new FileRequestListener<File>() {
@Override
public void onLoad(FileLoadRequest request, FileResponse<File> response) {
File loadedFile = response.getBody();
// do something with the file
}
@Override
public void onError(FileLoadRequest request, Throwable t) {
}
});
FileLoader.with(this)
.load("http://echo.jsontest.com/key1/value1/key2/value2")
.fromDirectory("test3", FileLoader.DIR_INTERNAL)
.asObject(new FileRequestListener<JsonTest>() {
@Override
public void onLoad(FileLoadRequest request, FileResponse<JsonTest> response) {
JsonTest jsonTest = response.getBody();
//do something with jsonTest object
}
@Override
public void onError(FileLoadRequest request, Throwable t) {
}
});
final String[] uris = {"https://images.pexels.com/photos/45170/kittens-cat-cat-puppy-rush-45170.jpeg",
"https://upload.wikimedia.org/wikipedia/commons/3/3c/Enrique_Simonet_-_Marina_veneciana_6MB.jpg",
"https://d15shllkswkct0.cloudfront.net/wp-content/blogs.dir/1/files/2017/01/Google-acquires-Fabric.png"};
FileLoader.multiFileDownload(this)
.fromDirectory(Environment.DIRECTORY_PICTURES, FileLoader.DIR_EXTERNAL_PUBLIC)
.progressListener(new MultiFileDownloadListener() {
@Override
public void onProgress(File downloadedFile, int progress, int totalFiles) {
}
@Override
public void onError(Exception e, int progress) {
super.onError(e, progress);
}
}).loadMultiple(uris);
List<MultiFileLoadRequest> multiFileLoadRequests = new ArrayList<>();
multiFileLoadRequests.add(new MultiFileLoadRequest(uris[0], "test2", FileLoader.DIR_INTERNAL, false));
multiFileLoadRequests.add(new MultiFileLoadRequest(uris[1], Environment.DIRECTORY_DOWNLOADS, FileLoader.DIR_EXTERNAL_PRIVATE, false));
multiFileLoadRequests.add(new MultiFileLoadRequest(uris[2], Environment.DIRECTORY_PICTURES, FileLoader.DIR_EXTERNAL_PUBLIC, false));
MultiFileDownloader multiFileDownloader = FileLoader.multiFileDownload(this);
multiFileDownloader.progressListener(new MultiFileDownloadListener() {
@Override
public void onProgress(File downloadedFile, int progress, int totalFiles) {
}
@Override
public void onError(Exception e, int progress) {
super.onError(e, progress);
}
}).loadMultiple(true, uris);
multiFileDownloader.cancelLoad();
final String[] uris = {"https://images.pexels.com/photos/45170/kittens-cat-cat-puppy-rush-45170.jpeg",
"https://upload.wikimedia.org/wikipedia/commons/3/3c/Enrique_Simonet_-_Marina_veneciana_6MB.jpg",
"https://d15shllkswkct0.cloudfront.net/wp-content/blogs.dir/1/files/2017/01/Google-acquires-Fabric.png"};
try {
FileLoader.deleteWith(this).fromDirectory("test2", FileLoader.DIR_INTERNAL).deleteFiles(uris);
} catch (Exception e) {
e.printStackTrace();
}
FileLoader.deleteWith(this).fromDirectory("test2", FileLoader.DIR_INTERNAL).deleteAllFiles();
FileLoader.deleteWith(this).fromDirectory("test3", FileLoader.DIR_INTERNAL).deleteAllFilesExcept(uris);
This is still in beta.Comments/bugs/questions/pull requests are always welcome!