Async file downloader for Android

Overview

What is FileBox

FileBox is an async file downloader library for Android.

Before we develop filebox, we though that URL content changes very rarely. So basically this library downloads a given URL, and if it is already downloaded, it provides downloaded content directly.

FileBox;

  • Shares ongoing download requests to the observers. So It reduces Data Usage.
  • Has TTL(Time To Live) duration. Filebox re-download the URL if TTL is expired.
  • Supports both Cache and External directory.
  • Supports the File Encryption for sensitive URL(images, videos, any file).
  • Allows you to create a custom folder destination.
  • Clears unreliable data automagically.
  • Does Etag Check. Filebox doesn't download the file again If the file's TLL(Time To Live) is up but the file has not changed.
  • Supports Multiple Download. If you have N file and want to get notified when all completed.
  • Runs on application scope. There is no pause/resume continuation support.

Flow Diagram

Modules

Basic Usage

val fileBoxRequest = FileBoxRequest("https://url1.png")

val filebox= FileBoxProvider.newInstance(applicationContext, FileBoxConfig.createDefault())

filebox.get(fileBoxRequest)
    .subscribeOn(Schedulers.io())
    .observeOn(AndroidSchedulers.mainThread())
    .subscribe { fileBoxResponse ->
        when (fileBoxResponse) {
            is FileBoxResponse.Downloading -> {
                val progress: Float = fileBoxResponse.progress
                val ongoingRecord: Record = fileBoxResponse.record
            }
            is FileBoxResponse.Complete -> {
                val savedRecord: Record = fileBoxResponse.record
                val savedPath = fileBoxResponse.record.getReadableFilePath()
            }
            is FileBoxResponse.Error -> {
                val savedRecord: Record = fileBoxResponse.record
                val error = fileBoxResponse.throwable
            }
        }
    }

Customize Config

val fileBoxConfig = FileBoxConfig.FileBoxConfigBuilder()
        .setCryptoType(CryptoType.CONCEAL) // Default is CryptoType.NONE
        .setTTLInMillis(TimeUnit.DAYS.toMillis(7)) // Default is 7 Days
        .setDirectory(DirectoryType.CACHE) // Default is External
        .setFolderName("MyPhotos") // Default is none
        .build()

Multiple Download Request

val fileBoxMultipleRequest = FileBoxMultiRequest(
            arrayListOf(
                FileBoxRequest("https://url1.png"),
                FileBoxRequest("https://url2.zip"),
                FileBoxRequest("https://url3.json"),
                FileBoxRequest("https://url4.mp4")
            )
        )

val filebox = FileBoxProvider.newInstance(applicationContext, FileBoxConfig.createDefault())

filebox.get(fileBoxMultipleRequest)
    .subscribeOn(Schedulers.io())
    .observeOn(AndroidSchedulers.mainThread())
    .subscribe { fileBoxResponse ->
        when (fileBoxResponse) {
            is FileBoxMultiResponse.Downloading -> {
                val progress = fileBoxResponse.progress
                val ongoingFileResponseList = fileBoxResponse.fileBoxResponseList
            }
            is FileBoxMultiResponse.Complete -> {
                val ongoingFileResponseList = fileBoxResponse.fileBoxResponseList
                ongoingFileResponseList.forEach { it.record.getReadableFilePath() }
            }
            is FileBoxMultiResponse.Error -> {
                val error = fileBoxResponse.throwable
                val ongoingFileResponseList = fileBoxResponse.fileBoxResponseList
            }
        }
    }

Destroy

Don't forget to destroy the filebox when your initialized scope is destroyed. If you create a filebox in your application class, It is application scoped. If you create a filebox in your activity class, It is activity scoped. Be aware of your lifecycle.

filebox.destroy()

Setup

allprojects {
     repositories {
	...
	maven { url 'https://jitpack.io' }
     }
}
dependencies {
      implementation 'com.github.lyrebirdstudio:filebox:0.1'
}

License

Copyright 2020 Lyrebird Studio.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
You might also like...
Square’s meticulous HTTP client for the JVM, Android, and GraalVM.

OkHttp See the project website for documentation and APIs. HTTP is the way modern applications network. It’s how we exchange data & media. Doing HTTP

A type-safe HTTP client for Android and the JVM

Retrofit A type-safe HTTP client for Android and Java. For more information please see the website. Download Download the latest JAR or grab from Mave

Android client for ProjectRTC - a WebRTC demo

AndroidRTC WebRTC Live Streaming An Android client for ProjectRTC. It is designed to demonstrate WebRTC video calls between androids and/or desktop br

IceNet - Fast, Simple and Easy Networking for Android

IceNet FAST, SIMPLE, EASY This library is an Android networking wrapper consisting of a combination of Volley, OkHttp and Gson. For more information s

Easy, asynchronous, annotation-based SOAP for Android

IceSoap IceSoap provides quick, easy, asynchronous access to SOAP web services from Android devices. It allows for SOAP responses to be bound to Java

Run Node.js on Android by rewrite Node.js in Java

node-android Run Node.js on Android by rewrite Node.js in Java with the compatible API. third-party: libuvpp, libuv-java JNI code by Oracle. Build Clo

dns library for android

Qiniu Happy DNS for Android 安装 直接安装 通过maven 使用方法 DnsManager 可以创建一次,一直使用。 IResolver[] resolvers = new IResolver[3]; resolvers[0] = AndroidDnsSe

HTTP Server for Android Instrumentation tests

RESTMock REST API mocking made easy. RESTMock is a library working on top of Square's okhttp/MockWebServer. It allows you to specify Hamcrest matchers

🚀 A Complete Fast Android Networking Library that also supports HTTP/2 🚀
🚀 A Complete Fast Android Networking Library that also supports HTTP/2 🚀

Fast Android Networking Library About Fast Android Networking Library Fast Android Networking Library is a powerful library for doing any type of netw

Comments
  • Hide library implementation details and refactor a few minor points

    Hide library implementation details and refactor a few minor points

    I've tested the changes on my own, but it is possible to miss something since I'm not that familiar with the implementation details. Please feel free to ask or update the points that I've missed.

    opened by erdemtopak 0
  • Custom File Naming

    Custom File Naming

    Hi I've been looking at your library and I wanted to know if there was a possibility to name any file that we would like to download. I tried looking if there was a way but I didn"t find any. Could you confirm it, or if there is a way, could you point it to me.

    opened by theshid 0
Releases(0.1)
Owner
Lyrebird Studio
Lyrebird Studio
:satellite: [Android Library] Simplified async networking in android

Android library that simplifies networking in android via an async http client. Also featured in [Awesome Android Newsletter #Issue 15 ] Built with ❤︎

Nishant Srivastava 36 May 14, 2022
A downloader to help in downloading to custom folders

Murerwa Downloader (Still in development) Murerwa downloader is a custom downloader library beside the default Android downloader that helps users dow

Kenneth Murerwa 5 Mar 31, 2022
Youtube Inline Downloader (YTILDL)

Youtube Inline Downloader (YTILDL) This is a userscript that allows you to download youtube videos by simply clicking a button on the YouTube video. T

null 1 Jun 13, 2022
android webview choose file to upload

Android WebView文件上传 本工程为大家演示在H5中如何上传文件,同时也提供了服务端代码,有兴趣的读者可以部署起来,测试文件上传功能。 如果只对客户端部分感兴趣,只需要关注WebView文件选择部分即可 服务端代码下载地址, 客户端可以用如下url来上传文件 http://your ip

yuzhiqiangqiangqiang 57 Sep 20, 2022
Utilizes the Range HTTP header to download a file with multiple connections in parallel, bypassing cheap bandwidth throttling

async-range-downloader Utilizes the Range HTTP header to download a file with multiple connections in parallel, bypassing cheap bandwidth throttling T

Torben 4 Apr 12, 2022
An App to download a file from Internet by clicking on a custom-built button

LoadApp LoadApp is an app to download a file from the Internet by clicking on a custom-built button where: Width of the button gets animated from left

Anas Tariq 2 Aug 29, 2022
Android network client based on Cronet. This library let you easily use QUIC protocol in your Android projects

Android network client based on Cronet. This library let you easily use QUIC protocol in your Android projects

VK.com 104 Dec 12, 2022
Android Easy Http - Simplest android http request library.

Android Easy Http Library 繁體中文文檔 About Android Easy Http Library Made on OkHttp. Easy to do http request, just make request and listen for the respons

null 13 Sep 30, 2022
Android Asynchronous Networking and Image Loading

Android Asynchronous Networking and Image Loading Download Maven Git Features Kotlin coroutine/suspend support Asynchronously download: Images into Im

Koushik Dutta 6.3k Dec 27, 2022