diff --git a/.travis.yml b/.travis.yml index 8853c2e..4b7f981 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,7 +9,7 @@ android: - tools # The BuildTools version used by your project - - build-tools-25.0.0 + - build-tools-25.0.2 # The SDK version used to compile your project - android-25 @@ -18,7 +18,6 @@ android: - extra-google-google_play_services - extra-google-m2repository - extra-android-m2repository - - addon-google_apis-google-23 before_install: - export JAVA8_HOME=/usr/lib/jvm/java-8-oracle diff --git a/CHANGELOG.md b/CHANGELOG.md index cdd21de..b62c40e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## Version 1.0.2 + +* Update dependencies (RxJava 2.0.7, Play Services 10.2.0) +* Fix bug which made activity recognition API unusable (#24) +* Add `StatusExceptionResumeNextTransformer` to help with handlig the resolution of a `Result` yourself (#17) + ## Version 1.0.1 * Add consumer ProGuard rules. (#7, #8 – thanks Evisceration) \ No newline at end of file diff --git a/README.md b/README.md index 55ac921..4e6b8d2 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Reactive Location API Library for Android -[![Build Status](https://travis-ci.org/patloew/RxLocation.svg?branch=master)](https://travis-ci.org/patloew/RxLocation) [![codecov](https://codecov.io/gh/patloew/RxLocation/branch/master/graph/badge.svg)](https://codecov.io/gh/patloew/RxLocation) [![Download](https://api.bintray.com/packages/patloew/maven/RxLocation/images/download.svg) ](https://bintray.com/patloew/maven/RxLocation/_latestVersion) [![API](https://img.shields.io/badge/API-9%2B-brightgreen.svg?style=flat)](https://android-arsenal.com/api?level=9) +[![Build Status](https://travis-ci.org/patloew/RxLocation.svg?branch=master)](https://travis-ci.org/patloew/RxLocation) [![codecov](https://codecov.io/gh/patloew/RxLocation/branch/master/graph/badge.svg)](https://codecov.io/gh/patloew/RxLocation) [![Download](https://api.bintray.com/packages/patloew/maven/RxLocation/images/download.svg) ](https://bintray.com/patloew/maven/RxLocation/_latestVersion) [![API](https://img.shields.io/badge/API-14%2B-brightgreen.svg?style=flat)](https://android-arsenal.com/api?level=14) This library wraps the Location APIs in [RxJava 2](https://github.com/ReactiveX/RxJava/tree/2.x) Observables, Singles, Maybes and Completables. No more managing GoogleApiClients! Also, the resolution of the location settings check is optionally handled by the lib. @@ -68,6 +68,8 @@ The following Exceptions are thrown in the lib and provided via `onError()`: * `SecurityException`: When you try to call an API without proper permissions. * `LocationSettingsNotSatisfiedException`: When you use `rxLocation.settings().checkAndHandleResolutionCompletable(...)` and the location settings were not satisfied, even after handling the resolution. +When using the Geocoding component of RxLocation, exceptions can be thrown even after disposing, which can lead to app crashes. To prevent this, install a global `RxJavaPlugins.setErrorHandler()`, e.g. in your Application class. + # Sample A basic sample app is available in the `sample` project. @@ -77,7 +79,7 @@ A basic sample app is available in the `sample` project. The lib is available on jCenter. Add the following to your `build.gradle`: dependencies { - compile 'com.patloew.rxlocation:rxlocation:1.0.1' + compile 'com.patloew.rxlocation:rxlocation:1.0.2' } # Testing diff --git a/build.gradle b/build.gradle index 179af08..04c541d 100644 --- a/build.gradle +++ b/build.gradle @@ -1,19 +1,22 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. +apply plugin: 'com.github.ben-manes.versions' buildscript { repositories { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:2.2.2' + classpath 'com.android.tools.build:gradle:2.3.0' - classpath 'me.tatarka:gradle-retrolambda:3.3.1' + classpath 'me.tatarka:gradle-retrolambda:3.6.0' - classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.1' + classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3' classpath "com.github.dcendents:android-maven-gradle-plugin:1.5" classpath 'com.dicedmelon.gradle:jacoco-android:0.1.1' + classpath 'com.github.ben-manes:gradle-versions-plugin:0.14.0' + // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 13372ae..8d36969 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 5642922..85335bb 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Mon Dec 28 10:00:20 PST 2015 +#Wed Mar 15 13:25:54 CET 2017 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-3.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-3.4.1-all.zip diff --git a/gradlew b/gradlew index 9d82f78..4453cce 100755 --- a/gradlew +++ b/gradlew @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#!/usr/bin/env sh ############################################################################## ## @@ -6,12 +6,30 @@ ## ############################################################################## -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS="" +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null APP_NAME="Gradle" APP_BASE_NAME=`basename "$0"` +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD="maximum" @@ -30,6 +48,7 @@ die ( ) { cygwin=false msys=false darwin=false +nonstop=false case "`uname`" in CYGWIN* ) cygwin=true @@ -40,26 +59,11 @@ case "`uname`" in MINGW* ) msys=true ;; + NONSTOP* ) + nonstop=true + ;; esac -# Attempt to set APP_HOME -# Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi -done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null - CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar # Determine the Java command to use to start the JVM. @@ -85,7 +89,7 @@ location of your Java installation." fi # Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then MAX_FD_LIMIT=`ulimit -H -n` if [ $? -eq 0 ] ; then if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then @@ -150,11 +154,19 @@ if $cygwin ; then esac fi -# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules -function splitJvmOpts() { - JVM_OPTS=("$@") +# Escape application args +save ( ) { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " } -eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS -JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" +APP_ARGS=$(save "$@") + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong +if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then + cd "$(dirname "$0")" +fi -exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat index aec9973..e95643d 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -8,14 +8,14 @@ @rem Set local scope for the variables with windows NT shell if "%OS%"=="Windows_NT" setlocal -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS= - set DIRNAME=%~dp0 if "%DIRNAME%" == "" set DIRNAME=. set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + @rem Find java.exe if defined JAVA_HOME goto findJavaFromJavaHome @@ -46,10 +46,9 @@ echo location of your Java installation. goto fail :init -@rem Get command-line arguments, handling Windowz variants +@rem Get command-line arguments, handling Windows variants if not "%OS%" == "Windows_NT" goto win9xME_args -if "%@eval[2+2]" == "4" goto 4NT_args :win9xME_args @rem Slurp the command line arguments. @@ -60,11 +59,6 @@ set _SKIP=2 if "x%~1" == "x" goto execute set CMD_LINE_ARGS=%* -goto execute - -:4NT_args -@rem Get arguments from the 4NT Shell from JP Software -set CMD_LINE_ARGS=%$ :execute @rem Setup the command line diff --git a/library/build.gradle b/library/build.gradle index a523dba..cc4dd3b 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -5,18 +5,18 @@ apply plugin: 'com.jfrog.bintray' apply plugin: 'com.github.dcendents.android-maven' group = 'com.patloew.rxlocation' -version = '1.0.1' +version = '1.0.2' project.archivesBaseName = 'rxlocation' android { compileSdkVersion 25 - buildToolsVersion "25.0.0" + buildToolsVersion "25.0.2" defaultConfig { - minSdkVersion 9 + minSdkVersion 14 targetSdkVersion 25 versionCode 2 - versionName "1.0.1" + versionName "1.0.2" } buildTypes { release { @@ -43,8 +43,8 @@ retrolambda { dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) - compile 'io.reactivex.rxjava2:rxjava:2.0.1' - compile 'com.google.android.gms:play-services-location:9.8.0' + compile 'io.reactivex.rxjava2:rxjava:2.0.7' + compile 'com.google.android.gms:play-services-location:10.2.0' testCompile 'junit:junit:4.12' testCompile 'org.mockito:mockito-core:1.10.19' diff --git a/library/src/main/java/com/patloew/rxlocation/RxLocationBaseOnSubscribe.java b/library/src/main/java/com/patloew/rxlocation/RxLocationBaseOnSubscribe.java index 23efcae..5d036c8 100644 --- a/library/src/main/java/com/patloew/rxlocation/RxLocationBaseOnSubscribe.java +++ b/library/src/main/java/com/patloew/rxlocation/RxLocationBaseOnSubscribe.java @@ -9,6 +9,7 @@ import com.google.android.gms.common.api.Result; import com.google.android.gms.common.api.ResultCallback; import com.google.android.gms.common.api.Scope; +import com.google.android.gms.location.ActivityRecognition; import com.google.android.gms.location.LocationServices; import java.util.concurrent.TimeUnit; @@ -41,7 +42,7 @@ abstract class RxLocationBaseOnSubscribe { protected RxLocationBaseOnSubscribe(@NonNull RxLocation rxLocation, Long timeout, TimeUnit timeUnit) { this.ctx = rxLocation.ctx; - this.services = new Api[]{LocationServices.API}; + this.services = new Api[]{ LocationServices.API, ActivityRecognition.API }; this.scopes = null; if (timeout != null && timeUnit != null) { diff --git a/library/src/main/java/com/patloew/rxlocation/SettingsCheckHandleSingleOnSubscribe.java b/library/src/main/java/com/patloew/rxlocation/SettingsCheckHandleSingleOnSubscribe.java index 4bdb00e..90db1de 100644 --- a/library/src/main/java/com/patloew/rxlocation/SettingsCheckHandleSingleOnSubscribe.java +++ b/library/src/main/java/com/patloew/rxlocation/SettingsCheckHandleSingleOnSubscribe.java @@ -118,7 +118,7 @@ protected void onGoogleApiClientReady(GoogleApiClient apiClient, SingleEmitter ResultCallback get(@NonNull SingleEmitter emitte @Override public void onResult(@NonNull T result) { if (!result.getStatus().isSuccess()) { - emitter.onError(new StatusException(result.getStatus())); + emitter.onError(new StatusException(result)); } else { try { emitter.onSuccess(mapper.apply(result)); diff --git a/library/src/main/java/com/patloew/rxlocation/StatusException.java b/library/src/main/java/com/patloew/rxlocation/StatusException.java index 8bae41c..01fd02f 100644 --- a/library/src/main/java/com/patloew/rxlocation/StatusException.java +++ b/library/src/main/java/com/patloew/rxlocation/StatusException.java @@ -1,5 +1,6 @@ package com.patloew.rxlocation; +import com.google.android.gms.common.api.Result; import com.google.android.gms.common.api.Status; /* Copyright (C) 2015 Michał Charmas (http://blog.charmas.pl) @@ -15,16 +16,25 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. + * + * ------------ + * + * + * FILE MODIFIED by Patrick Löwenstein 2017 */ -public class StatusException extends Exception { - private final Status status; +public class StatusException extends RuntimeException { + private final Result result; + + public StatusException(Result result) { + super(result.getStatus().toString()); + this.result = result; + } - public StatusException(Status status) { - super(status.toString()); - this.status = status; + public Result getResult() { + return result; } public Status getStatus() { - return status; + return result.getStatus(); } } diff --git a/library/src/main/java/com/patloew/rxlocation/StatusExceptionResumeNextTransformer.java b/library/src/main/java/com/patloew/rxlocation/StatusExceptionResumeNextTransformer.java new file mode 100644 index 0000000..e8a7de2 --- /dev/null +++ b/library/src/main/java/com/patloew/rxlocation/StatusExceptionResumeNextTransformer.java @@ -0,0 +1,77 @@ +package com.patloew.rxlocation; + +import com.google.android.gms.common.api.Result; + +import io.reactivex.Flowable; +import io.reactivex.FlowableTransformer; +import io.reactivex.Observable; +import io.reactivex.ObservableTransformer; +import io.reactivex.Single; +import io.reactivex.SingleTransformer; + +/* Copyright 2017 Patrick Löwenstein + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ +public class StatusExceptionResumeNextTransformer { + + public static FlowableTransformer forFlowable() { + return upstream -> upstream.onErrorResumeNext(throwable -> { + if(throwable instanceof StatusException) { + StatusException statusException = (StatusException) throwable; + + if(statusException.getStatus().hasResolution()) { + return Flowable.just((R) statusException.getResult()); + } else { + return Flowable.error(throwable); + } + + } else { + return Flowable.error(throwable); + } + }); + } + + public static ObservableTransformer forObservable() { + return upstream -> upstream.onErrorResumeNext(throwable -> { + if(throwable instanceof StatusException) { + StatusException statusException = (StatusException) throwable; + + if(statusException.getStatus().hasResolution()) { + return Observable.just((R) statusException.getResult()); + } else { + return Observable.error(throwable); + } + + } else { + return Observable.error(throwable); + } + }); + } + + public static SingleTransformer forSingle() { + return upstream -> upstream.onErrorResumeNext(throwable -> { + if(throwable instanceof StatusException) { + StatusException statusException = (StatusException) throwable; + + if(statusException.getStatus().hasResolution()) { + return Single.just((R) statusException.getResult()); + } else { + return Single.error(throwable); + } + + } else { + return Single.error(throwable); + } + }); + } +} diff --git a/library/src/main/res/values/strings.xml b/library/src/main/res/values/strings.xml index d12a048..27bc696 100644 --- a/library/src/main/res/values/strings.xml +++ b/library/src/main/res/values/strings.xml @@ -9,7 +9,7 @@ RxLocation This library wraps the Location APIs in RxJava 2 Observables, Singles and Maybes. No more managing GoogleApiClients! Also, the resolution of the location settings check is optionally handled by the lib. https://github.com/patloew/RxLocation - 1.0.0 + 1.0.2 true https://github.com/patloew/RxLocation diff --git a/sample/build.gradle b/sample/build.gradle index 7e6e010..e0ece6e 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -3,10 +3,10 @@ apply plugin: 'me.tatarka.retrolambda' android { compileSdkVersion 25 - buildToolsVersion "25.0.0" + buildToolsVersion "25.0.2" defaultConfig { - applicationId "com.patloew.rxfitsample" + applicationId "com.patloew.rxlocationsample" minSdkVersion 14 targetSdkVersion 22 versionCode 1 @@ -37,18 +37,20 @@ retrolambda { dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) testCompile 'junit:junit:4.12' - compile 'com.android.support:appcompat-v7:25.0.1' - compile "com.android.support:design:25.0.1" + compile 'com.android.support:appcompat-v7:25.3.0' + compile 'com.android.support:support-v4:25.3.0' + compile "com.android.support:design:25.3.0" + compile "com.android.support:cardview-v7:25.3.0" compile project(':library') - //compile 'com.patloew.rxlocation:rxlocation:1.0.1' + //compile 'com.patloew.rxlocation:rxlocation:1.0.2' compile 'io.reactivex.rxjava2:rxandroid:2.0.1' - compile 'io.reactivex.rxjava2:rxjava:2.0.1' + compile 'io.reactivex.rxjava2:rxjava:2.0.7' - compile 'com.google.android.gms:play-services-location:9.8.0' + compile 'com.google.android.gms:play-services-location:10.2.0' - compile('com.mikepenz:aboutlibraries:5.8.5@aar') { + compile('com.mikepenz:aboutlibraries:5.9.4@aar') { transitive = true }