Search in sources :

Example 1 with PoiTypesLoaded

use of io.jawg.osmcontributor.model.events.PoiTypesLoaded in project osm-contributor by jawg.

the class TypeManager method onInternalRemovePoiTypeEvent.

@Subscribe(threadMode = ThreadMode.ASYNC)
public void onInternalRemovePoiTypeEvent(InternalRemovePoiTypeEvent event) {
    PoiType poiType = event.getPoiType();
    poiManager.deletePoiType(poiType);
    Timber.i("Removed poi type %d", poiType.getId());
    bus.post(new PoiTypeDeletedEvent(poiType));
    bus.post(new PoiTypesLoaded(poiManager.getPoiTypesSortedByName()));
}
Also used : PoiTypeDeletedEvent(io.jawg.osmcontributor.ui.events.type.PoiTypeDeletedEvent) PoiType(io.jawg.osmcontributor.model.entities.PoiType) PoiTypesLoaded(io.jawg.osmcontributor.model.events.PoiTypesLoaded) Subscribe(org.greenrobot.eventbus.Subscribe)

Example 2 with PoiTypesLoaded

use of io.jawg.osmcontributor.model.events.PoiTypesLoaded in project osm-contributor by jawg.

the class SyncManager method syncDownloadPoiTypes.

// ********************************
// ************ public ************
// ********************************
/**
 * Download the list of PoiType from the backend and actualize the database.
 * <br/>
 * If there was new, modified or a deleted PoiType, send a
 * {@link PoiTypesLoaded} event containing the new list of PoiTypes.
 */
public void syncDownloadPoiTypes() {
    List<PoiType> poiTypes = backend.getPoiTypes();
    PoiType dbPoiType;
    boolean modified = false;
    List<PoiType> oldTypes = poiTypeDao.queryForAll();
    // Create and update the PoiTypes in database with the result from backend
    for (PoiType type : poiTypes) {
        dbPoiType = type.getBackendId() != null ? poiTypeDao.findByBackendId(type.getBackendId()) : null;
        if (dbPoiType != null) {
            type.setId(dbPoiType.getId());
        }
        type = poiManager.savePoiType(type);
        if (!modified && !type.equals(dbPoiType)) {
            modified = true;
        }
    }
    // Delete from database the PoiTypes who aren't in the new list of the backend.
    for (PoiType type : oldTypes) {
        if (!poiTypes.contains(type)) {
            poiManager.deletePoiType(type);
            modified = true;
        }
    }
    if (modified) {
        bus.postSticky(new PoiTypesLoaded(poiManager.getPoiTypesSortedByName()));
    }
}
Also used : PoiType(io.jawg.osmcontributor.model.entities.PoiType) PoiTypesLoaded(io.jawg.osmcontributor.model.events.PoiTypesLoaded)

Aggregations

PoiType (io.jawg.osmcontributor.model.entities.PoiType)2 PoiTypesLoaded (io.jawg.osmcontributor.model.events.PoiTypesLoaded)2 PoiTypeDeletedEvent (io.jawg.osmcontributor.ui.events.type.PoiTypeDeletedEvent)1 Subscribe (org.greenrobot.eventbus.Subscribe)1