├── .gitignore ├── .idea ├── .name ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── encodings.xml ├── gradle.xml ├── misc.xml ├── modules.xml ├── runConfigurations.xml └── vcs.xml ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── build.gradle ├── firebase-jobdispatcher ├── build.gradle └── firebase-jobdispatcher.aar ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── jobdispatcher_complete ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── google │ │ └── codelabs │ │ └── migratingtojobs │ │ └── jobdispatcher_complete │ │ ├── DownloaderJobService.java │ │ ├── JobDispatcherComponent.java │ │ ├── JobDispatcherEvents.java │ │ ├── JobDispatcherGlobalState.java │ │ ├── JobDispatcherModule.java │ │ ├── JobDispatchingCatalogListActivity.java │ │ └── JobDispatchingErrorListener.java │ └── res │ └── values │ ├── colors.xml │ ├── strings.xml │ └── styles.xml ├── jobscheduler_complete ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── google │ │ └── codelabs │ │ └── migratingtojobs │ │ └── jobscheduler_complete │ │ ├── DownloaderJobService.java │ │ ├── JobSchedulerComponent.java │ │ ├── JobSchedulerEvents.java │ │ ├── JobSchedulerGlobalState.java │ │ ├── JobSchedulingCatalogListActivity.java │ │ └── JobSchedulingErrorListener.java │ └── res │ └── values │ ├── colors.xml │ ├── strings.xml │ └── styles.xml ├── original_app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── google │ │ └── codelabs │ │ └── migratingtojobs │ │ └── original_app │ │ ├── ConnectivityChangeReceiver.java │ │ ├── OriginalCatalogListActivity.java │ │ ├── OriginalComponent.java │ │ └── OriginalGlobalState.java │ └── res │ └── values │ └── strings.xml ├── settings.gradle └── shared ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src └── main ├── AndroidManifest.xml ├── java └── com │ └── google │ └── codelabs │ └── migratingtojobs │ └── shared │ ├── AppModule.java │ ├── ApplicationDataStore.java │ ├── BaseEventListener.java │ ├── Book.java │ ├── CatalogItem.java │ ├── CatalogItemStore.java │ ├── CatalogListActivity.java │ ├── CatalogRecyclerAdaptor.java │ ├── Downloader.java │ ├── ErrorLoggingDownloadCallback.java │ ├── EventBus.java │ ├── PriorityThreadFactory.java │ ├── RootComponent.java │ ├── SharedInitializer.java │ ├── StoreArchiver.java │ └── Util.java ├── proto └── catalog_item.proto └── res ├── drawable ├── ic_cancel.xml ├── ic_delete.xml ├── ic_download.xml └── ic_error.xml ├── layout ├── activity_catalog_list.xml └── content_catalog_item.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 | # https://intellij-support.jetbrains.com/hc/en-us/articles/206544839-How-to-manage-projects-under-Version-Control-Systems 2 | # IntelliJ uses the following two files for user-specific settings: 3 | /.idea/workspace.xml 4 | /.idea/tasks.xml 5 | 6 | # And these ones are autogenerated from Gradle files: 7 | /.idea/libraries 8 | *.iml 9 | 10 | # Gradle settings 11 | .gradle 12 | /local.properties 13 | gradle.properties 14 | 15 | # Gradle artifacts 16 | /build 17 | /captures 18 | 19 | # Mac Finder settings 20 | .DS_Store 21 | -------------------------------------------------------------------------------- /.idea/.name: -------------------------------------------------------------------------------- 1 | android-migrate-to-jobs -------------------------------------------------------------------------------- /.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 | 23 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 46 | 47 | 48 | 49 | 50 | 1.8 51 | 52 | 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # How to become a contributor and submit your own code 2 | 3 | ## Contributor License Agreements 4 | 5 | We'd love to accept your patches! Before we can take them, we 6 | have to jump a couple of legal hurdles. 7 | 8 | ### Before you contribute 9 | Before we can use your code, you must sign the 10 | [Google Individual Contributor License Agreement](https://cla.developers.google.com/about/google-individual) 11 | (CLA), which you can do online. The CLA is necessary mainly because you own the 12 | copyright to your changes, even after your contribution becomes part of our 13 | codebase, so we need your permission to use and distribute your code. We also 14 | need to be sure of various other things—for instance that you'll tell us if you 15 | know that your code infringes on other people's patents. You don't have to sign 16 | the CLA until after you've submitted your code for review and a member has 17 | approved it, but you must do it before we can put your code into our codebase. 18 | Before you start working on a larger contribution, you should get in touch with 19 | us first through the issue tracker with your idea so that we can help out and 20 | possibly guide you. Coordinating up front makes it much easier to avoid 21 | frustration later on. 22 | 23 | ### Code reviews 24 | All submissions, including submissions by project members, require review. We 25 | use Github pull requests for this purpose. 26 | 27 | ### The small print 28 | Contributions made by corporations are covered by a different agreement than 29 | the one above, the 30 | [Software Grant and Corporate Contributor License Agreement](https://cla.developers.google.com/about/google-corporate). 31 | -------------------------------------------------------------------------------- /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 | # Removing dependencies on background services 2 | 3 | This is a sample project to illustrate the concepts discussed in the similarly 4 | named Android codelab. 5 | 6 | ## License 7 | 8 | ``` 9 | Copyright 2016 Google, Inc. 10 | 11 | Licensed to the Apache Software Foundation (ASF) under one or more contributor 12 | license agreements. See the NOTICE file distributed with this work for 13 | additional information regarding copyright ownership. The ASF licenses this 14 | file to you under the Apache License, Version 2.0 (the "License"); you may not 15 | use this file except in compliance with the License. You may obtain a copy of 16 | the License at 17 | 18 | http://www.apache.org/licenses/LICENSE-2.0 19 | 20 | Unless required by applicable law or agreed to in writing, software distributed 21 | under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 22 | CONDITIONS OF ANY KIND, either express or implied. See the License for the 23 | specific language governing permissions and limitations under the License. 24 | ``` 25 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // root 2 | 3 | buildscript { 4 | repositories { 5 | flatDir { 6 | dirs 'libs' 7 | } 8 | jcenter() 9 | mavenCentral() 10 | } 11 | 12 | dependencies { 13 | classpath 'com.android.tools.build:gradle:2.1.0' 14 | classpath 'com.google.protobuf:protobuf-gradle-plugin:0.7.7' 15 | 16 | // needed for dagger2 17 | classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8' 18 | } 19 | } 20 | 21 | allprojects { 22 | repositories { 23 | jcenter() 24 | } 25 | } 26 | 27 | task clean(type: Delete) { 28 | delete rootProject.buildDir 29 | } 30 | 31 | task wrapper(type: Wrapper) { 32 | gradleVersion = '2.13' 33 | } 34 | -------------------------------------------------------------------------------- /firebase-jobdispatcher/build.gradle: -------------------------------------------------------------------------------- 1 | configurations.maybeCreate("default") 2 | artifacts.add("default", file('firebase-jobdispatcher.aar')) -------------------------------------------------------------------------------- /firebase-jobdispatcher/firebase-jobdispatcher.aar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-migrate-to-jobs/561521d37d35486a98f5a204773d86c06b5adb82/firebase-jobdispatcher/firebase-jobdispatcher.aar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-migrate-to-jobs/561521d37d35486a98f5a204773d86c06b5adb82/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Sun May 08 18:42:02 PDT 2016 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.13-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 | -------------------------------------------------------------------------------- /jobdispatcher_complete/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /jobdispatcher_complete/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | apply plugin: 'com.neenbedankt.android-apt' 3 | 4 | android { 5 | compileSdkVersion 23 6 | buildToolsVersion "23.0.3" 7 | 8 | defaultConfig { 9 | applicationId "com.google.codelabs.migratingtojobs.jobdispatcher_complete" 10 | minSdkVersion 21 11 | targetSdkVersion 23 12 | versionCode 1 13 | versionName "1.0" 14 | } 15 | buildTypes { 16 | release { 17 | minifyEnabled false 18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 19 | } 20 | } 21 | dataBinding { 22 | enabled = true 23 | } 24 | } 25 | 26 | dependencies { 27 | compile fileTree(include: ['*.jar'], dir: 'libs') 28 | testCompile 'junit:junit:4.12' 29 | compile 'com.android.support:appcompat-v7:23.3.0' 30 | compile 'com.android.support:design:23.3.0' 31 | // https://github.com/google/dagger/issues/356 32 | apt 'com.google.guava:guava:19.0' 33 | compile 'com.google.dagger:dagger:2.4' 34 | apt 'com.google.dagger:dagger-compiler:2.4' 35 | provided 'javax.annotation:jsr250-api:1.0' 36 | compile project(':shared') 37 | compile project(':firebase-jobdispatcher') 38 | } 39 | -------------------------------------------------------------------------------- /jobdispatcher_complete/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 /usr/local/google/home/ciarandowney/aswb-android-sdk-linux/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 | -------------------------------------------------------------------------------- /jobdispatcher_complete/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 20 | 21 | " 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /jobdispatcher_complete/src/main/java/com/google/codelabs/migratingtojobs/jobdispatcher_complete/DownloaderJobService.java: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Google, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | //////////////////////////////////////////////////////////////////////////////// 16 | 17 | package com.google.codelabs.migratingtojobs.jobdispatcher_complete; 18 | 19 | import com.firebase.jobdispatcher.JobService; 20 | import com.firebase.jobdispatcher.JobParameters; 21 | import com.google.codelabs.migratingtojobs.shared.BaseEventListener; 22 | import com.google.codelabs.migratingtojobs.shared.CatalogItem; 23 | import com.google.codelabs.migratingtojobs.shared.CatalogItemStore; 24 | import com.google.codelabs.migratingtojobs.shared.EventBus; 25 | 26 | import java.util.LinkedList; 27 | import java.util.List; 28 | 29 | import javax.inject.Inject; 30 | 31 | public class DownloaderJobService extends JobService { 32 | /** 33 | * List of all listeners we register, so we can make sure they get unregistered when this 34 | * service goes away. 35 | */ 36 | final List eventListeners = new LinkedList<>(); 37 | 38 | @Inject 39 | EventBus bus; 40 | 41 | @Inject 42 | CatalogItemStore itemStore; 43 | 44 | @Override 45 | public boolean onStartJob(JobParameters jobParameters) { 46 | EventListener listener = new EventListener(this, jobParameters, bus); 47 | synchronized (eventListeners) { 48 | eventListeners.add(listener); 49 | bus.register(listener); 50 | } 51 | 52 | // TRIGGER WORK 53 | bus.postRetryDownloads(itemStore); 54 | 55 | return true; // true because there's more work being done on a separate thread 56 | } 57 | 58 | @Override 59 | public boolean onStopJob(JobParameters jobParameters) { 60 | // If this is being called it means we haven't explicitly finished our work yet. 61 | // Return true so we get rescheduled. 62 | return false; 63 | } 64 | 65 | @Override 66 | public void onCreate() { 67 | super.onCreate(); 68 | 69 | // Initialize everything if it's not already, plus inject dependencies. 70 | JobDispatcherGlobalState.get(getApplication()).inject(this); 71 | } 72 | 73 | @Override 74 | public void onDestroy() { 75 | synchronized (eventListeners) { 76 | for (EventBus.EventListener listener : eventListeners) { 77 | // unregistering prevents leaks. 78 | bus.unregister(listener); 79 | } 80 | } 81 | 82 | super.onDestroy(); 83 | } 84 | 85 | private final static class EventListener extends BaseEventListener { 86 | private final JobService service; 87 | private final JobParameters jobParameters; 88 | private final EventBus bus; 89 | 90 | public EventListener(JobService service, JobParameters jobParameters, EventBus bus) { 91 | this.service = service; 92 | this.jobParameters = jobParameters; 93 | this.bus = bus; 94 | } 95 | 96 | @Override 97 | public void onItemDownloadFailed(CatalogItem item) { 98 | service.jobFinished(jobParameters, true); 99 | JobDispatcherEvents.postDownloadJobFailed(bus); 100 | } 101 | 102 | @Override 103 | public void onAllDownloadsFinished() { 104 | service.jobFinished(jobParameters, false); 105 | JobDispatcherEvents.postDownloadJobFinished(bus); 106 | } 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /jobdispatcher_complete/src/main/java/com/google/codelabs/migratingtojobs/jobdispatcher_complete/JobDispatcherComponent.java: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Google, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | //////////////////////////////////////////////////////////////////////////////// 16 | 17 | package com.google.codelabs.migratingtojobs.jobdispatcher_complete; 18 | 19 | import com.google.codelabs.migratingtojobs.shared.AppModule; 20 | import com.google.codelabs.migratingtojobs.shared.RootComponent; 21 | 22 | import dagger.Component; 23 | 24 | import javax.inject.Singleton; 25 | 26 | @Singleton 27 | @Component(modules = {AppModule.class, JobDispatcherModule.class}) 28 | public interface JobDispatcherComponent extends RootComponent { 29 | void inject(JobDispatcherGlobalState jobDispatcherGlobalState); 30 | void inject(JobDispatchingCatalogListActivity activity); 31 | void inject(DownloaderJobService downloaderJobService); 32 | } 33 | -------------------------------------------------------------------------------- /jobdispatcher_complete/src/main/java/com/google/codelabs/migratingtojobs/jobdispatcher_complete/JobDispatcherEvents.java: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Google, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | //////////////////////////////////////////////////////////////////////////////// 16 | 17 | package com.google.codelabs.migratingtojobs.jobdispatcher_complete; 18 | 19 | import com.google.codelabs.migratingtojobs.shared.EventBus; 20 | 21 | public class JobDispatcherEvents { 22 | public static final int DOWNLOAD_JOB_FINISHED = EventBus.FIRST_UNUSED; 23 | public static final int DOWNLOAD_JOB_FAILED = EventBus.FIRST_UNUSED + 1; 24 | 25 | public static void postDownloadJobFinished(EventBus bus) { 26 | bus.send(DOWNLOAD_JOB_FINISHED); 27 | } 28 | 29 | public static void postDownloadJobFailed(EventBus bus) { 30 | bus.send(DOWNLOAD_JOB_FAILED); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /jobdispatcher_complete/src/main/java/com/google/codelabs/migratingtojobs/jobdispatcher_complete/JobDispatcherGlobalState.java: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Google, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | //////////////////////////////////////////////////////////////////////////////// 16 | 17 | package com.google.codelabs.migratingtojobs.jobdispatcher_complete; 18 | 19 | import android.app.Application; 20 | 21 | import com.google.codelabs.migratingtojobs.shared.AppModule; 22 | import com.google.codelabs.migratingtojobs.shared.EventBus; 23 | import com.google.codelabs.migratingtojobs.shared.SharedInitializer; 24 | 25 | import javax.inject.Inject; 26 | 27 | public class JobDispatcherGlobalState { 28 | private static JobDispatcherGlobalState sInstance; 29 | 30 | public static JobDispatcherComponent get(Application app) { 31 | if (sInstance == null) { 32 | synchronized (JobDispatcherGlobalState.class) { 33 | if (sInstance == null) { 34 | sInstance = new JobDispatcherGlobalState(app); 35 | 36 | sInstance.init(); 37 | } 38 | } 39 | } 40 | 41 | return sInstance.get(); 42 | } 43 | 44 | private final JobDispatcherComponent mComponent; 45 | 46 | @Inject 47 | SharedInitializer mSharedInitializer; 48 | 49 | @Inject 50 | EventBus mBus; 51 | 52 | @Inject 53 | JobDispatchingErrorListener mJobDispatchingErrorListener; 54 | 55 | public JobDispatcherGlobalState(Application app) { 56 | mComponent = DaggerJobDispatcherComponent.builder() 57 | .appModule(new AppModule(app)) 58 | .build(); 59 | 60 | mComponent.inject(this); 61 | } 62 | 63 | private void init() { 64 | mSharedInitializer.init(); 65 | 66 | mBus.register(mJobDispatchingErrorListener); 67 | } 68 | 69 | public JobDispatcherComponent get() { 70 | return mComponent; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /jobdispatcher_complete/src/main/java/com/google/codelabs/migratingtojobs/jobdispatcher_complete/JobDispatcherModule.java: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Google, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | //////////////////////////////////////////////////////////////////////////////// 16 | 17 | package com.google.codelabs.migratingtojobs.jobdispatcher_complete; 18 | 19 | import android.content.Context; 20 | 21 | import com.firebase.jobdispatcher.FirebaseJobDispatcher; 22 | import com.firebase.jobdispatcher.GooglePlayDriver; 23 | 24 | import javax.inject.Singleton; 25 | 26 | import dagger.Module; 27 | import dagger.Provides; 28 | 29 | @Module 30 | @Singleton 31 | public class JobDispatcherModule { 32 | @Provides 33 | @Singleton 34 | FirebaseJobDispatcher provideFirebaseJobDispatcher(Context context) { 35 | return new FirebaseJobDispatcher(new GooglePlayDriver(context)); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /jobdispatcher_complete/src/main/java/com/google/codelabs/migratingtojobs/jobdispatcher_complete/JobDispatchingCatalogListActivity.java: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Google, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | //////////////////////////////////////////////////////////////////////////////// 16 | 17 | package com.google.codelabs.migratingtojobs.jobdispatcher_complete; 18 | 19 | import com.google.codelabs.migratingtojobs.shared.CatalogListActivity; 20 | 21 | public class JobDispatchingCatalogListActivity extends CatalogListActivity { 22 | @Override 23 | protected void inject() { 24 | JobDispatcherGlobalState.get(getApplication()).inject(this); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /jobdispatcher_complete/src/main/java/com/google/codelabs/migratingtojobs/jobdispatcher_complete/JobDispatchingErrorListener.java: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Google, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | //////////////////////////////////////////////////////////////////////////////// 16 | 17 | package com.google.codelabs.migratingtojobs.jobdispatcher_complete; 18 | 19 | import android.os.Message; 20 | import android.support.annotation.NonNull; 21 | import android.util.Log; 22 | 23 | import com.firebase.jobdispatcher.Constraint; 24 | import com.firebase.jobdispatcher.FirebaseJobDispatcher; 25 | import com.firebase.jobdispatcher.Job; 26 | import com.google.codelabs.migratingtojobs.shared.BaseEventListener; 27 | import com.google.codelabs.migratingtojobs.shared.CatalogItem; 28 | 29 | import java.util.concurrent.ExecutorService; 30 | 31 | import javax.inject.Inject; 32 | import javax.inject.Named; 33 | 34 | public class JobDispatchingErrorListener extends BaseEventListener { 35 | @NonNull 36 | private final ExecutorService executorService; 37 | 38 | private final ScheduleRunnable scheduleRunnable; 39 | 40 | private boolean jobScheduled = false; 41 | 42 | @Inject public JobDispatchingErrorListener(@NonNull FirebaseJobDispatcher dispatcher, 43 | @NonNull @Named("worker") ExecutorService executorService) { 44 | this.executorService = executorService; 45 | this.scheduleRunnable = new ScheduleRunnable(dispatcher); 46 | } 47 | 48 | @Override 49 | public void onItemDownloadFailed(CatalogItem item) { 50 | // most checks shouldn't have to wait for the synch lock 51 | if (!jobScheduled) { 52 | synchronized (this) { 53 | if (!jobScheduled) { 54 | executorService.submit(scheduleRunnable); 55 | jobScheduled = true; 56 | } 57 | } 58 | } 59 | } 60 | 61 | @Override 62 | public void handle(Message msg) { 63 | if (msg.what == JobDispatcherEvents.DOWNLOAD_JOB_FINISHED) { 64 | synchronized (this) { 65 | jobScheduled = false; 66 | } 67 | } 68 | } 69 | 70 | private static class ScheduleRunnable implements Runnable { 71 | private static final String TAG = "FJD D/L Handler"; 72 | 73 | private final FirebaseJobDispatcher dispatcher; 74 | private final Job jobToSchedule; 75 | 76 | public ScheduleRunnable(FirebaseJobDispatcher dispatcher) { 77 | this.dispatcher = dispatcher; 78 | this.jobToSchedule = dispatcher.newJobBuilder() 79 | .setTag("downloader_job") 80 | .setService(DownloaderJobService.class) 81 | .setConstraints(Constraint.ON_ANY_NETWORK) 82 | .build(); 83 | } 84 | 85 | @Override 86 | public void run() { 87 | Log.v(TAG, "Scheduling download job"); 88 | dispatcher.mustSchedule(this.jobToSchedule); 89 | } 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /jobdispatcher_complete/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /jobdispatcher_complete/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | [FJD] Book Catalog 4 | 5 | -------------------------------------------------------------------------------- /jobdispatcher_complete/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /jobscheduler_complete/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /jobscheduler_complete/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | apply plugin: 'com.neenbedankt.android-apt' 3 | 4 | android { 5 | compileSdkVersion 23 6 | buildToolsVersion "23.0.3" 7 | 8 | defaultConfig { 9 | applicationId "com.google.codelabs.migratingtojobs.jobscheduler_complete" 10 | minSdkVersion 21 11 | targetSdkVersion 23 12 | versionCode 1 13 | versionName "1.0" 14 | } 15 | buildTypes { 16 | release { 17 | minifyEnabled false 18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 19 | } 20 | } 21 | dataBinding { 22 | enabled = true 23 | } 24 | } 25 | 26 | dependencies { 27 | compile fileTree(include: ['*.jar'], dir: 'libs') 28 | testCompile 'junit:junit:4.12' 29 | compile 'com.android.support:appcompat-v7:23.3.0' 30 | compile 'com.android.support:design:23.3.0' 31 | // https://github.com/google/dagger/issues/356 32 | apt 'com.google.guava:guava:19.0' 33 | compile 'com.google.dagger:dagger:2.4' 34 | apt 'com.google.dagger:dagger-compiler:2.4' 35 | provided 'javax.annotation:jsr250-api:1.0' 36 | compile project(':shared') 37 | } 38 | -------------------------------------------------------------------------------- /jobscheduler_complete/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 /Users/ciarandowney/Library/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 | -------------------------------------------------------------------------------- /jobscheduler_complete/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 10 | 11 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /jobscheduler_complete/src/main/java/com/google/codelabs/migratingtojobs/jobscheduler_complete/DownloaderJobService.java: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Google, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | //////////////////////////////////////////////////////////////////////////////// 16 | 17 | package com.google.codelabs.migratingtojobs.jobscheduler_complete; 18 | 19 | import android.app.job.JobParameters; 20 | import android.app.job.JobService; 21 | 22 | import com.google.codelabs.migratingtojobs.shared.BaseEventListener; 23 | import com.google.codelabs.migratingtojobs.shared.CatalogItem; 24 | import com.google.codelabs.migratingtojobs.shared.CatalogItemStore; 25 | import com.google.codelabs.migratingtojobs.shared.EventBus; 26 | 27 | import java.util.LinkedList; 28 | import java.util.List; 29 | 30 | import javax.inject.Inject; 31 | 32 | /** 33 | * DownloaderJobService is responsible for kicking off the download process via DownloaderThreads. 34 | */ 35 | public final class DownloaderJobService extends JobService { 36 | 37 | /** 38 | * List of all listeners we register, so we can make sure they get unregistered when this 39 | * service goes away. 40 | */ 41 | final List eventListeners = new LinkedList<>(); 42 | @Inject 43 | EventBus bus; 44 | @Inject 45 | CatalogItemStore itemStore; 46 | 47 | @Override 48 | public void onCreate() { 49 | super.onCreate(); 50 | 51 | // Initialize everything if it's not already, plus inject dependencies. 52 | JobSchedulerGlobalState.get(getApplication()).inject(this); 53 | } 54 | 55 | @Override 56 | public void onDestroy() { 57 | synchronized (eventListeners) { 58 | for (EventListener listener : eventListeners) { 59 | // unregistering prevents leaks. 60 | bus.unregister(listener); 61 | } 62 | } 63 | 64 | super.onDestroy(); 65 | } 66 | 67 | @Override 68 | public boolean onStartJob(JobParameters jobParameters) { 69 | EventListener listener = new EventListener(this, jobParameters, bus); 70 | synchronized (eventListeners) { 71 | eventListeners.add(listener); 72 | bus.register(listener); 73 | } 74 | 75 | // TRIGGER WORK 76 | bus.postRetryDownloads(itemStore); 77 | 78 | return true; // true because there's more work being done on a separate thread 79 | } 80 | 81 | @Override 82 | public boolean onStopJob(JobParameters jobParameters) { 83 | // if we haven't finished yet, it's safe to assume that there's more work to be done. 84 | // True means we'd like to be rescheduled. 85 | return true; 86 | } 87 | 88 | private final static class EventListener extends BaseEventListener { 89 | private final JobService service; 90 | private final JobParameters jobParameters; 91 | private final EventBus bus; 92 | 93 | public EventListener(JobService service, JobParameters jobParameters, EventBus bus) { 94 | this.service = service; 95 | this.jobParameters = jobParameters; 96 | this.bus = bus; 97 | } 98 | 99 | @Override 100 | public void onItemDownloadFailed(CatalogItem item) { 101 | service.jobFinished(jobParameters, true); 102 | JobSchedulerEvents.postDownloadJobFailed(bus); 103 | } 104 | 105 | @Override 106 | public void onAllDownloadsFinished() { 107 | service.jobFinished(jobParameters, false); 108 | JobSchedulerEvents.postDownloadJobFinished(bus); 109 | } 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /jobscheduler_complete/src/main/java/com/google/codelabs/migratingtojobs/jobscheduler_complete/JobSchedulerComponent.java: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Google, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | //////////////////////////////////////////////////////////////////////////////// 16 | 17 | package com.google.codelabs.migratingtojobs.jobscheduler_complete; 18 | 19 | import com.google.codelabs.migratingtojobs.shared.AppModule; 20 | import com.google.codelabs.migratingtojobs.shared.RootComponent; 21 | 22 | import javax.inject.Singleton; 23 | 24 | import dagger.Component; 25 | 26 | @Singleton 27 | @Component(modules = {AppModule.class}) 28 | public interface JobSchedulerComponent extends RootComponent { 29 | void inject(JobSchedulerGlobalState jobSchedulerGlobalState); 30 | 31 | void inject(JobSchedulingCatalogListActivity activity); 32 | 33 | void inject(DownloaderJobService jobService); 34 | } 35 | -------------------------------------------------------------------------------- /jobscheduler_complete/src/main/java/com/google/codelabs/migratingtojobs/jobscheduler_complete/JobSchedulerEvents.java: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Google, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | //////////////////////////////////////////////////////////////////////////////// 16 | 17 | package com.google.codelabs.migratingtojobs.jobscheduler_complete; 18 | 19 | import com.google.codelabs.migratingtojobs.shared.EventBus; 20 | 21 | public final class JobSchedulerEvents { 22 | static final int DOWNLOAD_JOB_FINISHED = 1 << EventBus.FIRST_UNUSED; 23 | static final int DOWNLOAD_JOB_FAILED = 1 << (EventBus.FIRST_UNUSED + 1); 24 | 25 | private JobSchedulerEvents() { 26 | } 27 | 28 | public static void postDownloadJobFinished(EventBus bus) { 29 | bus.send(DOWNLOAD_JOB_FINISHED); 30 | } 31 | 32 | public static void postDownloadJobFailed(EventBus bus) { 33 | bus.send(DOWNLOAD_JOB_FAILED); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /jobscheduler_complete/src/main/java/com/google/codelabs/migratingtojobs/jobscheduler_complete/JobSchedulerGlobalState.java: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Google, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | //////////////////////////////////////////////////////////////////////////////// 16 | 17 | package com.google.codelabs.migratingtojobs.jobscheduler_complete; 18 | 19 | import android.app.Application; 20 | 21 | import com.google.codelabs.migratingtojobs.shared.AppModule; 22 | import com.google.codelabs.migratingtojobs.shared.EventBus; 23 | import com.google.codelabs.migratingtojobs.shared.SharedInitializer; 24 | 25 | import javax.inject.Inject; 26 | 27 | public class JobSchedulerGlobalState { 28 | private static JobSchedulerGlobalState sInstance; 29 | 30 | public static JobSchedulerComponent get(Application app) { 31 | if (sInstance == null) { 32 | synchronized (JobSchedulerGlobalState.class) { 33 | if (sInstance == null) { 34 | sInstance = new JobSchedulerGlobalState(app); 35 | 36 | sInstance.init(); 37 | } 38 | } 39 | } 40 | 41 | return sInstance.get(); 42 | } 43 | 44 | private final JobSchedulerComponent component; 45 | @Inject 46 | SharedInitializer mSharedInitializer; 47 | @Inject 48 | EventBus bus; 49 | @Inject 50 | JobSchedulingErrorListener jobSchedulingErrorListener; 51 | 52 | public JobSchedulerGlobalState(Application app) { 53 | component = DaggerJobSchedulerComponent.builder() 54 | .appModule(new AppModule(app)) 55 | .build(); 56 | 57 | component.inject(this); 58 | } 59 | 60 | private void init() { 61 | mSharedInitializer.init(); 62 | 63 | bus.register(jobSchedulingErrorListener); 64 | } 65 | 66 | public JobSchedulerComponent get() { 67 | return component; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /jobscheduler_complete/src/main/java/com/google/codelabs/migratingtojobs/jobscheduler_complete/JobSchedulingCatalogListActivity.java: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Google, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | //////////////////////////////////////////////////////////////////////////////// 16 | 17 | package com.google.codelabs.migratingtojobs.jobscheduler_complete; 18 | 19 | import com.google.codelabs.migratingtojobs.shared.CatalogListActivity; 20 | 21 | public class JobSchedulingCatalogListActivity extends CatalogListActivity { 22 | @Override 23 | protected void inject() { 24 | // sets all our package-specific global state up and provides superclass dependencies 25 | JobSchedulerGlobalState.get(getApplication()).inject(this); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /jobscheduler_complete/src/main/java/com/google/codelabs/migratingtojobs/jobscheduler_complete/JobSchedulingErrorListener.java: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Google, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | //////////////////////////////////////////////////////////////////////////////// 16 | 17 | package com.google.codelabs.migratingtojobs.jobscheduler_complete; 18 | 19 | import android.app.job.JobInfo; 20 | import android.app.job.JobScheduler; 21 | import android.content.ComponentName; 22 | import android.content.Context; 23 | import android.os.Message; 24 | import android.support.annotation.NonNull; 25 | import android.util.Log; 26 | 27 | import com.google.codelabs.migratingtojobs.shared.BaseEventListener; 28 | import com.google.codelabs.migratingtojobs.shared.CatalogItem; 29 | 30 | import java.util.concurrent.ExecutorService; 31 | 32 | import javax.inject.Inject; 33 | import javax.inject.Named; 34 | 35 | public class JobSchedulingErrorListener extends BaseEventListener { 36 | public final static int DOWNLOAD_JOB_ID = 1; 37 | 38 | private static final String TAG = "JS D/L Handler"; 39 | 40 | private final ExecutorService executorService; 41 | /** 42 | * All calls to the JobScheduler go through IPC, so we do it all on a worker thread in this 43 | * Runnable. 44 | */ 45 | private final Runnable scheduleRunnable; 46 | /** 47 | * Whether we've already scheduled a job. We should avoid making too many expensive IPC calls, 48 | * so check here (synchronize on `this`) first. 49 | */ 50 | private boolean jobScheduled = false; 51 | 52 | @Inject 53 | public JobSchedulingErrorListener(@NonNull Context appContext, 54 | @Named("worker") ExecutorService executorService) { 55 | this.scheduleRunnable = new ScheduleRunnable(appContext); 56 | this.executorService = executorService; 57 | } 58 | 59 | @Override 60 | public void onItemDownloadFailed(CatalogItem item) { 61 | // most checks shouldn't have to wait for the synch lock 62 | if (!jobScheduled) { 63 | synchronized (this) { 64 | if (!jobScheduled) { 65 | executorService.submit(scheduleRunnable); 66 | jobScheduled = true; 67 | } 68 | } 69 | } 70 | } 71 | 72 | @Override 73 | public void handle(Message msg) { 74 | if (msg.what == JobSchedulerEvents.DOWNLOAD_JOB_FINISHED) { 75 | synchronized (this) { 76 | jobScheduled = false; 77 | } 78 | } 79 | } 80 | 81 | private static class ScheduleRunnable implements Runnable { 82 | private final Context appContext; 83 | private final JobInfo jobToSchedule; 84 | 85 | public ScheduleRunnable(Context appContext) { 86 | this.appContext = appContext; 87 | this.jobToSchedule = new JobInfo.Builder( 88 | DOWNLOAD_JOB_ID, new ComponentName(appContext, DownloaderJobService.class)) 89 | // Normally you'd want this be NETWORK_TYPE_UNMETERED, but the 90 | // ConnectivityManager hack we're using in Downloader only checks for "a" 91 | // connection, so let's emulate that here. 92 | .setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY) 93 | .build(); 94 | } 95 | 96 | @Override 97 | public void run() { 98 | JobScheduler js = (JobScheduler) appContext 99 | .getSystemService(Context.JOB_SCHEDULER_SERVICE); 100 | 101 | if (js == null) { 102 | Log.e(TAG, "unable to retrieve JobScheduler. What's going on?"); 103 | return; 104 | } 105 | 106 | Log.i(TAG, "scheduling new job"); 107 | if (js.schedule(jobToSchedule) == JobScheduler.RESULT_FAILURE) { 108 | Log.e(TAG, "encountered unknown error scheduling job"); 109 | } 110 | } 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /jobscheduler_complete/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /jobscheduler_complete/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | [JobS] Book Catalog 4 | 5 | -------------------------------------------------------------------------------- /jobscheduler_complete/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /original_app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /original_app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | apply plugin: 'com.neenbedankt.android-apt' 3 | 4 | android { 5 | compileSdkVersion 23 6 | buildToolsVersion "23.0.3" 7 | 8 | defaultConfig { 9 | applicationId "com.google.codelabs.migratingtojobs.original_app" 10 | minSdkVersion 21 11 | targetSdkVersion 23 12 | versionCode 1 13 | versionName "1.0" 14 | } 15 | buildTypes { 16 | release { 17 | minifyEnabled false 18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 19 | } 20 | } 21 | dataBinding { 22 | enabled = true 23 | } 24 | } 25 | 26 | dependencies { 27 | compile fileTree(include: ['*.jar'], dir: 'libs') 28 | compile 'com.android.support:appcompat-v7:23.3.0' 29 | compile 'com.android.support:design:23.3.0' 30 | // https://github.com/google/dagger/issues/356 31 | apt 'com.google.guava:guava:19.0' 32 | apt 'com.google.dagger:dagger-compiler:2.4' 33 | compile 'com.google.dagger:dagger:2.4' 34 | provided 'javax.annotation:jsr250-api:1.0' 35 | testCompile 'junit:junit:4.12' 36 | compile project(':shared') 37 | } 38 | -------------------------------------------------------------------------------- /original_app/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 /Users/ciarandowney/Library/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 | -------------------------------------------------------------------------------- /original_app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /original_app/src/main/java/com/google/codelabs/migratingtojobs/original_app/ConnectivityChangeReceiver.java: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Google, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | //////////////////////////////////////////////////////////////////////////////// 16 | 17 | package com.google.codelabs.migratingtojobs.original_app; 18 | 19 | import android.content.BroadcastReceiver; 20 | import android.content.Context; 21 | import android.content.Intent; 22 | import android.net.ConnectivityManager; 23 | import android.text.TextUtils; 24 | 25 | import com.google.codelabs.migratingtojobs.shared.CatalogItemStore; 26 | import com.google.codelabs.migratingtojobs.shared.EventBus; 27 | 28 | import javax.inject.Inject; 29 | 30 | public class ConnectivityChangeReceiver extends BroadcastReceiver { 31 | @Inject 32 | EventBus bus; 33 | @Inject 34 | ConnectivityManager connManager; 35 | @Inject 36 | CatalogItemStore itemStore; 37 | private boolean mIsInitialized; 38 | 39 | @Override 40 | public void onReceive(Context context, Intent intent) { 41 | if (intent == null) { 42 | return; 43 | } 44 | 45 | String action = intent.getAction(); 46 | if (TextUtils.isEmpty(action) || !ConnectivityManager.CONNECTIVITY_ACTION.equals(action)) { 47 | return; 48 | } 49 | 50 | injectOnce(context); 51 | bus.postRetryDownloads(itemStore); 52 | } 53 | 54 | private void injectOnce(Context context) { 55 | if (!mIsInitialized) { 56 | synchronized (this) { 57 | if (!mIsInitialized) { 58 | OriginalGlobalState.get(context.getApplicationContext()).inject(this); 59 | mIsInitialized = true; 60 | } 61 | } 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /original_app/src/main/java/com/google/codelabs/migratingtojobs/original_app/OriginalCatalogListActivity.java: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Google, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | //////////////////////////////////////////////////////////////////////////////// 16 | 17 | package com.google.codelabs.migratingtojobs.original_app; 18 | 19 | import com.google.codelabs.migratingtojobs.shared.CatalogListActivity; 20 | 21 | public class OriginalCatalogListActivity extends CatalogListActivity { 22 | @Override 23 | protected void inject() { 24 | OriginalGlobalState.get(getApplication()).inject(this); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /original_app/src/main/java/com/google/codelabs/migratingtojobs/original_app/OriginalComponent.java: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Google, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | //////////////////////////////////////////////////////////////////////////////// 16 | 17 | package com.google.codelabs.migratingtojobs.original_app; 18 | 19 | import com.google.codelabs.migratingtojobs.shared.AppModule; 20 | import com.google.codelabs.migratingtojobs.shared.RootComponent; 21 | 22 | import javax.inject.Singleton; 23 | 24 | import dagger.Component; 25 | 26 | @Singleton 27 | @Component(modules = {AppModule.class}) 28 | public interface OriginalComponent extends RootComponent { 29 | void inject(OriginalGlobalState originalGlobalState); 30 | 31 | void inject(OriginalCatalogListActivity activity); 32 | 33 | void inject(ConnectivityChangeReceiver receiver); 34 | } 35 | -------------------------------------------------------------------------------- /original_app/src/main/java/com/google/codelabs/migratingtojobs/original_app/OriginalGlobalState.java: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Google, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | //////////////////////////////////////////////////////////////////////////////// 16 | 17 | package com.google.codelabs.migratingtojobs.original_app; 18 | 19 | import android.content.Context; 20 | 21 | import com.google.codelabs.migratingtojobs.shared.AppModule; 22 | import com.google.codelabs.migratingtojobs.shared.ErrorLoggingDownloadCallback; 23 | import com.google.codelabs.migratingtojobs.shared.EventBus; 24 | import com.google.codelabs.migratingtojobs.shared.SharedInitializer; 25 | 26 | import javax.inject.Inject; 27 | 28 | public class OriginalGlobalState { 29 | private static OriginalGlobalState sInstance; 30 | private final OriginalComponent component; 31 | @Inject 32 | SharedInitializer sharedInitializer; 33 | @Inject 34 | EventBus bus; 35 | public OriginalGlobalState(Context app) { 36 | component = DaggerOriginalComponent.builder() 37 | .appModule(new AppModule(app)) 38 | .build(); 39 | 40 | component.inject(this); 41 | } 42 | 43 | public static OriginalComponent get(Context app) { 44 | if (sInstance == null) { 45 | synchronized (SharedInitializer.class) { 46 | if (sInstance == null) { 47 | sInstance = new OriginalGlobalState(app); 48 | 49 | sInstance.init(); 50 | } 51 | } 52 | } 53 | 54 | return sInstance.get(); 55 | } 56 | 57 | private void init() { 58 | sharedInitializer.init(); 59 | 60 | bus.register(new ErrorLoggingDownloadCallback()); 61 | } 62 | 63 | public OriginalComponent get() { 64 | return component; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /original_app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | [Orig] Book Catalog 4 | 5 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':original_app', ':shared', ':jobscheduler_complete', ':jobdispatcher_complete', ':firebase-jobdispatcher' 2 | -------------------------------------------------------------------------------- /shared/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /shared/build.gradle: -------------------------------------------------------------------------------- 1 | //noinspection GradleCompatible 2 | apply plugin: 'com.android.library' 3 | apply plugin: 'com.neenbedankt.android-apt' 4 | apply plugin: 'com.google.protobuf' 5 | 6 | protobuf { 7 | protoc { 8 | artifact = 'com.google.protobuf:protoc:3.0.0-beta-2' 9 | } 10 | } 11 | 12 | android { 13 | compileSdkVersion 23 14 | buildToolsVersion '23.0.3' 15 | 16 | defaultConfig { 17 | minSdkVersion 21 18 | targetSdkVersion 23 19 | versionCode 1 20 | versionName "1.0" 21 | } 22 | buildTypes { 23 | release { 24 | minifyEnabled false 25 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 26 | } 27 | } 28 | dataBinding { 29 | enabled = true 30 | } 31 | } 32 | 33 | dependencies { 34 | compile 'com.android.support:appcompat-v7:23.3.0' 35 | compile 'com.android.support:design:23.3.0' 36 | compile 'com.google.protobuf.nano:protobuf-javanano:3.0.0-alpha-2' 37 | // https://github.com/google/dagger/issues/356 38 | apt 'com.google.guava:guava:19.0' 39 | compile 'com.google.dagger:dagger:2.2' 40 | apt 'com.google.dagger:dagger-compiler:2.2' 41 | provided 'javax.annotation:jsr250-api:1.0' 42 | compile fileTree(include: ['*.jar'], dir: 'libs') 43 | testCompile 'junit:junit:4.12' 44 | } 45 | -------------------------------------------------------------------------------- /shared/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 /Users/ciarandowney/Library/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 | -------------------------------------------------------------------------------- /shared/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 12 | 13 | -------------------------------------------------------------------------------- /shared/src/main/java/com/google/codelabs/migratingtojobs/shared/AppModule.java: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Google, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | //////////////////////////////////////////////////////////////////////////////// 16 | 17 | package com.google.codelabs.migratingtojobs.shared; 18 | 19 | import android.content.Context; 20 | import android.content.SharedPreferences; 21 | import android.net.ConnectivityManager; 22 | import android.os.HandlerThread; 23 | 24 | import java.util.Random; 25 | import java.util.concurrent.ExecutorService; 26 | import java.util.concurrent.Executors; 27 | import java.util.concurrent.ThreadFactory; 28 | 29 | import javax.inject.Named; 30 | import javax.inject.Singleton; 31 | 32 | import dagger.Module; 33 | import dagger.Provides; 34 | 35 | @Module 36 | public class AppModule { 37 | private static final String PREFERENCES_NAME = "prefs"; 38 | 39 | private Context mContext; 40 | 41 | public AppModule(Context context) { 42 | mContext = context; 43 | } 44 | 45 | @Provides 46 | @Singleton 47 | public Context provideApplication() { 48 | return mContext; 49 | } 50 | 51 | @Singleton 52 | @Provides 53 | public SharedPreferences provideSharedPreferences() { 54 | return mContext.getSharedPreferences(PREFERENCES_NAME, 0); 55 | } 56 | 57 | @Provides 58 | @Singleton 59 | public CatalogItemStore provideCatalogItemStore(StoreArchiver archiver) { 60 | return archiver.read(); 61 | } 62 | 63 | @Provides 64 | @Singleton 65 | public ApplicationDataStore provideApplicationDataStore( 66 | @Named("worker") ExecutorService executorService, StoreArchiver archiver, 67 | CatalogItemStore catalogItemStore) { 68 | 69 | return new ApplicationDataStore(executorService, archiver, catalogItemStore); 70 | } 71 | 72 | @Provides 73 | @Named("worker") 74 | @Singleton 75 | public ExecutorService provideWorkerExecutorService( 76 | @Named("worker") ThreadFactory threadFactory) { 77 | 78 | return Executors.newFixedThreadPool(3, threadFactory); 79 | } 80 | 81 | @Provides 82 | @Named("worker") 83 | public ThreadFactory provideWorkerThreadFactory() { 84 | return new PriorityThreadFactory(Thread.MIN_PRIORITY); 85 | } 86 | 87 | @Provides 88 | @Singleton 89 | public ConnectivityManager provideConnectivityManager() { 90 | return (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE); 91 | } 92 | 93 | @Provides 94 | public Random provideRandom() { 95 | return new Random(); 96 | } 97 | 98 | @Provides 99 | @Singleton 100 | public EventBus provideEventBus() { 101 | HandlerThread ht = new HandlerThread("eventbus"); 102 | ht.setPriority(Thread.NORM_PRIORITY - 1); 103 | ht.start(); 104 | return new EventBus(ht.getLooper()); 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /shared/src/main/java/com/google/codelabs/migratingtojobs/shared/ApplicationDataStore.java: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Google, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | //////////////////////////////////////////////////////////////////////////////// 16 | 17 | package com.google.codelabs.migratingtojobs.shared; 18 | 19 | import java.util.concurrent.ExecutorService; 20 | import java.util.concurrent.atomic.AtomicInteger; 21 | 22 | import javax.inject.Inject; 23 | import javax.inject.Named; 24 | 25 | public class ApplicationDataStore extends BaseEventListener { 26 | private final ExecutorService mExecutor; 27 | 28 | private final Runnable mWriterRunnable; 29 | 30 | private final AtomicInteger mNumActivities = new AtomicInteger(0); 31 | 32 | @Inject 33 | public ApplicationDataStore(@Named("worker") ExecutorService executorService, 34 | StoreArchiver archiver, CatalogItemStore catalogItemStore) { 35 | 36 | mExecutor = executorService; 37 | mWriterRunnable = new WriterRunnable(archiver, catalogItemStore); 38 | } 39 | 40 | @Override 41 | public void onActivityCreated() { 42 | mNumActivities.incrementAndGet(); 43 | } 44 | 45 | @Override 46 | public void onActivityDestroyed() { 47 | if (mNumActivities.decrementAndGet() == 0) { 48 | mExecutor.submit(mWriterRunnable); 49 | } 50 | } 51 | 52 | private class WriterRunnable implements Runnable { 53 | private StoreArchiver mArchiver; 54 | private CatalogItemStore mCatalogItemStore; 55 | 56 | public WriterRunnable(StoreArchiver archiver, CatalogItemStore itemStore) { 57 | mArchiver = archiver; 58 | mCatalogItemStore = itemStore; 59 | } 60 | 61 | @Override 62 | public void run() { 63 | mArchiver.write(mCatalogItemStore); 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /shared/src/main/java/com/google/codelabs/migratingtojobs/shared/BaseEventListener.java: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Google, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | //////////////////////////////////////////////////////////////////////////////// 16 | 17 | package com.google.codelabs.migratingtojobs.shared; 18 | 19 | import android.os.Message; 20 | 21 | public class BaseEventListener implements EventBus.EventListener { 22 | @Override 23 | public void handle(Message msg) { 24 | } 25 | 26 | @Override 27 | public void onInit(CatalogItemStore itemStore) { 28 | } 29 | 30 | @Override 31 | public void onActivityCreated() { 32 | } 33 | 34 | @Override 35 | public void onActivityDestroyed() { 36 | } 37 | 38 | @Override 39 | public void onItemDownloadFailed(CatalogItem item) { 40 | } 41 | 42 | @Override 43 | public void onItemDownloadStarted(CatalogItem item) { 44 | } 45 | 46 | @Override 47 | public void onItemDownloadFinished(CatalogItem item) { 48 | } 49 | 50 | @Override 51 | public void onItemDownloadCancelled(CatalogItem item) { 52 | } 53 | 54 | @Override 55 | public void onItemDownloadInterrupted(CatalogItem item) { 56 | } 57 | 58 | @Override 59 | public void onItemDownloadIncrementProgress(CatalogItem item) { 60 | } 61 | 62 | @Override 63 | public void onItemDeleteLocalCopy(CatalogItem item) { 64 | } 65 | 66 | @Override 67 | public void onAllDownloadsFinished() { 68 | } 69 | 70 | @Override 71 | public void onRetryDownloads(CatalogItemStore itemStore) { 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /shared/src/main/java/com/google/codelabs/migratingtojobs/shared/Book.java: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Google, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | //////////////////////////////////////////////////////////////////////////////// 16 | 17 | package com.google.codelabs.migratingtojobs.shared; 18 | 19 | import com.google.codelabs.migratingtojobs.shared.nano.CatalogItemProtos; 20 | 21 | public class Book { 22 | private final CatalogItemProtos.Book mProto; 23 | 24 | public Book(String title, String author) { 25 | mProto = new CatalogItemProtos.Book(); 26 | mProto.title = title; 27 | mProto.author = author; 28 | } 29 | 30 | public Book(CatalogItemProtos.Book proto) { 31 | mProto = proto; 32 | } 33 | 34 | public CatalogItemProtos.Book getProto() { 35 | return mProto; 36 | } 37 | 38 | public String getTitle() { 39 | return mProto.title; 40 | } 41 | 42 | public String getAuthor() { 43 | return mProto.author; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /shared/src/main/java/com/google/codelabs/migratingtojobs/shared/CatalogItem.java: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Google, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | //////////////////////////////////////////////////////////////////////////////// 16 | 17 | package com.google.codelabs.migratingtojobs.shared; 18 | 19 | import android.databinding.Bindable; 20 | import android.databinding.BindingAdapter; 21 | import android.databinding.Observable; 22 | import android.databinding.PropertyChangeRegistry; 23 | import android.support.annotation.IntDef; 24 | import android.support.annotation.IntRange; 25 | import android.util.Log; 26 | import android.widget.ImageButton; 27 | 28 | import com.google.codelabs.migratingtojobs.shared.nano.CatalogItemProtos; 29 | 30 | import java.lang.annotation.Retention; 31 | import java.lang.annotation.RetentionPolicy; 32 | 33 | public class CatalogItem extends BaseEventListener implements Observable { 34 | public final static int AVAILABLE = CatalogItemProtos.CatalogItem.AVAILABLE; 35 | public final static int UNAVAILABLE = CatalogItemProtos.CatalogItem.UNAVAILABLE; 36 | public final static int DOWNLOADING = CatalogItemProtos.CatalogItem.DOWNLOADING; 37 | public final static int ERROR = CatalogItemProtos.CatalogItem.ERROR; 38 | /** 39 | * The size, in download "ticks", of this item. 40 | * 41 | * @see Downloader#MAX_MILLIS_PER_TICK 42 | */ 43 | public final static int TOTAL_NUM_CHUNKS = 300; 44 | private static final String TAG = "CatalogItem"; 45 | private final static String[] STATUS_STRINGS = 46 | {"UNKNOWN", "AVAILABLE", "UNAVAILABLE", "DOWNLOADING", "ERROR"}; 47 | private final PropertyChangeRegistry mPropertyChangeRegistry = new PropertyChangeRegistry(); 48 | private final CatalogItemProtos.CatalogItem mProto; 49 | private final Book mBook; 50 | 51 | public CatalogItem(Book book) { 52 | this(book, 0, UNAVAILABLE); 53 | } 54 | 55 | public CatalogItem(Book book, @IntRange(from = 0, to = TOTAL_NUM_CHUNKS) int progress, 56 | @ItemStatus int status) { 57 | mBook = book; 58 | 59 | mProto = new CatalogItemProtos.CatalogItem(); 60 | mProto.downloadProgress = progress; 61 | mProto.status = status; 62 | mProto.book = book.getProto(); 63 | } 64 | 65 | public CatalogItem(CatalogItemProtos.CatalogItem proto) { 66 | mProto = proto; 67 | mBook = new Book(mProto.book); 68 | } 69 | 70 | @BindingAdapter("catalogIconSource") 71 | public static void setCatalogIconSource(ImageButton button, int status) { 72 | switch (status) { 73 | case AVAILABLE: 74 | button.setImageResource(R.drawable.ic_delete); 75 | break; 76 | 77 | case UNAVAILABLE: 78 | button.setImageResource(R.drawable.ic_download); 79 | break; 80 | 81 | case DOWNLOADING: 82 | button.setImageResource(R.drawable.ic_cancel); 83 | break; 84 | 85 | case ERROR: 86 | button.setImageResource(R.drawable.ic_error); 87 | break; 88 | 89 | default: 90 | button.setImageResource(android.R.drawable.ic_dialog_alert); 91 | break; 92 | } 93 | } 94 | 95 | public CatalogItemProtos.CatalogItem getProto() { 96 | return mProto; 97 | } 98 | 99 | @Override 100 | public void addOnPropertyChangedCallback(OnPropertyChangedCallback onPropertyChangedCallback) { 101 | mPropertyChangeRegistry.add(onPropertyChangedCallback); 102 | } 103 | 104 | @Override 105 | public void removeOnPropertyChangedCallback(OnPropertyChangedCallback onPropertyChangedCallback) { 106 | mPropertyChangeRegistry.remove(onPropertyChangedCallback); 107 | } 108 | 109 | @Bindable 110 | public int getDownloadProgress() { 111 | return mProto.downloadProgress; 112 | } 113 | 114 | private void setDownloadProgress(int progress) { 115 | mProto.downloadProgress = progress; 116 | mPropertyChangeRegistry.notifyChange(this, BR.downloadProgress); 117 | } 118 | 119 | @Bindable 120 | public Book getBook() { 121 | return mBook; 122 | } 123 | 124 | @Bindable 125 | public int getStatus() { 126 | return mProto.status; 127 | } 128 | 129 | private synchronized void setStatus(int newStatus) { 130 | int oldStatus = mProto.status; 131 | if ((oldStatus == AVAILABLE && newStatus == UNAVAILABLE) 132 | || (oldStatus == DOWNLOADING && newStatus == ERROR) 133 | || (oldStatus == DOWNLOADING && newStatus == AVAILABLE) 134 | || (oldStatus == DOWNLOADING && newStatus == UNAVAILABLE) 135 | || (oldStatus == ERROR && newStatus == DOWNLOADING) 136 | || (oldStatus == UNAVAILABLE && newStatus == DOWNLOADING) 137 | ) { 138 | 139 | Log.v(TAG, 140 | "transitioning from state " + STATUS_STRINGS[oldStatus] 141 | + " to " + STATUS_STRINGS[newStatus]); 142 | mProto.status = newStatus; 143 | 144 | mPropertyChangeRegistry.notifyChange(this, BR.status); 145 | } 146 | } 147 | 148 | public boolean isDownloading() { 149 | return mProto.status == DOWNLOADING; 150 | } 151 | 152 | public boolean isAvailable() { 153 | return mProto.status == AVAILABLE; 154 | } 155 | 156 | public boolean isErroring() { 157 | return mProto.status == ERROR; 158 | } 159 | 160 | @Override 161 | public void onItemDownloadIncrementProgress(CatalogItem item) { 162 | if (item == this) { 163 | setDownloadProgress(mProto.downloadProgress + 1); 164 | if (mProto.downloadProgress >= TOTAL_NUM_CHUNKS) { 165 | setStatus(AVAILABLE); 166 | } 167 | } 168 | } 169 | 170 | @Override 171 | public void onItemDownloadInterrupted(CatalogItem item) { 172 | onItemDeleteLocalCopy(item); 173 | } 174 | 175 | @Override 176 | public void onItemDownloadCancelled(CatalogItem item) { 177 | onItemDeleteLocalCopy(item); 178 | } 179 | 180 | @Override 181 | public void onItemDeleteLocalCopy(CatalogItem item) { 182 | if (item == this) { 183 | setStatus(UNAVAILABLE); 184 | setDownloadProgress(0); 185 | } 186 | } 187 | 188 | @Override 189 | public void onItemDownloadFinished(CatalogItem item) { 190 | if (item == this) { 191 | item.setStatus(AVAILABLE); 192 | } 193 | } 194 | 195 | @Override 196 | public void onItemDownloadStarted(CatalogItem item) { 197 | if (item == this) { 198 | item.setStatus(DOWNLOADING); 199 | } 200 | } 201 | 202 | @Override 203 | public void onItemDownloadFailed(CatalogItem item) { 204 | if (item == this) { 205 | item.setStatus(ERROR); 206 | } 207 | } 208 | 209 | @IntDef({AVAILABLE, UNAVAILABLE, DOWNLOADING, ERROR}) 210 | @Retention(RetentionPolicy.SOURCE) 211 | @interface ItemStatus { 212 | } 213 | } 214 | -------------------------------------------------------------------------------- /shared/src/main/java/com/google/codelabs/migratingtojobs/shared/CatalogItemStore.java: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Google, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | //////////////////////////////////////////////////////////////////////////////// 16 | 17 | package com.google.codelabs.migratingtojobs.shared; 18 | 19 | import android.databinding.Observable; 20 | import android.support.annotation.NonNull; 21 | 22 | import com.google.codelabs.migratingtojobs.shared.nano.CatalogItemProtos; 23 | import com.google.protobuf.nano.MessageNano; 24 | 25 | import java.util.LinkedList; 26 | import java.util.List; 27 | 28 | public class CatalogItemStore { 29 | private final List mChangeListeners = new LinkedList<>(); 30 | private final Observable.OnPropertyChangedCallback mPropertyChangedCallback = 31 | new Observable.OnPropertyChangedCallback() { 32 | @Override 33 | public void onPropertyChanged(Observable observable, int i) { 34 | notifyItemDidChange(observable); 35 | } 36 | }; 37 | private final CatalogItemProtos.CatalogItemStore mProto; 38 | private final CatalogItem[] mItems; 39 | private Predicate mPredicateIsDownloading = new Predicate() { 40 | @Override 41 | public boolean apply(CatalogItem item) { 42 | return item.isErroring() || item.isDownloading(); 43 | } 44 | }; 45 | 46 | public CatalogItemStore(@NonNull CatalogItem[] items) { 47 | mProto = new CatalogItemProtos.CatalogItemStore(); 48 | mItems = items; 49 | 50 | mProto.items = new CatalogItemProtos.CatalogItem[mItems.length]; 51 | for (int i = 0; i < mItems.length; i++) { 52 | mProto.items[i] = mItems[i].getProto(); 53 | mItems[i].addOnPropertyChangedCallback(mPropertyChangedCallback); 54 | } 55 | } 56 | 57 | public CatalogItemStore(@NonNull CatalogItemProtos.CatalogItemStore protoStore) { 58 | mProto = protoStore; 59 | 60 | mItems = new CatalogItem[mProto.items.length]; 61 | for (int i = 0; i < mProto.items.length; i++) { 62 | mItems[i] = new CatalogItem(mProto.items[i]); 63 | mItems[i].addOnPropertyChangedCallback(mPropertyChangedCallback); 64 | } 65 | } 66 | 67 | public void addChangeListener(ChangeListener changeListener) { 68 | mChangeListeners.add(changeListener); 69 | } 70 | 71 | public void removeChangeListener(ChangeListener changeListener) { 72 | mChangeListeners.remove(changeListener); 73 | } 74 | 75 | private void notifyItemDidChange(Observable observable) { 76 | for (ChangeListener listener : mChangeListeners) { 77 | listener.onStoreDidChange(); 78 | } 79 | } 80 | 81 | public CatalogItem get(int position) { 82 | return mItems[position]; 83 | } 84 | 85 | public int size() { 86 | return mItems.length; 87 | } 88 | 89 | @NonNull 90 | public List getDownloadQueue() { 91 | return filter(mPredicateIsDownloading); 92 | } 93 | 94 | public byte[] toProtoBytes() { 95 | return MessageNano.toByteArray(mProto); 96 | } 97 | 98 | private List filter(Predicate predicate) { 99 | List newList = new LinkedList<>(); 100 | for (CatalogItem item : mItems) { 101 | if (predicate.apply(item)) { 102 | newList.add(item); 103 | } 104 | } 105 | 106 | return newList; 107 | } 108 | 109 | interface ChangeListener { 110 | void onStoreDidChange(); 111 | } 112 | 113 | private interface Predicate { 114 | boolean apply(T item); 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /shared/src/main/java/com/google/codelabs/migratingtojobs/shared/CatalogListActivity.java: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Google, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | //////////////////////////////////////////////////////////////////////////////// 16 | 17 | package com.google.codelabs.migratingtojobs.shared; 18 | 19 | import android.os.Bundle; 20 | import android.support.v7.app.AppCompatActivity; 21 | import android.support.v7.widget.LinearLayoutManager; 22 | import android.support.v7.widget.RecyclerView; 23 | import android.support.v7.widget.Toolbar; 24 | import android.view.GestureDetector; 25 | import android.view.MotionEvent; 26 | import android.view.View; 27 | 28 | import javax.inject.Inject; 29 | 30 | public abstract class CatalogListActivity extends AppCompatActivity { 31 | @Inject 32 | CatalogRecyclerAdaptor mAdaptor; 33 | 34 | @Inject 35 | EventBus mBus; 36 | 37 | /* @BindView(R.id.catalog_list) */ RecyclerView mCatalogList; 38 | 39 | protected void inject() { 40 | DaggerRootComponent.builder() 41 | .appModule(new AppModule(getApplication())) 42 | .build() 43 | .inject(this); 44 | } 45 | 46 | @Override 47 | protected void onCreate(Bundle savedInstanceState) { 48 | super.onCreate(savedInstanceState); 49 | 50 | setContentView(R.layout.activity_catalog_list); 51 | setSupportActionBar((Toolbar) findViewById(R.id.toolbar)); 52 | 53 | inject(); 54 | 55 | mBus.postActivityCreated(); 56 | 57 | mCatalogList = (RecyclerView) findViewById(R.id.catalog_list); 58 | mCatalogList.setLayoutManager(new LinearLayoutManager(this)); 59 | mCatalogList.setAdapter(mAdaptor); 60 | mCatalogList.addOnItemTouchListener(new OnCatalogItemTouchListener()); 61 | } 62 | 63 | @Override 64 | protected void onDestroy() { 65 | mBus.postActivityDestroyed(); 66 | 67 | super.onDestroy(); 68 | } 69 | 70 | private class OnCatalogItemTouchListener implements RecyclerView.OnItemTouchListener { 71 | private final GestureDetector mGestureDetector; 72 | 73 | public OnCatalogItemTouchListener() { 74 | mGestureDetector = new GestureDetector(getBaseContext(), new GestureDetector.SimpleOnGestureListener() { 75 | @Override 76 | public boolean onSingleTapUp(MotionEvent me) { 77 | return true; 78 | } 79 | }); 80 | } 81 | 82 | @Override 83 | public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) { 84 | View target = rv.findChildViewUnder(e.getX(), e.getY()); 85 | if (target != null && mGestureDetector.onTouchEvent(e)) { 86 | CatalogItem item = mAdaptor.getStore().get(rv.getChildAdapterPosition(target)); 87 | 88 | if (item.isAvailable()) { 89 | mBus.postItemDeleteLocalCopy(item); 90 | } else if (item.isDownloading()) { 91 | mBus.postItemDownloadCancelled(item); 92 | } else { 93 | mBus.postItemDownloadStarted(item); 94 | } 95 | 96 | return true; 97 | } 98 | 99 | return false; 100 | } 101 | 102 | @Override 103 | public void onTouchEvent(RecyclerView rv, MotionEvent e) { 104 | } 105 | 106 | @Override 107 | public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) { 108 | } 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /shared/src/main/java/com/google/codelabs/migratingtojobs/shared/CatalogRecyclerAdaptor.java: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Google, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | //////////////////////////////////////////////////////////////////////////////// 16 | 17 | package com.google.codelabs.migratingtojobs.shared; 18 | 19 | import android.databinding.DataBindingUtil; 20 | import android.databinding.ViewDataBinding; 21 | import android.support.annotation.NonNull; 22 | import android.support.v7.widget.RecyclerView; 23 | import android.view.LayoutInflater; 24 | import android.view.View; 25 | import android.view.ViewGroup; 26 | 27 | import javax.inject.Inject; 28 | 29 | public class CatalogRecyclerAdaptor extends RecyclerView.Adapter { 30 | private final CatalogItemStore mStore; 31 | 32 | @Inject 33 | public CatalogRecyclerAdaptor(@NonNull CatalogItemStore items) { 34 | mStore = items; 35 | } 36 | 37 | public CatalogItemStore getStore() { 38 | return mStore; 39 | } 40 | 41 | @Override 42 | public Holder onCreateViewHolder(ViewGroup parent, int viewType) { 43 | View v = LayoutInflater 44 | .from(parent.getContext()) 45 | .inflate(R.layout.content_catalog_item, parent, false); 46 | 47 | return new Holder(v); 48 | } 49 | 50 | @Override 51 | public void onBindViewHolder(Holder holder, int position) { 52 | CatalogItem item = mStore.get(position); 53 | holder.getBinding().setVariable(BR.item, item); 54 | 55 | // trigger queued bindings early (as opposed to next animation frame) 56 | holder.getBinding().executePendingBindings(); 57 | } 58 | 59 | @Override 60 | public int getItemCount() { 61 | return mStore.size(); 62 | } 63 | 64 | public class Holder extends RecyclerView.ViewHolder { 65 | private final ViewDataBinding mBinding; 66 | 67 | public Holder(View v) { 68 | super(v); 69 | 70 | mBinding = DataBindingUtil.bind(v); 71 | } 72 | 73 | public ViewDataBinding getBinding() { 74 | return mBinding; 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /shared/src/main/java/com/google/codelabs/migratingtojobs/shared/Downloader.java: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Google, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | //////////////////////////////////////////////////////////////////////////////// 16 | 17 | package com.google.codelabs.migratingtojobs.shared; 18 | 19 | import android.net.ConnectivityManager; 20 | import android.support.v4.util.SimpleArrayMap; 21 | import android.util.Log; 22 | 23 | import java.util.Locale; 24 | import java.util.Random; 25 | import java.util.concurrent.ExecutorService; 26 | import java.util.concurrent.Future; 27 | 28 | import javax.inject.Inject; 29 | import javax.inject.Named; 30 | 31 | /** 32 | * Downloader is responsible for simulating download requests. No actual HTTP requests are made. 33 | */ 34 | public class Downloader { 35 | public static final int SUCCESS = 0; 36 | public static final int ERROR = 1; 37 | 38 | public static final String TAG = "Downloader"; 39 | 40 | /** 41 | * @see CatalogItem#TOTAL_NUM_CHUNKS 42 | */ 43 | private static final int MAX_MILLIS_PER_TICK = 28; 44 | public final EventBus.EventListener eventListener = new DownloaderEventListener(); 45 | private final ExecutorService mExecutorService; 46 | private final ConnectivityManager mConnManager; 47 | private final Random mRandom; 48 | private final EventBus mBus; 49 | private final SimpleArrayMap> mMap = new SimpleArrayMap<>(); 50 | 51 | @Inject 52 | public Downloader(@Named("worker") ExecutorService executorService, 53 | ConnectivityManager connManager, Random random, EventBus eventBus) { 54 | mExecutorService = executorService; 55 | mConnManager = connManager; 56 | mRandom = random; 57 | mBus = eventBus; 58 | } 59 | 60 | /** 61 | * Start downloading the provided CatalogItem. 62 | */ 63 | private Future start(final CatalogItem item) { 64 | synchronized (mMap) { 65 | Future future = mMap.get(item); 66 | if (future != null) { 67 | Log.v(TAG, "found pending future for " + item.getBook().getTitle()); 68 | return future; 69 | } 70 | 71 | future = mExecutorService.submit(new DownloadRunner(item, mBus, mRandom, mConnManager)); 72 | mMap.put(item, future); 73 | return future; 74 | } 75 | } 76 | 77 | /** 78 | * Stop downloading the provided CatalogItem. 79 | */ 80 | private void stop(final CatalogItem item) { 81 | synchronized (mMap) { 82 | Future future = mMap.remove(item); 83 | if (future != null) { 84 | future.cancel(true); 85 | } 86 | } 87 | } 88 | 89 | private static class DownloadRunner implements Runnable { 90 | private final CatalogItem item; 91 | private final EventBus bus; 92 | private final Random random; 93 | private final ConnectivityManager connectivityManager; 94 | 95 | public DownloadRunner(CatalogItem item, EventBus bus, Random random, 96 | ConnectivityManager connectivityManager) { 97 | this.item = item; 98 | this.bus = bus; 99 | this.random = random; 100 | this.connectivityManager = connectivityManager; 101 | } 102 | 103 | public int attemptDownload() throws InterruptedException { 104 | while (!item.isAvailable()) { 105 | if (!Util.isNetworkActive(connectivityManager)) { 106 | // simulate an error if the network is down 107 | return ERROR; 108 | } 109 | 110 | Thread.sleep(random.nextInt(MAX_MILLIS_PER_TICK)); 111 | bus.postItemDownloadIncrementProgress(item); 112 | } 113 | 114 | return SUCCESS; 115 | } 116 | 117 | public void run() { 118 | Log.i(TAG, String.format(Locale.US, "starting to download \"%s\"", 119 | item.getBook().getTitle())); 120 | 121 | try { 122 | if (attemptDownload() == ERROR) { 123 | bus.postItemDownloadFailed(item); 124 | } else { 125 | bus.postItemDownloadFinished(item); 126 | } 127 | } catch (InterruptedException e) { 128 | bus.postItemDownloadInterrupted(item); 129 | } 130 | } 131 | } 132 | 133 | private class DownloaderEventListener extends BaseEventListener { 134 | @Override 135 | public void onItemDownloadStarted(CatalogItem item) { 136 | Log.v(TAG, "starting to download " + item.getBook().getTitle()); 137 | start(item); 138 | } 139 | 140 | @Override 141 | public void onItemDownloadCancelled(CatalogItem item) { 142 | stop(item); 143 | } 144 | 145 | @Override 146 | public void onItemDownloadFailed(CatalogItem item) { 147 | synchronized (mMap) { 148 | mMap.remove(item); 149 | } 150 | } 151 | 152 | @Override 153 | public void onItemDownloadFinished(CatalogItem item) { 154 | synchronized (mMap) { 155 | mMap.remove(item); 156 | 157 | if (mMap.size() == 0) { 158 | mBus.postAllDownloadsFinished(); 159 | } 160 | } 161 | } 162 | 163 | @Override 164 | public void onRetryDownloads(CatalogItemStore store) { 165 | Log.v(TAG, "retrying downloads"); 166 | 167 | for (CatalogItem item : store.getDownloadQueue()) { 168 | Log.v(TAG, "posting start for " + item.getBook().getTitle()); 169 | mBus.postItemDownloadStarted(item); 170 | } 171 | } 172 | } 173 | } 174 | -------------------------------------------------------------------------------- /shared/src/main/java/com/google/codelabs/migratingtojobs/shared/ErrorLoggingDownloadCallback.java: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Google, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | //////////////////////////////////////////////////////////////////////////////// 16 | 17 | package com.google.codelabs.migratingtojobs.shared; 18 | 19 | import android.util.Log; 20 | 21 | import java.util.Locale; 22 | 23 | public class ErrorLoggingDownloadCallback extends BaseEventListener { 24 | private static final String TAG = Downloader.TAG; 25 | 26 | @Override 27 | public void onItemDownloadFailed(CatalogItem item) { 28 | Log.i(TAG, String.format(Locale.US, 29 | "Encountered error downloading %s", item.getBook().getTitle())); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /shared/src/main/java/com/google/codelabs/migratingtojobs/shared/EventBus.java: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Google, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | //////////////////////////////////////////////////////////////////////////////// 16 | 17 | package com.google.codelabs.migratingtojobs.shared; 18 | 19 | import android.os.Handler; 20 | import android.os.Looper; 21 | import android.os.Message; 22 | import android.support.annotation.NonNull; 23 | import android.util.Log; 24 | 25 | import java.util.LinkedList; 26 | import java.util.List; 27 | 28 | public class EventBus { 29 | private static final int INIT = 1; 30 | private static final int ACTIVITY_CREATED = 2; 31 | private static final int ACTIVITY_DESTROYED = 3; 32 | private static final int ITEM_DOWNLOAD_FAILED = 4; 33 | private static final int ITEM_DOWNLOAD_STARTED = 5; 34 | private static final int ITEM_DOWNLOAD_FINISHED = 6; 35 | private static final int ITEM_DOWNLOAD_CANCELLED = 7; 36 | private static final int ITEM_DOWNLOAD_INTERRUPTED = 8; 37 | private static final int ITEM_DOWNLOAD_INCREMENT_PROGRESS = 9; 38 | private static final int ITEM_DELETE_LOCAL_COPY = 10; 39 | private static final int REGISTER = 11; 40 | private static final int UNREGISTER = 12; 41 | private static final int ALL_DOWNLOADS_FINISHED = 13; 42 | private static final int RETRY_DOWNLOADS = 14; 43 | public static final int FIRST_UNUSED = 15; 44 | 45 | private final EventBusHandler handler; 46 | 47 | public EventBus(Looper looper) { 48 | handler = getEventBusHandler(looper); 49 | } 50 | 51 | @NonNull 52 | protected EventBusHandler getEventBusHandler(Looper looper) { 53 | return new EventBusHandler(looper); 54 | } 55 | 56 | public void send(int what) { 57 | handler.sendEmptyMessage(what); 58 | } 59 | 60 | public void send(int what, Object arg) { 61 | handler.obtainMessage(what, arg).sendToTarget(); 62 | } 63 | 64 | public void register(EventListener eventListener) { 65 | send(REGISTER, eventListener); 66 | } 67 | 68 | public void unregister(EventListener eventListener) { 69 | send(UNREGISTER, eventListener); 70 | } 71 | 72 | public void postInit(CatalogItemStore store) { 73 | send(INIT, store); 74 | } 75 | 76 | public void postActivityCreated() { 77 | send(ACTIVITY_CREATED); 78 | } 79 | 80 | public void postActivityDestroyed() { 81 | send(ACTIVITY_DESTROYED); 82 | } 83 | 84 | public void postItemDownloadFailed(CatalogItem item) { 85 | send(ITEM_DOWNLOAD_FAILED, item); 86 | } 87 | 88 | public void postItemDownloadStarted(CatalogItem item) { 89 | send(ITEM_DOWNLOAD_STARTED, item); 90 | } 91 | 92 | public void postItemDownloadFinished(CatalogItem item) { 93 | send(ITEM_DOWNLOAD_FINISHED, item); 94 | } 95 | 96 | public void postItemDownloadCancelled(CatalogItem item) { 97 | send(ITEM_DOWNLOAD_CANCELLED, item); 98 | } 99 | 100 | public void postItemDownloadInterrupted(CatalogItem item) { 101 | send(ITEM_DOWNLOAD_INTERRUPTED, item); 102 | } 103 | 104 | public void postItemDownloadIncrementProgress(CatalogItem item) { 105 | send(ITEM_DOWNLOAD_INCREMENT_PROGRESS, item); 106 | } 107 | 108 | public void postRetryDownloads(CatalogItemStore itemStore) { 109 | send(RETRY_DOWNLOADS, itemStore); 110 | } 111 | 112 | public void postAllDownloadsFinished() { 113 | send(ALL_DOWNLOADS_FINISHED); 114 | } 115 | 116 | public void postItemDeleteLocalCopy(CatalogItem item) { 117 | send(ITEM_DELETE_LOCAL_COPY, item); 118 | } 119 | 120 | public interface EventListener { 121 | void handle(Message msg); 122 | 123 | void onInit(CatalogItemStore itemStore); 124 | 125 | void onActivityCreated(); 126 | 127 | void onActivityDestroyed(); 128 | 129 | void onItemDownloadFailed(CatalogItem item); 130 | 131 | void onItemDownloadStarted(CatalogItem item); 132 | 133 | void onItemDownloadFinished(CatalogItem item); 134 | 135 | void onItemDownloadCancelled(CatalogItem item); 136 | 137 | void onItemDownloadInterrupted(CatalogItem item); 138 | 139 | void onItemDownloadIncrementProgress(CatalogItem item); 140 | 141 | void onItemDeleteLocalCopy(CatalogItem item); 142 | 143 | void onAllDownloadsFinished(); 144 | 145 | void onRetryDownloads(CatalogItemStore itemStore); 146 | } 147 | 148 | public static class MultiplexingEventListener implements EventListener { 149 | protected final List listeners = new LinkedList<>(); 150 | 151 | void register(EventListener listener) { 152 | synchronized (listeners) { 153 | listeners.add(listener); 154 | } 155 | } 156 | 157 | void unregister(EventListener listener) { 158 | synchronized (listeners) { 159 | listeners.remove(listener); 160 | } 161 | } 162 | 163 | @Override 164 | public void handle(Message msg) { 165 | synchronized (listeners) { 166 | for (EventListener listener : listeners) { 167 | listener.handle(msg); 168 | } 169 | } 170 | } 171 | 172 | @Override 173 | public void onInit(CatalogItemStore itemStore) { 174 | synchronized (listeners) { 175 | for (EventListener listener : listeners) { 176 | listener.onInit(itemStore); 177 | } 178 | } 179 | } 180 | 181 | @Override 182 | public void onActivityCreated() { 183 | synchronized (listeners) { 184 | for (EventListener listener : listeners) { 185 | listener.onActivityCreated(); 186 | } 187 | } 188 | } 189 | 190 | @Override 191 | public void onActivityDestroyed() { 192 | synchronized (listeners) { 193 | for (EventListener listener : listeners) { 194 | listener.onActivityDestroyed(); 195 | } 196 | } 197 | } 198 | 199 | @Override 200 | public void onItemDownloadFailed(CatalogItem item) { 201 | synchronized (listeners) { 202 | for (EventListener listener : listeners) { 203 | listener.onItemDownloadFailed(item); 204 | } 205 | } 206 | } 207 | 208 | @Override 209 | public void onItemDownloadStarted(CatalogItem item) { 210 | synchronized (listeners) { 211 | for (EventListener listener : listeners) { 212 | listener.onItemDownloadStarted(item); 213 | } 214 | } 215 | } 216 | 217 | @Override 218 | public void onItemDownloadFinished(CatalogItem item) { 219 | synchronized (listeners) { 220 | for (EventListener listener : listeners) { 221 | listener.onItemDownloadFinished(item); 222 | } 223 | } 224 | } 225 | 226 | @Override 227 | public void onItemDownloadCancelled(CatalogItem item) { 228 | synchronized (listeners) { 229 | for (EventListener listener : listeners) { 230 | listener.onItemDownloadCancelled(item); 231 | } 232 | } 233 | } 234 | 235 | @Override 236 | public void onItemDownloadInterrupted(CatalogItem item) { 237 | synchronized (listeners) { 238 | for (EventListener listener : listeners) { 239 | listener.onItemDownloadInterrupted(item); 240 | } 241 | } 242 | } 243 | 244 | @Override 245 | public void onItemDownloadIncrementProgress(CatalogItem item) { 246 | synchronized (listeners) { 247 | for (EventListener listener : listeners) { 248 | listener.onItemDownloadIncrementProgress(item); 249 | } 250 | } 251 | } 252 | 253 | @Override 254 | public void onItemDeleteLocalCopy(CatalogItem item) { 255 | synchronized (listeners) { 256 | for (EventListener listener : listeners) { 257 | listener.onItemDeleteLocalCopy(item); 258 | } 259 | } 260 | } 261 | 262 | @Override 263 | public void onAllDownloadsFinished() { 264 | synchronized (listeners) { 265 | for (EventListener listener : listeners) { 266 | listener.onAllDownloadsFinished(); 267 | } 268 | } 269 | } 270 | 271 | @Override 272 | public void onRetryDownloads(CatalogItemStore itemStore) { 273 | synchronized (listeners) { 274 | for (EventListener listener : listeners) { 275 | listener.onRetryDownloads(itemStore); 276 | } 277 | } 278 | } 279 | } 280 | 281 | protected static class EventBusHandler extends Handler { 282 | protected final MultiplexingEventListener listener; 283 | 284 | public EventBusHandler(Looper looper) { 285 | super(looper); 286 | 287 | listener = getMultiplexingEventListener(); 288 | } 289 | 290 | @NonNull 291 | protected MultiplexingEventListener getMultiplexingEventListener() { 292 | return new MultiplexingEventListener(); 293 | } 294 | 295 | private void logHandleMessage(String what) { 296 | Log.v("EventBus", "received " + what); 297 | } 298 | 299 | @Override 300 | public void handleMessage(Message msg) { 301 | switch (msg.what) { 302 | case INIT: 303 | logHandleMessage("INIT"); 304 | listener.onInit((CatalogItemStore) msg.obj); 305 | break; 306 | 307 | case ACTIVITY_CREATED: 308 | logHandleMessage("ACTIVITY_CREATED"); 309 | listener.onActivityCreated(); 310 | break; 311 | 312 | case ACTIVITY_DESTROYED: 313 | logHandleMessage("ACTIVITY_DESTROYED"); 314 | listener.onActivityDestroyed(); 315 | break; 316 | 317 | case ITEM_DOWNLOAD_FAILED: 318 | logHandleMessage("ITEM_DOWNLOAD_FAILED"); 319 | listener.onItemDownloadFailed((CatalogItem) msg.obj); 320 | break; 321 | 322 | case ITEM_DOWNLOAD_STARTED: 323 | logHandleMessage("ITEM_DOWNLOAD_STARTED"); 324 | listener.onItemDownloadStarted((CatalogItem) msg.obj); 325 | break; 326 | 327 | case ITEM_DOWNLOAD_FINISHED: 328 | logHandleMessage("ITEM_DOWNLOAD_FINISHED"); 329 | listener.onItemDownloadFinished((CatalogItem) msg.obj); 330 | break; 331 | 332 | case ITEM_DOWNLOAD_CANCELLED: 333 | logHandleMessage("ITEM_DOWNLOAD_CANCELLED"); 334 | listener.onItemDownloadCancelled((CatalogItem) msg.obj); 335 | break; 336 | 337 | case ITEM_DOWNLOAD_INTERRUPTED: 338 | logHandleMessage("ITEM_DOWNLOAD_INTERRUPTED"); 339 | listener.onItemDownloadInterrupted((CatalogItem) msg.obj); 340 | break; 341 | 342 | case ITEM_DOWNLOAD_INCREMENT_PROGRESS: 343 | // Don't log, too spammy 344 | listener.onItemDownloadIncrementProgress((CatalogItem) msg.obj); 345 | break; 346 | 347 | case ITEM_DELETE_LOCAL_COPY: 348 | logHandleMessage("ITEM_DELETE_LOCAL_COPY"); 349 | listener.onItemDeleteLocalCopy((CatalogItem) msg.obj); 350 | break; 351 | 352 | case REGISTER: 353 | logHandleMessage("REGISTER"); 354 | listener.register((EventListener) msg.obj); 355 | break; 356 | 357 | case ALL_DOWNLOADS_FINISHED: 358 | logHandleMessage("ALL_DOWNLOADS_FINISHED"); 359 | listener.onAllDownloadsFinished(); 360 | break; 361 | 362 | case UNREGISTER: 363 | logHandleMessage("UNREGISTER"); 364 | listener.unregister((EventListener) msg.obj); 365 | break; 366 | 367 | case RETRY_DOWNLOADS: 368 | logHandleMessage("RETRY_DOWNLOADS"); 369 | listener.onRetryDownloads((CatalogItemStore) msg.obj); 370 | break; 371 | 372 | default: 373 | listener.handle(msg); 374 | break; 375 | } 376 | } 377 | } 378 | } 379 | -------------------------------------------------------------------------------- /shared/src/main/java/com/google/codelabs/migratingtojobs/shared/PriorityThreadFactory.java: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Google, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | //////////////////////////////////////////////////////////////////////////////// 16 | 17 | package com.google.codelabs.migratingtojobs.shared; 18 | 19 | import java.util.concurrent.ThreadFactory; 20 | 21 | public class PriorityThreadFactory implements ThreadFactory { 22 | private final int mPriority; 23 | 24 | public PriorityThreadFactory(int priority) { 25 | mPriority = priority; 26 | } 27 | 28 | @Override 29 | public Thread newThread(Runnable r) { 30 | Thread t = new Thread(r); 31 | t.setPriority(mPriority); 32 | return t; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /shared/src/main/java/com/google/codelabs/migratingtojobs/shared/RootComponent.java: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Google, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | //////////////////////////////////////////////////////////////////////////////// 16 | 17 | package com.google.codelabs.migratingtojobs.shared; 18 | 19 | import javax.inject.Singleton; 20 | 21 | import dagger.Component; 22 | 23 | @Singleton 24 | @Component(modules = {AppModule.class}) 25 | public interface RootComponent { 26 | void inject(SharedInitializer baseGlobalState); 27 | 28 | void inject(CatalogListActivity activity); 29 | } 30 | -------------------------------------------------------------------------------- /shared/src/main/java/com/google/codelabs/migratingtojobs/shared/SharedInitializer.java: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Google, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | //////////////////////////////////////////////////////////////////////////////// 16 | 17 | package com.google.codelabs.migratingtojobs.shared; 18 | 19 | import javax.inject.Inject; 20 | 21 | public class SharedInitializer { 22 | protected final EventBus bus; 23 | protected final CatalogItemStore itemStore; 24 | protected final Downloader downloader; 25 | protected final ApplicationDataStore appDataStore; 26 | 27 | @Inject 28 | SharedInitializer(EventBus bus, CatalogItemStore itemStore, Downloader downloader, 29 | ApplicationDataStore appDataStore) { 30 | this.bus = bus; 31 | this.itemStore = itemStore; 32 | this.downloader = downloader; 33 | this.appDataStore = appDataStore; 34 | } 35 | 36 | public void init() { 37 | bus.register(appDataStore); 38 | bus.register(downloader.eventListener); 39 | 40 | for (int i = 0; i < itemStore.size(); i++) { 41 | bus.register(itemStore.get(i)); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /shared/src/main/java/com/google/codelabs/migratingtojobs/shared/StoreArchiver.java: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Google, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | //////////////////////////////////////////////////////////////////////////////// 16 | 17 | package com.google.codelabs.migratingtojobs.shared; 18 | 19 | import android.content.SharedPreferences; 20 | import android.support.annotation.WorkerThread; 21 | import android.util.Base64; 22 | import android.util.Log; 23 | 24 | import com.google.codelabs.migratingtojobs.shared.nano.CatalogItemProtos; 25 | import com.google.protobuf.nano.InvalidProtocolBufferNanoException; 26 | 27 | import javax.inject.Inject; 28 | 29 | public final class StoreArchiver { 30 | private static final String STORE_KEY = "key"; 31 | private static final String TAG = "AppModule"; 32 | 33 | private final static CatalogItem[] DEFAULT_BOOKS = { 34 | new CatalogItem( 35 | new Book("Les Trois Mousquetaires", "Alexandre Dumas"), 36 | 100, 37 | CatalogItem.AVAILABLE 38 | ), 39 | new CatalogItem( 40 | new Book("Treasure Island", "Robert Louis Stevenson"), 41 | 100, 42 | CatalogItem.AVAILABLE 43 | ), 44 | new CatalogItem( 45 | new Book("Don Quixote", "Miguel de Cervantes Saavedra"), 46 | 0, 47 | CatalogItem.UNAVAILABLE 48 | ), 49 | new CatalogItem( 50 | new Book("The Dunwich Horror", "H. P. Lovecraft"), 51 | 0, 52 | CatalogItem.UNAVAILABLE 53 | ), 54 | new CatalogItem( 55 | new Book("Ulysses", "James Joyce"), 56 | 0, 57 | CatalogItem.UNAVAILABLE 58 | )}; 59 | 60 | private final SharedPreferences mSharedPreferences; 61 | 62 | @Inject 63 | public StoreArchiver(SharedPreferences sharedPreferences) { 64 | mSharedPreferences = sharedPreferences; 65 | } 66 | 67 | @WorkerThread 68 | public CatalogItemStore read() { 69 | String storeValue = mSharedPreferences.getString(STORE_KEY, ""); 70 | if ("".equals(storeValue)) { 71 | Log.e(TAG, "No saved value in SharedPrefs, using default books"); 72 | return new CatalogItemStore(DEFAULT_BOOKS); 73 | } 74 | 75 | try { 76 | CatalogItemProtos.CatalogItemStore store = CatalogItemProtos.CatalogItemStore.parseFrom( 77 | Base64.decode(storeValue, Base64.NO_WRAP)); 78 | 79 | new CatalogItemStore((store)); 80 | return new CatalogItemStore(store); 81 | } catch (InvalidProtocolBufferNanoException e) { 82 | Log.e(TAG, "Unable to parse serialized items", e); 83 | } 84 | 85 | return new CatalogItemStore(DEFAULT_BOOKS); 86 | } 87 | 88 | @WorkerThread 89 | public void write(CatalogItemStore store) { 90 | mSharedPreferences 91 | .edit() 92 | .putString( 93 | STORE_KEY, 94 | Base64.encodeToString(store.toProtoBytes(), Base64.NO_WRAP)) 95 | .apply(); 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /shared/src/main/java/com/google/codelabs/migratingtojobs/shared/Util.java: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Google, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | //////////////////////////////////////////////////////////////////////////////// 16 | 17 | package com.google.codelabs.migratingtojobs.shared; 18 | 19 | import android.net.ConnectivityManager; 20 | import android.net.NetworkInfo; 21 | 22 | public final class Util { 23 | private Util() { 24 | } 25 | 26 | public static boolean isNetworkActive(ConnectivityManager connManager) { 27 | NetworkInfo netInfo = connManager.getActiveNetworkInfo(); 28 | 29 | return netInfo != null && netInfo.isConnected() && netInfo.isAvailable(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /shared/src/main/proto/catalog_item.proto: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Google, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | //////////////////////////////////////////////////////////////////////////////// 16 | 17 | syntax = "proto3"; 18 | 19 | package schema; 20 | 21 | option java_package = "com.google.codelabs.migratingtojobs.shared"; 22 | option java_outer_classname = "CatalogItemProtos"; 23 | 24 | message Book { 25 | string title = 1; 26 | string author = 2; 27 | } 28 | 29 | message CatalogItem { 30 | Book book = 1; 31 | int32 downloadProgress = 2; 32 | enum Status { 33 | UNKNOWN = 0; 34 | AVAILABLE = 1; 35 | UNAVAILABLE = 2; 36 | DOWNLOADING = 3; 37 | ERROR = 4; 38 | } 39 | Status status = 3; 40 | } 41 | 42 | message CatalogItemStore { 43 | repeated CatalogItem items = 1; 44 | } 45 | -------------------------------------------------------------------------------- /shared/src/main/res/drawable/ic_cancel.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 11 | -------------------------------------------------------------------------------- /shared/src/main/res/drawable/ic_delete.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 11 | -------------------------------------------------------------------------------- /shared/src/main/res/drawable/ic_download.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 11 | -------------------------------------------------------------------------------- /shared/src/main/res/drawable/ic_error.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 11 | -------------------------------------------------------------------------------- /shared/src/main/res/layout/activity_catalog_list.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 12 | 13 | 18 | 19 | 23 | 24 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /shared/src/main/res/layout/content_catalog_item.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 14 | 15 | 16 | 20 | 21 | 27 | 28 | 29 | 30 | 35 | 36 | 42 | 43 | 46 | 52 | 53 | 63 | 64 | 65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /shared/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-migrate-to-jobs/561521d37d35486a98f5a204773d86c06b5adb82/shared/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /shared/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-migrate-to-jobs/561521d37d35486a98f5a204773d86c06b5adb82/shared/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /shared/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-migrate-to-jobs/561521d37d35486a98f5a204773d86c06b5adb82/shared/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /shared/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-migrate-to-jobs/561521d37d35486a98f5a204773d86c06b5adb82/shared/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /shared/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-migrate-to-jobs/561521d37d35486a98f5a204773d86c06b5adb82/shared/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /shared/src/main/res/values-v21/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | -------------------------------------------------------------------------------- /shared/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 64dp 7 | 8 | -------------------------------------------------------------------------------- /shared/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /shared/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 16dp 5 | 16dp 6 | 16dp 7 | 8 | -------------------------------------------------------------------------------- /shared/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /shared/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 11 | 12 | 16 | 17 |