Google places settings are ready now.
parent
d9b55bceab
commit
2af4e791a3
|
@ -20,5 +20,4 @@ public class AppConstants {
|
|||
static final String SAVED_CONFIG_KEY = "SAVED_CONFIG_KEY";
|
||||
public static final String GOOGLE_API_KEY = "AIzaSyBAJoK-pu_qnQ0U8EGjM1Zkz_g8oJV4w2g";
|
||||
public static final String DEF_WIKI_COUNTRY_CODE = "en";
|
||||
public static final Double DEF_PLACES_RADIUS = 5000.0;
|
||||
}
|
||||
|
|
|
@ -35,6 +35,7 @@ import pl.tpolgrabia.urbanexplorer.worker.GooglePlacesWorker;
|
|||
import pl.tpolgrabia.urbanexplorerutils.callbacks.StandardLocationListenerCallback;
|
||||
import pl.tpolgrabia.urbanexplorerutils.events.RefreshEvent;
|
||||
import pl.tpolgrabia.urbanexplorerutils.utils.LocationUtils;
|
||||
import pl.tpolgrabia.urbanexplorerutils.utils.SettingsUtils;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
|
@ -224,8 +225,8 @@ public class PlacesFragment extends Fragment {
|
|||
|
||||
GooglePlacesRequest request = new GooglePlacesRequest();
|
||||
request.setLocation(location);
|
||||
request.setSearchRadius(AppConstants.DEF_PLACES_RADIUS);
|
||||
request.setSearchItemType(GooglePlacesConstants.PLACES_SEARCH_TYPE);
|
||||
request.setSearchRadius(SettingsUtils.getDefaultPlacesSearchRadius(getActivity()));
|
||||
request.setSearchItemType(SettingsUtils.getPlacesSearchCategories(getActivity()));
|
||||
new GooglePlacesWorker(getActivity()).execute(request);
|
||||
}
|
||||
|
||||
|
@ -243,13 +244,18 @@ public class PlacesFragment extends Fragment {
|
|||
return;
|
||||
}
|
||||
|
||||
if (getActivity() == null) {
|
||||
lg.debug("Headless fragment, no activity - no context");
|
||||
return;
|
||||
}
|
||||
|
||||
lg.debug("Loading next page");
|
||||
|
||||
Location location = LocationUtils.getLastKnownLocation(getActivity());
|
||||
GooglePlacesRequest request = new GooglePlacesRequest();
|
||||
request.setLocation(location);
|
||||
request.setSearchRadius(AppConstants.DEF_PLACES_RADIUS);
|
||||
request.setSearchItemType(GooglePlacesConstants.PLACES_SEARCH_TYPE);
|
||||
request.setSearchRadius(SettingsUtils.getDefaultPlacesSearchRadius(getActivity()));
|
||||
request.setSearchItemType(SettingsUtils.getPlacesSearchCategories(getActivity()));
|
||||
request.setPageToken(nextPageToken);
|
||||
new GooglePlacesWorker(getActivity()).execute(request);
|
||||
}
|
||||
|
|
|
@ -20,4 +20,8 @@ public class UtilConstants {
|
|||
|
||||
public static final String PANORAMIO_BULK_SIZE_KEY = "pref_panoramio_bulk_size";
|
||||
public static final int PANORAMIO_BULK_SIZE_DEF_VALUE = 50;
|
||||
public static final double GOOGLE_PLACES_STD_UNIT = 1000.0;
|
||||
public static final String PREF_GOOGLE_PLACES_RADIUS = "pref_gplaces_radius";
|
||||
public static final Double DEF_PLACES_RADIUS = 5000.0;
|
||||
public static final String GOOGLE_PLACES_CATEGORIES_PREF = "pref_gplaces_categories";
|
||||
}
|
||||
|
|
|
@ -3,10 +3,13 @@ package pl.tpolgrabia.urbanexplorerutils.utils;
|
|||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.preference.PreferenceManager;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import pl.tpolgrabia.urbanexplorerutils.constants.UtilConstants;
|
||||
|
||||
import java.util.HashSet;
|
||||
|
||||
/**
|
||||
* Created by tpolgrabia on 24.09.16.
|
||||
*/
|
||||
|
@ -60,4 +63,21 @@ public class SettingsUtils {
|
|||
lg.debug("Pref wiki search results limit {}", prefWikiResultsLimit);
|
||||
return NumberUtils.safeParseLong(prefWikiResultsLimit);
|
||||
}
|
||||
|
||||
public static Double getDefaultPlacesSearchRadius(Context ctx) {
|
||||
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(ctx);
|
||||
try {
|
||||
return Double.parseDouble(sharedPrefs.getString(UtilConstants.PREF_GOOGLE_PLACES_RADIUS,
|
||||
UtilConstants.DEF_PLACES_RADIUS.toString())) * UtilConstants.GOOGLE_PLACES_STD_UNIT;
|
||||
} catch (NumberFormatException e) {
|
||||
lg.error("Invalid settings for google places search radius", e);
|
||||
return UtilConstants.DEF_PLACES_RADIUS;
|
||||
}
|
||||
}
|
||||
|
||||
public static String getPlacesSearchCategories(Context ctx) {
|
||||
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(ctx);
|
||||
return StringUtils.join("|",
|
||||
sharedPrefs.getStringSet(UtilConstants.GOOGLE_PLACES_CATEGORIES_PREF, new HashSet<String>()));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue