{"id":13427860,"url":"https://github.com/ssseasonnn/RxDownload","last_synced_at":"2025-03-16T00:32:25.208Z","repository":{"id":38428623,"uuid":"72172651","full_name":"ssseasonnn/RxDownload","owner":"ssseasonnn","description":"A multi-threaded download tool written with RxJava and Kotlin","archived":false,"fork":false,"pushed_at":"2021-10-28T03:03:13.000Z","size":6870,"stargazers_count":4135,"open_issues_count":47,"forks_count":612,"subscribers_count":113,"default_branch":"master","last_synced_at":"2024-10-16T16:16:57.944Z","etag":null,"topics":["kotlin","rxdownload","rxjava"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ssseasonnn.png","metadata":{"files":{"readme":"README.ch.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-10-28T04:13:42.000Z","updated_at":"2024-10-08T08:40:16.000Z","dependencies_parsed_at":"2022-07-11T19:28:16.190Z","dependency_job_id":null,"html_url":"https://github.com/ssseasonnn/RxDownload","commit_stats":null,"previous_names":[],"tags_count":76,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ssseasonnn%2FRxDownload","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ssseasonnn%2FRxDownload/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ssseasonnn%2FRxDownload/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ssseasonnn%2FRxDownload/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ssseasonnn","download_url":"https://codeload.github.com/ssseasonnn/RxDownload/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221631816,"owners_count":16855013,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["kotlin","rxdownload","rxjava"],"created_at":"2024-07-31T01:00:41.443Z","updated_at":"2024-10-27T05:30:29.996Z","avatar_url":"https://github.com/ssseasonnn.png","language":"Kotlin","funding_links":[],"categories":["开源库","Libraries","Rx"],"sub_categories":["下载"],"readme":"![](usage.png)\n\n# RxDownload\n\n![](https://img.shields.io/badge/language-kotlin-brightgreen.svg) ![](https://img.shields.io/badge/RxJava-2.0-blue.svg)\n\n[![](https://jitpack.io/v/ssseasonnn/RxDownload.svg)](https://jitpack.io/#ssseasonnn/RxDownload)\n\n基于RxJava打造的下载工具, 支持多线程下载和断点续传,使用Kotlin编写\n\n*Read this in other languages: [中文](README.ch.md), [English](README.md), [Changelog](CHANGELOG.md)* \n\n## Prepare\n\n- 添加jitpack仓库:\n\n    ```gradle\n    maven { url 'https://jitpack.io' }\n    \n- 添加RxDownload依赖:\n\n    ```gradle\n    //按需加载\n    implementation \"com.github.ssseasonnn.RxDownload:rxdownload4:1.1.4\"\n    implementation \"com.github.ssseasonnn.RxDownload:rxdownload4-manager:1.1.4\"\n    implementation \"com.github.ssseasonnn.RxDownload:rxdownload4-notification:1.1.4\"\n    implementation \"com.github.ssseasonnn.RxDownload:rxdownload4-recorder:1.1.4\"\n    \n    or: \n    //添加RxDownload4的所有依赖\n    implementation \"com.github.ssseasonnn:RxDownload:1.1.4\"\n    ```\n\n## Basic Usage\n\n- 开始下载:\n\n    ```kotlin\n    disposable = url.download()\n            .observeOn(AndroidSchedulers.mainThread())\n            .subscribeBy(\n                    onNext = { progress -\u003e\n                        //下载进度\n                        button.text = \"${progress.downloadSizeStr()}/${progress.totalSizeStr()}\"\n                        button.setProgress(progress)\n                    },\n                    onComplete = {\n                        //下载完成\n                        button.text = \"打开\"\n                    },\n                    onError = {\n                        //下载失败\n                        button.text = \"重试\"\n                    }\n            )    \n    ```\n\n- 停止下载:\n\n    ```kotlin\n    disposable.dispose()    \n    ```\n\n- 获取下载文件:\n\n    ```kotlin\n    val file = url.file() \n    // 或者\n    val file = task.file() \n    // 使用文件...    \n    ```\n- 删除下载的文件:\n\n    ```kotlin\n    url.delete()\n    // 或者\n    task.delete() \n    ```\n\n\n## Task Manager\n\n- 获取一个TaskManager对象:\n\n    ```kotlin\n    val taskManager = url.manager()\n    ```\n    \n- 订阅状态更新通知:\n\n    ```kotlin\n    //keep this tag for dispose\n    val tag = taskManager.subscribe { status -\u003e\n        // 获取下载状态\n        when (status) {\n            is Normal -\u003e {}\n            is Started -\u003e {}\n            is Downloading -\u003e {}\n            is Paused -\u003e {}\n            is Completed -\u003e {}\n            is Failed -\u003e {}\n            is Deleted -\u003e {}\n        }\n    }\n        \n    ``` \n    \n    \u003e **progress**可从**status**中获取, 当status为**Failed**时, 能额外从中获取**throwable**,代表失败的原因\n    \n- 取消状态更新订阅:\n\n    ```kotlin\n    //dispose tag\n    taskManager.dispose(tag)\n    ```\n    \n- 开始下载:\n\n    ```kotlin\n    taskManager.start()\n    ```\n\n- 停止下载:\n\n    ```kotlin\n    taskManager.stop()\n    ```\n    \n- 删除下载:\n\n    ```kotlin\n    taskManager.delete()\n    ```\n\n- 获取下载文件:\n\n    ```kotlin\n    val file = taskManager.file()\n    // 使用文件...  \n    ```\n\n## Task Recorder\n\n- 查询单个任务:\n\n    ```kotlin\n     // Query task with url\n     RxDownloadRecorder.getTask(\"url\")\n           .observeOn(AndroidSchedulers.mainThread())\n           .subscribeBy { TaskEntity -\u003e\n               // TaskEntity                        \n           } \n    ``` \n    \n- 查询一批任务:\n\n    ```kotlin\n     // Query task with urls\n     RxDownloadRecorder.getTaskList(\"url1\",\"url2\",\"url3\")\n           .observeOn(AndroidSchedulers.mainThread())\n           .subscribeBy { list -\u003e\n               // list of TaskEntity                        \n           } \n    ```    \n    \n- 获取所有下载记录列表:\n\n    ```kotlin\n     RxDownloadRecorder.getAllTask()\n           .observeOn(AndroidSchedulers.mainThread())\n           .subscribeBy { list -\u003e\n               //list of TaskEntity                        \n           }\n    ```\n    \n- 查询某个状态的所有下载记录:\n\n    ```kotlin\n     // 查询所有下载完成的记录\n     RxDownloadRecorder.getAllTaskWithStatus(Completed())\n           .observeOn(AndroidSchedulers.mainThread())\n           .subscribeBy { list -\u003e\n               //list of TaskEntity                        \n           } \n    ``` \n    \n- 分页查询下载记录列表:\n\n    ```kotlin\n     RxDownloadRecorder.getTaskList(page, pageSize)\n           .observeOn(AndroidSchedulers.mainThread())\n           .subscribeBy { list -\u003e\n               //list of TaskEntity                        \n           }\n    ```\n    \n- 分页查询某个状态下的下载记录列表:\n\n    ```kotlin\n     // 获取下载完成的分页列表\n     RxDownloadRecorder.getTaskListWithStatus(Completed(), page, pageSize)\n           .observeOn(AndroidSchedulers.mainThread())\n           .subscribeBy { list -\u003e\n               //list of TaskEntity                        \n           }\n    ```\n\n    \u003e **TaskEntity** 拥有一个**abnormalExit**字段, 该字段用来表示该Task是否是被APP强制杀进程导致的暂停\n\n\n- 全部开始:\n\n    ```kotlin\n     RxDownloadRecorder.startAll()\n    ```\n    \n- 全部暂停:\n\n    ```kotlin\n     RxDownloadRecorder.stopAll()\n    ```\n    \n- 全部删除:\n\n    ```kotlin\n     RxDownloadRecorder.deleteAll()\n    ```\n\n## License\n\n\u003e ```\n\u003e Copyright 2019 Season.Zlc\n\u003e\n\u003e Licensed under the Apache License, Version 2.0 (the \"License\");\n\u003e you may not use this file except in compliance with the License.\n\u003e You may obtain a copy of the License at\n\u003e\n\u003e    http://www.apache.org/licenses/LICENSE-2.0\n\u003e\n\u003e Unless required by applicable law or agreed to in writing, software\n\u003e distributed under the License is distributed on an \"AS IS\" BASIS,\n\u003e WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n\u003e See the License for the specific language governing permissions and\n\u003e limitations under the License.\n\u003e ```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fssseasonnn%2FRxDownload","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fssseasonnn%2FRxDownload","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fssseasonnn%2FRxDownload/lists"}