POI multiselection: persistent between program launches

This commit is contained in:
Roman Inflianskas 2016-04-22 11:22:27 +03:00
parent cf0f5e1121
commit 0048fb82c5
3 changed files with 29 additions and 30 deletions

View file

@ -489,6 +489,7 @@ public class AppInitializer implements IProgress {
notifyEvent(InitEvents.NATIVE_INITIALIZED); notifyEvent(InitEvents.NATIVE_INITIALIZED);
app.poiFilters.reloadAllPoiFilters(); app.poiFilters.reloadAllPoiFilters();
app.poiFilters.loadSelectedPoiFilters();
notifyEvent(InitEvents.POI_TYPES_INITIALIZED); notifyEvent(InitEvents.POI_TYPES_INITIALIZED);
indexRegionsBoundaries(warnings); indexRegionsBoundaries(warnings);
notifyEvent(InitEvents.INDEX_REGION_BOUNDARIES); notifyEvent(InitEvents.INDEX_REGION_BOUNDARIES);

View file

@ -120,7 +120,7 @@ public class PoiFiltersHelper {
private PoiUIFilter getFilterById(String filterId, PoiUIFilter... filters){ private PoiUIFilter getFilterById(String filterId, PoiUIFilter... filters){
for (PoiUIFilter pf : filters) { for (PoiUIFilter pf : filters) {
if(pf.getFilterId().equals(filterId)){ if (pf.getFilterId().equals(filterId)) {
return pf; return pf;
} }
} }
@ -128,11 +128,11 @@ public class PoiFiltersHelper {
} }
public PoiUIFilter getFilterById(String filterId){ public PoiUIFilter getFilterById(String filterId){
if(filterId == null){ if (filterId == null){
return null; return null;
} }
for(PoiUIFilter f : getTopDefinedPoiFilters()) { for (PoiUIFilter f : getTopDefinedPoiFilters()) {
if(f.getFilterId().equals(filterId)){ if (f.getFilterId().equals(filterId)) {
return f; return f;
} }
} }
@ -141,10 +141,10 @@ public class PoiFiltersHelper {
if (ff != null) { if (ff != null) {
return ff; return ff;
} }
if(filterId.startsWith(PoiUIFilter.STD_PREFIX)) { if (filterId.startsWith(PoiUIFilter.STD_PREFIX)) {
String typeId = filterId.substring(PoiUIFilter.STD_PREFIX.length()); String typeId = filterId.substring(PoiUIFilter.STD_PREFIX.length());
AbstractPoiType tp = application.getPoiTypes().getAnyPoiTypeByKey(typeId); AbstractPoiType tp = application.getPoiTypes().getAnyPoiTypeByKey(typeId);
if(tp != null) { if (tp != null) {
PoiUIFilter lf = new PoiUIFilter(tp, application, ""); PoiUIFilter lf = new PoiUIFilter(tp, application, "");
ArrayList<PoiUIFilter> copy = new ArrayList<PoiUIFilter>(cacheTopStandardFilters); ArrayList<PoiUIFilter> copy = new ArrayList<PoiUIFilter>(cacheTopStandardFilters);
copy.add(lf); copy.add(lf);
@ -153,7 +153,7 @@ public class PoiFiltersHelper {
return lf; return lf;
} }
AbstractPoiType lt = application.getPoiTypes().getAnyPoiAdditionalTypeByKey(typeId); AbstractPoiType lt = application.getPoiTypes().getAnyPoiAdditionalTypeByKey(typeId);
if(lt != null) { if (lt != null) {
PoiUIFilter lf = new PoiUIFilter(lt, application, ""); PoiUIFilter lf = new PoiUIFilter(lt, application, "");
ArrayList<PoiUIFilter> copy = new ArrayList<PoiUIFilter>(cacheTopStandardFilters); ArrayList<PoiUIFilter> copy = new ArrayList<PoiUIFilter>(cacheTopStandardFilters);
copy.add(lf); copy.add(lf);
@ -165,14 +165,6 @@ public class PoiFiltersHelper {
return null; return null;
} }
public List<PoiUIFilter> getFiltersById(String filtersId) {
List<PoiUIFilter> result = new ArrayList<PoiUIFilter>();
for (String filterId : filtersId.split(","))
result.add(getFilterById(filterId));
return result;
}
public void reloadAllPoiFilters() { public void reloadAllPoiFilters() {
showAllPOIFilter = null; showAllPOIFilter = null;
getShowAllPOIFilter(); getShowAllPOIFilter();
@ -180,7 +172,6 @@ public class PoiFiltersHelper {
getTopDefinedPoiFilters(); getTopDefinedPoiFilters();
} }
private List<PoiUIFilter> getUserDefinedPoiFilters() { private List<PoiUIFilter> getUserDefinedPoiFilters() {
ArrayList<PoiUIFilter> userDefinedFilters = new ArrayList<PoiUIFilter>(); ArrayList<PoiUIFilter> userDefinedFilters = new ArrayList<PoiUIFilter>();
PoiFilterDbHelper helper = openDbHelper(); PoiFilterDbHelper helper = openDbHelper();
@ -277,8 +268,6 @@ public class PoiFiltersHelper {
return res; return res;
} }
public boolean editPoiFilter(PoiUIFilter filter) { public boolean editPoiFilter(PoiUIFilter filter) {
if (filter.getFilterId().equals(PoiUIFilter.CUSTOM_FILTER_ID) || if (filter.getFilterId().equals(PoiUIFilter.CUSTOM_FILTER_ID) ||
filter.getFilterId().equals(PoiUIFilter.BY_NAME_FILTER_ID) || filter.getFilterId().startsWith(PoiUIFilter.STD_PREFIX)) { filter.getFilterId().equals(PoiUIFilter.BY_NAME_FILTER_ID) || filter.getFilterId().startsWith(PoiUIFilter.STD_PREFIX)) {
@ -294,23 +283,28 @@ public class PoiFiltersHelper {
} }
@NonNull @NonNull
public Set<PoiUIFilter> getSelectedPoiFilters() { return selectedPoiFilters; } public Set<PoiUIFilter> getSelectedPoiFilters() {
return selectedPoiFilters;
}
public void addSelectedPoiFilter(PoiUIFilter filter) { public void addSelectedPoiFilter(PoiUIFilter filter) {
selectedPoiFilters.add(filter); selectedPoiFilters.add(filter);
} saveSelectedPoiFilters();
public void addSelectedPoiFilter(String filterId) {
selectedPoiFilters.add(getFilterById(filterId));
} }
public void removeSelectedPoiFilter(PoiUIFilter filter) { public void removeSelectedPoiFilter(PoiUIFilter filter) {
selectedPoiFilters.remove(filter); selectedPoiFilters.remove(filter);
saveSelectedPoiFilters();
} }
public boolean isShowingAnyPoi() { return !selectedPoiFilters.isEmpty(); } public boolean isShowingAnyPoi() {
return !selectedPoiFilters.isEmpty();
}
public void clearSelectedPoiFilters() { selectedPoiFilters.clear(); } public void clearSelectedPoiFilters() {
selectedPoiFilters.clear();
saveSelectedPoiFilters();
}
public String getSelectedPoiFiltersName() { public String getSelectedPoiFiltersName() {
if (!isShowingAnyPoi()) { if (!isShowingAnyPoi()) {
@ -333,7 +327,13 @@ public class PoiFiltersHelper {
return false; return false;
} }
private void saveCurrentSelections() { public void loadSelectedPoiFilters() {
Set<String> filters = application.getSettings().getSelectedPoiFilters();
for (String f: filters)
selectedPoiFilters.add(getFilterById(f));
}
public void saveSelectedPoiFilters() {
Set<String> filters = new HashSet<>(); Set<String> filters = new HashSet<>();
for (PoiUIFilter f: selectedPoiFilters) for (PoiUIFilter f: selectedPoiFilters)
filters.add(f.filterId); filters.add(f.filterId);

View file

@ -111,8 +111,6 @@ public class PoiUIFilter implements SearchPoiTypeFilter, Comparable<PoiUIFilter>
updatePoiAdditionals(); updatePoiAdditionals();
} }
public String getFilterByName() { public String getFilterByName() {
return filterByName; return filterByName;
} }