Skip to content
A multi-threaded download tool written with RxJava and Kotlin
Branch: master
Clone or download
Season
Latest commit 992d1d0 Apr 11, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
gradle/wrapper add auto start config for each Mission May 30, 2018
java-demo better readme Feb 26, 2019
kotlin-demo fix empty range header not support bug Mar 26, 2019
rxdownload3 fix notification not enable bug Apr 11, 2019
.gitignore fix readme Aug 24, 2017
LICENSE commit code. Aug 18, 2017
README.ch.md better readme Feb 26, 2019
README.md better readme Feb 26, 2019
build.gradle better readme Feb 26, 2019
gradlew commit code. Sep 3, 2017
gradlew.bat first commit Oct 26, 2016
settings.gradle Revered my extra changes, ready to PR to original lib Jan 26, 2019

README.md

RxDownload

A multi-threaded download tool written with RxJava and Kotlin

Read this in other languages: 中文, English

How to Use

Preparation

Step 1. Add the dependency Download

dependencies{
    implementation 'zlc.season:rxdownload3:x.y.z'
}

Step 2. Add permissions

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

Usage

Step 1. Create a mission

val mission = Mission(URL, FILE_NAME, SAVE_PATH, IS_OVERRIDE)

Step 2. Subscribe to the mission updates

val disposable = RxDownload.create(mission, autoStart = false)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe { status ->

                }

Note: The mission status is received here Repeated calls DO NOT cause the task to be created more than once Don't forget to dispose disposable in onDestroy() or similar method (To dispose call dispose(disposable) )

Step 3. Start download

RxDownload.start(mission).subscribe()

Stop download

RxDownload.stop(mission).subscribe()

AutoStart Download

There are two simple ways:

  • Add the autoStart parameter to the create method,this only take effect for the current mission.
RxDownload.create(mission,autoStart)
       .subscribe{
           ...
       }
  • Enable AutoStart config, this will take effect for all missions.
DownloadConfig.Builder.create(context)
                  .enableAutoStart(true)

DownloadConfig.init(builder)

For more APIs please see RxDownload.kt

Override

You can configure Mission so that if file exists it will be re-downloaded. If not specified - false

val mission = Mission(...)
mission.overwrite = Boolen (true/false)

Configuration (optional)

Add your configuration when APP starts up, like this:

class BaseApplication : Application() {

    override fun onCreate() {
        super.onCreate()

        val builder = DownloadConfig.Builder.create(this)
                .enableDb(true)
                .enableNotification(true)
				...

        DownloadConfig.init(builder)
    }
}

or

DownloadConfig.Builder.create(this)
                .setDefaultPath("custom download path")     //Set the default download address
                .enableDb(true)     //Enable the database
                .setDbActor(CustomSqliteActor(this))    //Customize the database
                .enableService(true)    //Enable Service
                .useHeadMethod(true)    //Use http HEAD method.
                .setMaxRange(10)       // Maximum concurrency for each mission.
                .setRangeDownloadSize(4*1000*1000) //The size of each Range,unit byte
                .setMaxMission(3)      // The number of mission downloaded at the same time
                .enableNotification(true)   //Enable Notification
                .setNotificationFactory(NotificationFactoryImpl())      //Custom notification
                .setOkHttpClientFacotry(OkHttpClientFactoryImpl())      //Custom OKHTTP
                .addExtension(ApkInstallExtension::class.java)    //Add extension

Extension

Customize your exclusive operation

class CustomExtension:Extension {
    override fun init(mission: RealMission) {
        //Init
    }

    override fun action(): Maybe<Any> {
        //Your action
    }
}

Refer to the ApkInstallExtension code

Proguard

Add Retrofit and OKHTTP can be proguard

-dontnote retrofit2.Platform
-dontwarn retrofit2.Platform$Java8
-keepattributes Signature
-keepattributes Exceptions

-dontwarn okhttp3.**
-dontwarn okio.**
-dontwarn javax.annotation.**

License

Copyright 2017 Season.Zlc

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 can’t perform that action at this time.