Search in sources :

Example 26 with Poi

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

the class EditPoiManager method onPleaseApplyPoiChanges.

@Subscribe(threadMode = ThreadMode.ASYNC)
public void onPleaseApplyPoiChanges(PleaseApplyPoiChanges event) {
    Timber.d("please apply poi changes");
    Poi editPoi = poiManager.queryForId(event.getPoiChanges().getId());
    if (editPoi.hasChanges(event.getPoiChanges().getTagsMap())) {
        editPoi.setOldPoiId(saveOldVersionOfPoi(editPoi));
        // this is the edition of a new poi or we already edited this poi
        editPoi.applyChanges(event.getPoiChanges().getTagsMap());
        editPoi.applyChanges(applyConstraints(editPoi));
        editPoi.setUpdated(true);
        poiManager.savePoi(editPoi);
        poiManager.updatePoiTypeLastUse(editPoi.getType().getId());
    }
    eventBus.post(new PoiChangesApplyEvent());
}
Also used : PoiChangesApplyEvent(io.jawg.osmcontributor.ui.events.edition.PoiChangesApplyEvent) Poi(io.jawg.osmcontributor.model.entities.Poi) Subscribe(org.greenrobot.eventbus.Subscribe)

Example 27 with Poi

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

the class EditPoiManager method onPleaseDeletePoiEvent.

@Subscribe(threadMode = ThreadMode.ASYNC)
public void onPleaseDeletePoiEvent(PleaseDeletePoiEvent event) {
    Timber.d("Please delete poi");
    Poi poi = event.getPoi();
    if (poi.getId() != null) {
        poi = poiManager.queryForId(poi.getId());
    }
    if (poi.getBackendId() == null) {
        poiManager.deletePoi(poi);
    } else {
        poi.setOldPoiId(saveOldVersionOfPoi(poi));
        poi.setToDelete(true);
        poiManager.savePoi(poi);
    }
}
Also used : Poi(io.jawg.osmcontributor.model.entities.Poi) Subscribe(org.greenrobot.eventbus.Subscribe)

Example 28 with Poi

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

the class PoiManager method savePoisFromAssets.

/**
 * Load pois from assets and save them in the database.
 */
public void savePoisFromAssets() {
    List<Poi> pois = poiAssetLoader.loadPoisFromAssets();
    Timber.d("Loaded %s poi, trying to insert them", pois.size());
    for (Poi poi : pois) {
        Timber.d("saving poi %s", poi);
        savePoi(poi);
        Timber.d("poi saved");
    }
}
Also used : Poi(io.jawg.osmcontributor.model.entities.Poi)

Example 29 with Poi

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

the class PoiManager method revertPoi.

/**
 * Get the backup data and put it back in the active Poi, at the end the backup Poi is deleted.
 *
 * @param poiId The Id of the Poi to revert.
 */
private Poi revertPoi(Long poiId) {
    Poi poi = poiDao.queryForId(poiId);
    Poi backup = null;
    Long oldPoiId = poi.getOldPoiId();
    if (oldPoiId != null) {
        backup = poiDao.queryForId(oldPoiId);
        // we retrieve the backup data and put it back
        backup.setOld(false);
        backup.setId(poi.getId());
        savePoi(backup);
        // we prepare to delete the modifications
        poi.setId(oldPoiId);
    }
    deletePoi(poi);
    return backup;
}
Also used : Poi(io.jawg.osmcontributor.model.entities.Poi)

Example 30 with Poi

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

the class PoiManager method deleteOldPoiAssociated.

public void deleteOldPoiAssociated(Poi poi) {
    Long oldId = poi.getOldPoiId();
    if (oldId != null) {
        Poi old = poiDao.queryForId(oldId);
        if (old != null) {
            deletePoi(old);
        }
        poi.setOldPoiId(null);
    }
}
Also used : 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