Skip to content

Commit d363617

Browse files
committed
Android: rename interfaces to avoid name conflicts
1 parent ed73508 commit d363617

File tree

5 files changed

+34
-34
lines changed

5 files changed

+34
-34
lines changed

android/src/main/java/com/agontuk/RNFusedLocation/FusedLocationManager.java renamed to android/src/main/java/com/agontuk/RNFusedLocation/FusedLocationProvider.java

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,21 @@
2828

2929
import java.util.Random;
3030

31-
public class FusedLocationManager implements LocationManager {
31+
public class FusedLocationProvider implements LocationProvider {
3232
private final ReactApplicationContext context;
3333
private final FusedLocationProviderClient fusedLocationProviderClient;
3434
private final SettingsClient settingsClient;
3535

3636
private int activityRequestCode;
37+
private LocationChangeListener locationChangeListener;
3738
private LocationOptions locationOptions;
38-
private LocationListener locationListener;
3939
private LocationRequest locationRequest;
4040

4141
private boolean isSingleUpdate = false;
4242
private final LocationCallback locationCallback = new LocationCallback() {
4343
@Override
4444
public void onLocationResult(LocationResult locationResult) {
45-
locationListener.onLocationChange(locationResult.getLastLocation());
45+
locationChangeListener.onLocationChange(locationResult.getLastLocation());
4646

4747
if (isSingleUpdate) {
4848
timeoutHandler.removeCallbacks(timeoutRunnable);
@@ -55,7 +55,7 @@ public void onLocationAvailability(LocationAvailability locationAvailability) {
5555
if (!locationAvailability.isLocationAvailable() &&
5656
!LocationUtils.isLocationEnabled(context)
5757
) {
58-
locationListener.onLocationError(
58+
locationChangeListener.onLocationError(
5959
LocationError.POSITION_UNAVAILABLE,
6060
"Unable to retrieve location."
6161
);
@@ -66,22 +66,22 @@ public void onLocationAvailability(LocationAvailability locationAvailability) {
6666
private final Runnable timeoutRunnable = new Runnable() {
6767
@Override
6868
public void run() {
69-
locationListener.onLocationError(LocationError.TIMEOUT, null);
69+
locationChangeListener.onLocationError(LocationError.TIMEOUT, null);
7070
fusedLocationProviderClient.removeLocationUpdates(locationCallback);
7171
}
7272
};
7373

74-
public FusedLocationManager(ReactApplicationContext context) {
74+
public FusedLocationProvider(ReactApplicationContext context) {
7575
this.context = context;
7676
this.fusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(context);
7777
this.settingsClient = LocationServices.getSettingsClient(context);
7878
}
7979

8080
@SuppressLint("MissingPermission")
8181
@Override
82-
public void getCurrentLocation(final LocationOptions locationOptions, final LocationListener locationListener) {
82+
public void getCurrentLocation(final LocationOptions locationOptions, final LocationChangeListener locationChangeListener) {
8383
this.isSingleUpdate = true;
84-
this.locationListener = locationListener;
84+
this.locationChangeListener = locationChangeListener;
8585
this.locationOptions = locationOptions;
8686
this.locationRequest = buildLocationRequest(locationOptions);
8787

@@ -93,7 +93,7 @@ public void onSuccess(Location location) {
9393
(System.currentTimeMillis() - location.getTime()) < locationOptions.getMaximumAge()
9494
) {
9595
Log.i(RNFusedLocationModule.TAG, "returning cached location.");
96-
locationListener.onLocationChange(location);
96+
locationChangeListener.onLocationChange(location);
9797
return;
9898
}
9999

@@ -126,16 +126,16 @@ public boolean onActivityResult(int requestCode, int resultCode) {
126126
startLocationUpdates();
127127
} else {
128128
LocationError error = !forceRequestLocation ? LocationError.SETTINGS_NOT_SATISFIED : LocationError.POSITION_UNAVAILABLE;
129-
locationListener.onLocationError(error, null);
129+
locationChangeListener.onLocationError(error, null);
130130
}
131131

132132
return true;
133133
}
134134

135135
@Override
136-
public void requestLocationUpdates(LocationOptions locationOptions, final LocationListener locationListener) {
136+
public void requestLocationUpdates(LocationOptions locationOptions, final LocationChangeListener locationChangeListener) {
137137
this.isSingleUpdate = false;
138-
this.locationListener = locationListener;
138+
this.locationChangeListener = locationChangeListener;
139139
this.locationOptions = locationOptions;
140140
this.locationRequest = buildLocationRequest(locationOptions);
141141
checkLocationSettings();
@@ -178,7 +178,7 @@ public void onFailure(@NonNull Exception e) {
178178
switch (exception.getStatusCode()) {
179179
case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
180180
if (!locationOptions.isShowLocationDialog()) {
181-
locationListener.onLocationError(LocationError.SETTINGS_NOT_SATISFIED, null);
181+
locationChangeListener.onLocationError(LocationError.SETTINGS_NOT_SATISFIED, null);
182182
break;
183183
}
184184

@@ -187,7 +187,7 @@ public void onFailure(@NonNull Exception e) {
187187
Activity activity = context.getCurrentActivity();
188188

189189
if (activity == null) {
190-
locationListener.onLocationError(
190+
locationChangeListener.onLocationError(
191191
LocationError.INTERNAL_ERROR,
192192
"Tried to open location dialog while not attached to an Activity."
193193
);
@@ -197,9 +197,9 @@ public void onFailure(@NonNull Exception e) {
197197
activityRequestCode = getActivityRequestCode();
198198
resolvable.startResolutionForResult(activity, activityRequestCode);
199199
} catch (IntentSender.SendIntentException sie) {
200-
locationListener.onLocationError(LocationError.INTERNAL_ERROR, null);
200+
locationChangeListener.onLocationError(LocationError.INTERNAL_ERROR, null);
201201
} catch (ClassCastException cce) {
202-
locationListener.onLocationError(LocationError.INTERNAL_ERROR, null);
202+
locationChangeListener.onLocationError(LocationError.INTERNAL_ERROR, null);
203203
}
204204

205205
break;
@@ -211,7 +211,7 @@ public void onFailure(@NonNull Exception e) {
211211
break;
212212
}
213213
default:
214-
locationListener.onLocationError(LocationError.SETTINGS_NOT_SATISFIED, null);
214+
locationChangeListener.onLocationError(LocationError.SETTINGS_NOT_SATISFIED, null);
215215
break;
216216
}
217217
}

android/src/main/java/com/agontuk/RNFusedLocation/LocationListener.java renamed to android/src/main/java/com/agontuk/RNFusedLocation/LocationChangeListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import androidx.annotation.Nullable;
66

7-
public interface LocationListener {
7+
public interface LocationChangeListener {
88
void onLocationChange(Location location);
99

1010
void onLocationError(LocationError error, @Nullable String message);

android/src/main/java/com/agontuk/RNFusedLocation/AndroidLocationManager.java renamed to android/src/main/java/com/agontuk/RNFusedLocation/LocationManagerProvider.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package com.agontuk.RNFusedLocation;
22

3-
public class AndroidLocationManager implements LocationManager {
4-
public AndroidLocationManager() {
3+
public class LocationManagerProvider implements LocationProvider {
4+
public LocationManagerProvider() {
55
//
66
}
77

88
@Override
9-
public void getCurrentLocation(LocationOptions locationOptions, LocationListener locationListener) {
9+
public void getCurrentLocation(LocationOptions locationOptions, LocationChangeListener locationChangeListener) {
1010
//
1111
}
1212

@@ -16,7 +16,7 @@ public boolean onActivityResult(int requestCode, int resultCode) {
1616
}
1717

1818
@Override
19-
public void requestLocationUpdates(LocationOptions locationOptions, LocationListener locationListener) {
19+
public void requestLocationUpdates(LocationOptions locationOptions, LocationChangeListener listener) {
2020
//
2121
}
2222

Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package com.agontuk.RNFusedLocation;
22

3-
public interface LocationManager {
4-
void getCurrentLocation(LocationOptions locationOptions, LocationListener locationListener);
3+
public interface LocationProvider {
4+
void getCurrentLocation(LocationOptions locationOptions, LocationChangeListener locationChangeListener);
55

66
boolean onActivityResult(int requestCode, int resultCode);
77

8-
void requestLocationUpdates(LocationOptions locationOptions, LocationListener locationListener);
8+
void requestLocationUpdates(LocationOptions locationOptions, LocationChangeListener locationChangeListener);
99

1010
void removeLocationUpdates();
1111
}

android/src/main/java/com/agontuk/RNFusedLocation/RNFusedLocationModule.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@
1919

2020
public class RNFusedLocationModule extends ReactContextBaseJavaModule implements ActivityEventListener {
2121
public static final String TAG = "RNFusedLocation";
22-
private final LocationManager locationManager;
22+
private final LocationProvider locationProvider;
2323

2424
public RNFusedLocationModule(ReactApplicationContext reactContext) {
2525
super(reactContext);
2626

2727
reactContext.addActivityEventListener(this);
28-
this.locationManager = createLocationManager();
28+
this.locationProvider = createLocationProvider();
2929

3030
Log.i(TAG, TAG + " initialized");
3131
}
@@ -38,7 +38,7 @@ public String getName() {
3838

3939
@Override
4040
public void onActivityResult(Activity activity, int requestCode, int resultCode, Intent data) {
41-
locationManager.onActivityResult(requestCode, resultCode);
41+
locationProvider.onActivityResult(requestCode, resultCode);
4242
}
4343

4444
@Override
@@ -57,7 +57,7 @@ public void getCurrentPosition(ReadableMap options, final Callback success, fina
5757

5858
LocationOptions locationOptions = LocationOptions.fromReadableMap(options);
5959

60-
locationManager.getCurrentLocation(locationOptions, new LocationListener() {
60+
locationProvider.getCurrentLocation(locationOptions, new LocationChangeListener() {
6161
@Override
6262
public void onLocationChange(Location location) {
6363
success.invoke(LocationUtils.locationToMap(location));
@@ -84,7 +84,7 @@ public void startObserving(ReadableMap options) {
8484

8585
LocationOptions locationOptions = LocationOptions.fromReadableMap(options);
8686

87-
locationManager.requestLocationUpdates(locationOptions, new LocationListener() {
87+
locationProvider.requestLocationUpdates(locationOptions, new LocationChangeListener() {
8888
@Override
8989
public void onLocationChange(Location location) {
9090
emitEvent("geolocationDidChange", LocationUtils.locationToMap(location));
@@ -99,17 +99,17 @@ public void onLocationError(LocationError error, @Nullable String message) {
9999

100100
@ReactMethod
101101
public void stopObserving() {
102-
locationManager.removeLocationUpdates();
102+
locationProvider.removeLocationUpdates();
103103
}
104104

105-
private LocationManager createLocationManager() {
105+
private LocationProvider createLocationProvider() {
106106
ReactApplicationContext context = getContext();
107107

108108
if (LocationUtils.isGooglePlayServicesAvailable(context)) {
109-
return new FusedLocationManager(getContext());
109+
return new FusedLocationProvider(getContext());
110110
}
111111

112-
return new AndroidLocationManager();
112+
return new LocationManagerProvider();
113113
}
114114

115115
private void emitEvent(String eventName, WritableMap data) {

0 commit comments

Comments
 (0)