Search in sources :

Example 6 with Poi

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

the class PoiManager method loadPoiForCreation.

/**
 * Send a {@link PoiForEditionLoadedEvent} containing the suggestions for the PoiTypeTags and a new Poi to complete.
 *
 * @param event Event containing the position, level and PoiType of the Poi to create.
 */
private void loadPoiForCreation(PleaseLoadPoiForCreationEvent event) {
    Poi poi = new Poi();
    Set<Double> level = new HashSet<>();
    level.add(event.getLevel());
    poi.setLevel(level);
    poi.setLatitude(event.getLat());
    poi.setLongitude(event.getLng());
    poi.setType(poiTypeDao.queryForId(event.getPoiType()));
    Map<String, String> defaultTags = new HashMap<>();
    for (PoiTypeTag poiTypeTag : poi.getType().getTags()) {
        if (poiTypeTag.getValue() != null) {
            // default tags should be set in the corresponding POI
            defaultTags.put(poiTypeTag.getKey(), poiTypeTag.getValue());
        }
    }
    poi.applyChanges(defaultTags);
    bus.post(new PoiForEditionLoadedEvent(poi, suggestionsForTagsValue(poi.getType().getTags())));
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Poi(io.jawg.osmcontributor.model.entities.Poi) PoiForEditionLoadedEvent(io.jawg.osmcontributor.model.events.PoiForEditionLoadedEvent) PoiTypeTag(io.jawg.osmcontributor.model.entities.PoiTypeTag) HashSet(java.util.HashSet)

Example 7 with Poi

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

the class PoiManager method onPleaseLoadPoisToUpdateEvent.

@Subscribe(threadMode = ThreadMode.ASYNC)
public void onPleaseLoadPoisToUpdateEvent(PleaseLoadPoisToUpdateEvent event) {
    List<Poi> updatedPois = poiDao.queryForAllUpdated();
    List<Poi> newPois = poiDao.queryForAllNew();
    List<Poi> toDeletePois = poiDao.queryToDelete();
    List<PoiNodeRef> wayPoiNodeRef = poiNodeRefDao.queryAllToUpdate();
    List<PoiUpdateWrapper> allPois = new ArrayList<>();
    for (Poi p : updatedPois) {
        Long oldPoiId = p.getOldPoiId();
        if (oldPoiId != null) {
            allPois.add(new PoiUpdateWrapper(true, p, poiDao.queryForId(oldPoiId), null, PoiUpdateWrapper.PoiAction.UPDATE));
        }
    }
    for (Poi p : newPois) {
        allPois.add(new PoiUpdateWrapper(true, p, null, null, PoiUpdateWrapper.PoiAction.CREATE));
    }
    for (Poi p : toDeletePois) {
        allPois.add(new PoiUpdateWrapper(true, p, poiDao.queryForId(p.getOldPoiId()), null, PoiUpdateWrapper.PoiAction.DELETED));
    }
    for (PoiNodeRef p : wayPoiNodeRef) {
        allPois.add(new PoiUpdateWrapper(false, null, null, p, PoiUpdateWrapper.PoiAction.UPDATE));
    }
    bus.post(new PoisToUpdateLoadedEvent(allPois));
}
Also used : PoisToUpdateLoadedEvent(io.jawg.osmcontributor.model.events.PoisToUpdateLoadedEvent) ArrayList(java.util.ArrayList) Poi(io.jawg.osmcontributor.model.entities.Poi) PoiNodeRef(io.jawg.osmcontributor.model.entities.PoiNodeRef) PoiUpdateWrapper(io.jawg.osmcontributor.utils.upload.PoiUpdateWrapper) Subscribe(org.greenrobot.eventbus.Subscribe)

Example 8 with Poi

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

the class PoiManager method onPleaseRevertPoiEvent.

@Subscribe(threadMode = ThreadMode.ASYNC)
public void onPleaseRevertPoiEvent(PleaseRevertPoiEvent event) {
    Poi poi = revertPoi(event.getIdToRevert());
    bus.post(new RevertFinishedEvent(poi, LocationMarkerView.MarkerType.POI));
}
Also used : Poi(io.jawg.osmcontributor.model.entities.Poi) RevertFinishedEvent(io.jawg.osmcontributor.model.events.RevertFinishedEvent) Subscribe(org.greenrobot.eventbus.Subscribe)

Example 9 with Poi

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

the class MapFragmentPresenter method setIcon.

private void setIcon(LocationMarkerViewOptions markerOptions, Object relatedObject, boolean selected) {
    Bitmap bitmap;
    if (relatedObject instanceof Poi) {
        Poi poi = (Poi) relatedObject;
        bitmap = mapFragment.getBitmapHandler().getMarkerBitmap(poi.getType(), Poi.computeState(selected, false, poi.getUpdated()));
    } else {
        Note note = (Note) relatedObject;
        bitmap = mapFragment.getBitmapHandler().getNoteBitmap(Note.computeState(note, selected, false));
    }
    if (bitmap != null) {
        markerOptions.icon(IconFactory.getInstance(mapFragment.getActivity()).fromBitmap(bitmap));
    }
}
Also used : Bitmap(android.graphics.Bitmap) Note(io.jawg.osmcontributor.model.entities.Note) Poi(io.jawg.osmcontributor.model.entities.Poi)

Example 10 with Poi

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

the class MapFragmentPresenter method impacteLoadedPoi.

private void impacteLoadedPoi(List<Poi> pois) {
    List<MapElement> mapElements = new ArrayList<>(pois.size());
    for (Poi poi : pois) {
        mapElements.add(poi);
    }
    onLoaded(mapElements, LocationMarkerView.MarkerType.POI);
}
Also used : MapElement(io.jawg.osmcontributor.utils.core.MapElement) ArrayList(java.util.ArrayList) Poi(io.jawg.osmcontributor.model.entities.Poi)

Aggregations

Poi (io.jawg.osmcontributor.model.entities.Poi)36 ArrayList (java.util.ArrayList)9 Subscribe (org.greenrobot.eventbus.Subscribe)9 HashMap (java.util.HashMap)7 PoiNodeRef (io.jawg.osmcontributor.model.entities.PoiNodeRef)5 Bitmap (android.graphics.Bitmap)3 LatLng (com.mapbox.mapboxsdk.geometry.LatLng)3 PoiTag (io.jawg.osmcontributor.model.entities.PoiTag)3 Note (io.jawg.osmcontributor.model.entities.Note)2 PoiType (io.jawg.osmcontributor.model.entities.PoiType)2 PoiTypeTag (io.jawg.osmcontributor.model.entities.PoiTypeTag)2 PoiForEditionLoadedEvent (io.jawg.osmcontributor.model.events.PoiForEditionLoadedEvent)2 OsmDto (io.jawg.osmcontributor.rest.dtos.osm.OsmDto)2 PoiChangesApplyEvent (io.jawg.osmcontributor.ui.events.edition.PoiChangesApplyEvent)2 PleaseChangeValuesDetailPoiFragmentEvent (io.jawg.osmcontributor.ui.events.map.PleaseChangeValuesDetailPoiFragmentEvent)2 PoiManager (io.jawg.osmcontributor.ui.managers.PoiManager)2 MapElement (io.jawg.osmcontributor.utils.core.MapElement)2 IOException (java.io.IOException)2 HashSet (java.util.HashSet)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2