Skip to content

Commit 96a64a8

Browse files
committed
Add Geo Rx Bindings
1 parent e4c5c7d commit 96a64a8

File tree

6 files changed

+502
-2
lines changed

6 files changed

+502
-2
lines changed

.idea/codeStyles/Project.xml

Lines changed: 7 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rxbindings/build.gradle

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@
1313
* permissions and limitations under the License.
1414
*/
1515

16-
apply plugin: 'com.android.library'
16+
plugins {
17+
id "com.android.library"
18+
id "kotlin-android"
19+
}
20+
1721
apply from: rootProject.file("configuration/checkstyle.gradle")
1822
apply from: rootProject.file("configuration/publishing.gradle")
1923

@@ -26,6 +30,7 @@ dependencies {
2630
testImplementation project(path: ':testutils')
2731
testImplementation dependency.junit
2832
testImplementation dependency.mockito
33+
testImplementation dependency.mockk
2934
testImplementation dependency.androidx.test.core
3035
testImplementation dependency.robolectric
3136
testImplementation project(path: ':rxbindings')

rxbindings/src/main/java/com/amplifyframework/rx/RxAmplify.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ private RxAmplify() {}
4141
@SuppressWarnings({"checkstyle:all"}) public static final RxHubCategoryBehavior Hub = new RxHubBinding();
4242
@SuppressWarnings({"checkstyle:all"}) public static final RxDataStoreCategoryBehavior DataStore = new RxDataStoreBinding();
4343
@SuppressWarnings({"checkstyle:all"}) public static final RxPredictionsCategoryBehavior Predictions = new RxPredictionsBinding();
44+
@SuppressWarnings({"checkstyle:all"}) public static final RxGeoCategoryBehavior Geo = new RxGeoBinding();
4445

4546
/**
4647
* Read the configuration from amplifyconfiguration.json file.
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/*
2+
* Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
package com.amplifyframework.rx;
17+
18+
import androidx.annotation.NonNull;
19+
import androidx.annotation.VisibleForTesting;
20+
21+
import com.amplifyframework.core.Amplify;
22+
import com.amplifyframework.geo.GeoCategoryBehavior;
23+
import com.amplifyframework.geo.GeoException;
24+
import com.amplifyframework.geo.models.Coordinates;
25+
import com.amplifyframework.geo.models.MapStyle;
26+
import com.amplifyframework.geo.models.MapStyleDescriptor;
27+
import com.amplifyframework.geo.options.GeoSearchByCoordinatesOptions;
28+
import com.amplifyframework.geo.options.GeoSearchByTextOptions;
29+
import com.amplifyframework.geo.options.GetMapStyleDescriptorOptions;
30+
import com.amplifyframework.geo.result.GeoSearchResult;
31+
32+
import java.util.Collection;
33+
import java.util.Objects;
34+
35+
import io.reactivex.rxjava3.core.Single;
36+
37+
final class RxGeoBinding implements RxGeoCategoryBehavior {
38+
private final GeoCategoryBehavior delegate;
39+
40+
RxGeoBinding() {
41+
delegate = Amplify.Geo;
42+
}
43+
44+
@VisibleForTesting
45+
RxGeoBinding(@NonNull GeoCategoryBehavior delegate) {
46+
this.delegate = Objects.requireNonNull(delegate);
47+
}
48+
49+
@Override
50+
public Single<Collection<MapStyle>> getAvailableMaps() {
51+
return toSingle(delegate::getAvailableMaps);
52+
}
53+
54+
@Override
55+
public Single<MapStyle> getDefaultMap() {
56+
return toSingle(delegate::getDefaultMap);
57+
}
58+
59+
@Override
60+
public Single<MapStyleDescriptor> getMapStyleDescriptor() {
61+
return toSingle(delegate::getMapStyleDescriptor);
62+
}
63+
64+
@Override
65+
public Single<MapStyleDescriptor> getMapStyleDescriptor(@NonNull GetMapStyleDescriptorOptions options) {
66+
return toSingle((onResult, onError) -> delegate.getMapStyleDescriptor(options, onResult, onError));
67+
}
68+
69+
@Override
70+
public Single<GeoSearchResult> searchByText(@NonNull String query) {
71+
return toSingle((onResult, onError) -> delegate.searchByText(query, onResult, onError));
72+
}
73+
74+
@Override
75+
public Single<GeoSearchResult> searchByText(@NonNull String query, @NonNull GeoSearchByTextOptions options) {
76+
return toSingle((onResult, onError) -> delegate.searchByText(query, options, onResult, onError));
77+
}
78+
79+
@Override
80+
public Single<GeoSearchResult> searchByCoordinates(@NonNull Coordinates position) {
81+
return toSingle((onResult, onError) -> delegate.searchByCoordinates(position, onResult, onError));
82+
}
83+
84+
@Override
85+
public Single<GeoSearchResult> searchByCoordinates(
86+
@NonNull Coordinates position,
87+
@NonNull GeoSearchByCoordinatesOptions options
88+
) {
89+
return toSingle((onResult, onError) -> delegate.searchByCoordinates(position, options, onResult, onError));
90+
}
91+
92+
private static <T> Single<T> toSingle(RxAdapters.VoidBehaviors.ResultEmitter<T, GeoException> behavior) {
93+
return RxAdapters.VoidBehaviors.toSingle(behavior);
94+
}
95+
}
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
/*
2+
* Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
package com.amplifyframework.rx;
17+
18+
import androidx.annotation.NonNull;
19+
20+
import com.amplifyframework.geo.GeoCategoryBehavior;
21+
import com.amplifyframework.geo.GeoException;
22+
import com.amplifyframework.geo.models.Coordinates;
23+
import com.amplifyframework.geo.models.MapStyle;
24+
import com.amplifyframework.geo.models.MapStyleDescriptor;
25+
import com.amplifyframework.geo.options.GeoSearchByCoordinatesOptions;
26+
import com.amplifyframework.geo.options.GeoSearchByTextOptions;
27+
import com.amplifyframework.geo.options.GetMapStyleDescriptorOptions;
28+
import com.amplifyframework.geo.result.GeoSearchResult;
29+
30+
import java.util.Collection;
31+
32+
import io.reactivex.rxjava3.core.Single;
33+
34+
/**
35+
* An Rx-idiomatic expression of the behaviors in {@link GeoCategoryBehavior}.
36+
*/
37+
public interface RxGeoCategoryBehavior {
38+
/**
39+
* Gets a collection of maps and their corresponding styles.
40+
*
41+
* @return An Rx {@link Single} which emits a {@link MapStyle} on success, or a
42+
* {@link GeoException} on failure
43+
*/
44+
Single<Collection<MapStyle>> getAvailableMaps();
45+
46+
/**
47+
* Gets the default map and style from available maps.
48+
*
49+
* @return An Rx {@link Single} which emits a {@link MapStyle} on success, or a
50+
* {@link GeoException} on failure
51+
*/
52+
Single<MapStyle> getDefaultMap();
53+
54+
/**
55+
* Uses default options to get map style descriptor JSON.
56+
*
57+
* @return An Rx {@link Single} which emits a {@link MapStyleDescriptor} on success, or a
58+
* {@link GeoException} on failure
59+
*/
60+
Single<MapStyleDescriptor> getMapStyleDescriptor();
61+
62+
/**
63+
* Uses given options to get map style descriptor JSON.
64+
*
65+
* @param options Options to specify for this operation.
66+
* @return An Rx {@link Single} which emits a {@link MapStyleDescriptor} on success, or a
67+
* {@link GeoException} on failure
68+
*/
69+
Single<MapStyleDescriptor> getMapStyleDescriptor(@NonNull GetMapStyleDescriptorOptions options);
70+
71+
/**
72+
* Searches for locations that match text query.
73+
*
74+
* @param query Search query text.
75+
* @return An Rx {@link Single} which emits a {@link GeoSearchResult} on success, or a
76+
* {@link GeoException} on failure
77+
*/
78+
Single<GeoSearchResult> searchByText(@NonNull String query);
79+
80+
/**
81+
* Searches for locations that match text query.
82+
*
83+
* @param query Search query text.
84+
* @param options Search options to use.
85+
* @return An Rx {@link Single} which emits a {@link GeoSearchResult} on success, or a
86+
* {@link GeoException} on failure
87+
*/
88+
Single<GeoSearchResult> searchByText(
89+
@NonNull String query,
90+
@NonNull GeoSearchByTextOptions options
91+
);
92+
93+
/**
94+
* Searches for location with given set of coordinates.
95+
*
96+
* @param position Coordinates to look-up.
97+
* @return An Rx {@link Single} which emits a {@link GeoSearchResult} on success, or a
98+
* {@link GeoException} on failure
99+
*/
100+
Single<GeoSearchResult> searchByCoordinates(@NonNull Coordinates position);
101+
102+
/**
103+
* Searches for location with given set of coordinates.
104+
*
105+
* @param position Coordinates to look-up.
106+
* @param options Search options to use.
107+
* @return An Rx {@link Single} which emits a {@link GeoSearchResult} on success, or a
108+
* {@link GeoException} on failure
109+
*/
110+
Single<GeoSearchResult> searchByCoordinates(
111+
@NonNull Coordinates position,
112+
@NonNull GeoSearchByCoordinatesOptions options
113+
);
114+
}

0 commit comments

Comments
 (0)