@Injected shared preferences where needed

This commit is contained in:
Paul Hawke 2017-09-27 21:30:41 -05:00
parent 1b840502a9
commit 9aa021695b
20 changed files with 137 additions and 100 deletions

View file

@ -3,6 +3,7 @@ package fr.free.nrw.commons.nearby;
import android.Manifest;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.location.LocationManager;
import android.net.Uri;
@ -28,6 +29,7 @@ import com.google.gson.GsonBuilder;
import java.util.List;
import javax.inject.Inject;
import javax.inject.Named;
import butterknife.BindView;
import butterknife.ButterKnife;
@ -43,6 +45,7 @@ public class NearbyActivity extends NavigationBaseActivity {
@BindView(R.id.progressBar)
ProgressBar progressBar;
@Inject NearbyPlaces nearbyPlaces;
@Inject @Named("default_preferences") SharedPreferences prefs;
private boolean isMapViewActive = false;
private static final int LOCATION_REQUEST = 1;
@ -93,7 +96,7 @@ public class NearbyActivity extends NavigationBaseActivity {
locationManager = new LocationServiceManager(this);
locationManager.registerLocationManager();
curLatLang = locationManager.getLatestLocation();
nearbyAsyncTask = new NearbyAsyncTask(this, new NearbyController(nearbyPlaces));
nearbyAsyncTask = new NearbyAsyncTask(this, new NearbyController(nearbyPlaces, prefs));
nearbyAsyncTask.execute();
}
@ -232,7 +235,7 @@ public class NearbyActivity extends NavigationBaseActivity {
}
private void refreshView() {
nearbyAsyncTask = new NearbyAsyncTask(this, new NearbyController(nearbyPlaces));
nearbyAsyncTask = new NearbyAsyncTask(this, new NearbyController(nearbyPlaces, prefs));
nearbyAsyncTask.execute();
}

View file

@ -3,7 +3,6 @@ package fr.free.nrw.commons.nearby;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.preference.PreferenceManager;
import android.support.graphics.drawable.VectorDrawableCompat;
import com.mapbox.mapboxsdk.annotations.IconFactory;
@ -27,9 +26,11 @@ import static fr.free.nrw.commons.utils.LengthUtils.formatDistanceBetween;
public class NearbyController {
private static final int MAX_RESULTS = 1000;
private final NearbyPlaces nearbyPlaces;
private final SharedPreferences prefs;
public NearbyController(NearbyPlaces nearbyPlaces) {
public NearbyController(NearbyPlaces nearbyPlaces, SharedPreferences prefs) {
this.nearbyPlaces = nearbyPlaces;
this.prefs = prefs;
}
/**
@ -43,7 +44,6 @@ public class NearbyController {
if (curLatLng == null) {
return Collections.emptyList();
}
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
List<Place> places = prefs.getBoolean("useWikidata", true)
? nearbyPlaces.getFromWikidataQuery(curLatLng, Locale.getDefault().getLanguage())
: nearbyPlaces.getFromWikiNeedsPictures();