Search in sources :

Example 1 with OpeningHours

use of net.osmand.util.OpeningHoursParser.OpeningHours in project Osmand by osmandapp.

the class PoiUIFilter method getNameFilterInternal.

private AmenityNameFilter getNameFilterInternal(StringBuilder nmFilter, final boolean allTime, final boolean open, final List<PoiType> poiAdditionals) {
    final CollatorStringMatcher sm = nmFilter.length() > 0 ? new CollatorStringMatcher(nmFilter.toString().trim(), StringMatcherMode.CHECK_CONTAINS) : null;
    return new AmenityNameFilter() {

        @Override
        public boolean accept(Amenity a) {
            if (sm != null) {
                String lower = OsmAndFormatter.getPoiStringWithoutType(a, app.getSettings().MAP_PREFERRED_LOCALE.get(), app.getSettings().MAP_TRANSLITERATE_NAMES.get());
                if (!sm.matches(lower)) {
                    return false;
                }
            }
            if (poiAdditionals != null) {
                Map<PoiType, PoiType> textPoiAdditionalsMap = new HashMap<>();
                Map<String, List<PoiType>> poiAdditionalCategoriesMap = new HashMap<>();
                for (PoiType pt : poiAdditionals) {
                    String category = pt.getPoiAdditionalCategory();
                    List<PoiType> types = poiAdditionalCategoriesMap.get(category);
                    if (types == null) {
                        types = new ArrayList<>();
                        poiAdditionalCategoriesMap.put(category, types);
                    }
                    types.add(pt);
                    String osmTag = pt.getOsmTag();
                    if (osmTag.length() < pt.getKeyName().length()) {
                        PoiType textPoiType = poiTypes.getTextPoiAdditionalByKey(osmTag);
                        if (textPoiType != null) {
                            textPoiAdditionalsMap.put(pt, textPoiType);
                        }
                    }
                }
                for (List<PoiType> types : poiAdditionalCategoriesMap.values()) {
                    boolean acceptedAnyInCategory = false;
                    for (PoiType p : types) {
                        String inf = a.getAdditionalInfo(p.getKeyName());
                        if (inf != null) {
                            acceptedAnyInCategory = true;
                            break;
                        } else {
                            PoiType textPoiType = textPoiAdditionalsMap.get(p);
                            if (textPoiType != null) {
                                inf = a.getAdditionalInfo(textPoiType.getKeyName());
                                if (!Algorithms.isEmpty(inf)) {
                                    String[] items = inf.split(";");
                                    String val = p.getOsmValue().trim().toLowerCase();
                                    for (String item : items) {
                                        if (item.trim().toLowerCase().equals(val)) {
                                            acceptedAnyInCategory = true;
                                            break;
                                        }
                                    }
                                    if (acceptedAnyInCategory) {
                                        break;
                                    }
                                }
                            }
                        }
                    }
                    if (!acceptedAnyInCategory) {
                        return false;
                    }
                }
            }
            if (allTime) {
                if (!"24/7".equalsIgnoreCase(a.getOpeningHours()) && !"Mo-Su 00:00-24:00".equalsIgnoreCase(a.getOpeningHours())) {
                    return false;
                }
            }
            if (open) {
                OpeningHours rs = OpeningHoursParser.parseOpenedHours(a.getOpeningHours());
                if (rs != null) {
                    Calendar inst = Calendar.getInstance();
                    inst.setTimeInMillis(System.currentTimeMillis());
                    boolean work = rs.isOpenedForTime(inst);
                    if (!work) {
                        return false;
                    }
                } else {
                    return false;
                }
            }
            return true;
        }
    };
}
Also used : Amenity(net.osmand.data.Amenity) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Calendar(java.util.Calendar) AbstractPoiType(net.osmand.osm.AbstractPoiType) PoiType(net.osmand.osm.PoiType) OpeningHours(net.osmand.util.OpeningHoursParser.OpeningHours) CollatorStringMatcher(net.osmand.CollatorStringMatcher) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 CollatorStringMatcher (net.osmand.CollatorStringMatcher)1 Amenity (net.osmand.data.Amenity)1 AbstractPoiType (net.osmand.osm.AbstractPoiType)1 PoiType (net.osmand.osm.PoiType)1 OpeningHours (net.osmand.util.OpeningHoursParser.OpeningHours)1