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()));
}
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()));
}
}
Aggregations