mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 04:43:54 +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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ public class NearbyActivity extends NavigationBaseActivity {
|
|||
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
|
||||
setContentView(R.layout.activity_nearby);
|
||||
ButterKnife.bind(this);
|
||||
locationManager = new LocationServiceManager(this);
|
||||
locationManager = LocationServiceManager.getInstance();
|
||||
checkLocationPermission();
|
||||
bundle = new Bundle();
|
||||
initDrawer();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue