mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-29 05:43:55 +01:00
make location manager singleton
This commit is contained in:
parent
d4bafd94e0
commit
a59bf1bc4b
2 changed files with 14 additions and 3 deletions
|
|
@ -7,6 +7,7 @@ import android.location.LocationListener;
|
|||
import android.location.LocationManager;
|
||||
import android.os.Bundle;
|
||||
|
||||
import fr.free.nrw.commons.CommonsApplication;
|
||||
import timber.log.Timber;
|
||||
|
||||
public class LocationServiceManager implements LocationListener {
|
||||
|
|
@ -16,11 +17,21 @@ public class LocationServiceManager implements LocationListener {
|
|||
private LatLng latestLocation;
|
||||
private Float latestLocationAccuracy;
|
||||
|
||||
public LocationServiceManager(Context context) {
|
||||
this.locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
|
||||
private static LocationServiceManager locationServiceManager;
|
||||
|
||||
private LocationServiceManager() {
|
||||
Context applicationContext = CommonsApplication.getInstance().getApplicationContext();
|
||||
this.locationManager = (LocationManager) applicationContext.getSystemService(Context.LOCATION_SERVICE);
|
||||
provider = locationManager.getBestProvider(new Criteria(), true);
|
||||
}
|
||||
|
||||
public static LocationServiceManager getInstance() {
|
||||
if (locationServiceManager == null) {
|
||||
locationServiceManager = new LocationServiceManager();
|
||||
}
|
||||
return locationServiceManager;
|
||||
}
|
||||
|
||||
public boolean isProviderEnabled() {
|
||||
return locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue