Fix POI categories order
This commit is contained in:
parent
570b61427f
commit
9cc0d0b77a
4 changed files with 25 additions and 23 deletions
|
@ -39,7 +39,6 @@ import java.util.HashSet;
|
|||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
|
@ -346,7 +345,7 @@ public class SearchUICore {
|
|||
}
|
||||
}
|
||||
|
||||
public void setFilterOrders(Map<String, Integer> filterOrders) {
|
||||
public void setFilterOrders(List<String> filterOrders) {
|
||||
for (SearchCoreAPI capi : apis) {
|
||||
if (capi instanceof SearchAmenityTypesAPI) {
|
||||
((SearchAmenityTypesAPI) capi).setFilterOrders(filterOrders);
|
||||
|
|
|
@ -639,7 +639,7 @@ public class SearchCoreFactory {
|
|||
private List<CustomSearchPoiFilter> customPoiFilters = new ArrayList<>();
|
||||
private TIntArrayList customPoiFiltersPriorites = new TIntArrayList();
|
||||
private MapPoiTypes types;
|
||||
private Map<String, Integer> filterOrders = new HashMap<>();
|
||||
private List<String> filterOrders = new ArrayList<>();
|
||||
|
||||
public SearchAmenityTypesAPI(MapPoiTypes types) {
|
||||
super(ObjectType.POI_TYPE);
|
||||
|
@ -656,7 +656,7 @@ public class SearchCoreFactory {
|
|||
this.customPoiFiltersPriorites.add(priority);
|
||||
}
|
||||
|
||||
public void setFilterOrders(Map<String, Integer> filterOrders) {
|
||||
public void setFilterOrders(List<String> filterOrders) {
|
||||
this.filterOrders = filterOrders;
|
||||
}
|
||||
|
||||
|
@ -737,8 +737,8 @@ public class SearchCoreFactory {
|
|||
res.firstUnknownWordMatches = startMatch.matches(res.localeName);
|
||||
if (showTopFiltersOnly) {
|
||||
String stdFilterId = getStandardFilterId(pt);
|
||||
if (filterOrders.containsKey(stdFilterId)) {
|
||||
res.priority = SEARCH_AMENITY_TYPE_PRIORITY + filterOrders.get(stdFilterId);
|
||||
if (filterOrders.contains(stdFilterId)) {
|
||||
res.priority = SEARCH_AMENITY_TYPE_PRIORITY + filterOrders.indexOf(stdFilterId);
|
||||
resultMatcher.publish(res);
|
||||
}
|
||||
} else {
|
||||
|
@ -754,8 +754,8 @@ public class SearchCoreFactory {
|
|||
res.object = csf;
|
||||
res.objectType = ObjectType.POI_TYPE;
|
||||
if (showTopFiltersOnly) {
|
||||
if (filterOrders.containsKey(csf.getFilterId())) {
|
||||
res.priority = SEARCH_AMENITY_TYPE_PRIORITY + filterOrders.get(csf.getFilterId());
|
||||
if (filterOrders.contains(csf.getFilterId())) {
|
||||
res.priority = SEARCH_AMENITY_TYPE_PRIORITY + filterOrders.indexOf(csf.getFilterId());
|
||||
resultMatcher.publish(res);
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -27,7 +27,6 @@ import java.util.Iterator;
|
|||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
|
@ -314,12 +313,10 @@ public class PoiFiltersHelper {
|
|||
return result;
|
||||
}
|
||||
|
||||
public Map<String, Integer> getPoiFilterOrders(boolean onlyActive) {
|
||||
Map<String, Integer> filterOrders = new HashMap<>();
|
||||
List<PoiUIFilter> sortedFilters = getSortedPoiFilters(onlyActive);
|
||||
int order = 0;
|
||||
for (PoiUIFilter filter : sortedFilters) {
|
||||
filterOrders.put(filter.getFilterId(), order++);
|
||||
public List<String> getPoiFilterOrders(boolean onlyActive) {
|
||||
List<String> filterOrders = new ArrayList<>();
|
||||
for (PoiUIFilter filter : getSortedPoiFilters(onlyActive)) {
|
||||
filterOrders.add(filter.getFilterId());
|
||||
}
|
||||
return filterOrders;
|
||||
}
|
||||
|
|
|
@ -165,15 +165,16 @@ public class RearrangePoiFiltersFragment extends DialogFragment implements Selec
|
|||
applyButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
ApplicationMode selectedAppMode = getSelectedAppMode();
|
||||
if (isChanged) {
|
||||
if (activationModified) {
|
||||
app.getPoiFilters().saveInactiveFilters(appMode, availableFiltersKeys);
|
||||
app.getPoiFilters().saveInactiveFilters(selectedAppMode, availableFiltersKeys);
|
||||
} else if (wasReset) {
|
||||
app.getPoiFilters().saveInactiveFilters(appMode, null);
|
||||
app.getPoiFilters().saveInactiveFilters(selectedAppMode, null);
|
||||
}
|
||||
if (orderModified) {
|
||||
List<PoiUIFilter> dataToSave = new ArrayList<>();
|
||||
for (PoiUIFilter filter : getSortedPoiUiFilters(appMode, app)) {
|
||||
for (PoiUIFilter filter : getSortedPoiUiFilters(selectedAppMode, app)) {
|
||||
String filterId = filter.getFilterId();
|
||||
Integer order = poiFiltersOrders.get(filterId);
|
||||
if (order == null) {
|
||||
|
@ -191,13 +192,13 @@ public class RearrangePoiFiltersFragment extends DialogFragment implements Selec
|
|||
for (PoiUIFilter filter : dataToSave) {
|
||||
filterIds.add(filter.getFilterId());
|
||||
}
|
||||
app.getPoiFilters().saveFiltersOrder(appMode, filterIds);
|
||||
app.getPoiFilters().saveFiltersOrder(selectedAppMode, filterIds);
|
||||
} else if (wasReset) {
|
||||
app.getPoiFilters().saveFiltersOrder(appMode,null);
|
||||
app.getPoiFilters().saveFiltersOrder(selectedAppMode,null);
|
||||
}
|
||||
}
|
||||
if (resultCallback != null) {
|
||||
resultCallback.onApplyPoiFiltersState(getSelectedAppMode(), isChanged);
|
||||
resultCallback.onApplyPoiFiltersState(selectedAppMode, isChanged);
|
||||
}
|
||||
dismiss();
|
||||
}
|
||||
|
@ -282,7 +283,8 @@ public class RearrangePoiFiltersFragment extends DialogFragment implements Selec
|
|||
private void initFiltersOrders(OsmandApplication app, boolean arrangementByDefault) {
|
||||
poiFiltersOrders.clear();
|
||||
availableFiltersKeys.clear();
|
||||
List<PoiUIFilter> filters = getSortedPoiUiFilters(appMode, app);
|
||||
ApplicationMode selectedAppMode = getSelectedAppMode();
|
||||
List<PoiUIFilter> filters = getSortedPoiUiFilters(selectedAppMode, app);
|
||||
if (arrangementByDefault) {
|
||||
Collections.sort(filters, new Comparator<PoiUIFilter>() {
|
||||
@Override
|
||||
|
@ -365,6 +367,9 @@ public class RearrangePoiFiltersFragment extends DialogFragment implements Selec
|
|||
}
|
||||
|
||||
public ApplicationMode getSelectedAppMode() {
|
||||
if (appMode == null) {
|
||||
appMode = requireMyApplication().getSettings().getApplicationMode();
|
||||
}
|
||||
return appMode;
|
||||
}
|
||||
|
||||
|
@ -374,8 +379,9 @@ public class RearrangePoiFiltersFragment extends DialogFragment implements Selec
|
|||
|
||||
public List<ListItem> getPoiFilters(boolean isActive) {
|
||||
OsmandApplication app = requireMyApplication();
|
||||
ApplicationMode selectedAppMode = getSelectedAppMode();
|
||||
List<ListItem> result = new ArrayList<>();
|
||||
for (PoiUIFilter f : getSortedPoiUiFilters(appMode, app)) {
|
||||
for (PoiUIFilter f : getSortedPoiUiFilters(selectedAppMode, app)) {
|
||||
addFilterToList(result, f, isActive);
|
||||
}
|
||||
Collections.sort(result, new Comparator<ListItem>() {
|
||||
|
|
Loading…
Reference in a new issue