From 693e56323ae4d43b3267b74d4e80dee56a923b55 Mon Sep 17 00:00:00 2001 From: Laszlo Modis Date: Thu, 25 Oct 2018 12:35:50 +0300 Subject: [PATCH 1/6] Migrating to AndroidX --- android-reactive-location/build.gradle | 6 +++--- .../reactivelocation2/ReactiveLocationProvider.java | 4 ++-- .../ReactiveLocationProviderConfiguration.java | 2 +- .../observables/BaseObservableOnSubscribe.java | 2 +- .../observables/PendingResultObservableOnSubscribe.java | 2 +- .../observables/geocode/GeocodeObservable.java | 2 +- .../geofence/AddGeofenceObservableOnSubscribe.java | 2 +- ...moveGeofenceByPendingIntentObservableOnSubscribe.java | 2 +- .../RemoveGeofenceRequestIdsObservableOnSubscribe.java | 2 +- .../AddLocationIntentUpdatesObservableOnSubscribe.java | 2 +- .../location/MockLocationObservableOnSubscribe.java | 2 +- ...RemoveLocationIntentUpdatesObservableOnSubscribe.java | 2 +- build.gradle | 9 ++++++--- gradle.properties | 2 ++ gradle/wrapper/gradle-wrapper.properties | 4 ++-- sample/build.gradle | 6 +++--- .../android/reactivelocation2/sample/BaseActivity.java | 2 +- .../sample/GeofenceBroadcastReceiver.java | 2 +- .../reactivelocation2/sample/MockLocationsActivity.java | 2 +- .../reactivelocation2/sample/PlacesResultActivity.java | 2 +- .../reactivelocation2/sample/utils/RxTextView.java | 4 ++-- 21 files changed, 34 insertions(+), 29 deletions(-) diff --git a/android-reactive-location/build.gradle b/android-reactive-location/build.gradle index fc254d07..03a48a2b 100644 --- a/android-reactive-location/build.gradle +++ b/android-reactive-location/build.gradle @@ -19,9 +19,9 @@ android { //TODO: local maven deployment dependencies { - compile 'com.google.android.gms:play-services-location:11.0.4' - compile 'com.google.android.gms:play-services-places:11.0.4' - compile 'io.reactivex.rxjava2:rxjava:2.0.5' + api 'com.google.android.gms:play-services-location:16.0.0' + api 'com.google.android.gms:play-services-places:16.0.0' + api 'io.reactivex.rxjava2:rxjava:2.2.0' } // Comment this to deploy to local maven repository diff --git a/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/ReactiveLocationProvider.java b/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/ReactiveLocationProvider.java index f6c3533b..494d89a9 100644 --- a/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/ReactiveLocationProvider.java +++ b/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/ReactiveLocationProvider.java @@ -5,8 +5,8 @@ import android.location.Address; import android.location.Location; import android.os.Handler; -import android.support.annotation.Nullable; -import android.support.annotation.RequiresPermission; +import androidx.annotation.Nullable; +import androidx.annotation.RequiresPermission; import com.google.android.gms.common.api.Api; import com.google.android.gms.common.api.GoogleApiClient; diff --git a/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/ReactiveLocationProviderConfiguration.java b/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/ReactiveLocationProviderConfiguration.java index 2cbfe264..dc72428c 100644 --- a/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/ReactiveLocationProviderConfiguration.java +++ b/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/ReactiveLocationProviderConfiguration.java @@ -1,7 +1,7 @@ package pl.charmas.android.reactivelocation2; import android.os.Handler; -import android.support.annotation.Nullable; +import androidx.annotation.Nullable; /** * Configuration for location provider. Pleas use builder to create an instance. diff --git a/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/BaseObservableOnSubscribe.java b/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/BaseObservableOnSubscribe.java index 3b7adf6e..ee933927 100644 --- a/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/BaseObservableOnSubscribe.java +++ b/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/BaseObservableOnSubscribe.java @@ -3,7 +3,7 @@ import android.content.Context; import android.os.Bundle; import android.os.Handler; -import android.support.annotation.NonNull; +import androidx.annotation.NonNull; import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.api.Api; diff --git a/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/PendingResultObservableOnSubscribe.java b/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/PendingResultObservableOnSubscribe.java index f70eacad..68c048b2 100644 --- a/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/PendingResultObservableOnSubscribe.java +++ b/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/PendingResultObservableOnSubscribe.java @@ -1,6 +1,6 @@ package pl.charmas.android.reactivelocation2.observables; -import android.support.annotation.NonNull; +import androidx.annotation.NonNull; import com.google.android.gms.common.api.PendingResult; import com.google.android.gms.common.api.Result; diff --git a/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/geocode/GeocodeObservable.java b/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/geocode/GeocodeObservable.java index e74f1fc8..da162f97 100644 --- a/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/geocode/GeocodeObservable.java +++ b/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/geocode/GeocodeObservable.java @@ -3,7 +3,7 @@ import android.content.Context; import android.location.Address; import android.location.Geocoder; -import android.support.annotation.NonNull; +import androidx.annotation.NonNull; import com.google.android.gms.maps.model.LatLngBounds; diff --git a/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/geofence/AddGeofenceObservableOnSubscribe.java b/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/geofence/AddGeofenceObservableOnSubscribe.java index 300973d9..2a5e69ca 100644 --- a/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/geofence/AddGeofenceObservableOnSubscribe.java +++ b/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/geofence/AddGeofenceObservableOnSubscribe.java @@ -1,7 +1,7 @@ package pl.charmas.android.reactivelocation2.observables.geofence; import android.app.PendingIntent; -import android.support.annotation.NonNull; +import androidx.annotation.NonNull; import com.google.android.gms.common.api.GoogleApiClient; import com.google.android.gms.common.api.ResultCallback; diff --git a/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/geofence/RemoveGeofenceByPendingIntentObservableOnSubscribe.java b/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/geofence/RemoveGeofenceByPendingIntentObservableOnSubscribe.java index 551d9b70..0e814d44 100644 --- a/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/geofence/RemoveGeofenceByPendingIntentObservableOnSubscribe.java +++ b/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/geofence/RemoveGeofenceByPendingIntentObservableOnSubscribe.java @@ -1,7 +1,7 @@ package pl.charmas.android.reactivelocation2.observables.geofence; import android.app.PendingIntent; -import android.support.annotation.NonNull; +import androidx.annotation.NonNull; import com.google.android.gms.common.api.GoogleApiClient; import com.google.android.gms.common.api.ResultCallback; diff --git a/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/geofence/RemoveGeofenceRequestIdsObservableOnSubscribe.java b/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/geofence/RemoveGeofenceRequestIdsObservableOnSubscribe.java index 557b86e9..0037d9be 100644 --- a/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/geofence/RemoveGeofenceRequestIdsObservableOnSubscribe.java +++ b/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/geofence/RemoveGeofenceRequestIdsObservableOnSubscribe.java @@ -1,6 +1,6 @@ package pl.charmas.android.reactivelocation2.observables.geofence; -import android.support.annotation.NonNull; +import androidx.annotation.NonNull; import com.google.android.gms.common.api.GoogleApiClient; import com.google.android.gms.common.api.ResultCallback; diff --git a/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/location/AddLocationIntentUpdatesObservableOnSubscribe.java b/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/location/AddLocationIntentUpdatesObservableOnSubscribe.java index 5774a55f..2f4d60e5 100644 --- a/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/location/AddLocationIntentUpdatesObservableOnSubscribe.java +++ b/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/location/AddLocationIntentUpdatesObservableOnSubscribe.java @@ -1,7 +1,7 @@ package pl.charmas.android.reactivelocation2.observables.location; import android.app.PendingIntent; -import android.support.annotation.NonNull; +import androidx.annotation.NonNull; import com.google.android.gms.common.api.GoogleApiClient; import com.google.android.gms.common.api.ResultCallback; diff --git a/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/location/MockLocationObservableOnSubscribe.java b/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/location/MockLocationObservableOnSubscribe.java index f8c6cc76..cfd389ad 100644 --- a/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/location/MockLocationObservableOnSubscribe.java +++ b/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/location/MockLocationObservableOnSubscribe.java @@ -1,7 +1,7 @@ package pl.charmas.android.reactivelocation2.observables.location; import android.location.Location; -import android.support.annotation.NonNull; +import androidx.annotation.NonNull; import com.google.android.gms.common.api.GoogleApiClient; import com.google.android.gms.common.api.ResultCallback; diff --git a/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/location/RemoveLocationIntentUpdatesObservableOnSubscribe.java b/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/location/RemoveLocationIntentUpdatesObservableOnSubscribe.java index 881e35a5..ddf8351b 100644 --- a/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/location/RemoveLocationIntentUpdatesObservableOnSubscribe.java +++ b/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/location/RemoveLocationIntentUpdatesObservableOnSubscribe.java @@ -1,7 +1,7 @@ package pl.charmas.android.reactivelocation2.observables.location; import android.app.PendingIntent; -import android.support.annotation.NonNull; +import androidx.annotation.NonNull; import com.google.android.gms.common.api.GoogleApiClient; import com.google.android.gms.common.api.ResultCallback; diff --git a/build.gradle b/build.gradle index 1c6739a9..ed248b30 100644 --- a/build.gradle +++ b/build.gradle @@ -4,17 +4,18 @@ buildscript { repositories { mavenCentral() jcenter() + google() } dependencies { - classpath 'com.android.tools.build:gradle:2.3.3' + classpath 'com.android.tools.build:gradle:3.2.1' } } // To avoid manually setting the same values in all Android modules, set the value on the root // project and then reference this from the modules ext { - compileSdkVersion = 25 - targetSdkVersion = 25 + compileSdkVersion = 28 + targetSdkVersion = 28 buildToolsVersion = "25.0.3" } @@ -29,5 +30,7 @@ allprojects { repositories { mavenCentral() jcenter() + google() + maven { url 'https://jitpack.io' } } } diff --git a/gradle.properties b/gradle.properties index a0a4da92..e91cb4d9 100644 --- a/gradle.properties +++ b/gradle.properties @@ -13,3 +13,5 @@ POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt POM_LICENCE_DIST=repo POM_DEVELOPER_ID=mcharmas POM_DEVELOPER_NAME=Michal Charmas +android.useAndroidX=true +android.enableJetifier=true diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index cbb3db13..4b585d29 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Fri Sep 29 10:11:52 CEST 2017 +#Thu Oct 25 12:29:40 EEST 2018 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip diff --git a/sample/build.gradle b/sample/build.gradle index ddb75b0e..de71f894 100755 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -35,8 +35,8 @@ android { } dependencies { - compile 'com.android.support:appcompat-v7:25.3.1' - compile 'io.reactivex.rxjava2:rxandroid:2.0.1' - compile 'com.tbruyelle.rxpermissions2:rxpermissions:0.9.1@aar' + implementation 'androidx.appcompat:appcompat:1.0.0' + implementation 'io.reactivex.rxjava2:rxandroid:2.0.2' + implementation 'com.github.tbruyelle:rxpermissions:0.10.2' compile project(':android-reactive-location') } diff --git a/sample/src/main/java/pl/charmas/android/reactivelocation2/sample/BaseActivity.java b/sample/src/main/java/pl/charmas/android/reactivelocation2/sample/BaseActivity.java index 70a45c5c..d0597057 100755 --- a/sample/src/main/java/pl/charmas/android/reactivelocation2/sample/BaseActivity.java +++ b/sample/src/main/java/pl/charmas/android/reactivelocation2/sample/BaseActivity.java @@ -1,7 +1,7 @@ package pl.charmas.android.reactivelocation2.sample; import android.Manifest; -import android.support.v7.app.AppCompatActivity; +import androidx.appcompat.app.AppCompatActivity; import android.widget.Toast; import com.tbruyelle.rxpermissions2.RxPermissions; diff --git a/sample/src/main/java/pl/charmas/android/reactivelocation2/sample/GeofenceBroadcastReceiver.java b/sample/src/main/java/pl/charmas/android/reactivelocation2/sample/GeofenceBroadcastReceiver.java index 8b1c5c44..970f05ca 100644 --- a/sample/src/main/java/pl/charmas/android/reactivelocation2/sample/GeofenceBroadcastReceiver.java +++ b/sample/src/main/java/pl/charmas/android/reactivelocation2/sample/GeofenceBroadcastReceiver.java @@ -5,7 +5,7 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; -import android.support.v4.app.NotificationCompat; +import androidx.core.app.NotificationCompat; import com.google.android.gms.location.Geofence; import com.google.android.gms.location.GeofencingEvent; diff --git a/sample/src/main/java/pl/charmas/android/reactivelocation2/sample/MockLocationsActivity.java b/sample/src/main/java/pl/charmas/android/reactivelocation2/sample/MockLocationsActivity.java index c529304f..f37c087c 100755 --- a/sample/src/main/java/pl/charmas/android/reactivelocation2/sample/MockLocationsActivity.java +++ b/sample/src/main/java/pl/charmas/android/reactivelocation2/sample/MockLocationsActivity.java @@ -6,7 +6,7 @@ import android.os.Build; import android.os.Bundle; import android.os.SystemClock; -import android.support.v4.app.ActivityCompat; +import androidx.core.app.ActivityCompat; import android.util.Log; import android.view.View; import android.widget.Button; diff --git a/sample/src/main/java/pl/charmas/android/reactivelocation2/sample/PlacesResultActivity.java b/sample/src/main/java/pl/charmas/android/reactivelocation2/sample/PlacesResultActivity.java index cabde5d7..4c9b01b5 100755 --- a/sample/src/main/java/pl/charmas/android/reactivelocation2/sample/PlacesResultActivity.java +++ b/sample/src/main/java/pl/charmas/android/reactivelocation2/sample/PlacesResultActivity.java @@ -3,7 +3,7 @@ import android.content.Context; import android.content.Intent; import android.os.Bundle; -import android.support.annotation.NonNull; +import androidx.annotation.NonNull; import android.widget.TextView; import com.google.android.gms.location.places.Place; diff --git a/sample/src/main/java/pl/charmas/android/reactivelocation2/sample/utils/RxTextView.java b/sample/src/main/java/pl/charmas/android/reactivelocation2/sample/utils/RxTextView.java index 7c9ead44..99f62725 100644 --- a/sample/src/main/java/pl/charmas/android/reactivelocation2/sample/utils/RxTextView.java +++ b/sample/src/main/java/pl/charmas/android/reactivelocation2/sample/utils/RxTextView.java @@ -1,7 +1,7 @@ package pl.charmas.android.reactivelocation2.sample.utils; -import android.support.annotation.CheckResult; -import android.support.annotation.NonNull; +import androidx.annotation.CheckResult; +import androidx.annotation.NonNull; import android.widget.TextView; import io.reactivex.Observable; From a03ff2e02a49bb39611e89c60254c0f93c2fc95b Mon Sep 17 00:00:00 2001 From: Laszlo Modis Date: Thu, 25 Oct 2018 17:38:24 +0300 Subject: [PATCH 2/6] Implementing new fused location apis --- .../BaseFailureListener.java | 22 ++ .../LocationNotAvailableException.java | 4 + .../ReactiveLocationProvider.java | 305 +++++++----------- ...ReactiveLocationProviderConfiguration.java | 1 + .../BaseLocationObservableOnSubscribe.java | 9 - .../BaseObservableOnSubscribe.java | 19 +- .../GoogleAPIClientObservableOnSubscribe.java | 10 +- .../observables/ObservableEmitterWrapper.java | 2 +- .../PendingResultObservableOnSubscribe.java | 44 --- .../observables/TaskSingleOnSubscribe.java | 36 +++ .../ActivityUpdatesObservableOnSubscribe.java | 16 +- .../BaseActivityObservableOnSubscribe.java | 13 + .../geocode/GeocodeObservable.java | 2 +- .../AddGeofenceObservableOnSubscribe.java | 35 +- .../BaseGeofencingObservableOnSubscribe.java | 26 ++ ...eByPendingIntentObservableOnSubscribe.java | 30 +- .../RemoveGeofenceObservableOnSubscribe.java | 16 +- ...ofenceRequestIdsObservableOnSubscribe.java | 31 +- ...ionIntentUpdatesObservableOnSubscribe.java | 35 +- .../BaseLocationObservableOnSubscribe.java | 26 ++ ...astKnownLocationObservableOnSubscribe.java | 28 +- .../LocationUpdatesObservableOnSubscribe.java | 46 ++- .../MockLocationObservableOnSubscribe.java | 68 ++-- ...ionIntentUpdatesObservableOnSubscribe.java | 33 +- .../sample/GeofenceActivity.java | 22 +- .../sample/MainActivity.java | 38 ++- .../sample/MockLocationsActivity.java | 40 ++- .../sample/PlacesActivity.java | 34 +- .../sample/PlacesResultActivity.java | 12 +- 29 files changed, 503 insertions(+), 500 deletions(-) create mode 100644 android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/BaseFailureListener.java create mode 100644 android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/LocationNotAvailableException.java delete mode 100644 android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/BaseLocationObservableOnSubscribe.java delete mode 100644 android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/PendingResultObservableOnSubscribe.java create mode 100644 android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/TaskSingleOnSubscribe.java create mode 100644 android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/geofence/BaseGeofencingObservableOnSubscribe.java create mode 100644 android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/location/BaseLocationObservableOnSubscribe.java diff --git a/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/BaseFailureListener.java b/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/BaseFailureListener.java new file mode 100644 index 00000000..8c27eb5a --- /dev/null +++ b/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/BaseFailureListener.java @@ -0,0 +1,22 @@ +package pl.charmas.android.reactivelocation2; + +import com.google.android.gms.tasks.OnFailureListener; + +import androidx.annotation.NonNull; +import io.reactivex.ObservableEmitter; + +public class BaseFailureListener implements OnFailureListener { + + private final ObservableEmitter emitter; + + public BaseFailureListener(ObservableEmitter emitter) { + this.emitter = emitter; + } + + @Override + public void onFailure(@NonNull Exception exception) { + if (emitter.isDisposed()) return; + emitter.onError(exception); + emitter.onComplete(); + } +} diff --git a/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/LocationNotAvailableException.java b/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/LocationNotAvailableException.java new file mode 100644 index 00000000..4ce19d9a --- /dev/null +++ b/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/LocationNotAvailableException.java @@ -0,0 +1,4 @@ +package pl.charmas.android.reactivelocation2; + +public class LocationNotAvailableException extends RuntimeException { +} diff --git a/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/ReactiveLocationProvider.java b/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/ReactiveLocationProvider.java index 494d89a9..eeba2ce9 100644 --- a/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/ReactiveLocationProvider.java +++ b/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/ReactiveLocationProvider.java @@ -5,40 +5,37 @@ import android.location.Address; import android.location.Location; import android.os.Handler; -import androidx.annotation.Nullable; -import androidx.annotation.RequiresPermission; import com.google.android.gms.common.api.Api; -import com.google.android.gms.common.api.GoogleApiClient; -import com.google.android.gms.common.api.PendingResult; -import com.google.android.gms.common.api.Result; -import com.google.android.gms.common.api.Status; +import com.google.android.gms.common.api.Response; import com.google.android.gms.location.ActivityRecognitionResult; import com.google.android.gms.location.GeofencingRequest; import com.google.android.gms.location.LocationRequest; import com.google.android.gms.location.LocationServices; import com.google.android.gms.location.LocationSettingsRequest; -import com.google.android.gms.location.LocationSettingsResult; +import com.google.android.gms.location.LocationSettingsResponse; import com.google.android.gms.location.places.AutocompleteFilter; -import com.google.android.gms.location.places.AutocompletePredictionBuffer; -import com.google.android.gms.location.places.PlaceBuffer; +import com.google.android.gms.location.places.AutocompletePredictionBufferResponse; +import com.google.android.gms.location.places.PlaceBufferResponse; import com.google.android.gms.location.places.PlaceFilter; -import com.google.android.gms.location.places.PlaceLikelihoodBuffer; -import com.google.android.gms.location.places.PlacePhotoMetadata; -import com.google.android.gms.location.places.PlacePhotoMetadataResult; -import com.google.android.gms.location.places.PlacePhotoResult; +import com.google.android.gms.location.places.PlaceLikelihoodBufferResponse; +import com.google.android.gms.location.places.PlacePhotoMetadataResponse; import com.google.android.gms.location.places.Places; import com.google.android.gms.maps.model.LatLngBounds; +import com.google.android.gms.tasks.Task; import java.util.List; import java.util.Locale; +import androidx.annotation.Nullable; +import androidx.annotation.RequiresPermission; +import io.reactivex.Completable; import io.reactivex.Observable; -import io.reactivex.functions.Function; +import io.reactivex.Single; import pl.charmas.android.reactivelocation2.observables.GoogleAPIClientObservableOnSubscribe; import pl.charmas.android.reactivelocation2.observables.ObservableContext; import pl.charmas.android.reactivelocation2.observables.ObservableFactory; -import pl.charmas.android.reactivelocation2.observables.PendingResultObservableOnSubscribe; +import pl.charmas.android.reactivelocation2.observables.TaskSingleOnSubscribe; import pl.charmas.android.reactivelocation2.observables.activity.ActivityUpdatesObservableOnSubscribe; import pl.charmas.android.reactivelocation2.observables.geocode.GeocodeObservable; import pl.charmas.android.reactivelocation2.observables.geocode.ReverseGeocodeObservable; @@ -52,7 +49,7 @@ /** - * Factory of observables that can manipulate location + * Factory of streams that can manipulate location * delivered by Google Play Services. */ public class ReactiveLocationProvider { @@ -93,22 +90,22 @@ public ReactiveLocationProvider(Context ctx, Handler handler) { } /** - * Creates observable that obtains last known location and than completes. + * Creates single that obtains last known location. * Delivered location is never null - when it is unavailable Observable completes without emitting * any value. *

- * Observable can report {@link pl.charmas.android.reactivelocation2.observables.GoogleAPIConnectionException} - * when there are trouble connecting with Google Play Services and other exceptions that - * can be thrown on {@link com.google.android.gms.location.FusedLocationProviderApi#getLastLocation(com.google.android.gms.common.api.GoogleApiClient)}. + * Single can report {@link pl.charmas.android.reactivelocation2.observables.GoogleAPIConnectionException} + * when there are trouble connecting with Google Play Services and other exceptions that can be thrown by the api. + *

* Everything is delivered by {@link io.reactivex.Observer#onError(Throwable)}. * - * @return observable that serves last know location + * @return single that serves last know location */ @RequiresPermission( anyOf = {"android.permission.ACCESS_COARSE_LOCATION", "android.permission.ACCESS_FINE_LOCATION"} ) - public Observable getLastKnownLocation() { - return LastKnownLocationObservableOnSubscribe.createObservable(ctx, factory); + public Single getLastKnownLocation() { + return LastKnownLocationObservableOnSubscribe.createObservable(ctx, factory).singleOrError(); } /** @@ -117,8 +114,8 @@ public Observable getLastKnownLocation() { * then disconnected. *

* Observable can report {@link pl.charmas.android.reactivelocation2.observables.GoogleAPIConnectionException} - * when there are trouble connecting with Google Play Services and other exceptions that - * can be thrown on {@link com.google.android.gms.location.FusedLocationProviderApi#requestLocationUpdates(com.google.android.gms.common.api.GoogleApiClient, com.google.android.gms.location.LocationRequest, com.google.android.gms.location.LocationListener)}. + * when there are trouble connecting with Google Play Services and other exceptions that can be thrown by the api. + *

* Everything is delivered by {@link io.reactivex.Observer#onError(Throwable)}. * * @param locationRequest request object with info about what kind of location you need @@ -132,122 +129,114 @@ public Observable getUpdatedLocation(LocationRequest locationRequest) } /** - * Returns an observable which activates mock location mode when subscribed to, using the + * Returns an completable which activates mock location mode when subscribed to, using the * supplied observable as a source of mock locations. Mock locations will replace normal * location information for all users of the FusedLocationProvider API on the device while this - * observable is subscribed to. + * completable is subscribed to. *

* To use this method, mock locations must be enabled in developer options and your application * must hold the android.permission.ACCESS_MOCK_LOCATION permission, or a {@link java.lang.SecurityException} * will be thrown. *

- * All statuses that are not successful will be reported as {@link pl.charmas.android.reactivelocation2.observables.StatusException}. + * In case of any issue error is delivered. *

* Every exception is delivered by {@link io.reactivex.Observer#onError(Throwable)}. * * @param sourceLocationObservable observable that emits {@link android.location.Location} instances suitable to use as mock locations - * @return observable that emits {@link com.google.android.gms.common.api.Status} + * @return completable that waits until location observable completes */ @RequiresPermission( allOf = {"android.permission.ACCESS_COARSE_LOCATION", "android.permission.ACCESS_MOCK_LOCATION"} ) - public Observable mockLocation(Observable sourceLocationObservable) { - return MockLocationObservableOnSubscribe.createObservable(ctx, factory, sourceLocationObservable); + public Completable mockLocation(Observable sourceLocationObservable) { + return MockLocationObservableOnSubscribe.createObservable(ctx, factory, sourceLocationObservable).ignoreElements(); } /** - * Creates an observable that adds a {@link android.app.PendingIntent} as a location listener. - *

- * This invokes {@link com.google.android.gms.location.FusedLocationProviderApi#requestLocationUpdates(com.google.android.gms.common.api.GoogleApiClient, com.google.android.gms.location.LocationRequest, android.app.PendingIntent)}. + * Creates an completable that adds a {@link android.app.PendingIntent} as a location listener. *

* When location updates are no longer required, a call to {@link #removeLocationUpdates(android.app.PendingIntent)} * should be made. *

- * In case of unsuccessful status {@link pl.charmas.android.reactivelocation2.observables.StatusException} is delivered. + * In case of any issue error is delivered. * * @param locationRequest request object with info about what kind of location you need * @param intent PendingIntent that will be called with location updates - * @return observable that adds the request and PendingIntent + * @return completable that adds the request and PendingIntent */ @RequiresPermission( anyOf = {"android.permission.ACCESS_COARSE_LOCATION", "android.permission.ACCESS_FINE_LOCATION"} ) - public Observable requestLocationUpdates(LocationRequest locationRequest, PendingIntent intent) { - return AddLocationIntentUpdatesObservableOnSubscribe.createObservable(ctx, factory, locationRequest, intent); + public Completable requestLocationUpdates(LocationRequest locationRequest, PendingIntent intent) { + return AddLocationIntentUpdatesObservableOnSubscribe.createObservable(ctx, factory, locationRequest, intent).ignoreElements(); } /** - * Observable that can be used to remove {@link android.app.PendingIntent} location updates. + * Completable that can be used to remove {@link android.app.PendingIntent} location updates. *

- * In case of unsuccessful status {@link pl.charmas.android.reactivelocation2.observables.StatusException} is delivered. + * In case of any issue error is delivered. * * @param intent PendingIntent to remove location updates for - * @return observable that removes the PendingIntent + * @return single that removes the PendingIntent */ - public Observable removeLocationUpdates(PendingIntent intent) { - return RemoveLocationIntentUpdatesObservableOnSubscribe.createObservable(ctx, factory, intent); + public Completable removeLocationUpdates(PendingIntent intent) { + return RemoveLocationIntentUpdatesObservableOnSubscribe.createObservable(ctx, factory, intent).ignoreElements(); } /** - * Creates observable that translates latitude and longitude to list of possible addresses using + * Creates single that translates latitude and longitude to list of possible addresses using * included Geocoder class. In case geocoder fails with IOException("Service not Available") fallback - * decoder is used using google web api. You should subscribe for this observable on I/O thread. - * The stream finishes after address list is available. + * decoder is used using google web api. You should subscribe on I/O thread. * * @param lat latitude * @param lng longitude * @param maxResults maximal number of results you are interested in - * @return observable that serves list of address based on location + * @return single that serves list of address based on location */ - public Observable> getReverseGeocodeObservable(double lat, double lng, int maxResults) { - return ReverseGeocodeObservable.createObservable(ctx.getContext(), factory, Locale.getDefault(), lat, lng, maxResults); + public Single> reverseGeocode(double lat, double lng, int maxResults) { + return ReverseGeocodeObservable.createObservable(ctx.getContext(), factory, Locale.getDefault(), lat, lng, maxResults).singleOrError(); } /** - * Creates observable that translates latitude and longitude to list of possible addresses using + * Creates single that translates latitude and longitude to list of possible addresses using * included Geocoder class. In case geocoder fails with IOException("Service not Available") fallback - * decoder is used using google web api. You should subscribe for this observable on I/O thread. - * The stream finishes after address list is available. + * decoder is used using google web api. You should subscribe on I/O thread. * * @param locale locale for address language * @param lat latitude * @param lng longitude * @param maxResults maximal number of results you are interested in - * @return observable that serves list of address based on location + * @return single that serves list of address based on location */ - public Observable> getReverseGeocodeObservable(Locale locale, double lat, double lng, int maxResults) { - return ReverseGeocodeObservable.createObservable(ctx.getContext(), factory, locale, lat, lng, maxResults); + public Single> reverseGeocode(Locale locale, double lat, double lng, int maxResults) { + return ReverseGeocodeObservable.createObservable(ctx.getContext(), factory, locale, lat, lng, maxResults).singleOrError(); } /** - * Creates observable that translates a street address or other description into a list of - * possible addresses using included Geocoder class. You should subscribe for this - * observable on I/O thread. - * The stream finishes after address list is available. + * Creates single that translates a street address or other description into a list of + * possible addresses using included Geocoder class. You should subscribe on I/O thread. * * @param locationName a user-supplied description of a location * @param maxResults max number of results you are interested in - * @return observable that serves list of address based on location name + * @return single that serves list of address based on location name */ - public Observable> getGeocodeObservable(String locationName, int maxResults) { - return getGeocodeObservable(locationName, maxResults, null); + public Single> geocode(String locationName, int maxResults) { + return geocode(locationName, maxResults, null); } /** * Creates geocoder with default Locale. * - * @see ReactiveLocationProvider#getGeocodeObservable(String, int, LatLngBounds, Locale) + * @see ReactiveLocationProvider#geocode(String, int, LatLngBounds, Locale) */ - public Observable> getGeocodeObservable(String locationName, int maxResults, LatLngBounds bounds) { - return getGeocodeObservable(locationName, maxResults, bounds, null); + public Single> geocode(String locationName, int maxResults, LatLngBounds bounds) { + return geocode(locationName, maxResults, bounds, null); } /** - * Creates observable that translates a street address or other description into a list of - * possible addresses using included Geocoder class. You should subscribe for this - * observable on I/O thread. - * The stream finishes after address list is available. + * Creates single that translates a street address or other description into a list of + * possible addresses using included Geocoder class. You should subscribe on I/O thread. *

* You may specify a bounding box for the search results. * @@ -255,201 +244,157 @@ public Observable> getGeocodeObservable(String locationName, int m * @param maxResults max number of results you are interested in * @param bounds restricts the results to geographical bounds. May be null * @param locale locale passed to geocoder - * @return observable that serves list of address based on location name + * @return single that serves list of address based on location name */ - public Observable> getGeocodeObservable(String locationName, int maxResults, LatLngBounds bounds, Locale locale) { - return GeocodeObservable.createObservable(ctx.getContext(), factory, locationName, maxResults, bounds, locale); + public Single> geocode(String locationName, int maxResults, LatLngBounds bounds, Locale locale) { + return GeocodeObservable.createObservable(ctx.getContext(), factory, locationName, maxResults, bounds, locale).singleOrError(); } /** - * Creates observable that adds request and completes when the action is done. - *

- * Observable can report {@link pl.charmas.android.reactivelocation2.observables.GoogleAPIConnectionException} - * when there are trouble connecting with Google Play Services. + * Creates completable that adds request and completes when the action is done. *

- * In case of unsuccessful status {@link pl.charmas.android.reactivelocation2.observables.StatusException} is delivered. + * In case of any issue error is delivered. *

- * Other exceptions will be reported that can be thrown on {@link com.google.android.gms.location.GeofencingApi#addGeofences(com.google.android.gms.common.api.GoogleApiClient, com.google.android.gms.location.GeofencingRequest, android.app.PendingIntent)} + * Every exception is delivered by {@link io.reactivex.CompletableObserver#onError(Throwable)}. * * @param geofenceTransitionPendingIntent pending intent to register on geofence transition * @param request list of request to add - * @return observable that adds request + * @return completable that adds request */ @RequiresPermission("android.permission.ACCESS_FINE_LOCATION") - public Observable addGeofences(PendingIntent geofenceTransitionPendingIntent, GeofencingRequest request) { - return AddGeofenceObservableOnSubscribe.createObservable(ctx, factory, request, geofenceTransitionPendingIntent); + public Completable addGeofences(PendingIntent geofenceTransitionPendingIntent, GeofencingRequest request) { + return AddGeofenceObservableOnSubscribe.createObservable(ctx, factory, request, geofenceTransitionPendingIntent).ignoreElements(); } /** - * Observable that can be used to remove geofences from LocationClient. - *

- * In case of unsuccessful status {@link pl.charmas.android.reactivelocation2.observables.StatusException} is delivered. + * Completable that can be used to remove geofences from LocationClient. *

- * Other exceptions will be reported that can be thrown on {@link com.google.android.gms.location.GeofencingApi#removeGeofences(com.google.android.gms.common.api.GoogleApiClient, android.app.PendingIntent)}. + * In case of any issue error is delivered. *

- * Every exception is delivered by {@link io.reactivex.Observer#onError(Throwable)}. + * Every exception is delivered by {@link io.reactivex.CompletableObserver#onError(Throwable)}. * * @param pendingIntent key of registered geofences - * @return observable that removed geofences + * @return completable that removed geofences */ - public Observable removeGeofences(PendingIntent pendingIntent) { - return RemoveGeofenceObservableOnSubscribe.createObservable(ctx, factory, pendingIntent); + public Completable removeGeofences(PendingIntent pendingIntent) { + return RemoveGeofenceObservableOnSubscribe.createObservable(ctx, factory, pendingIntent).ignoreElements(); } /** - * Observable that can be used to remove geofences from LocationClient. + * Completable that can be used to remove geofences from LocationClient. *

- * In case of unsuccessful status {@link pl.charmas.android.reactivelocation2.observables.StatusException} is delivered. + * In case of any issue error is delivered. *

- * Other exceptions will be reported that can be thrown on {@link com.google.android.gms.location.GeofencingApi#removeGeofences(com.google.android.gms.common.api.GoogleApiClient, java.util.List)}. - *

- * Every exception is delivered by {@link io.reactivex.Observer#onError(Throwable)}. + * Every exception is delivered by {@link io.reactivex.CompletableObserver#onError(Throwable)}. * * @param requestIds geofences to remove - * @return observable that removed geofences + * @return completable that removed geofences */ - public Observable removeGeofences(List requestIds) { - return RemoveGeofenceObservableOnSubscribe.createObservable(ctx, factory, requestIds); + public Completable removeGeofences(List requestIds) { + return RemoveGeofenceObservableOnSubscribe.createObservable(ctx, factory, requestIds).ignoreElements(); } - /** * Observable that can be used to observe activity provided by Actity Recognition mechanism. * * @param detectIntervalMiliseconds detecion interval * @return observable that provides activity recognition */ - public Observable getDetectedActivity(int detectIntervalMiliseconds) { + public Observable detectedActivity(int detectIntervalMiliseconds) { return ActivityUpdatesObservableOnSubscribe.createObservable(ctx, factory, detectIntervalMiliseconds); } /** - * Observable that can be used to check settings state for given location request. + * Returns single that can be used to check settings state for given location request. + * To handle {@link com.google.android.gms.location.LocationSettingsResponse} you can use + * {@link DataBufferObservable}. * * @param locationRequest location request - * @return observable that emits check result of location settings - * @see com.google.android.gms.location.SettingsApi + * @return single that emits check result of location settings */ - public Observable checkLocationSettings(final LocationSettingsRequest locationRequest) { - return getGoogleApiClientObservable(LocationServices.API) - .flatMap(new Function>() { - @Override - public Observable apply(GoogleApiClient googleApiClient) { - return fromPendingResult(LocationServices.SettingsApi.checkLocationSettings(googleApiClient, locationRequest)); - } - }); + public Single checkLocationSettings(final LocationSettingsRequest locationRequest) { + return connectGoogleApiClient(LocationServices.API) + .andThen(fromTask(LocationServices.getSettingsClient(ctx.getContext()).checkLocationSettings(locationRequest))); } /** - * Returns observable that fetches current place from Places API. To flatmap and auto release - * buffer to {@link com.google.android.gms.location.places.PlaceLikelihood} observable use + * Returns single that fetches current place from Places API. + * To handle {@link com.google.android.gms.location.places.PlaceLikelihoodBufferResponse} you can use * {@link DataBufferObservable}. * * @param placeFilter filter - * @return observable that emits current places buffer and completes + * @return single that emits current places buffer */ - public Observable getCurrentPlace(@Nullable final PlaceFilter placeFilter) { - return getGoogleApiClientObservable(Places.PLACE_DETECTION_API, Places.GEO_DATA_API) - .flatMap(new Function>() { - @Override - public Observable apply(GoogleApiClient api) { - return fromPendingResult(Places.PlaceDetectionApi.getCurrentPlace(api, placeFilter)); - } - }); + @RequiresPermission("android.permission.ACCESS_FINE_LOCATION") + public Single getCurrentPlace(@Nullable final PlaceFilter placeFilter) { + return connectGoogleApiClient(Places.PLACE_DETECTION_API, Places.GEO_DATA_API) + .andThen(fromTask(Places.getPlaceDetectionClient(ctx.getContext()).getCurrentPlace(placeFilter))); } /** - * Returns observable that fetches a place from the Places API using the place ID. + * Returns single that fetches a place from the Places API using the place ID. + * To handle {@link com.google.android.gms.location.places.PlaceBufferResponse} you can use + * {@link DataBufferObservable}. * * @param placeId id for place - * @return observable that emits places buffer and completes + * @return single that emits places buffer */ - public Observable getPlaceById(@Nullable final String placeId) { - return getGoogleApiClientObservable(Places.PLACE_DETECTION_API, Places.GEO_DATA_API) - .flatMap(new Function>() { - @Override - public Observable apply(GoogleApiClient api) { - return fromPendingResult(Places.GeoDataApi.getPlaceById(api, placeId)); - } - }); + public Single getPlaceById(@Nullable final String placeId) { + return connectGoogleApiClient(Places.PLACE_DETECTION_API, Places.GEO_DATA_API) + .andThen(fromTask(Places.getGeoDataClient(ctx.getContext()).getPlaceById(placeId))); } /** - * Returns observable that fetches autocomplete predictions from Places API. To flatmap and autorelease - * {@link com.google.android.gms.location.places.AutocompletePredictionBuffer} you can use + * Returns single that fetches autocomplete predictions from Places API. + * To handle {@link com.google.android.gms.location.places.AutocompletePredictionBufferResponse} you can use * {@link DataBufferObservable}. * * @param query search query * @param bounds bounds where to fetch suggestions from * @param filter filter - * @return observable with suggestions buffer and completes + * @return single with suggestions buffer */ - public Observable getPlaceAutocompletePredictions(final String query, final LatLngBounds bounds, final AutocompleteFilter filter) { - return getGoogleApiClientObservable(Places.PLACE_DETECTION_API, Places.GEO_DATA_API) - .flatMap(new Function>() { - @Override - public Observable apply(GoogleApiClient api) { - return fromPendingResult(Places.GeoDataApi.getAutocompletePredictions(api, query, bounds, filter)); - } - }); + public Single getPlaceAutocompletePredictions(final String query, final LatLngBounds bounds, final + AutocompleteFilter filter) { + return connectGoogleApiClient(Places.PLACE_DETECTION_API, Places.GEO_DATA_API) + .andThen(fromTask(Places.getGeoDataClient(ctx.getContext()).getAutocompletePredictions(query, bounds, filter))); } /** - * Returns observable that fetches photo metadata from the Places API using the place ID. + * Returns single that fetches photo metadata from the Places API using the place ID. + * To handle {@link com.google.android.gms.location.places.PlacePhotoMetadataResponse} you can use + * {@link DataBufferObservable}. * * @param placeId id for place - * @return observable that emits metadata buffer and completes - */ - public Observable getPhotoMetadataById(final String placeId) { - return getGoogleApiClientObservable(Places.PLACE_DETECTION_API, Places.GEO_DATA_API) - .flatMap(new Function>() { - @Override - public Observable apply(GoogleApiClient api) { - return fromPendingResult(Places.GeoDataApi.getPlacePhotos(api, placeId)); - } - }); - } - - /** - * Returns observable that fetches a placePhotoMetadata from the Places API using the place placePhotoMetadata metadata. - * Use after fetching the place placePhotoMetadata metadata with {@link ReactiveLocationProvider#getPhotoMetadataById(String)} - * - * @param placePhotoMetadata the place photo meta data - * @return observable that emits the photo result and completes + * @return single that emits metadata buffer */ - public Observable getPhotoForMetadata(final PlacePhotoMetadata placePhotoMetadata) { - return getGoogleApiClientObservable(Places.PLACE_DETECTION_API, Places.GEO_DATA_API) - .flatMap(new Function>() { - @Override - public Observable apply(GoogleApiClient api) { - return fromPendingResult(placePhotoMetadata.getPhoto(api)); - } - }); + public Single getPhotoMetadataById(final String placeId) { + return connectGoogleApiClient(Places.PLACE_DETECTION_API, Places.GEO_DATA_API) + .andThen(fromTask(Places.getGeoDataClient(ctx.getContext()).getPlacePhotos(placeId))); } /** - * Observable that emits {@link com.google.android.gms.common.api.GoogleApiClient} object after connection. + * Completable that finishes after connection. * In case of error {@link pl.charmas.android.reactivelocation2.observables.GoogleAPIConnectionException} is emmited. - * When connection to Google Play Services is suspended {@link pl.charmas.android.reactivelocation2.observables.GoogleAPIConnectionSuspendedException} - * is emitted as error. + * When connection to Google Play Services is suspended + * {@link pl.charmas.android.reactivelocation2.observables.GoogleAPIConnectionSuspendedException} is emitted as error. * Do not disconnect from apis client manually - just unsubscribe. * * @param apis collection of apis to connect to - * @return observable that emits apis client after successful connection + * @return completable completes if successful connection */ - public Observable getGoogleApiClientObservable(Api... apis) { - //noinspection unchecked - return GoogleAPIClientObservableOnSubscribe.create(ctx, factory, apis); + private Completable connectGoogleApiClient(Api... apis) { + return GoogleAPIClientObservableOnSubscribe.create(ctx, factory, apis).ignoreElements(); } /** - * Util method that wraps {@link com.google.android.gms.common.api.PendingResult} in Observable. + * Util method that wraps {@link com.google.android.gms.tasks.Task} in Single. * * @param result pending result to wrap * @param parameter type of result - * @return observable that emits pending result and completes + * @return single that emits pending result */ - public static Observable fromPendingResult(PendingResult result) { - return Observable.create(new PendingResultObservableOnSubscribe<>(result)); + private Single fromTask(Task result) { + return Single.create(new TaskSingleOnSubscribe<>(result)); } } diff --git a/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/ReactiveLocationProviderConfiguration.java b/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/ReactiveLocationProviderConfiguration.java index dc72428c..f68fc98c 100644 --- a/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/ReactiveLocationProviderConfiguration.java +++ b/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/ReactiveLocationProviderConfiguration.java @@ -1,6 +1,7 @@ package pl.charmas.android.reactivelocation2; import android.os.Handler; + import androidx.annotation.Nullable; /** diff --git a/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/BaseLocationObservableOnSubscribe.java b/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/BaseLocationObservableOnSubscribe.java deleted file mode 100644 index 86278213..00000000 --- a/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/BaseLocationObservableOnSubscribe.java +++ /dev/null @@ -1,9 +0,0 @@ -package pl.charmas.android.reactivelocation2.observables; - -import com.google.android.gms.location.LocationServices; - -public abstract class BaseLocationObservableOnSubscribe extends BaseObservableOnSubscribe { - protected BaseLocationObservableOnSubscribe(ObservableContext ctx) { - super(ctx, LocationServices.API); - } -} diff --git a/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/BaseObservableOnSubscribe.java b/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/BaseObservableOnSubscribe.java index ee933927..926e647d 100644 --- a/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/BaseObservableOnSubscribe.java +++ b/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/BaseObservableOnSubscribe.java @@ -3,7 +3,6 @@ import android.content.Context; import android.os.Bundle; import android.os.Handler; -import androidx.annotation.NonNull; import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.api.Api; @@ -12,6 +11,7 @@ import java.util.Arrays; import java.util.List; +import androidx.annotation.NonNull; import io.reactivex.ObservableEmitter; import io.reactivex.ObservableOnSubscribe; import io.reactivex.disposables.Disposables; @@ -44,7 +44,7 @@ public void subscribe(ObservableEmitter emitter) throws Exception { emitter.setDisposable(Disposables.fromAction(new Action() { @Override public void run() throws Exception { - onDisposed(apiClient); + onDisposed(); apiClient.disconnect(); } })); @@ -52,7 +52,7 @@ public void run() throws Exception { private GoogleApiClient createApiClient(ObservableEmitter emitter) { - ApiClientConnectionCallbacks apiClientConnectionCallbacks = new ApiClientConnectionCallbacks(emitter); + ApiClientConnectionCallbacks apiClientConnectionCallbacks = new ApiClientConnectionCallbacks(ctx, emitter); GoogleApiClient.Builder apiClientBuilder = new GoogleApiClient.Builder(ctx); for (Api service : services) { @@ -72,27 +72,30 @@ private GoogleApiClient createApiClient(ObservableEmitter emitter) { return apiClient; } - protected void onDisposed(GoogleApiClient locationClient) { + protected void onDisposed() { } - protected abstract void onGoogleApiClientReady(GoogleApiClient apiClient, ObservableEmitter emitter); + protected abstract void onGoogleApiClientReady(Context context, GoogleApiClient googleApiClient, ObservableEmitter emitter); private class ApiClientConnectionCallbacks implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener { + final private Context context; + final private ObservableEmitter emitter; private GoogleApiClient apiClient; - private ApiClientConnectionCallbacks(ObservableEmitter emitter) { + private ApiClientConnectionCallbacks(Context context, ObservableEmitter emitter) { + this.context = context; this.emitter = emitter; } @Override public void onConnected(Bundle bundle) { try { - onGoogleApiClientReady(apiClient, emitter); + onGoogleApiClientReady(context, apiClient, emitter); } catch (Throwable ex) { if (!emitter.isDisposed()) { emitter.onError(ex); @@ -111,7 +114,7 @@ public void onConnectionSuspended(int cause) { public void onConnectionFailed(@NonNull ConnectionResult connectionResult) { if (!emitter.isDisposed()) { emitter.onError(new GoogleAPIConnectionException("Error connecting to GoogleApiClient.", - connectionResult)); + connectionResult)); } } diff --git a/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/GoogleAPIClientObservableOnSubscribe.java b/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/GoogleAPIClientObservableOnSubscribe.java index 2a09d33e..018ed51d 100644 --- a/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/GoogleAPIClientObservableOnSubscribe.java +++ b/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/GoogleAPIClientObservableOnSubscribe.java @@ -1,15 +1,17 @@ package pl.charmas.android.reactivelocation2.observables; +import android.content.Context; + import com.google.android.gms.common.api.Api; import com.google.android.gms.common.api.GoogleApiClient; import io.reactivex.Observable; import io.reactivex.ObservableEmitter; -public class GoogleAPIClientObservableOnSubscribe extends BaseObservableOnSubscribe { +public class GoogleAPIClientObservableOnSubscribe extends BaseObservableOnSubscribe { @SafeVarargs - public static Observable create(ObservableContext context, ObservableFactory factory, Api... apis) { + public static Observable create(ObservableContext context, ObservableFactory factory, Api... apis) { return factory.createObservable(new GoogleAPIClientObservableOnSubscribe(context, apis)); } @@ -19,8 +21,8 @@ private GoogleAPIClientObservableOnSubscribe(ObservableContext ctx, Api emitter) { + protected void onGoogleApiClientReady(Context context, GoogleApiClient googleApiClient, ObservableEmitter emitter) { if (emitter.isDisposed()) return; - emitter.onNext(apiClient); + emitter.onComplete(); } } diff --git a/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/ObservableEmitterWrapper.java b/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/ObservableEmitterWrapper.java index b7c9b8d1..c2f6e41b 100644 --- a/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/ObservableEmitterWrapper.java +++ b/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/ObservableEmitterWrapper.java @@ -17,7 +17,7 @@ public void onSubscribe(Disposable d) { @Override public void onNext(T t) { - if (!emitter.isDisposed()){ + if (!emitter.isDisposed()) { emitter.onNext(t); } } diff --git a/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/PendingResultObservableOnSubscribe.java b/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/PendingResultObservableOnSubscribe.java deleted file mode 100644 index 68c048b2..00000000 --- a/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/PendingResultObservableOnSubscribe.java +++ /dev/null @@ -1,44 +0,0 @@ -package pl.charmas.android.reactivelocation2.observables; - -import androidx.annotation.NonNull; - -import com.google.android.gms.common.api.PendingResult; -import com.google.android.gms.common.api.Result; -import com.google.android.gms.common.api.ResultCallback; - -import io.reactivex.ObservableEmitter; -import io.reactivex.ObservableOnSubscribe; -import io.reactivex.disposables.Disposables; -import io.reactivex.functions.Action; - -public class PendingResultObservableOnSubscribe implements ObservableOnSubscribe { - private final PendingResult result; - private boolean complete = false; - - public PendingResultObservableOnSubscribe(PendingResult result) { - this.result = result; - } - - @Override - public void subscribe(final ObservableEmitter emitter) throws Exception { - result.setResultCallback(new ResultCallback() { - @Override - public void onResult(@NonNull T t) { - if (!emitter.isDisposed()) { - emitter.onNext(t); - emitter.onComplete(); - } - complete = true; - } - }); - - emitter.setDisposable(Disposables.fromAction(new Action() { - @Override - public void run() { - if (!complete) { - result.cancel(); - } - } - })); - } -} diff --git a/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/TaskSingleOnSubscribe.java b/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/TaskSingleOnSubscribe.java new file mode 100644 index 00000000..dde4240f --- /dev/null +++ b/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/TaskSingleOnSubscribe.java @@ -0,0 +1,36 @@ +package pl.charmas.android.reactivelocation2.observables; + +import com.google.android.gms.common.api.Response; +import com.google.android.gms.tasks.OnFailureListener; +import com.google.android.gms.tasks.OnSuccessListener; +import com.google.android.gms.tasks.Task; + +import io.reactivex.SingleEmitter; +import io.reactivex.SingleOnSubscribe; + +public class TaskSingleOnSubscribe implements SingleOnSubscribe { + private final Task task; + + public TaskSingleOnSubscribe(Task task) { + this.task = task; + } + + @Override + public void subscribe(final SingleEmitter emitter) { + task.addOnSuccessListener(new OnSuccessListener() { + @Override + public void onSuccess(T t) { + if (!emitter.isDisposed()) { + emitter.onSuccess(t); + } + } + }).addOnFailureListener(new OnFailureListener() { + @Override + public void onFailure(Exception exception) { + if (!emitter.isDisposed()) { + emitter.onError(exception); + } + } + }); + } +} diff --git a/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/activity/ActivityUpdatesObservableOnSubscribe.java b/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/activity/ActivityUpdatesObservableOnSubscribe.java index 60abc354..666fb2c1 100644 --- a/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/activity/ActivityUpdatesObservableOnSubscribe.java +++ b/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/activity/ActivityUpdatesObservableOnSubscribe.java @@ -6,8 +6,7 @@ import android.content.Intent; import android.content.IntentFilter; -import com.google.android.gms.common.api.GoogleApiClient; -import com.google.android.gms.location.ActivityRecognition; +import com.google.android.gms.location.ActivityRecognitionClient; import com.google.android.gms.location.ActivityRecognitionResult; import io.reactivex.Observable; @@ -22,6 +21,7 @@ public class ActivityUpdatesObservableOnSubscribe extends BaseActivityObservable private final Context context; private final int detectionIntervalMilliseconds; + private ActivityRecognitionClient activityRecognitionClient; private ActivityUpdatesBroadcastReceiver receiver; public static Observable createObservable(ObservableContext ctx, ObservableFactory factory, int detectionIntervalMiliseconds) { @@ -35,11 +35,13 @@ private ActivityUpdatesObservableOnSubscribe(ObservableContext context, int dete } @Override - protected void onGoogleApiClientReady(GoogleApiClient apiClient, ObservableEmitter emitter) { + protected void onActivityRecognitionClientReady(ActivityRecognitionClient activityRecognitionClient, + ObservableEmitter emitter) { + this.activityRecognitionClient = activityRecognitionClient; receiver = new ActivityUpdatesBroadcastReceiver(emitter); context.registerReceiver(receiver, new IntentFilter(ACTION_ACTIVITY_DETECTED)); PendingIntent receiverIntent = getReceiverPendingIntent(); - ActivityRecognition.ActivityRecognitionApi.requestActivityUpdates(apiClient, detectionIntervalMilliseconds, receiverIntent); + activityRecognitionClient.requestActivityUpdates(detectionIntervalMilliseconds, receiverIntent); } private PendingIntent getReceiverPendingIntent() { @@ -47,9 +49,9 @@ private PendingIntent getReceiverPendingIntent() { } @Override - protected void onDisposed(GoogleApiClient apiClient) { - if (apiClient.isConnected()) { - ActivityRecognition.ActivityRecognitionApi.removeActivityUpdates(apiClient, getReceiverPendingIntent()); + protected void onDisposed() { + if (activityRecognitionClient != null) { + activityRecognitionClient.removeActivityTransitionUpdates(getReceiverPendingIntent()); } if (receiver != null) { context.unregisterReceiver(receiver); diff --git a/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/activity/BaseActivityObservableOnSubscribe.java b/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/activity/BaseActivityObservableOnSubscribe.java index 3101ffbd..b607cde8 100644 --- a/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/activity/BaseActivityObservableOnSubscribe.java +++ b/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/activity/BaseActivityObservableOnSubscribe.java @@ -1,7 +1,12 @@ package pl.charmas.android.reactivelocation2.observables.activity; +import android.content.Context; + +import com.google.android.gms.common.api.GoogleApiClient; import com.google.android.gms.location.ActivityRecognition; +import com.google.android.gms.location.ActivityRecognitionClient; +import io.reactivex.ObservableEmitter; import pl.charmas.android.reactivelocation2.observables.BaseObservableOnSubscribe; import pl.charmas.android.reactivelocation2.observables.ObservableContext; @@ -9,4 +14,12 @@ abstract class BaseActivityObservableOnSubscribe extends BaseObservableOnSubs BaseActivityObservableOnSubscribe(ObservableContext ctx) { super(ctx, ActivityRecognition.API); } + + @Override + protected final void onGoogleApiClientReady(Context context, GoogleApiClient googleApiClient, ObservableEmitter emitter) { + onActivityRecognitionClientReady(ActivityRecognition.getClient(context), emitter); + } + + protected abstract void onActivityRecognitionClientReady(ActivityRecognitionClient activityRecognitionClient, + ObservableEmitter emitter); } diff --git a/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/geocode/GeocodeObservable.java b/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/geocode/GeocodeObservable.java index da162f97..3cc46d72 100644 --- a/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/geocode/GeocodeObservable.java +++ b/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/geocode/GeocodeObservable.java @@ -3,7 +3,6 @@ import android.content.Context; import android.location.Address; import android.location.Geocoder; -import androidx.annotation.NonNull; import com.google.android.gms.maps.model.LatLngBounds; @@ -11,6 +10,7 @@ import java.util.List; import java.util.Locale; +import androidx.annotation.NonNull; import io.reactivex.Observable; import io.reactivex.ObservableEmitter; import io.reactivex.ObservableOnSubscribe; diff --git a/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/geofence/AddGeofenceObservableOnSubscribe.java b/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/geofence/AddGeofenceObservableOnSubscribe.java index 2a5e69ca..2d1a59ec 100644 --- a/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/geofence/AddGeofenceObservableOnSubscribe.java +++ b/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/geofence/AddGeofenceObservableOnSubscribe.java @@ -1,28 +1,25 @@ package pl.charmas.android.reactivelocation2.observables.geofence; import android.app.PendingIntent; -import androidx.annotation.NonNull; -import com.google.android.gms.common.api.GoogleApiClient; -import com.google.android.gms.common.api.ResultCallback; -import com.google.android.gms.common.api.Status; +import com.google.android.gms.location.GeofencingClient; import com.google.android.gms.location.GeofencingRequest; -import com.google.android.gms.location.LocationServices; +import com.google.android.gms.tasks.OnSuccessListener; import io.reactivex.Observable; import io.reactivex.ObservableEmitter; -import pl.charmas.android.reactivelocation2.observables.BaseLocationObservableOnSubscribe; +import pl.charmas.android.reactivelocation2.BaseFailureListener; import pl.charmas.android.reactivelocation2.observables.ObservableContext; import pl.charmas.android.reactivelocation2.observables.ObservableFactory; -import pl.charmas.android.reactivelocation2.observables.StatusException; @SuppressWarnings("MissingPermission") -public class AddGeofenceObservableOnSubscribe extends BaseLocationObservableOnSubscribe { +public class AddGeofenceObservableOnSubscribe extends BaseGeofencingObservableOnSubscribe { private final GeofencingRequest request; private final PendingIntent geofenceTransitionPendingIntent; - public static Observable createObservable(ObservableContext ctx, ObservableFactory factory, GeofencingRequest request, PendingIntent geofenceTransitionPendingIntent) { + public static Observable createObservable(ObservableContext ctx, ObservableFactory factory, GeofencingRequest request, PendingIntent + geofenceTransitionPendingIntent) { return factory.createObservable(new AddGeofenceObservableOnSubscribe(ctx, request, geofenceTransitionPendingIntent)); } @@ -33,21 +30,15 @@ private AddGeofenceObservableOnSubscribe(ObservableContext ctx, GeofencingReques } @Override - protected void onGoogleApiClientReady(GoogleApiClient apiClient, final ObservableEmitter emitter) { - LocationServices.GeofencingApi.addGeofences(apiClient, request, geofenceTransitionPendingIntent) - .setResultCallback(new ResultCallback() { + protected void onGeofencingClientReady(GeofencingClient geofencingClient, final ObservableEmitter emitter) { + geofencingClient.addGeofences(request, geofenceTransitionPendingIntent) + .addOnSuccessListener(new OnSuccessListener() { @Override - public void onResult(@NonNull Status status) { - if (emitter.isDisposed()) return; - if (status.isSuccess()) { - emitter.onNext(status); - emitter.onComplete(); - - } else { - emitter.onError(new StatusException(status)); - } + public void onSuccess(Void aVoid) { + emitter.onComplete(); } - }); + }) + .addOnFailureListener(new BaseFailureListener<>(emitter)); } } diff --git a/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/geofence/BaseGeofencingObservableOnSubscribe.java b/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/geofence/BaseGeofencingObservableOnSubscribe.java new file mode 100644 index 00000000..cec42207 --- /dev/null +++ b/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/geofence/BaseGeofencingObservableOnSubscribe.java @@ -0,0 +1,26 @@ +package pl.charmas.android.reactivelocation2.observables.geofence; + +import android.content.Context; + +import com.google.android.gms.common.api.GoogleApiClient; +import com.google.android.gms.location.GeofencingClient; +import com.google.android.gms.location.LocationServices; + +import io.reactivex.ObservableEmitter; +import pl.charmas.android.reactivelocation2.observables.BaseObservableOnSubscribe; +import pl.charmas.android.reactivelocation2.observables.ObservableContext; + +public abstract class BaseGeofencingObservableOnSubscribe extends BaseObservableOnSubscribe { + + protected BaseGeofencingObservableOnSubscribe(ObservableContext ctx) { + super(ctx, LocationServices.API); + } + + @Override + protected final void onGoogleApiClientReady(Context context, GoogleApiClient googleApiClient, ObservableEmitter emitter) { + onGeofencingClientReady(LocationServices.getGeofencingClient(context), emitter); + } + + protected abstract void onGeofencingClientReady(GeofencingClient geofencingClient, + ObservableEmitter emitter); +} diff --git a/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/geofence/RemoveGeofenceByPendingIntentObservableOnSubscribe.java b/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/geofence/RemoveGeofenceByPendingIntentObservableOnSubscribe.java index 0e814d44..52daa1b4 100644 --- a/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/geofence/RemoveGeofenceByPendingIntentObservableOnSubscribe.java +++ b/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/geofence/RemoveGeofenceByPendingIntentObservableOnSubscribe.java @@ -1,19 +1,16 @@ package pl.charmas.android.reactivelocation2.observables.geofence; import android.app.PendingIntent; -import androidx.annotation.NonNull; -import com.google.android.gms.common.api.GoogleApiClient; -import com.google.android.gms.common.api.ResultCallback; -import com.google.android.gms.common.api.Status; -import com.google.android.gms.location.LocationServices; +import com.google.android.gms.location.GeofencingClient; +import com.google.android.gms.tasks.OnSuccessListener; import io.reactivex.ObservableEmitter; +import pl.charmas.android.reactivelocation2.BaseFailureListener; import pl.charmas.android.reactivelocation2.observables.ObservableContext; -import pl.charmas.android.reactivelocation2.observables.StatusException; -class RemoveGeofenceByPendingIntentObservableOnSubscribe extends RemoveGeofenceObservableOnSubscribe { +class RemoveGeofenceByPendingIntentObservableOnSubscribe extends BaseGeofencingObservableOnSubscribe { private final PendingIntent pendingIntent; RemoveGeofenceByPendingIntentObservableOnSubscribe(ObservableContext ctx, PendingIntent pendingIntent) { @@ -22,19 +19,14 @@ class RemoveGeofenceByPendingIntentObservableOnSubscribe extends RemoveGeofenceO } @Override - protected void removeGeofences(GoogleApiClient locationClient, final ObservableEmitter emitter) { - LocationServices.GeofencingApi.removeGeofences(locationClient, pendingIntent) - .setResultCallback(new ResultCallback() { + protected void onGeofencingClientReady(GeofencingClient geofencingClient, final ObservableEmitter emitter) { + geofencingClient.removeGeofences(pendingIntent) + .addOnSuccessListener(new OnSuccessListener() { @Override - public void onResult(@NonNull Status status) { - if (emitter.isDisposed()) return; - if (status.isSuccess()) { - emitter.onNext(status); - emitter.onComplete(); - } else { - emitter.onError(new StatusException(status)); - } + public void onSuccess(Void aVoid) { + emitter.onComplete(); } - }); + }) + .addOnFailureListener(new BaseFailureListener<>(emitter)); } } diff --git a/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/geofence/RemoveGeofenceObservableOnSubscribe.java b/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/geofence/RemoveGeofenceObservableOnSubscribe.java index a5c4db0d..c2f77a0d 100644 --- a/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/geofence/RemoveGeofenceObservableOnSubscribe.java +++ b/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/geofence/RemoveGeofenceObservableOnSubscribe.java @@ -2,25 +2,23 @@ import android.app.PendingIntent; -import com.google.android.gms.common.api.GoogleApiClient; -import com.google.android.gms.common.api.Status; +import com.google.android.gms.location.GeofencingClient; import java.util.List; import io.reactivex.Observable; import io.reactivex.ObservableEmitter; -import pl.charmas.android.reactivelocation2.observables.BaseLocationObservableOnSubscribe; import pl.charmas.android.reactivelocation2.observables.ObservableContext; import pl.charmas.android.reactivelocation2.observables.ObservableFactory; -public abstract class RemoveGeofenceObservableOnSubscribe extends BaseLocationObservableOnSubscribe { +public abstract class RemoveGeofenceObservableOnSubscribe extends BaseGeofencingObservableOnSubscribe { - public static Observable createObservable(ObservableContext ctx, ObservableFactory factory, PendingIntent pendingIntent) { + public static Observable createObservable(ObservableContext ctx, ObservableFactory factory, PendingIntent pendingIntent) { return factory.createObservable(new RemoveGeofenceByPendingIntentObservableOnSubscribe(ctx, pendingIntent)); } - public static Observable createObservable(ObservableContext ctx, ObservableFactory factory, List requestIds) { + public static Observable createObservable(ObservableContext ctx, ObservableFactory factory, List requestIds) { return factory.createObservable(new RemoveGeofenceRequestIdsObservableOnSubscribe(ctx, requestIds)); } @@ -29,10 +27,10 @@ public static Observable createObservable(ObservableContext ctx, Observa } @Override - protected void onGoogleApiClientReady(GoogleApiClient apiClient, final ObservableEmitter emitter) { - removeGeofences(apiClient, emitter); + protected void onGeofencingClientReady(GeofencingClient geofencingClient, final ObservableEmitter emitter) { + removeGeofences(geofencingClient, emitter); } - protected abstract void removeGeofences(GoogleApiClient locationClient, ObservableEmitter emitter); + protected abstract void removeGeofences(GeofencingClient geofencingClient, ObservableEmitter emitter); } diff --git a/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/geofence/RemoveGeofenceRequestIdsObservableOnSubscribe.java b/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/geofence/RemoveGeofenceRequestIdsObservableOnSubscribe.java index 0037d9be..6045ff4e 100644 --- a/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/geofence/RemoveGeofenceRequestIdsObservableOnSubscribe.java +++ b/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/geofence/RemoveGeofenceRequestIdsObservableOnSubscribe.java @@ -1,20 +1,16 @@ package pl.charmas.android.reactivelocation2.observables.geofence; -import androidx.annotation.NonNull; - -import com.google.android.gms.common.api.GoogleApiClient; -import com.google.android.gms.common.api.ResultCallback; -import com.google.android.gms.common.api.Status; -import com.google.android.gms.location.LocationServices; +import com.google.android.gms.location.GeofencingClient; +import com.google.android.gms.tasks.OnSuccessListener; import java.util.List; import io.reactivex.ObservableEmitter; +import pl.charmas.android.reactivelocation2.BaseFailureListener; import pl.charmas.android.reactivelocation2.observables.ObservableContext; -import pl.charmas.android.reactivelocation2.observables.StatusException; -class RemoveGeofenceRequestIdsObservableOnSubscribe extends RemoveGeofenceObservableOnSubscribe { +class RemoveGeofenceRequestIdsObservableOnSubscribe extends RemoveGeofenceObservableOnSubscribe { private final List geofenceRequestIds; RemoveGeofenceRequestIdsObservableOnSubscribe(ObservableContext ctx, List geofenceRequestIds) { @@ -23,19 +19,14 @@ class RemoveGeofenceRequestIdsObservableOnSubscribe extends RemoveGeofenceObserv } @Override - protected void removeGeofences(GoogleApiClient locationClient, final ObservableEmitter emitter) { - LocationServices.GeofencingApi.removeGeofences(locationClient, geofenceRequestIds) - .setResultCallback(new ResultCallback() { + protected void removeGeofences(GeofencingClient geofencingClient, final ObservableEmitter emitter) { + geofencingClient.removeGeofences(geofenceRequestIds) + .addOnSuccessListener(new OnSuccessListener() { @Override - public void onResult(@NonNull Status status) { - if (emitter.isDisposed()) return; - if (status.isSuccess()) { - emitter.onNext(status); - emitter.onComplete(); - } else { - emitter.onError(new StatusException(status)); - } + public void onSuccess(Void aVoid) { + emitter.onComplete(); } - }); + }) + .addOnFailureListener(new BaseFailureListener<>(emitter)); } } diff --git a/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/location/AddLocationIntentUpdatesObservableOnSubscribe.java b/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/location/AddLocationIntentUpdatesObservableOnSubscribe.java index 2f4d60e5..e86e7fb2 100644 --- a/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/location/AddLocationIntentUpdatesObservableOnSubscribe.java +++ b/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/location/AddLocationIntentUpdatesObservableOnSubscribe.java @@ -1,28 +1,25 @@ package pl.charmas.android.reactivelocation2.observables.location; import android.app.PendingIntent; -import androidx.annotation.NonNull; -import com.google.android.gms.common.api.GoogleApiClient; -import com.google.android.gms.common.api.ResultCallback; -import com.google.android.gms.common.api.Status; +import com.google.android.gms.location.FusedLocationProviderClient; import com.google.android.gms.location.LocationRequest; -import com.google.android.gms.location.LocationServices; +import com.google.android.gms.tasks.OnSuccessListener; import io.reactivex.Observable; import io.reactivex.ObservableEmitter; -import pl.charmas.android.reactivelocation2.observables.BaseLocationObservableOnSubscribe; +import pl.charmas.android.reactivelocation2.BaseFailureListener; import pl.charmas.android.reactivelocation2.observables.ObservableContext; import pl.charmas.android.reactivelocation2.observables.ObservableFactory; -import pl.charmas.android.reactivelocation2.observables.StatusException; @SuppressWarnings("MissingPermission") -public class AddLocationIntentUpdatesObservableOnSubscribe extends BaseLocationObservableOnSubscribe { +public class AddLocationIntentUpdatesObservableOnSubscribe extends BaseLocationObservableOnSubscribe { private final LocationRequest locationRequest; private final PendingIntent intent; - public static Observable createObservable(ObservableContext ctx, ObservableFactory factory, LocationRequest locationRequest, PendingIntent intent) { + public static Observable createObservable(ObservableContext ctx, ObservableFactory factory, LocationRequest locationRequest, + PendingIntent intent) { return factory.createObservable(new AddLocationIntentUpdatesObservableOnSubscribe(ctx, locationRequest, intent)); } @@ -33,20 +30,16 @@ private AddLocationIntentUpdatesObservableOnSubscribe(ObservableContext ctx, Loc } @Override - protected void onGoogleApiClientReady(GoogleApiClient apiClient, final ObservableEmitter emitter) { - LocationServices.FusedLocationApi.requestLocationUpdates(apiClient, locationRequest, intent) - .setResultCallback(new ResultCallback() { + protected void onLocationProviderClientReady(FusedLocationProviderClient locationProviderClient, + final ObservableEmitter emitter) { + locationProviderClient.requestLocationUpdates(locationRequest, intent) + .addOnSuccessListener(new OnSuccessListener() { @Override - public void onResult(@NonNull Status status) { + public void onSuccess(Void aVoid) { if (emitter.isDisposed()) return; - if (!status.isSuccess()) { - emitter.onError(new StatusException(status)); - } else { - emitter.onNext(status); - emitter.onComplete(); - } + emitter.onComplete(); } - }); - + }) + .addOnFailureListener(new BaseFailureListener<>(emitter)); } } diff --git a/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/location/BaseLocationObservableOnSubscribe.java b/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/location/BaseLocationObservableOnSubscribe.java new file mode 100644 index 00000000..9744fe27 --- /dev/null +++ b/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/location/BaseLocationObservableOnSubscribe.java @@ -0,0 +1,26 @@ +package pl.charmas.android.reactivelocation2.observables.location; + +import android.content.Context; + +import com.google.android.gms.common.api.GoogleApiClient; +import com.google.android.gms.location.FusedLocationProviderClient; +import com.google.android.gms.location.LocationServices; + +import io.reactivex.ObservableEmitter; +import pl.charmas.android.reactivelocation2.observables.BaseObservableOnSubscribe; +import pl.charmas.android.reactivelocation2.observables.ObservableContext; + +public abstract class BaseLocationObservableOnSubscribe extends BaseObservableOnSubscribe { + + protected BaseLocationObservableOnSubscribe(ObservableContext ctx) { + super(ctx, LocationServices.API); + } + + @Override + protected final void onGoogleApiClientReady(Context context, GoogleApiClient googleApiClient, ObservableEmitter emitter) { + onLocationProviderClientReady(LocationServices.getFusedLocationProviderClient(context), emitter); + } + + protected abstract void onLocationProviderClientReady(FusedLocationProviderClient locationProviderClient, + ObservableEmitter emitter); +} diff --git a/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/location/LastKnownLocationObservableOnSubscribe.java b/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/location/LastKnownLocationObservableOnSubscribe.java index 3a6fef6a..ca0baadc 100644 --- a/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/location/LastKnownLocationObservableOnSubscribe.java +++ b/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/location/LastKnownLocationObservableOnSubscribe.java @@ -2,17 +2,18 @@ import android.location.Location; -import com.google.android.gms.common.api.GoogleApiClient; -import com.google.android.gms.location.LocationServices; +import com.google.android.gms.location.FusedLocationProviderClient; +import com.google.android.gms.tasks.OnSuccessListener; import io.reactivex.Observable; import io.reactivex.ObservableEmitter; -import pl.charmas.android.reactivelocation2.observables.BaseLocationObservableOnSubscribe; +import pl.charmas.android.reactivelocation2.BaseFailureListener; import pl.charmas.android.reactivelocation2.observables.ObservableContext; import pl.charmas.android.reactivelocation2.observables.ObservableFactory; @SuppressWarnings("MissingPermission") public class LastKnownLocationObservableOnSubscribe extends BaseLocationObservableOnSubscribe { + public static Observable createObservable(ObservableContext ctx, ObservableFactory factory) { return factory.createObservable(new LastKnownLocationObservableOnSubscribe(ctx)); } @@ -22,12 +23,19 @@ private LastKnownLocationObservableOnSubscribe(ObservableContext ctx) { } @Override - protected void onGoogleApiClientReady(GoogleApiClient apiClient, ObservableEmitter emitter) { - Location location = LocationServices.FusedLocationApi.getLastLocation(apiClient); - if (emitter.isDisposed()) return; - if (location != null) { - emitter.onNext(location); - } - emitter.onComplete(); + protected void onLocationProviderClientReady(FusedLocationProviderClient locationProviderClient, + final ObservableEmitter emitter) { + locationProviderClient.getLastLocation() + .addOnSuccessListener(new OnSuccessListener() { + @Override + public void onSuccess(Location location) { + if (emitter.isDisposed()) return; + if (location != null) { + emitter.onNext(location); + } + emitter.onComplete(); + } + }) + .addOnFailureListener(new BaseFailureListener<>(emitter)); } } diff --git a/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/location/LocationUpdatesObservableOnSubscribe.java b/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/location/LocationUpdatesObservableOnSubscribe.java index 5b0c0254..047c9e9d 100644 --- a/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/location/LocationUpdatesObservableOnSubscribe.java +++ b/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/location/LocationUpdatesObservableOnSubscribe.java @@ -2,16 +2,19 @@ import android.location.Location; -import com.google.android.gms.common.api.GoogleApiClient; -import com.google.android.gms.location.LocationListener; +import com.google.android.gms.location.FusedLocationProviderClient; +import com.google.android.gms.location.LocationAvailability; +import com.google.android.gms.location.LocationCallback; import com.google.android.gms.location.LocationRequest; -import com.google.android.gms.location.LocationServices; +import com.google.android.gms.location.LocationResult; +import com.google.android.gms.tasks.Task; import java.lang.ref.WeakReference; import io.reactivex.Observable; import io.reactivex.ObservableEmitter; -import pl.charmas.android.reactivelocation2.observables.BaseLocationObservableOnSubscribe; +import pl.charmas.android.reactivelocation2.BaseFailureListener; +import pl.charmas.android.reactivelocation2.LocationNotAvailableException; import pl.charmas.android.reactivelocation2.observables.ObservableContext; import pl.charmas.android.reactivelocation2.observables.ObservableFactory; @@ -28,7 +31,8 @@ public static Observable createObservable(ObservableContext ctx, Obser } private final LocationRequest locationRequest; - private LocationListener listener; + private FusedLocationProviderClient fusedLocationProviderClient; + private LocationCallback listener; private LocationUpdatesObservableOnSubscribe(ObservableContext ctx, LocationRequest locationRequest) { super(ctx); @@ -36,19 +40,22 @@ private LocationUpdatesObservableOnSubscribe(ObservableContext ctx, LocationRequ } @Override - protected void onGoogleApiClientReady(GoogleApiClient apiClient, final ObservableEmitter emitter) { + protected void onLocationProviderClientReady(FusedLocationProviderClient locationProviderClient, + final ObservableEmitter emitter) { + fusedLocationProviderClient = locationProviderClient; listener = new LocationUpdatesLocationListener(emitter); - LocationServices.FusedLocationApi.requestLocationUpdates(apiClient, locationRequest, listener); + Task task = locationProviderClient.requestLocationUpdates(locationRequest, listener, null); + task.addOnFailureListener(new BaseFailureListener(emitter)); } @Override - protected void onDisposed(GoogleApiClient locationClient) { - if (locationClient.isConnected()) { - LocationServices.FusedLocationApi.removeLocationUpdates(locationClient, listener); + protected void onDisposed() { + if (fusedLocationProviderClient != null) { + fusedLocationProviderClient.removeLocationUpdates(listener); } } - private static class LocationUpdatesLocationListener implements LocationListener { + private static class LocationUpdatesLocationListener extends LocationCallback { private final WeakReference> weakRef; LocationUpdatesLocationListener(ObservableEmitter emitter) { @@ -56,10 +63,23 @@ private static class LocationUpdatesLocationListener implements LocationListener } @Override - public void onLocationChanged(Location location) { + public void onLocationResult(LocationResult locationResult) { final ObservableEmitter observer = weakRef.get(); if (observer != null && !observer.isDisposed()) { - observer.onNext(location); + for (Location location : locationResult.getLocations()) { + observer.onNext(location); + } + } + } + + @Override + public void onLocationAvailability(LocationAvailability locationAvailability) { + super.onLocationAvailability(locationAvailability); + if (!locationAvailability.isLocationAvailable()) { + final ObservableEmitter observer = weakRef.get(); + if (observer != null && !observer.isDisposed()) { + observer.onError(new LocationNotAvailableException()); + } } } } diff --git a/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/location/MockLocationObservableOnSubscribe.java b/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/location/MockLocationObservableOnSubscribe.java index cfd389ad..8b02cdef 100644 --- a/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/location/MockLocationObservableOnSubscribe.java +++ b/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/location/MockLocationObservableOnSubscribe.java @@ -1,29 +1,26 @@ package pl.charmas.android.reactivelocation2.observables.location; import android.location.Location; -import androidx.annotation.NonNull; -import com.google.android.gms.common.api.GoogleApiClient; -import com.google.android.gms.common.api.ResultCallback; -import com.google.android.gms.common.api.Status; -import com.google.android.gms.location.LocationServices; +import com.google.android.gms.location.FusedLocationProviderClient; +import com.google.android.gms.tasks.OnSuccessListener; import io.reactivex.Observable; import io.reactivex.ObservableEmitter; import io.reactivex.disposables.Disposable; import io.reactivex.functions.Action; import io.reactivex.functions.Consumer; -import pl.charmas.android.reactivelocation2.observables.BaseLocationObservableOnSubscribe; +import pl.charmas.android.reactivelocation2.BaseFailureListener; import pl.charmas.android.reactivelocation2.observables.ObservableContext; import pl.charmas.android.reactivelocation2.observables.ObservableFactory; -import pl.charmas.android.reactivelocation2.observables.StatusException; @SuppressWarnings("MissingPermission") -public class MockLocationObservableOnSubscribe extends BaseLocationObservableOnSubscribe { +public class MockLocationObservableOnSubscribe extends BaseLocationObservableOnSubscribe { private final Observable locationObservable; + private FusedLocationProviderClient fusedLocationProviderClient; private Disposable mockLocationSubscription; - public static Observable createObservable(ObservableContext context, ObservableFactory factory, Observable locationObservable) { + public static Observable createObservable(ObservableContext context, ObservableFactory factory, Observable locationObservable) { return factory.createObservable(new MockLocationObservableOnSubscribe(context, locationObservable)); } @@ -33,50 +30,38 @@ private MockLocationObservableOnSubscribe(ObservableContext ctx, Observable emitter) { - // this throws SecurityException if permissions are bad or mock locations are not enabled, - // which is passed to observer's onError by BaseObservable - LocationServices.FusedLocationApi.setMockMode(apiClient, true) - .setResultCallback(new ResultCallback() { + protected void onLocationProviderClientReady(final FusedLocationProviderClient locationProviderClient, + final ObservableEmitter emitter) { + fusedLocationProviderClient = locationProviderClient; + locationProviderClient.setMockMode(true) + .addOnSuccessListener(new OnSuccessListener() { @Override - public void onResult(@NonNull Status status) { - if (status.isSuccess()) { - startLocationMocking(apiClient, emitter); - } else { - emitter.onError(new StatusException(status)); - } + public void onSuccess(Void aVoid) { + startLocationMocking(locationProviderClient, emitter); } - }); + }) + .addOnFailureListener(new BaseFailureListener<>(emitter)); } - private void startLocationMocking(final GoogleApiClient apiClient, final ObservableEmitter emitter) { + private void startLocationMocking(final FusedLocationProviderClient locationProviderClient, final ObservableEmitter emitter) { mockLocationSubscription = locationObservable .subscribe(new Consumer() { @Override - public void accept(Location location) throws Exception { - LocationServices.FusedLocationApi.setMockLocation(apiClient, location) - .setResultCallback(new ResultCallback() { - @Override - public void onResult(@NonNull Status status) { - if (status.isSuccess()) { - emitter.onNext(status); - } else { - emitter.onError(new StatusException(status)); - } - } - }); + public void accept(Location location) { + locationProviderClient.setMockLocation(location) + .addOnFailureListener(new BaseFailureListener<>(emitter)); } }, new Consumer() { @Override - public void accept(Throwable throwable) throws Exception { + public void accept(Throwable throwable) { emitter.onError(throwable); } }, new Action() { @Override - public void run() throws Exception { + public void run() { emitter.onComplete(); } }); @@ -84,14 +69,9 @@ public void run() throws Exception { } @Override - protected void onDisposed(GoogleApiClient locationClient) { - if (locationClient.isConnected()) { - try { - LocationServices.FusedLocationApi.setMockMode(locationClient, false); - } catch (SecurityException e) { - // if this happens then we couldn't have switched mock mode on in the first place, - // and the observer's onError will already have been called - } + protected void onDisposed() { + if (fusedLocationProviderClient != null) { + fusedLocationProviderClient.setMockMode(false); } if (mockLocationSubscription != null && !mockLocationSubscription.isDisposed()) { mockLocationSubscription.dispose(); diff --git a/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/location/RemoveLocationIntentUpdatesObservableOnSubscribe.java b/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/location/RemoveLocationIntentUpdatesObservableOnSubscribe.java index ddf8351b..ca722e25 100644 --- a/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/location/RemoveLocationIntentUpdatesObservableOnSubscribe.java +++ b/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/location/RemoveLocationIntentUpdatesObservableOnSubscribe.java @@ -1,25 +1,21 @@ package pl.charmas.android.reactivelocation2.observables.location; import android.app.PendingIntent; -import androidx.annotation.NonNull; -import com.google.android.gms.common.api.GoogleApiClient; -import com.google.android.gms.common.api.ResultCallback; -import com.google.android.gms.common.api.Status; -import com.google.android.gms.location.LocationServices; +import com.google.android.gms.location.FusedLocationProviderClient; +import com.google.android.gms.tasks.OnSuccessListener; import io.reactivex.Observable; import io.reactivex.ObservableEmitter; -import pl.charmas.android.reactivelocation2.observables.BaseLocationObservableOnSubscribe; +import pl.charmas.android.reactivelocation2.BaseFailureListener; import pl.charmas.android.reactivelocation2.observables.ObservableContext; import pl.charmas.android.reactivelocation2.observables.ObservableFactory; -import pl.charmas.android.reactivelocation2.observables.StatusException; -public class RemoveLocationIntentUpdatesObservableOnSubscribe extends BaseLocationObservableOnSubscribe { +public class RemoveLocationIntentUpdatesObservableOnSubscribe extends BaseLocationObservableOnSubscribe { private final PendingIntent intent; - public static Observable createObservable(ObservableContext ctx, ObservableFactory factory, PendingIntent intent) { + public static Observable createObservable(ObservableContext ctx, ObservableFactory factory, PendingIntent intent) { return factory.createObservable(new RemoveLocationIntentUpdatesObservableOnSubscribe(ctx, intent)); } @@ -29,19 +25,16 @@ private RemoveLocationIntentUpdatesObservableOnSubscribe(ObservableContext ctx, } @Override - protected void onGoogleApiClientReady(GoogleApiClient apiClient, final ObservableEmitter emitter) { - LocationServices.FusedLocationApi.removeLocationUpdates(apiClient, intent) - .setResultCallback(new ResultCallback() { + protected void onLocationProviderClientReady(FusedLocationProviderClient locationProviderClient, + final ObservableEmitter emitter) { + locationProviderClient.removeLocationUpdates(intent) + .addOnSuccessListener(new OnSuccessListener() { @Override - public void onResult(@NonNull Status status) { + public void onSuccess(Void aVoid) { if (emitter.isDisposed()) return; - if (status.isSuccess()) { - emitter.onNext(status); - emitter.onComplete(); - } else { - emitter.onError(new StatusException(status)); - } + emitter.onComplete(); } - }); + }) + .addOnFailureListener(new BaseFailureListener<>(emitter)); } } diff --git a/sample/src/main/java/pl/charmas/android/reactivelocation2/sample/GeofenceActivity.java b/sample/src/main/java/pl/charmas/android/reactivelocation2/sample/GeofenceActivity.java index 51d498bb..d1f1ace8 100755 --- a/sample/src/main/java/pl/charmas/android/reactivelocation2/sample/GeofenceActivity.java +++ b/sample/src/main/java/pl/charmas/android/reactivelocation2/sample/GeofenceActivity.java @@ -13,8 +13,11 @@ import com.google.android.gms.location.Geofence; import com.google.android.gms.location.GeofencingRequest; +import io.reactivex.CompletableObserver; +import io.reactivex.CompletableSource; import io.reactivex.Observable; import io.reactivex.disposables.Disposable; +import io.reactivex.functions.Action; import io.reactivex.functions.Consumer; import io.reactivex.functions.Function; import pl.charmas.android.reactivelocation2.ReactiveLocationProvider; @@ -77,9 +80,10 @@ protected void onStop() { private void clearGeofence() { reactiveLocationProvider .removeGeofences(createNotificationBroadcastPendingIntent()) - .subscribe(new Consumer() { + .subscribe(new Action() { + @Override - public void accept(Status status) throws Exception { + public void run() throws Exception { toast("Geofences removed"); } }, new Consumer() { @@ -107,17 +111,11 @@ private void addGeofence() { reactiveLocationProvider .removeGeofences(pendingIntent) - .flatMap(new Function>() { - @Override - public Observable apply(Status status) throws Exception { - return reactiveLocationProvider.addGeofences(pendingIntent, geofencingRequest); - } - - }) - .subscribe(new Consumer() { + .concatWith(reactiveLocationProvider.addGeofences(pendingIntent, geofencingRequest)) + .subscribe(new Action() { @Override - public void accept(Status addGeofenceResult) { - toast("Geofence added, success: " + addGeofenceResult.isSuccess()); + public void run() throws Exception { + toast("Geofence added, success"); } }, new Consumer() { @Override diff --git a/sample/src/main/java/pl/charmas/android/reactivelocation2/sample/MainActivity.java b/sample/src/main/java/pl/charmas/android/reactivelocation2/sample/MainActivity.java index 6ab3f2b9..3bb6c182 100755 --- a/sample/src/main/java/pl/charmas/android/reactivelocation2/sample/MainActivity.java +++ b/sample/src/main/java/pl/charmas/android/reactivelocation2/sample/MainActivity.java @@ -1,7 +1,6 @@ package pl.charmas.android.reactivelocation2.sample; import android.content.Intent; -import android.content.IntentSender; import android.location.Address; import android.location.Location; import android.os.Bundle; @@ -12,17 +11,17 @@ import android.widget.TextView; import android.widget.Toast; -import com.google.android.gms.common.api.Status; +import com.google.android.gms.common.api.ResolvableApiException; import com.google.android.gms.location.ActivityRecognitionResult; import com.google.android.gms.location.LocationRequest; import com.google.android.gms.location.LocationSettingsRequest; -import com.google.android.gms.location.LocationSettingsResult; +import com.google.android.gms.location.LocationSettingsResponse; import com.google.android.gms.location.LocationSettingsStates; -import com.google.android.gms.location.LocationSettingsStatusCodes; import java.util.List; import io.reactivex.Observable; +import io.reactivex.Single; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.Disposable; import io.reactivex.functions.Consumer; @@ -48,7 +47,7 @@ public class MainActivity extends BaseActivity { private TextView addressLocationView; private TextView currentActivityView; - private Observable lastKnownLocationObservable; + private Single lastKnownLocationObservable; private Observable locationUpdatesObservable; private Observable activityObservable; @@ -89,32 +88,31 @@ protected void onCreate(Bundle savedInstanceState) { .setAlwaysShow(true) //Refrence: http://stackoverflow.com/questions/29824408/google-play-services-locationservices-api-new-option-never .build() ) - .doOnNext(new Consumer() { + .doOnError(new Consumer() { @Override - public void accept(LocationSettingsResult locationSettingsResult) { - Status status = locationSettingsResult.getStatus(); - if (status.getStatusCode() == LocationSettingsStatusCodes.RESOLUTION_REQUIRED) { - try { - status.startResolutionForResult(MainActivity.this, REQUEST_CHECK_SETTINGS); - } catch (IntentSender.SendIntentException th) { - Log.e("MainActivity", "Error opening settings activity.", th); - } + public void accept(Throwable throwable) throws Exception { + if (throwable instanceof ResolvableApiException) { + // Cast to a resolvable exception. + ResolvableApiException resolvable = (ResolvableApiException) throwable; + // Show the dialog by calling startResolutionForResult(), + // and check the result in onActivityResult(). + resolvable.startResolutionForResult(MainActivity.this, REQUEST_CHECK_SETTINGS); } } }) - .flatMap(new Function>() { + .flatMapObservable(new Function>() { @Override - public Observable apply(LocationSettingsResult locationSettingsResult) { + public Observable apply(LocationSettingsResponse locationSettingsResponse) { return locationProvider.getUpdatedLocation(locationRequest); } }) .observeOn(AndroidSchedulers.mainThread()); addressObservable = locationProvider.getUpdatedLocation(locationRequest) - .flatMap(new Function>>() { + .flatMapSingle(new Function>>() { @Override - public Observable> apply(Location location) { - return locationProvider.getReverseGeocodeObservable(location.getLatitude(), location.getLongitude(), 1); + public Single> apply(Location location) { + return locationProvider.reverseGeocode(location.getLatitude(), location.getLongitude(), 1); } }) .map(new Function, Address>() { @@ -128,7 +126,7 @@ public Address apply(List

addresses) { .observeOn(AndroidSchedulers.mainThread()); activityObservable = locationProvider - .getDetectedActivity(50) + .detectedActivity(50) .observeOn(AndroidSchedulers.mainThread()); } diff --git a/sample/src/main/java/pl/charmas/android/reactivelocation2/sample/MockLocationsActivity.java b/sample/src/main/java/pl/charmas/android/reactivelocation2/sample/MockLocationsActivity.java index f37c087c..40f038ed 100755 --- a/sample/src/main/java/pl/charmas/android/reactivelocation2/sample/MockLocationsActivity.java +++ b/sample/src/main/java/pl/charmas/android/reactivelocation2/sample/MockLocationsActivity.java @@ -6,7 +6,6 @@ import android.os.Build; import android.os.Bundle; import android.os.SystemClock; -import androidx.core.app.ActivityCompat; import android.util.Log; import android.view.View; import android.widget.Button; @@ -16,14 +15,14 @@ import android.widget.Toast; import android.widget.ToggleButton; -import com.google.android.gms.common.api.Status; import com.google.android.gms.location.LocationRequest; import java.util.Date; +import androidx.core.app.ActivityCompat; import io.reactivex.Observable; import io.reactivex.disposables.Disposable; -import io.reactivex.functions.BiFunction; +import io.reactivex.functions.Action; import io.reactivex.functions.Consumer; import io.reactivex.functions.Function; import io.reactivex.subjects.PublishSubject; @@ -45,6 +44,7 @@ public class MockLocationsActivity extends BaseActivity { private ReactiveLocationProvider locationProvider; private Observable mockLocationObservable; + private Disposable mockDisposable; private Disposable mockLocationDisposable; private Disposable updatedLocationDisposable; @@ -94,7 +94,8 @@ protected void onLocationPermissionGranted() { .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY) .setInterval(2000); - if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { + if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && + ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { return; } @@ -126,19 +127,28 @@ private void setMockMode(boolean toggle) { return; } - mockLocationDisposable = - Observable.zip(locationProvider.mockLocation(mockLocationObservable), - mockLocationObservable, new BiFunction() { - int count = 0; - - @Override - public String apply(Status result, Location location) { - return new LocationToStringFunc().apply(location) + " " + count++; - } - }) - .subscribe(new DisplayTextOnViewAction(mockLocationView), new ErrorHandler()); + + mockDisposable = locationProvider.mockLocation(mockLocationObservable).subscribe(new Action() { + @Override + public void run() { + } + }, new Consumer() { + @Override + public void accept(Throwable throwable) { + throwable.printStackTrace(); + } + }); + mockLocationDisposable = mockLocationObservable.map(new Function() { + int count = 0; + + @Override + public String apply(Location location) { + return new LocationToStringFunc().apply(location) + " " + count++; + } + }).subscribe(new DisplayTextOnViewAction(mockLocationView), new ErrorHandler()); } else { mockLocationDisposable.dispose(); + mockDisposable.dispose(); } } diff --git a/sample/src/main/java/pl/charmas/android/reactivelocation2/sample/PlacesActivity.java b/sample/src/main/java/pl/charmas/android/reactivelocation2/sample/PlacesActivity.java index 26966661..dc639905 100755 --- a/sample/src/main/java/pl/charmas/android/reactivelocation2/sample/PlacesActivity.java +++ b/sample/src/main/java/pl/charmas/android/reactivelocation2/sample/PlacesActivity.java @@ -12,9 +12,9 @@ import android.widget.TextView; import com.google.android.gms.location.places.AutocompletePrediction; -import com.google.android.gms.location.places.AutocompletePredictionBuffer; +import com.google.android.gms.location.places.AutocompletePredictionBufferResponse; import com.google.android.gms.location.places.PlaceLikelihood; -import com.google.android.gms.location.places.PlaceLikelihoodBuffer; +import com.google.android.gms.location.places.PlaceLikelihoodBufferResponse; import com.google.android.gms.maps.model.LatLng; import com.google.android.gms.maps.model.LatLngBounds; @@ -22,7 +22,10 @@ import java.util.List; import java.util.concurrent.TimeUnit; +import io.reactivex.Maybe; +import io.reactivex.MaybeSource; import io.reactivex.Observable; +import io.reactivex.Single; import io.reactivex.disposables.CompositeDisposable; import io.reactivex.functions.BiFunction; import io.reactivex.functions.Consumer; @@ -64,14 +67,14 @@ protected void onLocationPermissionGranted() { compositeDisposable = new CompositeDisposable(); compositeDisposable.add( reactiveLocationProvider.getCurrentPlace(null) - .subscribe(new Consumer() { + .subscribe(new Consumer() { @Override - public void accept(PlaceLikelihoodBuffer buffer) { - PlaceLikelihood likelihood = buffer.get(0); + public void accept(PlaceLikelihoodBufferResponse response) throws Exception { + PlaceLikelihood likelihood = response.get(0); if (likelihood != null) { currentPlaceView.setText(likelihood.getPlace().getName()); } - buffer.release(); + response.release(); } }, new Consumer() { @Override @@ -96,18 +99,19 @@ public boolean test(String s) { return !TextUtils.isEmpty(s); } }); - Observable lastKnownLocationObservable = reactiveLocationProvider.getLastKnownLocation(); - Observable suggestionsObservable = Observable - .combineLatest(queryObservable, lastKnownLocationObservable, + Single lastKnownLocationObservable = reactiveLocationProvider.getLastKnownLocation(); + Observable suggestionsObservable = Observable + .combineLatest(queryObservable, lastKnownLocationObservable.toObservable(), new BiFunction() { @Override public QueryWithCurrentLocation apply(String query, Location currentLocation) { return new QueryWithCurrentLocation(query, currentLocation); } - }).flatMap(new Function>() { + }) + .flatMapMaybe(new Function>() { @Override - public Observable apply(QueryWithCurrentLocation q) { - if (q.location == null) return Observable.empty(); + public MaybeSource apply(QueryWithCurrentLocation q) { + if (q.location == null) return Maybe.empty(); double latitude = q.location.getLatitude(); double longitude = q.location.getLongitude(); @@ -115,13 +119,13 @@ public Observable apply(QueryWithCurrentLocation q new LatLng(latitude - 0.05, longitude - 0.05), new LatLng(latitude + 0.05, longitude + 0.05) ); - return reactiveLocationProvider.getPlaceAutocompletePredictions(q.query, bounds, null); + return reactiveLocationProvider.getPlaceAutocompletePredictions(q.query, bounds, null).toMaybe(); } }); - compositeDisposable.add(suggestionsObservable.subscribe(new Consumer() { + compositeDisposable.add(suggestionsObservable.subscribe(new Consumer() { @Override - public void accept(AutocompletePredictionBuffer buffer) { + public void accept(AutocompletePredictionBufferResponse buffer) { List infos = new ArrayList<>(); for (AutocompletePrediction prediction : buffer) { infos.add(new AutocompleteInfo(prediction.getFullText(null).toString(), prediction.getPlaceId())); diff --git a/sample/src/main/java/pl/charmas/android/reactivelocation2/sample/PlacesResultActivity.java b/sample/src/main/java/pl/charmas/android/reactivelocation2/sample/PlacesResultActivity.java index 4c9b01b5..fff05180 100755 --- a/sample/src/main/java/pl/charmas/android/reactivelocation2/sample/PlacesResultActivity.java +++ b/sample/src/main/java/pl/charmas/android/reactivelocation2/sample/PlacesResultActivity.java @@ -3,12 +3,12 @@ import android.content.Context; import android.content.Intent; import android.os.Bundle; -import androidx.annotation.NonNull; import android.widget.TextView; import com.google.android.gms.location.places.Place; -import com.google.android.gms.location.places.PlaceBuffer; +import com.google.android.gms.location.places.PlaceBufferResponse; +import androidx.annotation.NonNull; import io.reactivex.disposables.CompositeDisposable; import io.reactivex.functions.Consumer; import pl.charmas.android.reactivelocation2.ReactiveLocationProvider; @@ -60,16 +60,16 @@ private void getPlaceIdFromIntent() { protected void onLocationPermissionGranted() { compositeSubscription = new CompositeDisposable(); compositeSubscription.add(reactiveLocationProvider.getPlaceById(placeId) - .subscribe(new Consumer() { + .subscribe(new Consumer() { @Override - public void accept(PlaceBuffer buffer) { - Place place = buffer.get(0); + public void accept(PlaceBufferResponse response) { + Place place = response.get(0); if (place != null) { placeNameView.setText(place.getName()); placeLocationView.setText(place.getLatLng().latitude + ", " + place.getLatLng().longitude); placeAddressView.setText(place.getAddress()); } - buffer.release(); + response.release(); } })); } From 23228b70845d0d5ece8634a0f88e285f0ce2c657 Mon Sep 17 00:00:00 2001 From: Laszlo Modis Date: Thu, 25 Oct 2018 17:47:06 +0300 Subject: [PATCH 3/6] Removing build tools version --- android-reactive-location/build.gradle | 1 - build.gradle | 1 - sample/build.gradle | 1 - 3 files changed, 3 deletions(-) diff --git a/android-reactive-location/build.gradle b/android-reactive-location/build.gradle index 03a48a2b..07089d9d 100644 --- a/android-reactive-location/build.gradle +++ b/android-reactive-location/build.gradle @@ -3,7 +3,6 @@ apply plugin: 'maven' android { compileSdkVersion rootProject.ext.compileSdkVersion - buildToolsVersion rootProject.ext.buildToolsVersion defaultConfig { minSdkVersion 14 diff --git a/build.gradle b/build.gradle index ed248b30..0d9fdb57 100644 --- a/build.gradle +++ b/build.gradle @@ -16,7 +16,6 @@ buildscript { ext { compileSdkVersion = 28 targetSdkVersion = 28 - buildToolsVersion = "25.0.3" } def isReleaseBuild() { diff --git a/sample/build.gradle b/sample/build.gradle index de71f894..7f731ed1 100755 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -9,7 +9,6 @@ def getGooglePlayServicesApiKey() { android { compileSdkVersion rootProject.ext.compileSdkVersion - buildToolsVersion rootProject.ext.buildToolsVersion defaultConfig { minSdkVersion 14 From cd4ac2bae0861bc3538b1450e0351e24cfeef8e2 Mon Sep 17 00:00:00 2001 From: Laszlo Modis Date: Thu, 25 Oct 2018 17:48:03 +0300 Subject: [PATCH 4/6] Adding empty REACTIVE_LOCATION_GMS_API_KEY --- gradle.properties | 3 +++ 1 file changed, 3 insertions(+) diff --git a/gradle.properties b/gradle.properties index e91cb4d9..e90878d6 100644 --- a/gradle.properties +++ b/gradle.properties @@ -13,5 +13,8 @@ POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt POM_LICENCE_DIST=repo POM_DEVELOPER_ID=mcharmas POM_DEVELOPER_NAME=Michal Charmas + +REACTIVE_LOCATION_GMS_API_KEY= + android.useAndroidX=true android.enableJetifier=true From 81414cba70a6babc8a2a47c6d9298eb3e129c1e4 Mon Sep 17 00:00:00 2001 From: robertbakk Date: Wed, 26 Apr 2023 17:03:53 +0300 Subject: [PATCH 5/6] updated play services libraries --- android-reactive-location/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/android-reactive-location/build.gradle b/android-reactive-location/build.gradle index 07089d9d..9f03d52b 100644 --- a/android-reactive-location/build.gradle +++ b/android-reactive-location/build.gradle @@ -18,8 +18,8 @@ android { //TODO: local maven deployment dependencies { - api 'com.google.android.gms:play-services-location:16.0.0' - api 'com.google.android.gms:play-services-places:16.0.0' + api 'com.google.android.gms:play-services-location:21.0.1' + api 'com.google.android.gms:play-services-places:17.0.0' api 'io.reactivex.rxjava2:rxjava:2.2.0' } From 3f0141ad33479972625f6a966a316017e2c3b56a Mon Sep 17 00:00:00 2001 From: Laszlo Modis Date: Thu, 18 Jul 2024 16:52:13 +0300 Subject: [PATCH 6/6] Update gradle and libraries --- android-reactive-location/build.gradle | 54 ++++---- .../src/main/AndroidManifest.xml | 2 +- .../ActivityUpdatesObservableOnSubscribe.java | 2 +- build.gradle | 16 +-- gradle.properties | 18 +-- gradle/wrapper/gradle-wrapper.properties | 4 +- maven_push.gradle | 115 ------------------ sample/build.gradle | 21 ++-- sample/src/main/AndroidManifest.xml | 27 ++-- 9 files changed, 72 insertions(+), 187 deletions(-) delete mode 100644 maven_push.gradle diff --git a/android-reactive-location/build.gradle b/android-reactive-location/build.gradle index 9f03d52b..27ab5610 100644 --- a/android-reactive-location/build.gradle +++ b/android-reactive-location/build.gradle @@ -1,41 +1,43 @@ apply plugin: 'com.android.library' -apply plugin: 'maven' +apply plugin: 'maven-publish' android { - compileSdkVersion rootProject.ext.compileSdkVersion + namespace 'pl.charmas.android.reactivelocation2' + compileSdk rootProject.ext.compileSdkVersion defaultConfig { - minSdkVersion 14 + minSdkVersion 21 targetSdkVersion rootProject.ext.targetSdkVersion } compileOptions { - sourceCompatibility JavaVersion.VERSION_1_7 - targetCompatibility JavaVersion.VERSION_1_7 + sourceCompatibility JavaVersion.VERSION_17 + targetCompatibility JavaVersion.VERSION_17 } -} -//TODO: local maven deployment + publishing { + singleVariant("release") { + withSourcesJar() + withJavadocJar() + } + } +} dependencies { - api 'com.google.android.gms:play-services-location:21.0.1' - api 'com.google.android.gms:play-services-places:17.0.0' - api 'io.reactivex.rxjava2:rxjava:2.2.0' + api 'com.google.android.gms:play-services-location:21.3.0' + api 'com.google.android.gms:play-services-places:17.1.0' + api 'io.reactivex.rxjava2:rxjava:2.2.21' } -// Comment this to deploy to local maven repository -apply from: '../maven_push.gradle' - - -//TODO: clean up -//This is for local maven deployment - -//apply plugin: 'maven' -//uploadArchives { -// repositories { -// mavenDeployer { -// repository url: 'file://' + new File(System.getProperty('user.home'), '.m2/repository').absolutePath -// } -// } -//} -//task install(dependsOn: uploadArchives) +afterEvaluate { + publishing { + publications { + register("gpr", MavenPublication) { + from(components["release"]) + groupId = GROUP + artifactId = 'android-reactive-location2' + version = VERSION_NAME + } + } + } +} \ No newline at end of file diff --git a/android-reactive-location/src/main/AndroidManifest.xml b/android-reactive-location/src/main/AndroidManifest.xml index cd701d43..ca4ef6c0 100644 --- a/android-reactive-location/src/main/AndroidManifest.xml +++ b/android-reactive-location/src/main/AndroidManifest.xml @@ -1,5 +1,5 @@ - + diff --git a/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/activity/ActivityUpdatesObservableOnSubscribe.java b/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/activity/ActivityUpdatesObservableOnSubscribe.java index 666fb2c1..66a8b1da 100644 --- a/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/activity/ActivityUpdatesObservableOnSubscribe.java +++ b/android-reactive-location/src/main/java/pl/charmas/android/reactivelocation2/observables/activity/ActivityUpdatesObservableOnSubscribe.java @@ -45,7 +45,7 @@ protected void onActivityRecognitionClientReady(ActivityRecognitionClient activi } private PendingIntent getReceiverPendingIntent() { - return PendingIntent.getBroadcast(context, 0, new Intent(ACTION_ACTIVITY_DETECTED), PendingIntent.FLAG_UPDATE_CURRENT); + return PendingIntent.getBroadcast(context, 0, new Intent(ACTION_ACTIVITY_DETECTED), PendingIntent.FLAG_IMMUTABLE | PendingIntent.FLAG_UPDATE_CURRENT); } @Override diff --git a/build.gradle b/build.gradle index 0d9fdb57..2f2e1fee 100644 --- a/build.gradle +++ b/build.gradle @@ -3,32 +3,24 @@ buildscript { repositories { mavenCentral() - jcenter() google() } + dependencies { - classpath 'com.android.tools.build:gradle:3.2.1' + classpath 'com.android.tools.build:gradle:8.5.1' } } // To avoid manually setting the same values in all Android modules, set the value on the root // project and then reference this from the modules ext { - compileSdkVersion = 28 - targetSdkVersion = 28 -} - -def isReleaseBuild() { - return version.contains("SNAPSHOT") == false + compileSdkVersion = 34 + targetSdkVersion = 34 } allprojects { - version = VERSION_NAME - group = GROUP - repositories { mavenCentral() - jcenter() google() maven { url 'https://jitpack.io' } } diff --git a/gradle.properties b/gradle.properties index e90878d6..1c766bcd 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,20 +1,10 @@ -VERSION_NAME=2.1 -VERSION_CODE=102 +VERSION_NAME=3.0 +VERSION_CODE=103 GROUP=pl.charmas.android - -POM_DESCRIPTION=Small library that wraps Google Play Service API in brilliant RxJava Observables reducing boilerplate to minimum. -POM_URL=https://github.com/mcharmas/Android-ReactiveLocation -POM_SCM_URL=https://github.com/mcharmas/Android-ReactiveLocation -POM_SCM_CONNECTION=scm:git@github.com:mcharmas/Android-ReactiveLocation.git -POM_SCM_DEV_CONNECTION=scm:git@github.com:mcharmas/Android-ReactiveLocation.git -POM_LICENCE_NAME=The Apache Software License, Version 2.0 -POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt -POM_LICENCE_DIST=repo -POM_DEVELOPER_ID=mcharmas -POM_DEVELOPER_NAME=Michal Charmas - REACTIVE_LOCATION_GMS_API_KEY= android.useAndroidX=true android.enableJetifier=true +android.nonTransitiveRClass=false +android.nonFinalResIds=false diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 4b585d29..e81e8870 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Thu Oct 25 12:29:40 EEST 2018 +#Thu Jul 18 16:33:36 EEST 2024 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip diff --git a/maven_push.gradle b/maven_push.gradle deleted file mode 100644 index 712abf68..00000000 --- a/maven_push.gradle +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Copyright 2013 Chris Banes - * - * 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. - */ - -apply plugin: 'maven' -apply plugin: 'signing' - -def isReleaseBuild() { - return VERSION_NAME.contains("SNAPSHOT") == false -} - -def getReleaseRepositoryUrl() { - return hasProperty('RELEASE_REPOSITORY_URL') ? RELEASE_REPOSITORY_URL - : "https://oss.sonatype.org/service/local/staging/deploy/maven2/" -} - -def getSnapshotRepositoryUrl() { - return hasProperty('SNAPSHOT_REPOSITORY_URL') ? SNAPSHOT_REPOSITORY_URL - : "https://oss.sonatype.org/content/repositories/snapshots/" -} - -def getRepositoryUsername() { - return hasProperty('NEXUS_USERNAME') ? NEXUS_USERNAME : "" -} - -def getRepositoryPassword() { - return hasProperty('NEXUS_PASSWORD') ? NEXUS_PASSWORD : "" -} - -afterEvaluate { project -> - uploadArchives { - repositories { - mavenDeployer { - beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) } - - pom.groupId = GROUP - pom.artifactId = POM_ARTIFACT_ID - pom.version = VERSION_NAME - - repository(url: getReleaseRepositoryUrl()) { - authentication(userName: getRepositoryUsername(), password: getRepositoryPassword()) - } - snapshotRepository(url: getSnapshotRepositoryUrl()) { - authentication(userName: getRepositoryUsername(), password: getRepositoryPassword()) - } - - pom.project { - name POM_NAME - packaging POM_PACKAGING - description POM_DESCRIPTION - url POM_URL - - scm { - url POM_SCM_URL - connection POM_SCM_CONNECTION - developerConnection POM_SCM_DEV_CONNECTION - } - - licenses { - license { - name POM_LICENCE_NAME - url POM_LICENCE_URL - distribution POM_LICENCE_DIST - } - } - - developers { - developer { - id POM_DEVELOPER_ID - name POM_DEVELOPER_NAME - } - } - } - } - } - } - - signing { - required { isReleaseBuild() && gradle.taskGraph.hasTask("uploadArchives") } - sign configurations.archives - } - - task androidJavadocs(type: Javadoc) { - source = android.sourceSets.main.java.srcDirs - classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) - failOnError = false - } - - task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) { - classifier = 'javadoc' - from androidJavadocs.destinationDir - } - - task androidSourcesJar(type: Jar) { - classifier = 'sources' - from android.sourceSets.main.java.sourceFiles - } - - artifacts { - archives androidSourcesJar - archives androidJavadocsJar - } -} diff --git a/sample/build.gradle b/sample/build.gradle index 7f731ed1..5f776908 100755 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -8,34 +8,39 @@ def getGooglePlayServicesApiKey() { } android { - compileSdkVersion rootProject.ext.compileSdkVersion + namespace 'pl.charmas.android.reactivelocation2.sample' + compileSdk rootProject.ext.compileSdkVersion defaultConfig { - minSdkVersion 14 + minSdkVersion 21 targetSdkVersion rootProject.ext.targetSdkVersion + versionName project.VERSION_NAME versionCode Integer.parseInt(project.VERSION_CODE) + resValue "string", "API_KEY", getGooglePlayServicesApiKey() } compileOptions { - sourceCompatibility JavaVersion.VERSION_1_7 - targetCompatibility JavaVersion.VERSION_1_7 + sourceCompatibility JavaVersion.VERSION_17 + targetCompatibility JavaVersion.VERSION_17 } + buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt' } } - lintOptions { + + lint { abortOnError false } } dependencies { - implementation 'androidx.appcompat:appcompat:1.0.0' - implementation 'io.reactivex.rxjava2:rxandroid:2.0.2' + implementation 'androidx.appcompat:appcompat:1.7.0' + implementation 'io.reactivex.rxjava2:rxandroid:2.1.1' implementation 'com.github.tbruyelle:rxpermissions:0.10.2' - compile project(':android-reactive-location') + implementation project(':android-reactive-location') } diff --git a/sample/src/main/AndroidManifest.xml b/sample/src/main/AndroidManifest.xml index c7122be9..9e585128 100644 --- a/sample/src/main/AndroidManifest.xml +++ b/sample/src/main/AndroidManifest.xml @@ -1,10 +1,10 @@ + xmlns:tools="http://schemas.android.com/tools"> - @@ -24,6 +24,7 @@ @@ -32,15 +33,25 @@ - + - + - + - + - +