mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-11-03 16:23:54 +01:00
Finished removing coupling between classes around the getInstance() method.
This commit is contained in:
parent
dbcbeed822
commit
ed1ae98d8e
18 changed files with 154 additions and 125 deletions
|
|
@ -31,7 +31,6 @@ import javax.inject.Inject;
|
|||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import dagger.android.AndroidInjection;
|
||||
import fr.free.nrw.commons.CommonsApplication;
|
||||
import fr.free.nrw.commons.R;
|
||||
import fr.free.nrw.commons.location.LatLng;
|
||||
|
|
@ -95,7 +94,7 @@ public class NearbyActivity extends NavigationBaseActivity {
|
|||
locationManager = new LocationServiceManager(this);
|
||||
locationManager.registerLocationManager();
|
||||
curLatLang = locationManager.getLatestLocation();
|
||||
nearbyAsyncTask = new NearbyAsyncTask(this, application);
|
||||
nearbyAsyncTask = new NearbyAsyncTask(this, new NearbyController(application));
|
||||
nearbyAsyncTask.execute();
|
||||
}
|
||||
|
||||
|
|
@ -234,7 +233,7 @@ public class NearbyActivity extends NavigationBaseActivity {
|
|||
}
|
||||
|
||||
private void refreshView() {
|
||||
nearbyAsyncTask = new NearbyAsyncTask(this, application);
|
||||
nearbyAsyncTask = new NearbyAsyncTask(this, new NearbyController(application));
|
||||
nearbyAsyncTask.execute();
|
||||
}
|
||||
|
||||
|
|
@ -249,11 +248,11 @@ public class NearbyActivity extends NavigationBaseActivity {
|
|||
private class NearbyAsyncTask extends AsyncTask<Void, Integer, List<Place>> {
|
||||
|
||||
private final Context mContext;
|
||||
private final CommonsApplication application;
|
||||
private final NearbyController nearbyController;
|
||||
|
||||
private NearbyAsyncTask(Context context, CommonsApplication application) {
|
||||
mContext = context;
|
||||
this.application = application;
|
||||
private NearbyAsyncTask(Context context, NearbyController nearbyController) {
|
||||
this.mContext = context;
|
||||
this.nearbyController = nearbyController;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -263,8 +262,7 @@ public class NearbyActivity extends NavigationBaseActivity {
|
|||
|
||||
@Override
|
||||
protected List<Place> doInBackground(Void... params) {
|
||||
return NearbyController
|
||||
.loadAttractionsFromLocation(curLatLang, application);
|
||||
return nearbyController.loadAttractionsFromLocation(curLatLang, application);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ import com.mapbox.mapboxsdk.annotations.IconFactory;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
|
@ -29,18 +28,24 @@ import static fr.free.nrw.commons.utils.LengthUtils.formatDistanceBetween;
|
|||
public class NearbyController {
|
||||
private static final int MAX_RESULTS = 1000;
|
||||
|
||||
private final CommonsApplication application;
|
||||
|
||||
public NearbyController(CommonsApplication application) {
|
||||
this.application = application;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares Place list to make their distance information update later.
|
||||
* @param curLatLng current location for user
|
||||
* @param context context
|
||||
* @return Place list without distance information
|
||||
*/
|
||||
public static List<Place> loadAttractionsFromLocation(LatLng curLatLng, Context context) {
|
||||
public List<Place> loadAttractionsFromLocation(LatLng curLatLng, Context context) {
|
||||
Timber.d("Loading attractions near %s", curLatLng);
|
||||
if (curLatLng == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
NearbyPlaces nearbyPlaces = CommonsApplication.getInstance().getNearbyPlaces();
|
||||
NearbyPlaces nearbyPlaces = application.getNearbyPlaces();
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
List<Place> places = prefs.getBoolean("useWikidata", true)
|
||||
? nearbyPlaces.getFromWikidataQuery(curLatLng, Locale.getDefault().getLanguage())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue