├── .gitignore ├── GIF.gif ├── LICENSE ├── README.md ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle └── simple ├── .gitignore ├── .idea ├── .name ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── gradle.xml ├── libraries │ ├── Android_FastDownloader_1_0_3.xml │ ├── animated_vector_drawable_23_2_1.xml │ ├── appcompat_v7_23_2_1.xml │ ├── butterknife_8_4_0.xml │ ├── butterknife_annotations_8_4_0.xml │ ├── design_23_2_1.xml │ ├── espresso_core_2_2_2.xml │ ├── espresso_idling_resource_2_2_2.xml │ ├── exposed_instrumentation_api_publish_0_5.xml │ ├── hamcrest_core_1_3.xml │ ├── hamcrest_integration_1_3.xml │ ├── hamcrest_library_1_3.xml │ ├── javawriter_2_1_1.xml │ ├── javax_annotation_api_1_2.xml │ ├── javax_inject_1.xml │ ├── jsr305_2_0_1.xml │ ├── junit_4_12.xml │ ├── logging_interceptor_3_3_1.xml │ ├── okhttp_3_3_1.xml │ ├── okio_1_8_0.xml │ ├── recyclerview_v7_23_2_1.xml │ ├── rules_0_5.xml │ ├── runner_0_5.xml │ ├── support_annotations_24_1_0.xml │ ├── support_v4_23_2_1.xml │ └── support_vector_drawable_23_2_1.xml ├── misc.xml ├── modules.xml ├── runConfigurations.xml └── workspace.xml ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── proguard-rules.pro └── src └── main ├── AndroidManifest.xml ├── java └── com │ └── tamic │ └── fastdownsimple │ ├── DownApplication.java │ ├── DownLoadAddActivity.java │ ├── DownLoadListActivity.java │ ├── DownloadSimpleActivity.java │ ├── DownloadViewHolder.java │ ├── MainActivity.java │ ├── SingleSimpleActivity.java │ ├── down │ ├── DLDownloadListener.java │ ├── DLFrameCallback.java │ ├── DLNormalCallback.java │ └── DownloadInit.java │ └── widget │ ├── AbstractAdapter.java │ ├── AbstractViewHolder.java │ ├── Bridge.java │ ├── Configure.java │ ├── DataSetObservable.java │ ├── DownloadAdapter.java │ ├── PracticalRecyclerView.java │ ├── SectionItem.java │ ├── SectionItemImpl.java │ └── WaitingDialog.java └── res ├── drawable ├── apk.png ├── file.png ├── image.png ├── pdf.png ├── status_alert.png ├── status_cancel.png ├── status_down.png ├── status_download.png ├── status_faile.png ├── status_pused.png ├── status_right.png ├── txt.png ├── video.png └── zip.png ├── layout ├── activity_dowmload_list.xml ├── activity_down_load_add.xml ├── activity_download_simple.xml ├── activity_main_app.xml ├── activity_single.xml ├── activity_single_simple.xml ├── content_main.xml ├── content_single.xml ├── default_empty_layout.xml ├── default_error_layout.xml ├── default_load_more_failed_layout.xml ├── default_load_more_layout.xml ├── default_loading_layout.xml ├── default_no_more_layout.xml ├── reclye_download_item.xml └── recycler_layout.xml ├── mipmap-hdpi └── ic_launcher.png ├── mipmap-mdpi └── ic_launcher.png ├── mipmap-xhdpi └── ic_launcher.png ├── mipmap-xxhdpi └── ic_launcher.png ├── mipmap-xxxhdpi └── ic_launcher.png ├── values-v21 └── styles.xml ├── values-w820dp └── dimens.xml └── values ├── colors.xml ├── dimens.xml ├── strings.xml └── styles.xml /.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # Files for the ART/Dalvik VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # Generated files 12 | bin/ 13 | gen/ 14 | out/ 15 | 16 | # Gradle files 17 | .gradle/ 18 | build/ 19 | 20 | # Local configuration file (sdk path, etc) 21 | local.properties 22 | 23 | # Proguard folder generated by Eclipse 24 | proguard/ 25 | 26 | # Log Files 27 | *.log 28 | 29 | # Android Studio Navigation editor temp files 30 | .navigation/ 31 | 32 | # Android Studio captures folder 33 | captures/ 34 | 35 | # Intellij 36 | *.iml 37 | .idea/workspace.xml 38 | 39 | # Keystore files 40 | *.jks 41 | -------------------------------------------------------------------------------- /GIF.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tamicer/FastDownloader/6cf35c3d346b2eb1646bdf307f4440700b80955a/GIF.gif -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # FastDownloader 2 | 基于Okhttp3, 结合Builder,Okio ,加入多种设计模式,实现的android平台多线程下载利器! 3 | 4 | # 功能 # 5 | 6 | - 多线程多任务下载功能 7 | - 基本的断点续传 8 | - 下载数据持久,程序退出仍可以保留 9 | - 支持视频,小说,文件,应用,文本多模式下载 10 | - 支持通知栏下载进度同步更新 11 | - 支持静默和非静默下载 12 | - 支持多种参数定制,文件名,存储路径定制功能 13 | - 智能进行优先级下载,wifi自动恢复失败任务 14 | - 提供进度回调,可实现自定义的操作 15 | 16 | # 效果 17 | 18 | ![效果](https://github.com/Tamicer/FastDownloader/blob/master/GIF.gif) 19 | 20 | # 实践 # 21 | 22 | ## 依赖 ## 23 | 24 | gradle依赖远程maven包: 25 | 26 | 27 | compile 'com.tamic.fastdownloader:Android-FastDownloader:1.0.3' 28 | 29 | ## 初始化 ## 30 | 31 | Application中初始化下载 32 | 33 | @Override 34 | public void onCreate() { 35 | super.onCreate(); 36 | DownloadInit.initDownload(getApplicationContext()); 37 | 38 | } 39 | 40 | ## 调用 ## 41 | 42 | **simple 1**: 43 | 44 | new Download.Builder() 45 | .url(url) 46 | .build(this) 47 | .start(); 48 | 49 | 只要设置下载Url即可,文件名下载库会自动抓取, 50 | 默认优先级为中等,回调UI下载自动处理,默认的保存路径为:你的apk包名+ /tamic/downloads/ 下 51 | 52 | **simple 2:** 53 | 54 | 55 | 56 | 57 | new Download.Builder() 58 | .url("this is url")//下载url 59 | .priority(Priority.HIGH) 60 | .savepath("保存路径") 61 | .isImplicit(false)//是否显示UI 62 | .channel(3000)//渠道可选 63 | .client(DLClientFactory.createClient(Type.NORMAL, this))//下载器 64 | .setCallback(new DLCallback())//下载回调 65 | .build(this) 66 | .start(); 67 | 68 | 69 | 这种配置 可定制下载的文件名,存储路径,优先级,以及渠道,是否显示通知栏更新UI等,并且回调可以自我实现,譬如下载完成后显示安装对话框等 70 | 71 | # 高级API 72 | 73 | **重新开始下载** 74 | 75 | 通过`reStart()` 对已有的下载任务开始强制重新下载,将会删除已下载的缓存文件。 76 | 77 | ``` 78 | new Download.Builder() 79 | .url(url) 80 | .build(this) 81 |               .reStart(); 82 | 83 | ``` 84 | **创建新的下载** 85 | 86 | newStart() 创建新的下载 不删除以前文件。 87 | 88 | 89 | ``` 90 | new Download.Builder() 91 | .url(url) 92 | .build(this) 93 |               .newStart(); 94 | 95 | ``` 96 | 97 | 98 | **下载Task模式** 99 | 100 | 101 | 102 | `DownMode`  通过.mode(DownMode.SINGLE)设置下载任务模式,默认为DownMode.SINGLE:只存在一个此Url的下载记录, 再次下载不会创建新任务。 103 | 104 | new Download.Builder().mode(DownMode.SINGLE).url(url) 105 | .build(this).start(); 106 | 107 | 108 | **SINGLE**: 任务栈只存在一个此Url的下载记录。 再次下载不会创建新任务 109 | 110 | 111 | **TOP**: 任务栈如果存在此Tag的下载记录。 再次下载不会新任务。但是会重新下载,不会删除以前的文件 112 |     113 | 114 | 115 | **NEW_TASK**: 任务栈如果存在此Url的下载记录。 再次下载会新任务。 会重新下载,并且会删除以前的文件 116 | 117 |                 118 | 119 | **下载Tag** 120 | 121 | 可以通过`tag(String)` 设置下载ID 122 | 123 | ``` 124 | new Download.Builder() 125 | .tag("key") 126 | .url(url) 127 | .build(this) 128 |               .Start(); 129 | 130 | ``` 131 | 132 | 133 | 134 | 135 | 如果不设置Tag, 默认为Url+当前系统时间, 有了这个Tag你可以做暂停需取消等操作 136 | 137 | 138 | String tag = new Download.Builder() 139 | .url(url) 140 | .client(DLClientFactory.createClient(NORMAL, this)) 141 | .build(this) 142 | .start(); 143 |           144 | 145 | 146 | 147 | **自定义回调**   148 | 149 | 对某个下载进行操作可以单独加回调处理,使用`setCallback`如果忽略不设置,系统则默认不处理。 150 | 151 | 152 | 153 | new Download.Builder() 154 | .setCallback(new IDLCallback() { 155 | @Override 156 | public void onStart(String key, long fileLength, long downloaded, String savePath, String filenNme) { 157 | 158 | } 159 | 160 | @Override 161 | public void onSuccess(String key, long fileLength, long downloaded, String savePath, String filenNme, long aSpeed, String aAppiconName) { 162 | 163 | } 164 | 165 | @Override 166 | public void onAppSuccess(String key, long fileLength, long downloaded, String savePath, String filenNme, long aSpeed, String aAppiconName, int downloadType, int appType) { 167 | 168 | } 169 | 170 | @Override 171 | public void onFail(String key, long downloaded, String savePath, String filenNme, String aErrinfo) { 172 | 173 | } 174 | 175 | @Override 176 | public void onCancel(String key, long fileLength, long downloaded, String savePath, String filenNme) { 177 | 178 | } 179 | 180 | @Override 181 | public void onPause(String key, long fileLength, long downloaded, String savePath, String filenNme) { 182 | 183 | } 184 | 185 | @Override 186 | public void onDownloading(String key, long fileLength, long downloadLength, long speed, String fileName, int downloadType) { 187 | 188 | } 189 | 190 | @Override 191 | public void onRefresh(List infos) { 192 | 193 | } 194 | }) 195 | 196 | 197 | #License 198 | -------- 199 | 200 | Copyright 2013 Square, Inc. 201 | 202 | Licensed under the Apache License, Version 2.0 (the "License"); 203 | you may not use this file except in compliance with the License. 204 | You may obtain a copy of the License at 205 | 206 | http://www.apache.org/licenses/LICENSE-2.0 207 | 208 | Unless required by applicable law or agreed to in writing, software 209 | distributed under the License is distributed on an "AS IS" BASIS, 210 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 211 | See the License for the specific language governing permissions and 212 | limitations under the License. 213 | 214 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | //maven { url "http://maven.ipo.com/nexus/content/groups/public/" } 6 | jcenter() 7 | mavenCentral() 8 | //maven { url "https://jitpack.io" } 9 | } 10 | dependencies { 11 | classpath 'com.android.tools.build:gradle:1.3.0' 12 | classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8' 13 | 14 | classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.5' 15 | classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3' 16 | 17 | // NOTE: Do not place your application dependencies here; they belong 18 | // in the individual module build.gradle files 19 | } 20 | } 21 | 22 | allprojects { 23 | repositories { 24 | //maven { url "http://maven.ipo.com/nexus/content/groups/public/" } 25 | jcenter() 26 | mavenCentral() 27 | //maven { url "https://jitpack.io" } 28 | } 29 | } 30 | 31 | task clean(type: Delete) { 32 | delete rootProject.buildDir 33 | } 34 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | ## Project-wide Gradle settings. 2 | # 3 | # For more details on how to configure your build environment visit 4 | # http://www.gradle.org/docs/current/userguide/build_environment.html 5 | # 6 | # Specifies the JVM arguments used for the daemon process. 7 | # The setting is particularly useful for tweaking memory settings. 8 | # Default value: -Xmx1024m -XX:MaxPermSize=256m 9 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 10 | # 11 | # When configured, Gradle will run in incubating parallel mode. 12 | # This option should only be used with decoupled projects. More details, visit 13 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 14 | # org.gradle.parallel=true 15 | #Fri Dec 30 10:54:21 CST 2016 16 | systemProp.http.proxyPort=3128 17 | android.useDeprecatedNdk=true 18 | systemProp.https.proxyHost=10.59.72.13 19 | systemProp.http.proxyHost=10.59.72.13 20 | systemProp.https.proxyPort=3128 21 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tamicer/FastDownloader/6cf35c3d346b2eb1646bdf307f4440700b80955a/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Dec 28 10:00:20 PST 2015 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':simple' 2 | -------------------------------------------------------------------------------- /simple/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /simple/.idea/.name: -------------------------------------------------------------------------------- 1 | FastDownloader -------------------------------------------------------------------------------- /simple/.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /simple/.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /simple/.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 18 | -------------------------------------------------------------------------------- /simple/.idea/libraries/Android_FastDownloader_1_0_3.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /simple/.idea/libraries/animated_vector_drawable_23_2_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /simple/.idea/libraries/appcompat_v7_23_2_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /simple/.idea/libraries/butterknife_8_4_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /simple/.idea/libraries/butterknife_annotations_8_4_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /simple/.idea/libraries/design_23_2_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /simple/.idea/libraries/espresso_core_2_2_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /simple/.idea/libraries/espresso_idling_resource_2_2_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /simple/.idea/libraries/exposed_instrumentation_api_publish_0_5.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /simple/.idea/libraries/hamcrest_core_1_3.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /simple/.idea/libraries/hamcrest_integration_1_3.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /simple/.idea/libraries/hamcrest_library_1_3.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /simple/.idea/libraries/javawriter_2_1_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /simple/.idea/libraries/javax_annotation_api_1_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /simple/.idea/libraries/javax_inject_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /simple/.idea/libraries/jsr305_2_0_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /simple/.idea/libraries/junit_4_12.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /simple/.idea/libraries/logging_interceptor_3_3_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /simple/.idea/libraries/okhttp_3_3_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /simple/.idea/libraries/okio_1_8_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /simple/.idea/libraries/recyclerview_v7_23_2_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /simple/.idea/libraries/rules_0_5.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /simple/.idea/libraries/runner_0_5.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /simple/.idea/libraries/support_annotations_24_1_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /simple/.idea/libraries/support_v4_23_2_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /simple/.idea/libraries/support_vector_drawable_23_2_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /simple/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 16 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 43 | -------------------------------------------------------------------------------- /simple/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /simple/.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /simple/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | apply plugin: 'com.neenbedankt.android-apt' 3 | android { 4 | compileSdkVersion 23 5 | buildToolsVersion "23.0.1" 6 | defaultConfig { 7 | applicationId "com.tamic.fastdownsimple" 8 | minSdkVersion 21 9 | targetSdkVersion 23 10 | versionCode 2 11 | versionName "1.2" 12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | debug { 20 | minifyEnabled false 21 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 22 | } 23 | } 24 | } 25 | 26 | dependencies { 27 | compile fileTree(dir: 'libs', include: ['*.jar']) 28 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 29 | exclude group: 'com.android.support', module: 'support-annotations' 30 | }) 31 | compile 'com.android.support:appcompat-v7:23.2.1' 32 | compile 'com.android.support:design:23.2.1' 33 | compile 'com.jakewharton:butterknife:8.4.0' 34 | apt 'com.jakewharton:butterknife-compiler:8.4.0' 35 | //compile 'com.android.support:recyclerview-v7:23.2.1' 36 | compile 'com.tamic.fastdownloader:Android-FastDownloader:1.0.3' 37 | testCompile 'junit:junit:4.12' 38 | compile 'com.android.support.test.espresso:espresso-core:2.2.2' 39 | } 40 | -------------------------------------------------------------------------------- /simple/gradle.properties: -------------------------------------------------------------------------------- 1 | ## Project-wide Gradle settings. 2 | # 3 | # For more details on how to configure your build environment visit 4 | # http://www.gradle.org/docs/current/userguide/build_environment.html 5 | # 6 | # Specifies the JVM arguments used for the daemon process. 7 | # The setting is particularly useful for tweaking memory settings. 8 | # Default value: -Xmx1024m -XX:MaxPermSize=256m 9 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 10 | # 11 | # When configured, Gradle will run in incubating parallel mode. 12 | # This option should only be used with decoupled projects. More details, visit 13 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 14 | # org.gradle.parallel=true 15 | #Mon May 08 14:57:37 CST 2017 16 | systemProp.http.proxyHost=10.59.72.13 17 | systemProp.http.proxyPort=3128 18 | -------------------------------------------------------------------------------- /simple/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tamicer/FastDownloader/6cf35c3d346b2eb1646bdf307f4440700b80955a/simple/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /simple/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Dec 28 10:00:20 PST 2015 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip 7 | -------------------------------------------------------------------------------- /simple/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /simple/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /simple/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in D:\Users\liuyongkui726\AppData\Local\Android\android-sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -optimizationpasses 7 19 | -dontusemixedcaseclassnames 20 | -dontskipnonpubliclibraryclasses 21 | -dontskipnonpubliclibraryclassmembers 22 | -dontpreverify 23 | -verbose 24 | -allowaccessmodification 25 | -optimizations !code/simplification/arithmetic,!field/*,!class/merging/* 26 | 27 | -dontwarn android.webkit** 28 | -keepattributes *Annotation* 29 | 30 | -keep public class * extends android.app.Activity 31 | -keep public class * extends android.app.Application 32 | -keep public class * extends android.app.Service 33 | -keep public class * extends android.content.BroadcastReceiver 34 | -keep public class * extends android.content.ContentProvider 35 | -keep public class com.android.vending.licensing.ILicensingService 36 | 37 | 38 | -keepattributes *Annotation* 39 | 40 | 41 | -keepattributes SourceFile,LineNumberTable 42 | 43 | -keep public class * extends android.view.View 44 | 45 | 46 | -keepclassmembers enum * { 47 | public static **[] values(); 48 | public static ** valueOf(java.lang.String); 49 | } 50 | 51 | -keep class android.support.v4.** { *; } 52 | -keep public class * extends android.support.v4.** 53 | -keep public class * extends android.app.Fragment 54 | -dontwarn android.support.** 55 | 56 | -keep public class * extends android.view.View { 57 | public (android.content.Context); 58 | public (android.content.Context, android.util.AttributeSet); 59 | public (android.content.Context, android.util.AttributeSet, int); 60 | public void set*(...); 61 | public void get*(...); 62 | } 63 | 64 | -keepclassmembers class * implements android.os.Parcelable { 65 | static android.os.Parcelable$Creator CREATOR; 66 | } 67 | 68 | -keepclassmembers class **.R$* { 69 | public static ; 70 | } 71 | 72 | #== okhttp===== 73 | -dontwarn com.squareup.okhttp** 74 | -keep class com.squareup.okhttp.**{*;} 75 | -dontwarn okio** 76 | -keep class okio.**{*;} 77 | 78 | #=== butterknife==== 79 | -keep class butterknife.** { *; } 80 | -dontwarn butterknife.internal.** 81 | -keep class **$$ViewBinder { *; } 82 | 83 | -keepclasseswithmembernames class * { 84 | @butterknife.* ; 85 | } 86 | 87 | -keepclasseswithmembernames class * { 88 | @butterknife.* ; 89 | } -------------------------------------------------------------------------------- /simple/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 47 | 50 | 51 | 54 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /simple/src/main/java/com/tamic/fastdownsimple/DownApplication.java: -------------------------------------------------------------------------------- 1 | package com.tamic.fastdownsimple; 2 | 3 | import android.app.Application; 4 | 5 | import com.tamic.fastdownsimple.down.DLDownloadListener; 6 | import com.tamic.fastdownsimple.down.DLNormalCallback; 7 | import com.tamic.fastdownsimple.down.DownloadInit; 8 | import com.tamic.fastdownsimple.widget.DownloadAdapter; 9 | import com.tamic.rx.fastdown.client.DLClientFactory; 10 | import com.tamic.rx.fastdown.client.Type; 11 | import com.tamic.rx.fastdown.core.Download; 12 | import com.tamic.rx.fastdown.core.RxDownloadManager; 13 | 14 | 15 | /** 16 | * Created by Tamic on 2016-12-22. 17 | */ 18 | public class DownApplication extends Application { 19 | 20 | public static DownloadAdapter downloadAdapter; 21 | @Override 22 | public void onCreate() { 23 | super.onCreate(); 24 | init(); 25 | } 26 | 27 | private void init() { 28 | 29 | DownloadInit.init(getBaseContext()); 30 | 31 | new Download.ConfigBuilder<>() 32 | .addMaxCount(5) 33 | .downloadListener(new DLDownloadListener(this.getBaseContext())) 34 | .baseClient(DLClientFactory.createClient(Type.NORMAL, getBaseContext())) 35 | .newbuild(this, downloadAdapter); 36 | /* RxDownloadManager manager = RxDownloadManager.getInstance(); 37 | manager.init(getBaseContext(), null); 38 | manager.setContext(getBaseContext()); 39 | manager.setListener(new DLDownloadListener(getBaseContext())); 40 | 41 | 42 | DLNormalCallback normalCallback = new DLNormalCallback(); 43 | if (manager.getClient() != null) { 44 | manager.getClient().setCallback(normalCallback); 45 | }*/ 46 | 47 | 48 | 49 | 50 | 51 | 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /simple/src/main/java/com/tamic/fastdownsimple/DownLoadAddActivity.java: -------------------------------------------------------------------------------- 1 | package com.tamic.fastdownsimple; 2 | 3 | 4 | import android.support.v7.app.AppCompatActivity; 5 | 6 | import android.os.Bundle; 7 | import android.text.TextUtils; 8 | import android.view.View; 9 | import android.widget.AutoCompleteTextView; 10 | import android.widget.Button; 11 | import android.widget.Toast; 12 | 13 | import com.tamic.rx.fastdown.client.DLClientFactory; 14 | import com.tamic.rx.fastdown.client.Type; 15 | import com.tamic.rx.fastdown.core.Download; 16 | import com.tamic.rx.fastdown.core.Priority; 17 | 18 | import butterknife.ButterKnife; 19 | import butterknife.OnClick; 20 | import okhttp3.HttpUrl; 21 | 22 | 23 | /** 24 | * DownLoadAddActivity 25 | */ 26 | public class DownLoadAddActivity extends AppCompatActivity { 27 | 28 | // UI references. 29 | private AutoCompleteTextView mUrlView; 30 | Button mGoDownButton; 31 | 32 | @Override 33 | protected void onCreate(Bundle savedInstanceState) { 34 | super.onCreate(savedInstanceState); 35 | setContentView(R.layout.activity_down_load_add); 36 | ButterKnife.bind(this, this); 37 | // Set up the url form. 38 | mUrlView = (AutoCompleteTextView) findViewById(R.id.down_Loadurl); 39 | mGoDownButton = (Button) findViewById(R.id.down_in_button); 40 | 41 | } 42 | 43 | 44 | /** 45 | * Attempts to sign in or register the account specified by the login form. 46 | * If there are form errors (invalid url, missing fields, etc.), the 47 | * errors are presented and no actual login attempt is made. 48 | */ 49 | @OnClick(R.id.down_in_button) 50 | void attemptDown() { 51 | 52 | // Reset errors. 53 | mUrlView.setError(null); 54 | 55 | // Store values at the time of the login attempt. 56 | String url = mUrlView.getText().toString(); 57 | 58 | boolean cancel = false; 59 | View focusView = null; 60 | 61 | // Check for a valid url address. 62 | if (TextUtils.isEmpty(url)) { 63 | mUrlView.setError(getString(R.string.error_field_required)); 64 | Toast.makeText(this, R.string.error_field_required, Toast.LENGTH_SHORT).show(); 65 | focusView = mUrlView; 66 | cancel = true; 67 | focusView.requestFocus(); 68 | return; 69 | } 70 | // Check for a valid url address. 71 | 72 | if (HttpUrl.parse(url) == null || TextUtils.isEmpty(HttpUrl.parse(url).url().toString())) { 73 | mUrlView.setError(getString(R.string.error_field_required)); 74 | Toast.makeText(this, R.string.error_invalid_url, Toast.LENGTH_SHORT).show(); 75 | focusView = mUrlView; 76 | cancel = true; 77 | focusView.requestFocus(); 78 | return; 79 | } 80 | 81 | 82 | // perform the down attempt. 83 | new Download.Builder() 84 | .url(url) 85 | .priority(Priority.LOW) 86 | .type(Type.NORMAL) 87 | // .client(DLClientFactory.createClient(DLClientFactory.NORMAL, this)) 88 | .build(this) 89 | .start(); 90 | 91 | } 92 | 93 | } 94 | 95 | -------------------------------------------------------------------------------- /simple/src/main/java/com/tamic/fastdownsimple/DownLoadListActivity.java: -------------------------------------------------------------------------------- 1 | package com.tamic.fastdownsimple; 2 | 3 | import android.os.Bundle; 4 | import android.support.v7.app.AppCompatActivity; 5 | import android.support.v7.widget.LinearLayoutManager; 6 | import android.widget.RelativeLayout; 7 | 8 | import com.tamic.fastdownsimple.widget.DownloadAdapter; 9 | import com.tamic.fastdownsimple.widget.PracticalRecyclerView; 10 | import com.tamic.rx.fastdown.client.Type; 11 | import com.tamic.rx.fastdown.content.DownLoadInfo; 12 | import com.tamic.rx.fastdown.core.RxDownLoadCenter; 13 | import com.tamic.rx.fastdown.core.RxDownloadManager; 14 | import com.tamic.rx.fastdown.listener.IUIDownHandler; 15 | 16 | import java.util.ArrayList; 17 | import java.util.Collections; 18 | import java.util.Comparator; 19 | import java.util.HashSet; 20 | import java.util.List; 21 | 22 | import butterknife.BindView; 23 | import butterknife.ButterKnife; 24 | 25 | /** 26 | * DownLoadList 27 | * Created by Tamic on 2016-12-27. 28 | */ 29 | public class DownLoadListActivity extends AppCompatActivity implements IUIDownHandler { 30 | @BindView(R.id.content_main) 31 | RelativeLayout mContentMain; 32 | @BindView(R.id.recycler) 33 | PracticalRecyclerView mRecycler; 34 | DownloadAdapter mAdapter; 35 | 36 | List data = new ArrayList<>(); 37 | HashSet set = new HashSet<>(); 38 | 39 | @Override 40 | protected void onCreate(Bundle savedInstanceState) { 41 | super.onCreate(savedInstanceState); 42 | setContentView(R.layout.activity_dowmload_list); 43 | ButterKnife.bind(this, this); 44 | 45 | mAdapter = new DownloadAdapter(); 46 | 47 | RxDownloadManager.getInstance().setUiDownHandler(this); 48 | RxDownLoadCenter.getInstance(this).loadTask(); 49 | 50 | 51 | //mAdapter = DownApplication.downloadAdapter; 52 | mRecycler.setLayoutManager(new LinearLayoutManager(this)); 53 | mRecycler.setAdapterWithLoading(mAdapter); 54 | // Data references. 55 | List allinfo = RxDownLoadCenter.getInstance(this).getAllInfoWithType(Type.NORMAL); 56 | List allSuccessinfo = RxDownLoadCenter.getInstance(this).getAllSuccessInfo(); 57 | 58 | if (!data.containsAll(allinfo)) { 59 | data.addAll(allinfo); 60 | } 61 | 62 | if (data.addAll(allSuccessinfo)) { 63 | data.addAll(allSuccessinfo); 64 | } 65 | 66 | mAdapter.getData().clear(); 67 | mAdapter.addAll(data); 68 | } 69 | 70 | @Override 71 | public void notifyComplete(DownLoadInfo info) { 72 | mAdapter.notifyDataSetChanged(); 73 | } 74 | 75 | @Override 76 | public void notifyRefresh(DownLoadInfo downLoadInfo) { 77 | mAdapter.notifyDataSetChanged(); 78 | 79 | } 80 | 81 | @Override 82 | public void notifyRefresh() { 83 | 84 | mAdapter.notifyDataSetChanged(); 85 | } 86 | 87 | @Override 88 | public void notifyNewTask(DownLoadInfo info) { 89 | // checkEmpty(); 90 | RxDownloadManager.getInstance().loadTask(); 91 | loadData(null); 92 | mAdapter.notifyDataSetChanged(); 93 | 94 | } 95 | 96 | public void loadData(String tag) { 97 | List infos = RxDownLoadCenter.getInstance(this).getAllInfoWithType(Type.NORMAL); 98 | data.clear(); 99 | for (DownLoadInfo info : infos) { 100 | data.add(info); 101 | } 102 | mAdapter.clearData(); 103 | mAdapter.addAll(data); 104 | sort(); 105 | } 106 | 107 | private void sort() { 108 | Collections.sort(data, new Comparator() { 109 | @Override 110 | public int compare(DownLoadInfo item1, DownLoadInfo item2) { 111 | return (int) (item2.mCreatedtime - item1.mCreatedtime); 112 | } 113 | }); 114 | } 115 | 116 | 117 | /*private void unsubscribe() { 118 | List list = mAdapter.getData(); 119 | for (DownLoadInfo each : list) { 120 | each.unsubscrbe(); 121 | } 122 | }*/ 123 | } 124 | -------------------------------------------------------------------------------- /simple/src/main/java/com/tamic/fastdownsimple/DownloadSimpleActivity.java: -------------------------------------------------------------------------------- 1 | package com.tamic.fastdownsimple; 2 | 3 | import android.os.Bundle; 4 | import android.support.v7.app.AppCompatActivity; 5 | import android.widget.Button; 6 | 7 | import com.tamic.fastdownsimple.down.DLFrameCallback; 8 | import com.tamic.fastdownsimple.down.DLNormalCallback; 9 | import com.tamic.rx.fastdown.client.DLClientFactory; 10 | import com.tamic.rx.fastdown.core.Download; 11 | import com.tamic.rx.fastdown.core.Priority; 12 | 13 | import butterknife.BindView; 14 | import butterknife.ButterKnife; 15 | import butterknife.OnClick; 16 | 17 | import static com.tamic.rx.fastdown.client.Type.FRAME; 18 | import static com.tamic.rx.fastdown.client.Type.NORMAL; 19 | 20 | public class DownloadSimpleActivity extends AppCompatActivity { 21 | 22 | 23 | // UI references. 24 | @BindView(R.id.downpk) 25 | Button downApk; 26 | @BindView(R.id.downdf) 27 | Button downPdf; 28 | @BindView(R.id.downImag) 29 | Button downImage; 30 | 31 | String url = "http://wifiapi02.51y5.net/wifiapi/rd.do?f=wk00003&b=gwanz02&rurl=http%3A%2F%2Fdl.lianwifi.com%2Fdownload%2Fandroid%2FWifiKey-3091-guanwang.apk"; 32 | private String url_sougou = "http://wap.dl.pinyin.sogou.com/wapdl/hole/201512/03/SogouInput_android_v7.11_sweb.apk"; 33 | @Override 34 | protected void onCreate(Bundle savedInstanceState) { 35 | super.onCreate(savedInstanceState); 36 | setContentView(R.layout.activity_download_simple); 37 | ButterKnife.bind(this, this); 38 | } 39 | 40 | @OnClick(R.id.downdf) 41 | void calldownPdf() { 42 | new Download.Builder() 43 | .url("http://downloads2.txt99.com/d/file/p/txt/2016/%E5%BD%B1%E5%B8%9D%E7%9A%84%E8%80%81%E5%A9%86.txt") 44 | .priority(Priority.HIGH) 45 | .isImplicit(false) 46 | .channel(3000) 47 | .client(DLClientFactory.createClient(NORMAL, this)) 48 | .setCallback(new DLFrameCallback()) 49 | .build(this) 50 | .start(); 51 | } 52 | 53 | @OnClick(R.id.downpk) 54 | void calldownApK() { 55 | 56 | new Download.Builder() 57 | .url(url) 58 | .priority(Priority.HIGH) 59 | .name("simple.apk") 60 | .isImplicit(false) 61 | .type(FRAME) 62 | .channel(2000) 63 | .setCallback(new DLNormalCallback()) 64 | .build(this).start(); 65 | 66 | } 67 | 68 | @OnClick(R.id.downImag) 69 | void calldownImage() { 70 | //http://cdn2.parllay.cn/2016102217/gr7s7ygyd5sg0.mp4 71 | // "http://p2.gexing.com/kongjianpifu/20120713/1622/4fffdacf88244.jpg" 72 | new Download.Builder() 73 | .url("http://cdn2.parllay.cn/2016102217/gr7s7ygyd5sg0.mp4") 74 | .priority(Priority.MEDIUM) 75 | .isImplicit(false) 76 | .channel(1000) 77 | .client(DLClientFactory.createClient(NORMAL, this)) 78 | .build(this) 79 | .start(); 80 | 81 | } 82 | 83 | @OnClick(R.id.downloadSogou) 84 | void calldownSogou() { 85 | 86 | String key = new Download.Builder() 87 | .tag("key") 88 | .url(url_sougou) 89 | .priority(Priority.HIGH) 90 | .isImplicit(false) 91 | .client(DLClientFactory.createClient(NORMAL, this)) 92 | .build(this) 93 | .start(); 94 | 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /simple/src/main/java/com/tamic/fastdownsimple/DownloadViewHolder.java: -------------------------------------------------------------------------------- 1 | package com.tamic.fastdownsimple; 2 | 3 | import android.content.Context; 4 | import android.support.annotation.DrawableRes; 5 | import android.text.format.Formatter; 6 | import android.view.View; 7 | import android.view.ViewGroup; 8 | import android.widget.Button; 9 | import android.widget.ImageView; 10 | import android.widget.ProgressBar; 11 | import android.widget.TextView; 12 | import android.widget.Toast; 13 | 14 | import com.tamic.fastdownsimple.widget.AbstractViewHolder; 15 | import com.tamic.rx.fastdown.DLMimeType; 16 | import com.tamic.rx.fastdown.content.DownLoadInfo; 17 | import com.tamic.rx.fastdown.core.RxDownLoadCenter; 18 | import com.tamic.rx.fastdown.core.DownLoadBuilder; 19 | import com.tamic.rx.fastdown.core.RxDownLoadCenter; 20 | import com.tamic.rx.fastdown.core.RxDownloadManager; 21 | import com.tamic.rx.fastdown.util.Utils; 22 | 23 | import butterknife.BindView; 24 | import butterknife.ButterKnife; 25 | import butterknife.OnClick; 26 | 27 | import static com.tamic.fastdownsimple.R.id.percent; 28 | 29 | 30 | /** 31 | * DownloadViewHolder 32 | * Created by Tamic on 2016-12-27. 33 | */ 34 | public class DownloadViewHolder extends AbstractViewHolder { 35 | 36 | @BindView(R.id.img) 37 | public ImageView mImg; 38 | @BindView(percent) 39 | public TextView mPercent; 40 | @BindView(R.id.progress) 41 | public ProgressBar mProgress; 42 | @BindView(R.id.size) 43 | public TextView mSize; 44 | @BindView(R.id.filesize) 45 | public TextView mFlieSize; 46 | @BindView(R.id.speed) 47 | public TextView mSpeed; 48 | @BindView(R.id.status) 49 | public Button mStatus; 50 | 51 | DownLoadInfo data; 52 | private Context mContext; 53 | 54 | public DownloadViewHolder(ViewGroup parent) { 55 | super(parent, R.layout.reclye_download_item); 56 | ButterKnife.bind(this, itemView); 57 | mContext = parent.getContext(); 58 | 59 | } 60 | 61 | @Override 62 | public void setData(DownLoadInfo data) { 63 | this.data = data; 64 | checkTypeUI(data); 65 | mProgress.setMax((int) data.mTotalbytes); 66 | mProgress.setProgress((int) data.mDownloadedbytes); 67 | mSpeed.setText(Formatter.formatFileSize(mContext, data.mSpeed) + "/s"); 68 | mPercent.setText(data.mFilename); 69 | mSize.setText(Utils.formatFilesize(data.mDownloadedbytes) + "/" ); 70 | mFlieSize.setText(Utils.formatFilesize(data.mTotalbytes)); 71 | checkUI(data); 72 | } 73 | 74 | private void checkTypeUI(DownLoadInfo data) { 75 | 76 | switch (data.itemFileType()) { 77 | 78 | case DLMimeType.APK: 79 | mImg.setBackgroundResource(R.drawable.apk); 80 | break; 81 | 82 | case DLMimeType.JPEG: 83 | mImg.setBackgroundResource(R.drawable.image); 84 | break; 85 | 86 | case DLMimeType.BMP: 87 | mImg.setBackgroundResource(R.drawable.image); 88 | break; 89 | 90 | case DLMimeType.PNG: 91 | mImg.setBackgroundResource(R.drawable.image); 92 | break; 93 | 94 | case DLMimeType.PDF: 95 | mImg.setBackgroundResource(R.drawable.pdf); 96 | break; 97 | 98 | case DLMimeType.TXT: 99 | mImg.setBackgroundResource(R.drawable.txt); 100 | 101 | break; 102 | 103 | case DLMimeType.VIDEO: 104 | mImg.setBackgroundResource(R.drawable.video); 105 | 106 | break; 107 | 108 | case DLMimeType.OTHERS: 109 | mImg.setBackgroundResource(R.drawable.file); 110 | break; 111 | 112 | default: 113 | mImg.setBackgroundResource(R.drawable.file); 114 | break; 115 | // more Type , you need to add 。。。。。 116 | 117 | } 118 | 119 | } 120 | 121 | 122 | private void checkUI(DownLoadInfo data) { 123 | 124 | switch (data.mStatus) { 125 | case RUNNING: 126 | setSatus(R.drawable.status_down, "下载中"); 127 | mSize.setVisibility(View.VISIBLE); 128 | break; 129 | 130 | case SUCCESS: 131 | setSatus(R.drawable.status_right, "完成"); 132 | mSpeed.setText("下载已完成"); 133 | mProgress.setMax(100); 134 | mProgress.setProgress(100); 135 | mSize.setVisibility(View.INVISIBLE); 136 | 137 | break; 138 | 139 | case PAUSED: 140 | setSatus(R.drawable.status_pused, "继续"); 141 | mSpeed.setText("已暂停,点击继续"); 142 | break; 143 | 144 | case FAIL: 145 | setSatus(R.drawable.status_alert, "重试"); 146 | mSpeed.setText("下载出错,请重试"); 147 | mSize.setVisibility(View.INVISIBLE); 148 | break; 149 | 150 | case AUTOPAUSE: 151 | setSatus(R.drawable.status_down, "继续"); 152 | mSpeed.setText("下载已自动暂停,点击继续"); 153 | mSize.setVisibility(View.VISIBLE); 154 | break; 155 | 156 | case READY: 157 | setSatus(R.drawable.status_pused, "等待中"); 158 | mSpeed.setText("任务正在排队中,请稍后...."); 159 | mSize.setVisibility(View.INVISIBLE); 160 | break; 161 | 162 | default: 163 | setSatus(R.drawable.status_down, "开始"); 164 | break; 165 | } 166 | } 167 | 168 | private void setSatus(@DrawableRes int resId, String tpis) { 169 | // mStatus.setText(tpis); 170 | mStatus.setBackgroundResource(resId); 171 | } 172 | 173 | @OnClick(R.id.status) 174 | public void onClick() { 175 | switch (data.mStatus) { 176 | case RUNNING: 177 | RxDownLoadCenter.getInstance(mContext).pausetask(data.mKey, true); 178 | Toast.makeText(mContext, "已暂停", Toast.LENGTH_SHORT).show(); 179 | case READY: 180 | //点击暂停 181 | RxDownLoadCenter.getInstance(mContext).pausetask(data.mKey, true); 182 | Toast.makeText(mContext, "已暂停", Toast.LENGTH_SHORT).show(); 183 | break; 184 | case PAUSED: 185 | RxDownLoadCenter.getInstance(mContext).resumeTask(data.mKey, true); 186 | 187 | break; 188 | case FAIL: 189 | RxDownLoadCenter.getInstance(mContext).addTask(data); 190 | break; 191 | case SUCCESS: 192 | Toast.makeText(mContext, "已下载完成,不要重复点啦", Toast.LENGTH_SHORT).show(); 193 | break; 194 | default: 195 | break; 196 | } 197 | } 198 | 199 | } 200 | -------------------------------------------------------------------------------- /simple/src/main/java/com/tamic/fastdownsimple/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.tamic.fastdownsimple; 2 | 3 | import android.content.Intent; 4 | import android.support.v7.app.AppCompatActivity; 5 | import android.os.Bundle; 6 | import android.widget.Button; 7 | 8 | import com.tamic.rx.fastdown.core.RxDownloadManager; 9 | 10 | import butterknife.BindView; 11 | import butterknife.ButterKnife; 12 | import butterknife.OnClick; 13 | 14 | /** 15 | * Created by Tamic on 2016-12-27. 16 | */ 17 | public class MainActivity extends AppCompatActivity { 18 | 19 | @BindView(R.id.downloadList) 20 | Button openList; 21 | @BindView(R.id.downloadMore) 22 | Button openMore; 23 | @BindView(R.id.downloadbase) 24 | Button openBase; 25 | @BindView(R.id.downMode) 26 | Button openMode; 27 | 28 | @Override 29 | protected void onCreate(Bundle savedInstanceState) { 30 | super.onCreate(savedInstanceState); 31 | setContentView(R.layout.activity_main_app); 32 | ButterKnife.bind(this, this); 33 | } 34 | 35 | @OnClick(R.id.downloadList) 36 | void openList() { 37 | startActivity(new Intent(this, DownLoadListActivity.class)); 38 | } 39 | 40 | @OnClick(R.id.downloadMore) 41 | void openMore() { 42 | startActivity(new Intent(this, DownLoadAddActivity.class)); 43 | } 44 | 45 | @OnClick(R.id.downloadbase) 46 | void openBase() { 47 | startActivity(new Intent(this, DownloadSimpleActivity.class)); 48 | } 49 | 50 | @OnClick(R.id.downMode) 51 | void openMode() { 52 | startActivity(new Intent(this, SingleSimpleActivity.class)); 53 | } 54 | 55 | @OnClick(R.id.loadCache) 56 | void loadCache() { 57 | //非必须 ,扫描存在文件,也可以只在首次安装进行扫描 58 | RxDownloadManager.getInstance().scanDefaultFolder(); 59 | } 60 | 61 | @OnClick(R.id.statusCation) 62 | void removeTasks() { 63 | RxDownloadManager.getInstance().removeTasks(true); 64 | } 65 | 66 | 67 | } 68 | -------------------------------------------------------------------------------- /simple/src/main/java/com/tamic/fastdownsimple/SingleSimpleActivity.java: -------------------------------------------------------------------------------- 1 | package com.tamic.fastdownsimple; 2 | 3 | import android.os.Bundle; 4 | import android.support.v7.app.AppCompatActivity; 5 | import android.widget.Button; 6 | 7 | 8 | import com.tamic.fastdownsimple.down.DLNormalCallback; 9 | import com.tamic.rx.fastdown.callback.IDLCallback; 10 | import com.tamic.rx.fastdown.client.DLClientFactory; 11 | import com.tamic.rx.fastdown.content.DownLoadInfo; 12 | import com.tamic.rx.fastdown.core.Download; 13 | import com.tamic.rx.fastdown.core.Priority; 14 | 15 | import java.util.List; 16 | 17 | import butterknife.BindView; 18 | import butterknife.ButterKnife; 19 | import butterknife.OnClick; 20 | 21 | import static com.tamic.rx.fastdown.client.Type.FRAME; 22 | import static com.tamic.rx.fastdown.client.Type.NORMAL; 23 | 24 | /** 25 | * Created by Tamic on 2016-12-27. 26 | */ 27 | public class SingleSimpleActivity extends AppCompatActivity { 28 | 29 | // UI references. 30 | @BindView(R.id.singledown) 31 | Button mSingle; 32 | @BindView(R.id.taskdown) 33 | Button mTaskdown; 34 | @BindView(R.id.newdown) 35 | Button mNewDown; 36 | @Override 37 | protected void onCreate(Bundle savedInstanceState) { 38 | super.onCreate(savedInstanceState); 39 | setContentView(R.layout.activity_single_simple); 40 | ButterKnife.bind(this, this); 41 | 42 | 43 | } 44 | 45 | 46 | @OnClick(R.id.singledown) 47 | void sinleDown() { 48 | 49 | new Download.Builder() 50 | .priority(Priority.HIGH) 51 | .name("simple.apk") 52 | .isImplicit(false) 53 | .savepath("可以指定目录") 54 | .type(FRAME) 55 | .channel(2000) 56 | .setCallback(new IDLCallback() { 57 | @Override 58 | public void onStart(String key, long fileLength, long downloaded, String savePath, String filenNme) { 59 | 60 | } 61 | 62 | @Override 63 | public void onSuccess(String key, long fileLength, long downloaded, String savePath, String filenNme, long aSpeed, String aAppiconName) { 64 | 65 | } 66 | 67 | @Override 68 | public void onAppSuccess(String key, long fileLength, long downloaded, String savePath, String filenNme, long aSpeed, String aAppiconName, int downloadType, int appType) { 69 | 70 | } 71 | 72 | @Override 73 | public void onFail(String key, long downloaded, String savePath, String filenNme, String aErrinfo) { 74 | 75 | } 76 | 77 | @Override 78 | public void onCancel(String key, long fileLength, long downloaded, String savePath, String filenNme) { 79 | 80 | } 81 | 82 | @Override 83 | public void onPause(String key, long fileLength, long downloaded, String savePath, String filenNme) { 84 | 85 | } 86 | 87 | @Override 88 | public void onDownloading(String key, long fileLength, long downloadLength, long speed, String fileName, int downloadType) { 89 | 90 | } 91 | 92 | @Override 93 | public void onRefresh(List infos) { 94 | 95 | } 96 | }) 97 | 98 | .client(DLClientFactory.createClient(FRAME, this)) 99 | .build(this).start(); 100 | } 101 | 102 | @OnClick(R.id.taskdown) 103 | void callTaskDown() { 104 | 105 | new Download.Builder() 106 | .url("http://p2.gexing.com/kongjianpifu/20120713/1622/4fffdacf88244.jpg") 107 | .priority(Priority.MEDIUM) 108 | .isImplicit(false) 109 | .channel(1000) 110 | .client(DLClientFactory.createClient(NORMAL, this)) 111 | .build(this) 112 | .start(); 113 | 114 | } 115 | 116 | @OnClick(R.id.newdown) 117 | void callnewDown() { 118 | 119 | new Download.Builder() 120 | .url("http://p2.gexing.com/kongjianpifu/20120713/1622/4fffdacf88244.jpg") 121 | .priority(Priority.MEDIUM) 122 | .isImplicit(false) 123 | .channel(1000) 124 | .client(DLClientFactory.createClient(NORMAL, this)) 125 | .build(this) 126 | .start(); 127 | 128 | } 129 | 130 | } 131 | -------------------------------------------------------------------------------- /simple/src/main/java/com/tamic/fastdownsimple/down/DLDownloadListener.java: -------------------------------------------------------------------------------- 1 | package com.tamic.fastdownsimple.down; 2 | 3 | import android.content.Context; 4 | import android.widget.Toast; 5 | 6 | import com.tamic.rx.fastdown.PopupDialogParams; 7 | import com.tamic.rx.fastdown.client.DLClientFactory; 8 | import com.tamic.rx.fastdown.client.Type; 9 | import com.tamic.rx.fastdown.content.DownLoadInfo; 10 | import com.tamic.rx.fastdown.core.RxDownloadManager; 11 | import com.tamic.rx.fastdown.listener.IDownloadListener; 12 | import com.tamic.rx.fastdown.listener.IUIDownHandler; 13 | import com.tamic.rx.fastdown.util.Utils; 14 | 15 | /** 16 | * Created by Tamic on 2015-12-22. 17 | */ 18 | public class DLDownloadListener implements IDownloadListener { 19 | 20 | private Context mContext; 21 | 22 | public DLDownloadListener(Context aContext) { 23 | mContext = aContext; 24 | } 25 | 26 | @Override 27 | public void showPopupDialog(PopupDialogParams params) { 28 | } 29 | 30 | @Override 31 | public void dismissDialog() { 32 | } 33 | 34 | @Override 35 | public void showToast(String toastContent) { 36 | Toast.makeText(mContext, toastContent, Toast.LENGTH_SHORT).show(); 37 | } 38 | 39 | @Override 40 | public void openUrl(String aUrl) { 41 | } 42 | 43 | @Override 44 | public String getCookie(String aUrl) { 45 | // 你的Cookie 46 | return null; 47 | } 48 | 49 | @Override 50 | public String getUA() { 51 | // 你的设备UA 52 | return null; 53 | } 54 | 55 | @Override 56 | public void onInstallFrame(String aFileName) { 57 | Utils.openFile(Utils.getDefaultSavepath(Type.FRAME) + aFileName, RxDownloadManager.getInstance().getContext()); 58 | } 59 | 60 | @Override 61 | public void onIemClick(DownLoadInfo info) { 62 | 63 | } 64 | 65 | @Override 66 | public IUIDownHandler onHander() { 67 | return null; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /simple/src/main/java/com/tamic/fastdownsimple/down/DLFrameCallback.java: -------------------------------------------------------------------------------- 1 | package com.tamic.fastdownsimple.down; 2 | 3 | import com.tamic.rx.fastdown.DLToastManager; 4 | import com.tamic.rx.fastdown.callback.IDLCallback; 5 | import com.tamic.rx.fastdown.content.DownLoadInfo; 6 | import com.tamic.rx.fastdown.core.RxDownLoadCenter; 7 | import com.tamic.rx.fastdown.core.RxDownloadManager; 8 | 9 | import java.util.List; 10 | 11 | 12 | 13 | /** 14 | * apk Callback 15 | */ 16 | public class DLFrameCallback implements IDLCallback { 17 | 18 | 19 | @Override 20 | public void onStart(String tag, long fileLength, long downloaded, String savePath, String filenNme) { 21 | 22 | } 23 | 24 | @Override 25 | public void onSuccess(String tag, long fileLength, long downloaded, String savePath, String filenNme, long aSpeed, String aAppiconName) { 26 | RxDownloadManager.getInstance().removeDialog(); 27 | DownLoadInfo info = RxDownLoadCenter.getInstance(null).getSingleinfo(tag); 28 | if (info.isImplicit == 0) { 29 | RxDownLoadCenter.getInstance(null).sendShowToastMessage("升级包下载已完成", 30 | DLToastManager.TYPE_CLICKABLE, filenNme); 31 | } 32 | } 33 | 34 | 35 | @Override 36 | public void onAppSuccess(String atag, long aFilelength, long downloaded, final String aFilepath, final String aFilename, long aSpeed, String aAppiconName, int downloadType, int appType) { 37 | 38 | // 39 | RxDownloadManager.getInstance().removeDialog(); 40 | DownLoadInfo info = RxDownLoadCenter.getInstance(null).getSingleinfo(atag); 41 | if (info.isImplicit == 1) { 42 | return; 43 | 44 | } 45 | RxDownLoadCenter.getInstance(null).sendShowToastMessage("安装包下载已完成", 46 | DLToastManager.TYPE_CLICKABLE, aFilename); 47 | } 48 | 49 | @Override 50 | public void onFail(String atag, long downloaded, String aFilepath, String aFilename, 51 | String aErrinfo) { 52 | RxDownloadManager.getInstance().removeDialog(); 53 | } 54 | 55 | @Override 56 | public void onCancel(String tag, long fileLength, long downloaded, String savePath, String filenNme) { 57 | 58 | } 59 | 60 | @Override 61 | public void onPause(String tag, long fileLength, long downloaded, String savePath, String filenNme) { 62 | 63 | } 64 | 65 | 66 | @Override 67 | public void onDownloading(String atag, long aFilelength, long downloaded, long aSpeed, String aFilename, int downloadType) { 68 | 69 | RxDownLoadCenter.getInstance(null).sendShowToastMessage("下载中 >> + " + downloaded, 70 | DLToastManager.TYPE_CLICKABLE, aFilename); 71 | } 72 | 73 | 74 | @Override 75 | public void onRefresh(List infos) { 76 | 77 | } 78 | 79 | } 80 | -------------------------------------------------------------------------------- /simple/src/main/java/com/tamic/fastdownsimple/down/DLNormalCallback.java: -------------------------------------------------------------------------------- 1 | package com.tamic.fastdownsimple.down; 2 | 3 | import android.os.Handler; 4 | import android.os.Looper; 5 | 6 | import com.tamic.rx.fastdown.RxConstants; 7 | import com.tamic.rx.fastdown.DLToastManager; 8 | import com.tamic.rx.fastdown.callback.IDLCallback; 9 | import com.tamic.rx.fastdown.content.DownLoadInfo; 10 | import com.tamic.rx.fastdown.core.RxDownLoadCenter; 11 | import com.tamic.rx.fastdown.listener.ICompleteListener; 12 | 13 | import java.util.ArrayList; 14 | import java.util.List; 15 | 16 | /** 17 | * Normal Callback 18 | */ 19 | public class DLNormalCallback implements IDLCallback { 20 | 21 | private List mListeners; 22 | public DLNormalCallback() { 23 | mListeners = new ArrayList<>(); 24 | } 25 | 26 | public void addListener(ICompleteListener aListener) { 27 | if (!mListeners.contains(aListener)) { 28 | mListeners.add(aListener); 29 | } 30 | } 31 | 32 | public void removeListener(ICompleteListener aListener) { 33 | mListeners.remove(aListener); 34 | } 35 | 36 | 37 | 38 | @Override 39 | public void onStart(String tag, long fileLength, long downloaded, String savePath, String filenNme) { 40 | 41 | } 42 | 43 | @Override 44 | public void onSuccess(String tag, long fileLength, long downloaded, String savePath, final String filenNme, long aSpeed, String aAppiconName) { 45 | //install 46 | new Handler(Looper.getMainLooper()).post(new Runnable() { 47 | @Override 48 | public void run() { 49 | RxDownLoadCenter.getInstance(null).sendShowToastMessage(filenNme + "下载已完成", 50 | DLToastManager.TYPE_CLICKABLE, filenNme); 51 | } 52 | }); 53 | } 54 | 55 | @Override 56 | public void onAppSuccess(String tag, long fileLength, long downloaded, String savePath, final String filenNme, long aSpeed, String aAppiconName, int downloadType, int appType) { 57 | 58 | //install 59 | new Handler(Looper.getMainLooper()).post(new Runnable() { 60 | @Override 61 | public void run() { 62 | RxDownLoadCenter.getInstance(null).sendShowToastMessage(filenNme + "下载已完成", 63 | DLToastManager.TYPE_CLICKABLE, filenNme); 64 | } 65 | }); 66 | } 67 | 68 | @Override 69 | public void onFail(String tag, long downloaded, String aFilepath, String aFilename, 70 | String aErrinfo) { 71 | try { 72 | if (mListeners != null) { 73 | for (ICompleteListener listener : mListeners) { 74 | if (listener.onFail(tag, downloaded, aFilepath, aFilename, aErrinfo)) { 75 | continue; 76 | } 77 | } 78 | } 79 | if (aErrinfo.equals(RxConstants.ERROR_INVALID_FILE)) { 80 | RxDownLoadCenter.getInstance(null).sendShowToastMessage("SD卡异常,请稍后重试", 81 | DLToastManager.TYPE_CLICKABLE, aFilename); 82 | } else if (aErrinfo.equals(RxConstants.ERROR_INSUFFICIENT_STORAGE)) { 83 | RxDownLoadCenter.getInstance(null).sendShowToastMessage("SD卡容量不足", 84 | DLToastManager.TYPE_CLICKABLE, aFilename); 85 | 86 | } 87 | } catch (Exception e) { 88 | e.printStackTrace(); 89 | } 90 | } 91 | 92 | @Override 93 | public void onCancel(String tag, long aFilelength, long downloaded, String aFilepath, 94 | String aFilename) { 95 | try { 96 | if (mListeners != null) { 97 | for (ICompleteListener listener : mListeners) { 98 | if (listener.onCancel(tag, aFilelength, downloaded, aFilepath, aFilename)) { 99 | continue; 100 | } 101 | } 102 | } 103 | } catch (Exception e) { 104 | e.printStackTrace(); 105 | } 106 | } 107 | 108 | @Override 109 | public void onPause(String tag, long aFilelength, long downloaded, String aFilepath, 110 | String aFilename) { 111 | try { 112 | if (mListeners != null) { 113 | for (ICompleteListener listener : mListeners) { 114 | if (listener.onPause(tag, aFilelength, downloaded, aFilepath, aFilename)) { 115 | } 116 | } 117 | } 118 | } catch (Exception e) { 119 | e.printStackTrace(); 120 | } 121 | } 122 | 123 | @Override 124 | public void onDownloading(String key, long filelength, long downloaded, long speed, String filename, int downloadType) { 125 | RxDownLoadCenter.getInstance(null).sendShowToastMessage("正在下载中..." + downloaded, 126 | DLToastManager.TYPE_CLICKABLE, filename); 127 | } 128 | 129 | @Override 130 | public void onRefresh(List infos) { 131 | 132 | } 133 | 134 | 135 | } 136 | -------------------------------------------------------------------------------- /simple/src/main/java/com/tamic/fastdownsimple/down/DownloadInit.java: -------------------------------------------------------------------------------- 1 | package com.tamic.fastdownsimple.down; 2 | 3 | import android.content.Context; 4 | 5 | import com.tamic.fastdownsimple.widget.DownloadAdapter; 6 | import com.tamic.rx.fastdown.RxConstants; 7 | import com.tamic.rx.fastdown.core.RxDownLoadCenter; 8 | import com.tamic.rx.fastdown.core.RxDownloadManager; 9 | 10 | /** 11 | * 下载模块初始化 12 | * Created By Tamic On 2015-8-15 13 | */ 14 | public final class DownloadInit { 15 | 16 | /** 17 | * private constructor 18 | */ 19 | private DownloadInit() { 20 | } 21 | 22 | 23 | public static void init(Context aContext) { 24 | //设置点击栏目知想打开的页面 25 | RxConstants.CLASSNAME = "MainActivty"; 26 | 27 | RxDownloadManager manager = RxDownloadManager.getInstance(); 28 | manager.init(aContext, new DownloadAdapter()); 29 | manager.setContext(aContext); 30 | manager.setListener(new DLDownloadListener(aContext)); 31 | DLNormalCallback normalCallback = new DLNormalCallback(); 32 | if (manager.getClient() != null) { 33 | manager.getClient().setCallback(normalCallback); 34 | } 35 | RxDownLoadCenter.getInstance(aContext).loadTask(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /simple/src/main/java/com/tamic/fastdownsimple/widget/AbstractAdapter.java: -------------------------------------------------------------------------------- 1 | package com.tamic.fastdownsimple.widget; 2 | 3 | import android.os.Handler; 4 | import android.os.Looper; 5 | import android.support.v7.widget.GridLayoutManager; 6 | import android.support.v7.widget.RecyclerView; 7 | import android.support.v7.widget.StaggeredGridLayoutManager; 8 | import android.view.View; 9 | import android.view.ViewGroup; 10 | 11 | import com.tamic.rx.fastdown.widget.DownItemType; 12 | 13 | import java.util.ArrayList; 14 | import java.util.List; 15 | import java.util.Observer; 16 | 17 | import static android.support.v7.widget.RecyclerView.SCROLL_STATE_IDLE; 18 | 19 | 20 | /** 21 | * Created by liuyongkui726 on 2016-12-21. 22 | */ 23 | public abstract class AbstractAdapter extends 24 | RecyclerView.Adapter { 25 | private DataSetObservable dataSet; 26 | private RecyclerView mRecyclerView; 27 | 28 | public AbstractAdapter() { 29 | dataSet = new DataSetObservable<>(); 30 | } 31 | 32 | public void clear() { 33 | dataSet.clear(); 34 | } 35 | 36 | public void clearData() { 37 | dataSet.data.clear(); 38 | } 39 | 40 | public void clearHeader() { 41 | dataSet.header.clear(); 42 | } 43 | 44 | public void clearFooter() { 45 | dataSet.footer.clear(); 46 | } 47 | 48 | public void addHeader(SectionItem header) { 49 | dataSet.header.add(header); 50 | } 51 | 52 | public void addFooter(SectionItem footer) { 53 | dataSet.footer.add(footer); 54 | } 55 | 56 | public T get(int position) { 57 | return dataSet.data.get(position); 58 | } 59 | 60 | public List getData() { 61 | return dataSet.data.getAll(); 62 | } 63 | 64 | /** 65 | * 添加数据, 并触发刷新. 66 | * 添加之后数据总数为0, 显示EmptyView; 67 | * 添加之后数据总数大于0, 当添加0个数据时,自动停止LoadMore; 68 | * 69 | * @param data list of data 70 | */ 71 | public void addAll(List data) { 72 | dataSet.data.addAll(data); 73 | notifyDataSetChanged(); 74 | 75 | if (dataSet.totalSize() == 0) { 76 | dataSet.notifyEmpty(); 77 | } else { 78 | dataSet.notifyContent(); 79 | if (data.size() == 0) { 80 | dataSet.notifyNoMore(); 81 | } 82 | } 83 | } 84 | 85 | /** 86 | * 正常插入数据 87 | * 88 | * @param adapterPosition 插入的位置 89 | * @param item 插入的数据 90 | */ 91 | public void insert(int adapterPosition, T item) { 92 | dataSet.data.insert(adapterPosition, item); 93 | notifyItemInserted(adapterPosition); 94 | } 95 | 96 | public void insertAll(int adapterPosition, List items) { 97 | dataSet.data.insertAll(adapterPosition, items); 98 | notifyItemRangeInserted(adapterPosition, items.size()); 99 | } 100 | 101 | /** 102 | * 插入数据到position之后 103 | * 104 | * @param adapterPosition position 105 | * @param item 插入的数据 106 | */ 107 | public void insertBack(int adapterPosition, T item) { 108 | dataSet.data.insertBack(adapterPosition, item); 109 | notifyItemInserted(adapterPosition + 1); 110 | } 111 | 112 | public void insertAllBack(int adapterPosition, List items) { 113 | dataSet.data.insertAllBack(adapterPosition, items); 114 | notifyItemRangeInserted(adapterPosition + 1, items.size()); 115 | } 116 | 117 | public void swap(int fromAdapterPosition, int toAdapterPosition) { 118 | dataSet.data.swap(fromAdapterPosition, toAdapterPosition); 119 | notifyItemMoved(fromAdapterPosition, toAdapterPosition); 120 | } 121 | 122 | /** 123 | * 正常的删除 124 | * 125 | * @param adapterPosition 待删除的位置 126 | */ 127 | public void remove(int adapterPosition) { 128 | dataSet.data.remove(adapterPosition); 129 | notifyItemRemoved(adapterPosition); 130 | } 131 | 132 | /** 133 | * 从指定的position之后删除size个数据 134 | * 135 | * @param adapterPosition position 136 | * @param removeSize 删除的数据大小 137 | */ 138 | public void removeBack(int adapterPosition, int removeSize) { 139 | dataSet.data.removeAllBack(adapterPosition, removeSize); 140 | notifyItemRangeRemoved(adapterPosition + 1, removeSize); 141 | } 142 | 143 | /** 144 | * 显示Loading View 145 | */ 146 | public void showLoading() { 147 | dataSet.notifyLoading(); 148 | } 149 | 150 | /** 151 | * 清除当前所有数据,并显示ErrorView 152 | */ 153 | public void showError() { 154 | dataSet.clear(); 155 | notifyDataSetChanged(); 156 | dataSet.notifyError(); 157 | } 158 | 159 | /** 160 | * 显示底部LoadMoreErrorView 161 | */ 162 | public void loadMoreFailed() { 163 | dataSet.notifyLoadMoreFailed(); 164 | } 165 | 166 | /** 167 | * 恢复LoadMore 168 | */ 169 | public void resumeLoadMore() { 170 | dataSet.notifyResumeLoadMore(); 171 | } 172 | 173 | /** 174 | * 手动触发加载更多, 显示LoadMoreView ,并执行loadMore逻辑 175 | */ 176 | public void manualLoadMore() { 177 | dataSet.notifyManualLoadMore(); 178 | } 179 | 180 | @Override 181 | public VH onCreateViewHolder(ViewGroup parent, int viewType) { 182 | VH viewHolder = createHeaderFooterViewHolder(parent, viewType); 183 | if (viewHolder != null) return viewHolder; 184 | return onNewCreateViewHolder(parent, viewType); 185 | } 186 | 187 | @Override 188 | public void onBindViewHolder(VH holder, int position) { 189 | if (dataSet.header.is(position)) { 190 | dataSet.header.get(position).onBind(); 191 | } else if (dataSet.data.is(position)) { 192 | onNewBindViewHolder(holder, position); 193 | } else if (dataSet.footer.is(position)) { 194 | dataSet.footer.get(position).onBind(); 195 | } else { 196 | dataSet.extra.get(position).onBind(); 197 | } 198 | } 199 | 200 | @Override 201 | public final int getItemViewType(int position) { 202 | //用header和footer的HashCode表示它们的ItemType, 203 | //普通类型的数据由该数据类型的ItemType决定 204 | 205 | if (dataSet.header.is(position)) { 206 | return dataSet.header.get(position).hashCode(); 207 | } else if (dataSet.footer.is(position)) { 208 | return dataSet.footer.get(position).hashCode(); 209 | } else if (dataSet.data.is(position)){ 210 | return dataSet.data.get(position).itemType(); 211 | } 212 | else { 213 | return dataSet.extra.get(position).hashCode(); 214 | } 215 | } 216 | 217 | @Override 218 | public final int getItemCount() { 219 | return dataSet.totalSize(); 220 | } 221 | 222 | @Override 223 | public void onViewAttachedToWindow(VH holder) { 224 | super.onViewAttachedToWindow(holder); 225 | int position = holder.getAdapterPosition(); 226 | 227 | //瀑布流的 Header Footer 宽度处理 228 | ViewGroup.LayoutParams lp = holder.itemView.getLayoutParams(); 229 | if (lp != null && lp instanceof StaggeredGridLayoutManager.LayoutParams) { 230 | StaggeredGridLayoutManager.LayoutParams p = (StaggeredGridLayoutManager.LayoutParams) lp; 231 | if (!dataSet.data.is(position)) { 232 | p.setFullSpan(true); 233 | } 234 | } 235 | 236 | //判断是否需要自动加载 237 | if (mRecyclerView.getScrollState() != SCROLL_STATE_IDLE) return; 238 | if (dataSet.extra.size() == 0) { 239 | if (position == dataSet.totalSize() - 1) { 240 | loadMore(); 241 | } 242 | } else { 243 | if (position == dataSet.totalSize() - 1 - dataSet.extra.size()) { 244 | loadMore(); 245 | } 246 | } 247 | } 248 | 249 | @Override 250 | public void onAttachedToRecyclerView(RecyclerView recyclerView) { 251 | super.onAttachedToRecyclerView(recyclerView); 252 | mRecyclerView = recyclerView; 253 | 254 | //Grid的 Header Footer 宽度处理 255 | RecyclerView.LayoutManager manager = recyclerView.getLayoutManager(); 256 | if (manager instanceof GridLayoutManager) { 257 | final GridLayoutManager gridManager = ((GridLayoutManager) manager); 258 | gridManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() { 259 | @Override 260 | public int getSpanSize(int position) { 261 | boolean isData = dataSet.data.is(position); 262 | if (isData) { 263 | return 1; 264 | } else { 265 | return gridManager.getSpanCount(); 266 | } 267 | } 268 | }); 269 | } 270 | } 271 | 272 | void resolveSwipeConflicts(boolean enabled) { 273 | dataSet.notifyResolveSwipeConflicts(enabled); 274 | } 275 | 276 | boolean canDrag(int adapterPosition) { 277 | return dataSet.data.is(adapterPosition); 278 | } 279 | 280 | void show(View view, boolean enabled) { 281 | if (dataSet.extra.size() == 0) { 282 | if (enabled) { 283 | dataSet.extra.add(new SectionItemImpl(view)); 284 | notifyItemInserted(dataSet.extra.position()); 285 | } 286 | } else { 287 | if (!dataSet.extra.get(dataSet.extra.position()).createView(null).equals(view)) { 288 | if (enabled) { 289 | dataSet.extra.set(dataSet.extra.position(), new SectionItemImpl(view)); 290 | notifyItemChanged(dataSet.extra.position()); 291 | } 292 | } else { 293 | if (!enabled) { 294 | int position = dataSet.extra.position(); 295 | dataSet.extra.remove(position); 296 | notifyItemRemoved(position); 297 | } 298 | } 299 | } 300 | } 301 | 302 | void registerObserver(Observer observer) { 303 | dataSet.addObserver(observer); 304 | } 305 | 306 | protected abstract VH onNewCreateViewHolder(ViewGroup parent, int viewType); 307 | 308 | protected abstract void onNewBindViewHolder(VH holder, int position); 309 | 310 | private void loadMore() { 311 | new Handler(Looper.getMainLooper()).post(new Runnable() { 312 | @Override 313 | public void run() { 314 | dataSet.notifyAutoLoadMore(); 315 | } 316 | }); 317 | } 318 | 319 | @SuppressWarnings("unchecked") 320 | private VH createHeaderFooterViewHolder(ViewGroup parent, int viewType) { 321 | List tempContainer = new ArrayList<>(); 322 | tempContainer.addAll(dataSet.header.getAll()); 323 | tempContainer.addAll(dataSet.footer.getAll()); 324 | tempContainer.addAll(dataSet.extra.getAll()); 325 | 326 | for (SectionItem each : tempContainer) { 327 | if (each.hashCode() == viewType) { 328 | View view = each.createView(parent); 329 | return (VH) new SectionItemViewHolder(view); 330 | } 331 | } 332 | return null; 333 | } 334 | 335 | private class SectionItemViewHolder extends AbstractViewHolder { 336 | 337 | SectionItemViewHolder(View itemView) { 338 | super(itemView); 339 | } 340 | 341 | @Override 342 | public void setData(DownItemType data) { 343 | 344 | } 345 | } 346 | } 347 | 348 | -------------------------------------------------------------------------------- /simple/src/main/java/com/tamic/fastdownsimple/widget/AbstractViewHolder.java: -------------------------------------------------------------------------------- 1 | package com.tamic.fastdownsimple.widget; 2 | 3 | import android.view.LayoutInflater; 4 | import android.view.View; 5 | import android.view.ViewGroup; 6 | 7 | import android.support.v7.widget.RecyclerView; 8 | 9 | import com.tamic.rx.fastdown.widget.DownItemType; 10 | 11 | 12 | /** 13 | * Created by liuyongkui726 on 2016-12-21. 14 | */ 15 | 16 | public abstract class AbstractViewHolder extends RecyclerView.ViewHolder { 17 | 18 | public AbstractViewHolder(View itemView) { 19 | super(itemView); 20 | } 21 | 22 | public AbstractViewHolder(ViewGroup parent, int res) { 23 | super(LayoutInflater.from(parent.getContext()).inflate(res, parent, false)); 24 | } 25 | 26 | public abstract void setData(T data); 27 | } 28 | -------------------------------------------------------------------------------- /simple/src/main/java/com/tamic/fastdownsimple/widget/Bridge.java: -------------------------------------------------------------------------------- 1 | package com.tamic.fastdownsimple.widget; 2 | 3 | /** 4 | * Created by liuyongkui726 on 2016-12-21. 5 | */ 6 | 7 | public interface Bridge { 8 | void doSomething(PracticalRecyclerView host); 9 | 10 | class Loading implements Bridge { 11 | 12 | @Override 13 | public void doSomething(PracticalRecyclerView host) { 14 | host.displayLoadingAndResetStatus(); 15 | } 16 | } 17 | 18 | class Empty implements Bridge { 19 | 20 | @Override 21 | public void doSomething(PracticalRecyclerView host) { 22 | host.displayEmptyAndResetStatus(); 23 | } 24 | } 25 | 26 | class Content implements Bridge { 27 | 28 | @Override 29 | public void doSomething(PracticalRecyclerView host) { 30 | host.displayContentAndResetStatus(); 31 | } 32 | } 33 | 34 | class Error implements Bridge { 35 | 36 | @Override 37 | public void doSomething(PracticalRecyclerView host) { 38 | host.displayErrorAndResetStatus(); 39 | } 40 | } 41 | 42 | class NoMore implements Bridge { 43 | 44 | @Override 45 | public void doSomething(PracticalRecyclerView host) { 46 | host.showNoMoreIfEnabled(); 47 | } 48 | } 49 | 50 | class LoadMoreFailed implements Bridge { 51 | 52 | @Override 53 | public void doSomething(PracticalRecyclerView host) { 54 | host.showLoadMoreFailedIfEnabled(); 55 | } 56 | } 57 | 58 | class ResumeLoadMore implements Bridge { 59 | 60 | @Override 61 | public void doSomething(PracticalRecyclerView host) { 62 | host.resumeLoadMoreIfEnabled(); 63 | } 64 | } 65 | 66 | class AutoLoadMore implements Bridge { 67 | 68 | @Override 69 | public void doSomething(PracticalRecyclerView host) { 70 | host.autoLoadMoreIfEnabled(); 71 | } 72 | } 73 | 74 | class ManualLoadMore implements Bridge { 75 | 76 | @Override 77 | public void doSomething(PracticalRecyclerView host) { 78 | host.manualLoadMoreIfEnabled(); 79 | } 80 | } 81 | 82 | class SwipeConflicts implements Bridge { 83 | 84 | private boolean enabled; 85 | 86 | SwipeConflicts(boolean enabled) { 87 | this.enabled = enabled; 88 | } 89 | 90 | @Override 91 | public void doSomething(PracticalRecyclerView host) { 92 | host.resolveSwipeConflicts(enabled); 93 | } 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /simple/src/main/java/com/tamic/fastdownsimple/widget/Configure.java: -------------------------------------------------------------------------------- 1 | package com.tamic.fastdownsimple.widget; 2 | 3 | import android.view.View; 4 | 5 | /** 6 | * Created by liuyongkui726 on 2016-12-21. 7 | */ 8 | 9 | public interface Configure { 10 | void configureEmptyView(View emptyView); 11 | 12 | void configureErrorView(View errorView); 13 | 14 | void configureLoadingView(View loadingView); 15 | 16 | void configureLoadMoreView(View loadMoreView); 17 | 18 | void configureNoMoreView(View noMoreView); 19 | 20 | void configureLoadMoreFailedView(View loadMoreFailedView); 21 | } 22 | -------------------------------------------------------------------------------- /simple/src/main/java/com/tamic/fastdownsimple/widget/DataSetObservable.java: -------------------------------------------------------------------------------- 1 | package com.tamic.fastdownsimple.widget; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | import java.util.Observable; 6 | 7 | /** 8 | * Created by liuyongkui726 on 2016-12-21. 9 | */ 10 | 11 | class DataSetObservable extends Observable { 12 | Segment header = new HeaderSegment(); 13 | Segment data = new DataSegment(); 14 | Segment footer = new FooterSegment(); 15 | Segment extra = new ExtraSegment(); 16 | 17 | private List mHeader = new ArrayList<>(); 18 | private List mData = new ArrayList<>(); 19 | private List mFooter = new ArrayList<>(); 20 | private List mExtra = new ArrayList<>(); 21 | 22 | 23 | //------------------------------ 24 | //|position size item | 25 | //|----------------------------| 26 | //| 0 header0 | 27 | //| 1 2 header1 | 28 | //|----------------------------| 29 | //| 2 data0 | 30 | //| 3 data1 | 31 | //| 4 data2 | 32 | //| 5 4 data3 | 33 | //|----------------------------| 34 | //| 6 footer0 | 35 | //| 7 2 footer1 | 36 | //|----------------------------| 37 | //| 8 extra0 | 38 | //| 9 2 extra1 | 39 | //------------------------------ 40 | 41 | int totalSize() { 42 | return mHeader.size() + mData.size() + mFooter.size() + mExtra.size(); 43 | } 44 | 45 | void clear() { 46 | mHeader.clear(); 47 | mData.clear(); 48 | mFooter.clear(); 49 | mExtra.clear(); 50 | } 51 | 52 | void notifyLoading() { 53 | super.setChanged(); 54 | super.notifyObservers(new Bridge.Loading()); 55 | } 56 | 57 | void notifyContent() { 58 | super.setChanged(); 59 | super.notifyObservers(new Bridge.Content()); 60 | } 61 | 62 | void notifyError() { 63 | super.setChanged(); 64 | super.notifyObservers(new Bridge.Error()); 65 | } 66 | 67 | void notifyEmpty() { 68 | super.setChanged(); 69 | super.notifyObservers(new Bridge.Empty()); 70 | } 71 | 72 | void notifyLoadMoreFailed() { 73 | super.setChanged(); 74 | super.notifyObservers(new Bridge.LoadMoreFailed()); 75 | } 76 | 77 | void notifyResumeLoadMore() { 78 | super.setChanged(); 79 | super.notifyObservers(new Bridge.ResumeLoadMore()); 80 | } 81 | 82 | void notifyNoMore() { 83 | super.setChanged(); 84 | super.notifyObservers(new Bridge.NoMore()); 85 | } 86 | 87 | void notifyAutoLoadMore() { 88 | super.setChanged(); 89 | super.notifyObservers(new Bridge.AutoLoadMore()); 90 | } 91 | 92 | void notifyManualLoadMore() { 93 | super.setChanged(); 94 | super.notifyObservers(new Bridge.ManualLoadMore()); 95 | } 96 | 97 | void notifyResolveSwipeConflicts(boolean enabled) { 98 | super.setChanged(); 99 | super.notifyObservers(new Bridge.SwipeConflicts(enabled)); 100 | } 101 | 102 | abstract class Segment { 103 | 104 | /** 105 | * 正常的插入 106 | * 107 | * @param adapterPosition 待插入的位置 108 | * @param item 待插入的数据 109 | */ 110 | final void insert(int adapterPosition, T item) { 111 | if (is(adapterPosition)) { 112 | insertImpl(adapterPosition - positionImpl(), item); 113 | } else { 114 | throw new IndexOutOfBoundsException("Insert error, insert position"); 115 | } 116 | } 117 | 118 | final void insertAll(int adapterPosition, List items) { 119 | if (is(adapterPosition)) { 120 | insertAllImpl(adapterPosition - positionImpl(), items); 121 | } else { 122 | throw new IndexOutOfBoundsException("Insert error, check your insert position"); 123 | } 124 | } 125 | 126 | /** 127 | * 插入到position之后 128 | * 129 | * @param adapterPosition 待插入的位置的前一个 130 | * @param item 待插入的数据 131 | */ 132 | final void insertBack(int adapterPosition, T item) { 133 | if (is(adapterPosition)) { 134 | int insertPosition = adapterPosition - positionImpl() + 1; 135 | if (insertPosition == size()) { 136 | add(item); 137 | } else { 138 | insertImpl(insertPosition, item); 139 | } 140 | } else { 141 | throw new IndexOutOfBoundsException("Insert error, check your insert position"); 142 | } 143 | } 144 | 145 | final boolean insertAllBack(int adapterPosition, List items) { 146 | if (is(adapterPosition)) { 147 | int insertPosition = adapterPosition - positionImpl() + 1; 148 | if (insertPosition == size()) { 149 | addAll(items); 150 | } else { 151 | insertAllImpl(insertPosition, items); 152 | } 153 | return true; 154 | } else { 155 | throw new IndexOutOfBoundsException("Insert error, check your insert position"); 156 | } 157 | } 158 | 159 | /** 160 | * 从指定位置后删除size个数据 161 | * 162 | * @param adapterPosition 指定的位置 163 | * @param removeSize 删除的大小 164 | */ 165 | final void removeAllBack(int adapterPosition, int removeSize) { 166 | if (is(adapterPosition)) { 167 | int removePosition = adapterPosition - positionImpl() + 1; 168 | for (int i = 0; i < removeSize; i++) { 169 | removeImpl(removePosition); 170 | } 171 | } else { 172 | throw new IndexOutOfBoundsException("Remove error, check your remove position"); 173 | } 174 | } 175 | 176 | final T get(int adapterPosition) { 177 | if (is(adapterPosition)) { 178 | return getImpl(adapterPosition - positionImpl()); 179 | } else { 180 | throw new NullPointerException(); 181 | } 182 | } 183 | 184 | final int position() { 185 | if (size() == 0) return -1; 186 | return positionImpl(); 187 | } 188 | 189 | final boolean is(int adapterPosition) { 190 | return adapterPosition >= 0 && size() > 0 && adapterPosition - positionImpl() < size() 191 | && adapterPosition - positionImpl() >= 0; 192 | } 193 | 194 | final void set(int adapterPosition, T newItem) { 195 | if (is(adapterPosition)) { 196 | setImpl(adapterPosition - positionImpl(), newItem); 197 | } else { 198 | throw new IndexOutOfBoundsException("Set error, check your set position"); 199 | } 200 | } 201 | 202 | final void remove(int adapterPosition) { 203 | if (is(adapterPosition)) { 204 | removeImpl(adapterPosition - positionImpl()); 205 | } else { 206 | throw new IndexOutOfBoundsException("Remove error, check your remove position"); 207 | } 208 | } 209 | 210 | final void remove(T needRemove) { 211 | if (size() != 0) { 212 | removeImpl(needRemove); 213 | } else { 214 | throw new IndexOutOfBoundsException("Remove error, check your remove position"); 215 | } 216 | } 217 | 218 | @SuppressWarnings({"rawtypes", "unchecked"}) 219 | void swap(int fromAdapterPosition, int toAdapterPosition) { 220 | final List l = getAll(); 221 | fromAdapterPosition = fromAdapterPosition - positionImpl(); 222 | toAdapterPosition = toAdapterPosition - positionImpl(); 223 | l.set(fromAdapterPosition, l.set(toAdapterPosition, l.get(fromAdapterPosition))); 224 | } 225 | 226 | abstract int size(); 227 | 228 | abstract void clear(); 229 | 230 | abstract void add(T item); 231 | 232 | abstract void addAll(List items); 233 | 234 | abstract List getAll(); 235 | 236 | abstract int positionImpl(); 237 | 238 | abstract void insertImpl(int position, T item); 239 | 240 | abstract void insertAllImpl(int position, List items); 241 | 242 | abstract T getImpl(int position); 243 | 244 | abstract void setImpl(int position, T newItem); 245 | 246 | abstract void removeImpl(int position); 247 | 248 | abstract void removeImpl(T needRemove); 249 | 250 | } 251 | 252 | private class HeaderSegment extends Segment { 253 | 254 | @Override 255 | int size() { 256 | return mHeader.size(); 257 | } 258 | 259 | @Override 260 | void clear() { 261 | mHeader.clear(); 262 | } 263 | 264 | @Override 265 | List getAll() { 266 | return mHeader; 267 | } 268 | 269 | @Override 270 | void add(SectionItem item) { 271 | mHeader.add(item); 272 | } 273 | 274 | @Override 275 | void addAll(List items) { 276 | mHeader.addAll(items); 277 | } 278 | 279 | @Override 280 | int positionImpl() { 281 | return 0; 282 | } 283 | 284 | @Override 285 | void insertImpl(int position, SectionItem item) { 286 | mHeader.add(position, item); 287 | } 288 | 289 | @Override 290 | void insertAllImpl(int position, List items) { 291 | mHeader.addAll(position, items); 292 | } 293 | 294 | @Override 295 | SectionItem getImpl(int position) { 296 | return mHeader.get(position); 297 | } 298 | 299 | @Override 300 | void setImpl(int position, SectionItem newItem) { 301 | mHeader.set(position, newItem); 302 | } 303 | 304 | @Override 305 | void removeImpl(int position) { 306 | mHeader.remove(position); 307 | } 308 | 309 | @Override 310 | void removeImpl(SectionItem needRemove) { 311 | mHeader.remove(needRemove); 312 | } 313 | } 314 | 315 | private class DataSegment extends Segment { 316 | 317 | @Override 318 | int size() { 319 | return mData.size(); 320 | } 321 | 322 | @Override 323 | void clear() { 324 | mData.clear(); 325 | } 326 | 327 | @Override 328 | void add(E item) { 329 | mData.add(item); 330 | } 331 | 332 | @Override 333 | void addAll(List items) { 334 | mData.addAll(items); 335 | } 336 | 337 | @Override 338 | List getAll() { 339 | return mData; 340 | } 341 | 342 | @Override 343 | int positionImpl() { 344 | return header.size(); 345 | } 346 | 347 | @Override 348 | void insertImpl(int position, E item) { 349 | mData.add(position, item); 350 | } 351 | 352 | @Override 353 | void insertAllImpl(int position, List items) { 354 | mData.addAll(position, items); 355 | } 356 | 357 | @Override 358 | E getImpl(int position) { 359 | return mData.get(position); 360 | } 361 | 362 | @Override 363 | void setImpl(int position, E newItem) { 364 | mData.set(position, newItem); 365 | } 366 | 367 | @Override 368 | void removeImpl(int position) { 369 | mData.remove(position); 370 | } 371 | 372 | @Override 373 | void removeImpl(E needRemove) { 374 | mData.remove(needRemove); 375 | } 376 | } 377 | 378 | private class FooterSegment extends Segment { 379 | 380 | @Override 381 | int size() { 382 | return mFooter.size(); 383 | } 384 | 385 | @Override 386 | void clear() { 387 | mFooter.clear(); 388 | } 389 | 390 | @Override 391 | List getAll() { 392 | return mFooter; 393 | } 394 | 395 | @Override 396 | void add(SectionItem item) { 397 | mFooter.add(item); 398 | } 399 | 400 | @Override 401 | void addAll(List items) { 402 | mFooter.addAll(items); 403 | } 404 | 405 | @Override 406 | int positionImpl() { 407 | return header.size() + data.size(); 408 | } 409 | 410 | @Override 411 | void insertImpl(int position, SectionItem item) { 412 | mFooter.add(position, item); 413 | } 414 | 415 | @Override 416 | void insertAllImpl(int position, List items) { 417 | mFooter.addAll(position, items); 418 | } 419 | 420 | @Override 421 | SectionItem getImpl(int position) { 422 | return mFooter.get(position); 423 | } 424 | 425 | @Override 426 | void setImpl(int position, SectionItem newItem) { 427 | mFooter.set(position, newItem); 428 | } 429 | 430 | @Override 431 | void removeImpl(int position) { 432 | mFooter.remove(position); 433 | } 434 | 435 | @Override 436 | void removeImpl(SectionItem needRemove) { 437 | mFooter.remove(needRemove); 438 | } 439 | } 440 | 441 | private class ExtraSegment extends Segment { 442 | 443 | @Override 444 | int size() { 445 | return mExtra.size(); 446 | } 447 | 448 | @Override 449 | void clear() { 450 | mExtra.clear(); 451 | } 452 | 453 | @Override 454 | List getAll() { 455 | return mExtra; 456 | } 457 | 458 | @Override 459 | void add(SectionItem item) { 460 | mExtra.add(item); 461 | } 462 | 463 | @Override 464 | void addAll(List items) { 465 | mExtra.addAll(items); 466 | } 467 | 468 | @Override 469 | int positionImpl() { 470 | return header.size() + data.size() + footer.size(); 471 | } 472 | 473 | @Override 474 | void insertImpl(int position, SectionItem item) { 475 | mExtra.add(position, item); 476 | } 477 | 478 | @Override 479 | void insertAllImpl(int position, List items) { 480 | mExtra.addAll(position, items); 481 | } 482 | 483 | @Override 484 | SectionItem getImpl(int position) { 485 | return mExtra.get(position); 486 | } 487 | 488 | @Override 489 | void setImpl(int position, SectionItem newItem) { 490 | mExtra.set(position, newItem); 491 | } 492 | 493 | @Override 494 | void removeImpl(int position) { 495 | mExtra.remove(position); 496 | } 497 | 498 | @Override 499 | void removeImpl(SectionItem needRemove) { 500 | mExtra.remove(needRemove); 501 | } 502 | } 503 | 504 | } 505 | 506 | -------------------------------------------------------------------------------- /simple/src/main/java/com/tamic/fastdownsimple/widget/DownloadAdapter.java: -------------------------------------------------------------------------------- 1 | package com.tamic.fastdownsimple.widget; 2 | 3 | import android.util.Log; 4 | import android.view.ViewGroup; 5 | 6 | import com.tamic.fastdownsimple.DownloadViewHolder; 7 | import com.tamic.rx.fastdown.content.DownLoadInfo; 8 | import com.tamic.rx.fastdown.core.RxDownloadManager; 9 | import com.tamic.rx.fastdown.listener.IUIDownHandler; 10 | 11 | import java.util.List; 12 | 13 | 14 | /** 15 | * DownloadAdapter 16 | */ 17 | public class DownloadAdapter extends AbstractAdapter implements IUIDownHandler { 18 | 19 | private DownLoadInfo loadInfo; 20 | private DownloadViewHolder holder; 21 | 22 | @Override 23 | protected DownloadViewHolder onNewCreateViewHolder(ViewGroup parent, int viewType) { 24 | return new DownloadViewHolder(parent); 25 | } 26 | 27 | @Override 28 | protected void onNewBindViewHolder(DownloadViewHolder holder, int position) { 29 | this.holder = holder; 30 | loadInfo = get(position); 31 | holder.setData(loadInfo); 32 | } 33 | 34 | @Override 35 | public void onBindViewHolder(DownloadViewHolder holder, int position, List payloads) { 36 | if (payloads.isEmpty() || payloads.size() == 0) { 37 | onNewBindViewHolder(holder, position); 38 | } else { 39 | this.holder = holder; 40 | loadInfo = get(position); 41 | holder.setData(loadInfo); 42 | } 43 | } 44 | 45 | @Override 46 | public void notifyComplete(DownLoadInfo info) { 47 | holder.setData(loadInfo); 48 | notifyDataSetChanged(); 49 | } 50 | 51 | @Override 52 | public void notifyRefresh(DownLoadInfo info) { 53 | 54 | if (holder == null) { 55 | return; 56 | } 57 | loadInfo = info; 58 | Log.d("nsygsb", loadInfo.toString()); 59 | holder.setData(info); 60 | notifyDataSetChanged(); 61 | } 62 | 63 | @Override 64 | public void notifyRefresh() { 65 | 66 | } 67 | 68 | @Override 69 | public void notifyNewTask(DownLoadInfo info) { 70 | Log.d("nsygsb", "a new task>> :" + loadInfo.toString()); 71 | getData().add(info); 72 | holder.setData(info); 73 | RxDownloadManager.getInstance().loadTask(); 74 | notifyDataSetChanged(); 75 | } 76 | 77 | 78 | } 79 | -------------------------------------------------------------------------------- /simple/src/main/java/com/tamic/fastdownsimple/widget/PracticalRecyclerView.java: -------------------------------------------------------------------------------- 1 | package com.tamic.fastdownsimple.widget; 2 | 3 | import android.annotation.TargetApi; 4 | import android.content.Context; 5 | import android.content.res.TypedArray; 6 | import android.os.Build; 7 | import android.support.v4.widget.SwipeRefreshLayout; 8 | import android.support.v7.widget.GridLayoutManager; 9 | import android.support.v7.widget.LinearLayoutManager; 10 | import android.support.v7.widget.RecyclerView; 11 | import android.support.v7.widget.StaggeredGridLayoutManager; 12 | import android.support.v7.widget.helper.ItemTouchHelper; 13 | import android.util.AttributeSet; 14 | import android.view.LayoutInflater; 15 | import android.view.View; 16 | import android.widget.FrameLayout; 17 | import android.widget.LinearLayout; 18 | 19 | import com.tamic.fastdownsimple.R; 20 | 21 | import java.util.Observable; 22 | import java.util.Observer; 23 | 24 | /** 25 | * Created by liuyongkui726 on 2016-12-21. 26 | */ 27 | 28 | public class PracticalRecyclerView extends FrameLayout { 29 | 30 | private boolean mAutoLoadMoreEnabled = true; 31 | private boolean mNoMoreViewEnabled = true; 32 | private boolean mLoadMoreViewEnabled = true; 33 | private boolean mLoadMoreFailedViewEnabled = true; 34 | 35 | private OnRefreshListener mRefreshListener; 36 | private OnLoadMoreListener mLoadMoreListener; 37 | 38 | private FrameLayout mMainContainer; 39 | private FrameLayout mLoadingContainer; 40 | private FrameLayout mErrorContainer; 41 | private FrameLayout mEmptyContainer; 42 | private LinearLayout mContentContainer; 43 | 44 | private SwipeRefreshLayout mSwipeRefreshLayout; 45 | private RecyclerView mRecyclerView; 46 | 47 | private View mEmptyView; 48 | private View mLoadingView; 49 | private View mErrorView; 50 | 51 | private View mLoadMoreView; 52 | private View mNoMoreView; 53 | private View mLoadMoreFailedView; 54 | 55 | private boolean isRefreshing = false; 56 | private boolean nowLoading = false; 57 | private boolean noMore = false; 58 | private boolean loadMoreFailed = false; 59 | 60 | private OnScrollListener mScrollListener = new OnScrollListener(); 61 | private DataSetObserver mObserver = new DataSetObserver(); 62 | 63 | public PracticalRecyclerView(Context context) { 64 | this(context, null); 65 | } 66 | 67 | public PracticalRecyclerView(Context context, AttributeSet attrs) { 68 | this(context, attrs, 0); 69 | } 70 | 71 | public PracticalRecyclerView(Context context, AttributeSet attrs, int defStyleAttr) { 72 | super(context, attrs, defStyleAttr); 73 | initMainView(context); 74 | obtainStyledAttributes(context, attrs); 75 | configDefaultBehavior(); 76 | } 77 | 78 | @TargetApi(Build.VERSION_CODES.LOLLIPOP) 79 | public PracticalRecyclerView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { 80 | super(context, attrs, defStyleAttr, defStyleRes); 81 | initMainView(context); 82 | obtainStyledAttributes(context, attrs); 83 | configDefaultBehavior(); 84 | } 85 | 86 | public void configureView(Configure configure) { 87 | if (configure == null) { 88 | return; 89 | } 90 | configure.configureEmptyView(mEmptyView); 91 | configure.configureErrorView(mErrorView); 92 | configure.configureLoadingView(mLoadingView); 93 | configure.configureLoadMoreView(mLoadMoreView); 94 | configure.configureNoMoreView(mNoMoreView); 95 | configure.configureLoadMoreFailedView(mLoadMoreFailedView); 96 | } 97 | 98 | public RecyclerView get() { 99 | return mRecyclerView; 100 | } 101 | 102 | public void setRefreshListener(OnRefreshListener refreshListener) { 103 | if (refreshListener == null) return; 104 | mSwipeRefreshLayout.setEnabled(true); 105 | mRefreshListener = refreshListener; 106 | } 107 | 108 | public void setLoadMoreListener(OnLoadMoreListener loadMoreListener) { 109 | if (loadMoreListener == null) return; 110 | mLoadMoreListener = loadMoreListener; 111 | } 112 | 113 | public void setLayoutManager(RecyclerView.LayoutManager layoutManager) { 114 | mRecyclerView.setLayoutManager(layoutManager); 115 | } 116 | 117 | public void attachItemTouchHelper(ItemTouchHelper itemTouchHelper) { 118 | itemTouchHelper.attachToRecyclerView(mRecyclerView); 119 | } 120 | 121 | public void setAdapter(RecyclerView.Adapter adapter) { 122 | mRecyclerView.setAdapter(adapter); 123 | } 124 | 125 | public void setAdapterWithLoading(RecyclerView.Adapter adapter) { 126 | if (adapter instanceof AbstractAdapter) { 127 | AbstractAdapter abstractAdapter = (AbstractAdapter) adapter; 128 | subscribeWithAdapter(abstractAdapter); 129 | } 130 | displayLoadingAndResetStatus(); 131 | mRecyclerView.setAdapter(adapter); 132 | } 133 | 134 | /** 135 | * 开启或关闭自动加载功能 136 | * 注意, 仍然会显示LoadMoreView, 如需关闭LoadMoreView, 请往下看 137 | * 138 | * @param autoLoadMoreEnable true 为到自动加载, false为手动触发加载 139 | */ 140 | public void setAutoLoadEnable(boolean autoLoadMoreEnable) { 141 | mAutoLoadMoreEnabled = autoLoadMoreEnable; 142 | } 143 | 144 | /** 145 | * 显示或关闭LoadMoreView , 不建议使用 146 | * 注意, 仅仅只是不显示, 但仍会继续加载, 如需关闭自动加载功能, 请往上看 147 | * 148 | * @param enabled true 为显示, false为不显示 149 | */ 150 | public void setLoadMoreViewEnabled(boolean enabled) { 151 | mLoadMoreViewEnabled = enabled; 152 | if (!enabled) { 153 | displayLoadMoreViewOrDisappear(); 154 | } else { 155 | if (mScrollListener.isLastItem(mRecyclerView)) { 156 | autoLoadMoreIfEnabled(); 157 | smoothScrollToPosition(mRecyclerView.getLayoutManager().getItemCount() - 1); 158 | } 159 | } 160 | } 161 | 162 | /** 163 | * 显示或关闭LoadMoreFailedView, 不建议使用 164 | * 165 | * @param enabled true 为显示, false为关闭 166 | */ 167 | public void setLoadMoreFailedViewEnabled(boolean enabled) { 168 | mLoadMoreFailedViewEnabled = enabled; 169 | if (!enabled) { 170 | displayLoadMoreFailedViewOrDisappear(); 171 | } else { 172 | if (loadMoreFailed) { 173 | displayLoadMoreFailedViewOrDisappear(); 174 | smoothScrollToPosition(mRecyclerView.getLayoutManager().getItemCount() - 1); 175 | } 176 | } 177 | } 178 | 179 | /** 180 | * 显示或关闭NoMoreView, 按需使用 181 | * 182 | * @param enabled true为显示, false为关闭 183 | */ 184 | public void setNoMoreViewEnabled(boolean enabled) { 185 | mNoMoreViewEnabled = enabled; 186 | if (!enabled) { 187 | displayNoMoreViewOrDisappear(); 188 | } else { 189 | if (noMore) { 190 | displayNoMoreViewOrDisappear(); 191 | smoothScrollToPosition(mRecyclerView.getLayoutManager().getItemCount() - 1); 192 | } 193 | } 194 | } 195 | 196 | public void setHasFixedSize(boolean hasFixedSize) { 197 | mRecyclerView.setHasFixedSize(hasFixedSize); 198 | } 199 | 200 | public void smoothScrollToPosition(int position) { 201 | mRecyclerView.smoothScrollToPosition(position); 202 | } 203 | 204 | public void setItemAnimator(RecyclerView.ItemAnimator animator) { 205 | mRecyclerView.setItemAnimator(animator); 206 | } 207 | 208 | public void addItemDecoration(RecyclerView.ItemDecoration itemDecoration) { 209 | mRecyclerView.addItemDecoration(itemDecoration); 210 | } 211 | 212 | public void addItemDecoration(RecyclerView.ItemDecoration itemDecoration, int index) { 213 | mRecyclerView.addItemDecoration(itemDecoration, index); 214 | } 215 | 216 | public void removeItemDecoration(RecyclerView.ItemDecoration decor) { 217 | mRecyclerView.removeItemDecoration(decor); 218 | } 219 | 220 | void resolveSwipeConflicts(boolean enabled) { 221 | if (mRefreshListener == null) { 222 | return; 223 | } 224 | mSwipeRefreshLayout.setEnabled(enabled); 225 | } 226 | 227 | void displayLoadingAndResetStatus() { 228 | mErrorContainer.setVisibility(GONE); 229 | mContentContainer.setVisibility(GONE); 230 | mEmptyContainer.setVisibility(GONE); 231 | mLoadingContainer.setVisibility(VISIBLE); 232 | resetStatus(); 233 | } 234 | 235 | void displayContentAndResetStatus() { 236 | mLoadingContainer.setVisibility(GONE); 237 | mErrorContainer.setVisibility(GONE); 238 | mEmptyContainer.setVisibility(GONE); 239 | mContentContainer.setVisibility(VISIBLE); 240 | resetStatus(); 241 | } 242 | 243 | void displayEmptyAndResetStatus() { 244 | mLoadingContainer.setVisibility(GONE); 245 | mContentContainer.setVisibility(GONE); 246 | mErrorContainer.setVisibility(GONE); 247 | mEmptyContainer.setVisibility(VISIBLE); 248 | resetStatus(); 249 | } 250 | 251 | void displayErrorAndResetStatus() { 252 | mLoadingContainer.setVisibility(GONE); 253 | mContentContainer.setVisibility(GONE); 254 | mEmptyContainer.setVisibility(GONE); 255 | mErrorContainer.setVisibility(VISIBLE); 256 | resetStatus(); 257 | } 258 | 259 | void showNoMoreIfEnabled() { 260 | displayNoMoreViewOrDisappear(); 261 | noMore = true; 262 | } 263 | 264 | void showLoadMoreFailedIfEnabled() { 265 | displayLoadMoreFailedViewOrDisappear(); 266 | loadMoreFailed = true; 267 | } 268 | 269 | void resumeLoadMoreIfEnabled() { 270 | loadMoreFailed = false; 271 | autoLoadMoreIfEnabled(); 272 | } 273 | 274 | void autoLoadMoreIfEnabled() { 275 | if (canNotLoadMore()) return; 276 | displayLoadMoreViewOrDisappear(); 277 | if (mAutoLoadMoreEnabled) { 278 | nowLoading = true; 279 | mLoadMoreListener.onLoadMore(); 280 | } 281 | } 282 | 283 | void manualLoadMoreIfEnabled() { 284 | if (canNotLoadMore()) return; 285 | displayLoadMoreViewOrDisappear(); 286 | nowLoading = true; 287 | mLoadMoreListener.onLoadMore(); 288 | } 289 | 290 | private void displayNoMoreViewOrDisappear() { 291 | displayOrDisappear(mNoMoreView, mNoMoreViewEnabled); 292 | } 293 | 294 | private void displayLoadMoreFailedViewOrDisappear() { 295 | displayOrDisappear(mLoadMoreFailedView, mLoadMoreFailedViewEnabled); 296 | } 297 | 298 | private void displayLoadMoreViewOrDisappear() { 299 | displayOrDisappear(mLoadMoreView, mLoadMoreViewEnabled); 300 | } 301 | 302 | private void displayOrDisappear(View view, boolean enabled) { 303 | if (!(mRecyclerView.getAdapter() instanceof AbstractAdapter)) return; 304 | AbstractAdapter adapter = (AbstractAdapter) mRecyclerView.getAdapter(); 305 | adapter.show(view, enabled); 306 | } 307 | 308 | private void resetStatus() { 309 | isRefreshing = false; 310 | nowLoading = false; 311 | loadMoreFailed = false; 312 | noMore = false; 313 | } 314 | 315 | private void initMainView(Context context) { 316 | mMainContainer = (FrameLayout) LayoutInflater.from(context).inflate(R.layout.recycler_layout, this, true); 317 | mLoadingContainer = (FrameLayout) mMainContainer.findViewById(R.id.practical_loading); 318 | mErrorContainer = (FrameLayout) mMainContainer.findViewById(R.id.practical_error); 319 | mEmptyContainer = (FrameLayout) mMainContainer.findViewById(R.id.practical_empty); 320 | mContentContainer = (LinearLayout) mMainContainer.findViewById(R.id.practical_content); 321 | 322 | mSwipeRefreshLayout = (SwipeRefreshLayout) mMainContainer.findViewById(R.id.practical_swipe_refresh); 323 | mRecyclerView = (RecyclerView) mMainContainer.findViewById(R.id.practical_recycler); 324 | } 325 | 326 | private void configDefaultBehavior() { 327 | //默认为关闭,设置OnRefreshListener时打开 328 | mSwipeRefreshLayout.setEnabled(false); 329 | mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { 330 | @Override 331 | public void onRefresh() { 332 | refresh(); 333 | } 334 | }); 335 | 336 | mRecyclerView.addOnScrollListener(mScrollListener); 337 | 338 | //设置error view 默认行为,点击刷新 339 | mErrorView.setOnClickListener(new OnClickListener() { 340 | @Override 341 | public void onClick(View v) { 342 | displayLoadingAndResetStatus(); 343 | refresh(); 344 | } 345 | }); 346 | //设置load more failed view 默认行为, 点击恢复加载 347 | mLoadMoreFailedView.setOnClickListener(new OnClickListener() { 348 | @Override 349 | public void onClick(View v) { 350 | resumeLoadMoreIfEnabled(); 351 | displayOrDisappear(mLoadMoreFailedView, false); 352 | } 353 | }); 354 | } 355 | 356 | private void refresh() { 357 | if (canNotRefresh()) { 358 | closeRefreshing(); 359 | return; 360 | } 361 | mRefreshListener.onRefresh(); 362 | isRefreshing = true; 363 | } 364 | 365 | private void closeRefreshing() { 366 | if (mSwipeRefreshLayout.isRefreshing()) { 367 | mSwipeRefreshLayout.setRefreshing(false); 368 | isRefreshing = false; 369 | } 370 | } 371 | 372 | private void closeLoadingMore() { 373 | if (nowLoading) { 374 | nowLoading = false; 375 | } 376 | } 377 | 378 | private boolean canNotRefresh() { 379 | return mRefreshListener == null || isRefreshing || nowLoading; 380 | } 381 | 382 | private boolean canNotLoadMore() { 383 | return mLoadMoreListener == null || isRefreshing || nowLoading || loadMoreFailed || noMore; 384 | } 385 | 386 | private void obtainStyledAttributes(Context context, AttributeSet attrs) { 387 | TypedArray attributes = context.obtainStyledAttributes(attrs, R.styleable.PracticalRecyclerView); 388 | int loadingResId = attributes.getResourceId(R.styleable.PracticalRecyclerView_loading_layout, R.layout 389 | .default_loading_layout); 390 | int emptyResId = attributes.getResourceId(R.styleable.PracticalRecyclerView_empty_layout, R.layout 391 | .default_empty_layout); 392 | int errorResId = attributes.getResourceId(R.styleable.PracticalRecyclerView_error_layout, R.layout 393 | .default_error_layout); 394 | 395 | int loadMoreResId = attributes.getResourceId(R.styleable.PracticalRecyclerView_load_more_layout, R.layout 396 | .default_load_more_layout); 397 | int noMoreResId = attributes.getResourceId(R.styleable.PracticalRecyclerView_no_more_layout, R.layout 398 | .default_no_more_layout); 399 | int loadMoreErrorResId = attributes.getResourceId(R.styleable.PracticalRecyclerView_load_more_failed_layout, R 400 | .layout.default_load_more_failed_layout); 401 | 402 | mLoadingView = LayoutInflater.from(context).inflate(loadingResId, mLoadingContainer, true); 403 | mEmptyView = LayoutInflater.from(context).inflate(emptyResId, mEmptyContainer, true); 404 | mErrorView = LayoutInflater.from(context).inflate(errorResId, mErrorContainer, true); 405 | 406 | mLoadMoreView = LayoutInflater.from(context).inflate(loadMoreResId, mMainContainer, false); 407 | mNoMoreView = LayoutInflater.from(context).inflate(noMoreResId, mMainContainer, false); 408 | mLoadMoreFailedView = LayoutInflater.from(context).inflate(loadMoreErrorResId, mMainContainer, false); 409 | 410 | attributes.recycle(); 411 | } 412 | 413 | private void subscribeWithAdapter(AbstractAdapter adapter) { 414 | adapter.registerObserver(mObserver); 415 | } 416 | 417 | public interface OnRefreshListener { 418 | void onRefresh(); 419 | } 420 | 421 | public interface OnLoadMoreListener { 422 | void onLoadMore(); 423 | } 424 | 425 | private class DataSetObserver implements Observer { 426 | 427 | @Override 428 | public void update(Observable o, Object arg) { 429 | closeRefreshing(); 430 | closeLoadingMore(); 431 | Bridge type = (Bridge) arg; 432 | type.doSomething(PracticalRecyclerView.this); 433 | } 434 | } 435 | 436 | private class OnScrollListener extends RecyclerView.OnScrollListener { 437 | 438 | @Override 439 | public void onScrollStateChanged(RecyclerView recyclerView, int newState) { 440 | super.onScrollStateChanged(recyclerView, newState); 441 | //当滚动到最后一个item时,自动加载更多 442 | if (isLastItem(recyclerView)) { 443 | autoLoadMoreIfEnabled(); 444 | } 445 | } 446 | 447 | private boolean isLastItem(RecyclerView recyclerView) { 448 | RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager(); 449 | int visibleItemCount = layoutManager.getChildCount(); 450 | int totalItemCount = layoutManager.getItemCount(); 451 | int lastVisibleItemPosition = getLastVisibleItemPosition(layoutManager); 452 | 453 | return visibleItemCount > 0 && lastVisibleItemPosition >= totalItemCount - 1 && 454 | totalItemCount >= visibleItemCount; 455 | } 456 | 457 | private int getLastVisibleItemPosition(RecyclerView.LayoutManager layoutManager) { 458 | int lastVisibleItemPosition; 459 | if (layoutManager instanceof GridLayoutManager) { 460 | lastVisibleItemPosition = ((GridLayoutManager) layoutManager).findLastVisibleItemPosition(); 461 | } else if (layoutManager instanceof StaggeredGridLayoutManager) { 462 | int[] into = new int[((StaggeredGridLayoutManager) layoutManager).getSpanCount()]; 463 | ((StaggeredGridLayoutManager) layoutManager).findLastVisibleItemPositions(into); 464 | lastVisibleItemPosition = findMax(into); 465 | } else { 466 | lastVisibleItemPosition = ((LinearLayoutManager) layoutManager).findLastVisibleItemPosition(); 467 | } 468 | return lastVisibleItemPosition; 469 | } 470 | 471 | private int findMax(int[] lastPositions) { 472 | int max = lastPositions[0]; 473 | for (int value : lastPositions) { 474 | if (value > max) { 475 | max = value; 476 | } 477 | } 478 | return max; 479 | } 480 | } 481 | } 482 | -------------------------------------------------------------------------------- /simple/src/main/java/com/tamic/fastdownsimple/widget/SectionItem.java: -------------------------------------------------------------------------------- 1 | package com.tamic.fastdownsimple.widget; 2 | 3 | import android.view.View; 4 | import android.view.ViewGroup; 5 | 6 | /** 7 | * Created by liuyongkui726 on 2016-12-21. 8 | */ 9 | 10 | public interface SectionItem { 11 | 12 | View createView(ViewGroup parent); 13 | 14 | void onBind(); 15 | } -------------------------------------------------------------------------------- /simple/src/main/java/com/tamic/fastdownsimple/widget/SectionItemImpl.java: -------------------------------------------------------------------------------- 1 | package com.tamic.fastdownsimple.widget; 2 | 3 | import android.view.View; 4 | import android.view.ViewGroup; 5 | 6 | /** 7 | * Created by Tamic on 2016-12-21. 8 | */ 9 | 10 | public class SectionItemImpl implements SectionItem{ 11 | private View mView; 12 | 13 | public SectionItemImpl() { 14 | } 15 | 16 | public SectionItemImpl(View view) { 17 | mView = view; 18 | } 19 | 20 | @Override 21 | public View createView(ViewGroup parent) { 22 | return mView; 23 | } 24 | 25 | @Override 26 | public void onBind() { 27 | 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /simple/src/main/java/com/tamic/fastdownsimple/widget/WaitingDialog.java: -------------------------------------------------------------------------------- 1 | package com.tamic.fastdownsimple.widget; 2 | 3 | import android.annotation.SuppressLint; 4 | import android.app.Activity; 5 | import android.app.Dialog; 6 | import android.content.Context; 7 | import android.graphics.Color; 8 | import android.os.Bundle; 9 | import android.util.DisplayMetrics; 10 | import android.util.TypedValue; 11 | import android.view.Gravity; 12 | import android.widget.FrameLayout; 13 | import android.widget.LinearLayout; 14 | import android.widget.ProgressBar; 15 | import android.widget.TextView; 16 | 17 | import com.tamic.fastdownsimple.R; 18 | 19 | /** 20 | * WaitingDialog 21 | */ 22 | public class WaitingDialog extends Dialog { 23 | private static final int TEXT_SIZE = 16; 24 | private static final int MESSAGE_PADDING = 12; 25 | private String mMessage; 26 | private Context mContext; 27 | 28 | /** 29 | * constructor 30 | * @param context context 31 | */ 32 | public WaitingDialog(Context context) { 33 | super(context, R.style.BdWaitingDialog); 34 | 35 | mContext = context; 36 | } 37 | 38 | public static WaitingDialog show(Context context, CharSequence message) { 39 | return show(context, message, false); 40 | } 41 | 42 | 43 | public static WaitingDialog show(Context context, CharSequence message, boolean cancelable) { 44 | return show(context, message, cancelable, null); 45 | } 46 | 47 | public static WaitingDialog show(Context context, CharSequence message, boolean cancelable, 48 | OnCancelListener aCancelListener) { 49 | WaitingDialog dialog = new WaitingDialog(context); 50 | dialog.setMessage(message); 51 | dialog.setCancelable(cancelable); 52 | dialog.setOnCancelListener(aCancelListener); 53 | dialog.show(); 54 | return dialog; 55 | } 56 | 57 | @Override 58 | protected void onCreate(Bundle savedInstanceState) { 59 | super.onCreate(savedInstanceState); 60 | 61 | setContentView(new WaitingView(mContext)); 62 | } 63 | 64 | /** 65 | * set a msg 66 | * @param message msg in String 67 | */ 68 | public void setMessage(String message) { 69 | mMessage = message; 70 | } 71 | 72 | /** 73 | * set a msg 74 | * @param message msg in CharSequence 75 | */ 76 | public void setMessage(CharSequence message) { 77 | mMessage = message.toString(); 78 | } 79 | 80 | /** 81 | * set a msg 82 | * @param resId msg in res id 83 | */ 84 | public void setMessage(int resId) { 85 | mMessage = mContext.getResources().getString(resId); 86 | } 87 | 88 | /** 89 | * waiting content view in waiting dialog 90 | */ 91 | private class WaitingView extends LinearLayout { 92 | /** text size */ 93 | private int mTextSize; 94 | /** msg padding */ 95 | private int mMessagePadding; 96 | /** screen width */ 97 | private int mScreenWidth; 98 | /** context */ 99 | private Context mContext; 100 | 101 | /** 102 | * constructor 103 | * @param context context 104 | */ 105 | public WaitingView(Context context) { 106 | super(context); 107 | 108 | mContext = context; 109 | 110 | loadConfiguration(); 111 | 112 | layoutDesign(); 113 | } 114 | 115 | /** 116 | * load configuration 117 | */ 118 | private void loadConfiguration() { 119 | DisplayMetrics dm = new DisplayMetrics(); 120 | ((Activity) mContext).getWindowManager().getDefaultDisplay().getMetrics(dm); 121 | float density = dm.density; 122 | mScreenWidth = dm.widthPixels; 123 | 124 | mTextSize = (int) (TEXT_SIZE * Math.sqrt(density)); 125 | mMessagePadding = (int) (MESSAGE_PADDING * density); 126 | } 127 | 128 | 129 | @SuppressLint("InlinedApi") 130 | private void layoutDesign() { 131 | setOrientation(LinearLayout.VERTICAL); 132 | FrameLayout.LayoutParams lParams0 = new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, 133 | LayoutParams.WRAP_CONTENT); 134 | setLayoutParams(lParams0); 135 | setBackgroundColor(Color.TRANSPARENT); 136 | 137 | ProgressBar progressBar = new ProgressBar(mContext); 138 | progressBar.setBackgroundColor(Color.TRANSPARENT); 139 | LayoutParams lParams1 = new LayoutParams(LayoutParams.WRAP_CONTENT, 140 | LayoutParams.WRAP_CONTENT); 141 | lParams1.gravity = Gravity.CENTER; 142 | progressBar.setLayoutParams(lParams1); 143 | addView(progressBar); 144 | TextView textView = new TextView(mContext); 145 | textView.setText(mMessage); 146 | LayoutParams lParams2 = new LayoutParams(LayoutParams.MATCH_PARENT, 147 | LayoutParams.WRAP_CONTENT); 148 | lParams2.gravity = Gravity.CENTER; 149 | lParams2.width = mScreenWidth; 150 | textView.setGravity(Gravity.CENTER); 151 | textView.setLayoutParams(lParams2); 152 | textView.setBackgroundColor(Color.TRANSPARENT); 153 | textView.setPadding(mMessagePadding, mMessagePadding, mMessagePadding, mMessagePadding); 154 | textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mTextSize); 155 | textView.setTextColor(0xffe5e5e5); 156 | addView(textView); 157 | } 158 | } 159 | 160 | } 161 | -------------------------------------------------------------------------------- /simple/src/main/res/drawable/apk.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tamicer/FastDownloader/6cf35c3d346b2eb1646bdf307f4440700b80955a/simple/src/main/res/drawable/apk.png -------------------------------------------------------------------------------- /simple/src/main/res/drawable/file.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tamicer/FastDownloader/6cf35c3d346b2eb1646bdf307f4440700b80955a/simple/src/main/res/drawable/file.png -------------------------------------------------------------------------------- /simple/src/main/res/drawable/image.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tamicer/FastDownloader/6cf35c3d346b2eb1646bdf307f4440700b80955a/simple/src/main/res/drawable/image.png -------------------------------------------------------------------------------- /simple/src/main/res/drawable/pdf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tamicer/FastDownloader/6cf35c3d346b2eb1646bdf307f4440700b80955a/simple/src/main/res/drawable/pdf.png -------------------------------------------------------------------------------- /simple/src/main/res/drawable/status_alert.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tamicer/FastDownloader/6cf35c3d346b2eb1646bdf307f4440700b80955a/simple/src/main/res/drawable/status_alert.png -------------------------------------------------------------------------------- /simple/src/main/res/drawable/status_cancel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tamicer/FastDownloader/6cf35c3d346b2eb1646bdf307f4440700b80955a/simple/src/main/res/drawable/status_cancel.png -------------------------------------------------------------------------------- /simple/src/main/res/drawable/status_down.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tamicer/FastDownloader/6cf35c3d346b2eb1646bdf307f4440700b80955a/simple/src/main/res/drawable/status_down.png -------------------------------------------------------------------------------- /simple/src/main/res/drawable/status_download.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tamicer/FastDownloader/6cf35c3d346b2eb1646bdf307f4440700b80955a/simple/src/main/res/drawable/status_download.png -------------------------------------------------------------------------------- /simple/src/main/res/drawable/status_faile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tamicer/FastDownloader/6cf35c3d346b2eb1646bdf307f4440700b80955a/simple/src/main/res/drawable/status_faile.png -------------------------------------------------------------------------------- /simple/src/main/res/drawable/status_pused.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tamicer/FastDownloader/6cf35c3d346b2eb1646bdf307f4440700b80955a/simple/src/main/res/drawable/status_pused.png -------------------------------------------------------------------------------- /simple/src/main/res/drawable/status_right.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tamicer/FastDownloader/6cf35c3d346b2eb1646bdf307f4440700b80955a/simple/src/main/res/drawable/status_right.png -------------------------------------------------------------------------------- /simple/src/main/res/drawable/txt.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tamicer/FastDownloader/6cf35c3d346b2eb1646bdf307f4440700b80955a/simple/src/main/res/drawable/txt.png -------------------------------------------------------------------------------- /simple/src/main/res/drawable/video.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tamicer/FastDownloader/6cf35c3d346b2eb1646bdf307f4440700b80955a/simple/src/main/res/drawable/video.png -------------------------------------------------------------------------------- /simple/src/main/res/drawable/zip.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tamicer/FastDownloader/6cf35c3d346b2eb1646bdf307f4440700b80955a/simple/src/main/res/drawable/zip.png -------------------------------------------------------------------------------- /simple/src/main/res/layout/activity_dowmload_list.xml: -------------------------------------------------------------------------------- 1 | 2 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /simple/src/main/res/layout/activity_down_load_add.xml: -------------------------------------------------------------------------------- 1 | 12 | 13 | 17 | 18 | 23 | 24 | 27 | 28 | 36 | 37 | 38 | 39 | 40 | 41 |