-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Customizable Component
冉天华 edited this page Aug 3, 2018
·
7 revisions
From now on, FileDownloader support following components to be customized by yourself:
| Name | Interface | Default Impl |
|---|---|---|
| Connection | FileDownloadConnection | FileDownloadUrlConnection |
| OutputStream | FileDownloadOutputStream | FileDownloadRandomAccessFile |
| Database | FileDownloadDatabase | DefaultDatabaseImpl |
| ConnectionCountAdapter | ConnectionCountAdapter | DefaultConnectionCountAdapter |
| IdGenerator | IdGenerator | DefaultIdGenerator |
| ForegroundServiceConfig | ForegroundServiceConfig | ForegroundServiceConfig |
The default connection count strategy for each task, you can customize it through ConnectionCountAdapter:
- one connection: file length [0, 1MB)
- two connections: file length [1MB, 5MB)
- three connections: file length [5MB, 50MB)
- four connections: file length [50MB, 100MB)
- five connections: file length [100MB, -)
You can refer to here to know about customizing ForegroundServiceConfig.
Just create your own DownloadMgrInitialParams.InitCustomMaker and put those customized components to it, finally init the FileDownloader with it: FileDownloader#init
Implementing your own customized component if you want. P.S: You can refer the default-impl.
Putting it into FileDownloader when you setup the FileDownloader on the Application#onCreate method:
FileDownloader.setupOnApplicationOnCreate(this)
.database(/*You can put your customized database component here*/)
.outputStreamCreator(/*You can put your customized output-stream component here*/)
.connectionCreator(/*You can put your customized connection component here*/)
.commit();If you want to use okhttp as your connection component, the simplest way is this repo.
- Initialization
- Start downloading
- Pause or Stop
- Get the internal stored data
- Customizable Component
- Interface