Search in sources :

Example 6 with PoiType

use of io.jawg.osmcontributor.model.entities.PoiType in project osm-contributor by jawg.

the class PoiMapper method convertDtoToPoi.

public Poi convertDtoToPoi(boolean typeFiltering, List<PoiType> availableTypes, PoiDto dto) {
    List<PoiNodeRef> nodeRefs = new ArrayList<>();
    List<PoiTag> tags = new ArrayList<>();
    PoiType type;
    if (FlavorUtils.isBus()) {
        type = availableTypes.get(0);
    } else {
        type = findType(dto, availableTypes);
    }
    if (type == null && typeFiltering) {
        return null;
    }
    Poi poi = new Poi();
    poi.setType(type);
    poi.setLatitude(dto.getLat());
    poi.setLongitude(dto.getLon());
    poi.setBackendId(dto.getId());
    poi.setVersion(String.valueOf(dto.getVersion()));
    poi.setUpdated(false);
    poi.setUpdateDate(dto.getTimestamp());
    poi.setWay(dto.isWay());
    for (TagDto tagDto : dto.getTagsDtoList()) {
        PoiTag tag = new PoiTag();
        tag.setPoi(poi);
        tag.setKey(tagDto.getKey());
        tag.setValue(tagDto.getValue());
        tags.add(tag);
        if (tag.getKey().equals("name")) {
            poi.setName(tag.getValue());
        }
        if (tag.getKey().equals("level")) {
            poi.setLevel(tag.getValue());
        }
    }
    poi.setTags(tags);
    int counter = 0;
    for (NdDto ndDto : dto.getNdDtoList()) {
        PoiNodeRef nodeRef = new PoiNodeRef();
        nodeRef.setPoi(poi);
        nodeRef.setNodeBackendId(ndDto.getRef());
        nodeRef.setOrdinal(counter++);
        nodeRef.setLatitude(ndDto.getLat());
        nodeRef.setLongitude(ndDto.getLon());
        nodeRef.setUpdated(false);
        nodeRefs.add(nodeRef);
    }
    poi.setNodeRefs(nodeRefs);
    return poi;
}
Also used : PoiTag(io.jawg.osmcontributor.model.entities.PoiTag) NdDto(io.jawg.osmcontributor.rest.dtos.osm.NdDto) ArrayList(java.util.ArrayList) PoiType(io.jawg.osmcontributor.model.entities.PoiType) TagDto(io.jawg.osmcontributor.rest.dtos.osm.TagDto) Poi(io.jawg.osmcontributor.model.entities.Poi) PoiNodeRef(io.jawg.osmcontributor.model.entities.PoiNodeRef)

Example 7 with PoiType

use of io.jawg.osmcontributor.model.entities.PoiType in project osm-contributor by jawg.

the class MapActivity method onPleaseInitializeDrawer.

@Subscribe(threadMode = ThreadMode.MAIN)
public void onPleaseInitializeDrawer(PleaseInitializeDrawer event) {
    Timber.d("initializing drawer with poiType");
    if (filtersItemList == null) {
        filtersItemList = new ArrayList<>();
    }
    List<PoiType> poiTypes = event.getPoiTypes();
    poiTypesHidden = event.getPoiTypeHidden();
    filters.clear();
    for (PoiType poiType : poiTypes) {
        Long id = poiType.getId();
        filters.add(new PoiTypeFilter(poiType.getName(), id, poiType.getIcon(), !poiTypesHidden.contains(id)));
    }
    Collections.sort(filters);
    Menu menu = filterView.getMenu();
    int order = 1;
    for (PoiTypeFilter poiTypeFilter : filters) {
        PoiTypeFilter nextPoiTypeFilter = null;
        if (order < filters.size()) {
            nextPoiTypeFilter = filters.get(order);
        }
        // Add only menu if not present
        if (menu.findItem(poiTypeFilter.getPoiTypeId().intValue()) == null) {
            filtersItemList.add(menu.add(Menu.NONE, poiTypeFilter.getPoiTypeId().intValue(), (nextPoiTypeFilter != null ? (poiTypeFilter.compareTo(nextPoiTypeFilter) > 0 ? order - 1 : order) : order), poiTypeFilter.getPoiTypeName()).setChecked(poiTypeFilter.isActive()).setIcon(bitmapHandler.getDrawable(poiTypeFilter.getPoiTypeIconName())));
        }
        order++;
    }
    // Remove only filter removed by user
    if (filters.size() < filtersItemList.size()) {
        List<MenuItem> temp = new ArrayList<>(filters.size());
        for (MenuItem menuItem : filtersItemList) {
            PoiTypeFilter poiTypeFilter = new PoiTypeFilter("", (long) menuItem.getItemId(), "", true);
            if (!filters.contains(poiTypeFilter)) {
                menu.removeItem(poiTypeFilter.getPoiTypeId().intValue());
            } else {
                temp.add(menuItem);
            }
        }
        filtersItemList.clear();
        filtersItemList.addAll(temp);
        temp.clear();
    }
    selectAllMenuItem.setChecked(poiTypesHidden.isEmpty());
}
Also used : PoiTypeFilter(io.jawg.osmcontributor.ui.utils.PoiTypeFilter) PoiType(io.jawg.osmcontributor.model.entities.PoiType) ArrayList(java.util.ArrayList) MenuItem(android.view.MenuItem) Menu(android.view.Menu) Subscribe(org.greenrobot.eventbus.Subscribe)

Example 8 with PoiType

use of io.jawg.osmcontributor.model.entities.PoiType in project osm-contributor by jawg.

the class TypeManager method onInternalUpdatePoiTagsEvent.

@Subscribe(threadMode = ThreadMode.ASYNC)
public void onInternalUpdatePoiTagsEvent(InternalUpdatePoiTagsEvent event) {
    PoiType poiType = event.getPoiType();
    poiManager.savePoiType(poiType);
    bus.post(new PoiTagsUpdatedEvent(poiType));
}
Also used : PoiTagsUpdatedEvent(io.jawg.osmcontributor.ui.events.type.PoiTagsUpdatedEvent) PoiType(io.jawg.osmcontributor.model.entities.PoiType) Subscribe(org.greenrobot.eventbus.Subscribe)

Example 9 with PoiType

use of io.jawg.osmcontributor.model.entities.PoiType in project osm-contributor by jawg.

the class TypeManager method getPoiTypeSuggested.

// *********************************
// ************ private ************
// *********************************
/**
 * Return the PoiType suggested for a given key.
 *
 * @param key The name of the wished PoiType.
 * @return The suggested PoiType.
 */
private PoiType getPoiTypeSuggested(String key) {
    if (StringUtils.isEmpty(key)) {
        return null;
    }
    Wiki wiki = tagInfoRestClient.getWikiPages(key);
    PoiType poiType = new PoiType();
    poiType.setName(key);
    poiType.setIcon(key);
    poiType.setLastUse(DateTime.now());
    int ordinal = 0;
    List<PoiTypeTag> poiTypeTags = new ArrayList<>();
    // Request for the English wiki and keep the tags of the tags_combination field.
    for (WikiDataDto data : wiki.getDatas()) {
        if ("en".equals(data.getLang())) {
            for (String tagCombination : data.getTagsCombination()) {
                String[] splitResult = tagCombination.split("=");
                if (splitResult.length > 1) {
                    poiTypeTags.add(PoiTypeTag.builder().key(splitResult[0]).value(splitResult[1]).mandatory(true).poiType(poiType).ordinal(ordinal++).build());
                } else {
                    poiTypeTags.add(PoiTypeTag.builder().key(tagCombination).mandatory(false).poiType(poiType).ordinal(ordinal++).build());
                }
            }
            break;
        }
    }
    // If there was no relevant information in the English wiki, query for tags combinations.
    if (poiTypeTags.size() == 0) {
        CombinationsDto combinationsDto = tagInfoRestClient.getCombinations(key, 1, 5);
        for (CombinationsDataDto data : combinationsDto.getData()) {
            if (tagsGroup.contains(data.getOtherKey())) {
                poiTypeTags.add(PoiTypeTag.builder().key(data.getOtherKey()).value(key).mandatory(true).poiType(poiType).ordinal(ordinal++).build());
            } else {
                poiTypeTags.add(PoiTypeTag.builder().key(data.getOtherKey()).mandatory(false).poiType(poiType).ordinal(ordinal++).build());
            }
        }
    }
    poiType.setTags(poiTypeTags);
    return poiType;
}
Also used : CombinationsDataDto(io.jawg.osmcontributor.rest.dtos.osm.CombinationsDataDto) PoiType(io.jawg.osmcontributor.model.entities.PoiType) ArrayList(java.util.ArrayList) Wiki(io.jawg.osmcontributor.rest.dtos.osm.Wiki) CombinationsDto(io.jawg.osmcontributor.rest.dtos.osm.CombinationsDto) PoiTypeTag(io.jawg.osmcontributor.model.entities.PoiTypeTag) WikiDataDto(io.jawg.osmcontributor.rest.dtos.osm.WikiDataDto)

Example 10 with PoiType

use of io.jawg.osmcontributor.model.entities.PoiType in project osm-contributor by jawg.

the class TypeManager method onInternalSavePoiTagEvent.

@Subscribe(threadMode = ThreadMode.ASYNC)
public void onInternalSavePoiTagEvent(InternalSavePoiTagEvent event) {
    PoiTypeTag poiTypeTag = event.getPoiTypeTag();
    PoiType poiType = poiTypeTag.getPoiType();
    poiManager.savePoiType(poiType);
    bus.post(new PoiTagCreatedEvent(poiTypeTag));
}
Also used : PoiTagCreatedEvent(io.jawg.osmcontributor.ui.events.type.PoiTagCreatedEvent) PoiType(io.jawg.osmcontributor.model.entities.PoiType) PoiTypeTag(io.jawg.osmcontributor.model.entities.PoiTypeTag) Subscribe(org.greenrobot.eventbus.Subscribe)

Aggregations

PoiType (io.jawg.osmcontributor.model.entities.PoiType)28 PoiTypeTag (io.jawg.osmcontributor.model.entities.PoiTypeTag)9 Subscribe (org.greenrobot.eventbus.Subscribe)9 ArrayList (java.util.ArrayList)7 PleaseLoadLastUsedPoiType (io.jawg.osmcontributor.ui.events.map.PleaseLoadLastUsedPoiType)5 View (android.view.View)3 ImageView (android.widget.ImageView)2 TextView (android.widget.TextView)2 BindView (butterknife.BindView)2 Poi (io.jawg.osmcontributor.model.entities.Poi)2 PoiTag (io.jawg.osmcontributor.model.entities.PoiTag)2 PoiTypesLoaded (io.jawg.osmcontributor.model.events.PoiTypesLoaded)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 DateTime (org.joda.time.DateTime)2 NonNull (android.support.annotation.NonNull)1 Snackbar (android.support.design.widget.Snackbar)1 Menu (android.view.Menu)1 MenuItem (android.view.MenuItem)1 ListView (android.widget.ListView)1