Search in sources :

Example 21 with PoiType

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

the class TypeManager method onInternalSavePoiTypeEvent.

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

Example 22 with PoiType

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

the class TypeListActivityPresenter method onPleaseSavePoiTag.

/* ========== POI type/tag edition ========== */
@Subscribe(threadMode = ThreadMode.MAIN)
public void onPleaseSavePoiTag(PleaseSavePoiTag event) {
    PoiTypeTag poiTypeTag = null;
    PoiType poiType = currentPoiType;
    if (poiType == null) {
        throw new IllegalStateException("Not currently displaying tags of a specific POI type");
    }
    Long id = event.getId();
    if (id != null) {
        // We edit an existing tag, so find it in the list...
        for (PoiTypeTag tag : poiType.getTags()) {
            if (tag.getId().equals(id)) {
                poiTypeTag = tag;
                break;
            }
        }
        if (poiTypeTag == null) {
            throw new IllegalStateException("Edited tag not found in current POI type");
        }
    } else {
        // Create a new tag
        poiTypeTag = new PoiTypeTag();
        poiTypeTag.setPoiType(poiType);
        Collection<PoiTypeTag> tags = poiType.getTags();
        poiTypeTag.setOrdinal(tags.size());
        tags.add(poiTypeTag);
    }
    poiTypeTag.setKey(event.getKey());
    poiTypeTag.setValue(event.getValue());
    poiTypeTag.setMandatory(event.isMandatory());
    typeManager.savePoiTag(poiTypeTag);
}
Also used : PoiType(io.jawg.osmcontributor.model.entities.PoiType) PoiTypeTag(io.jawg.osmcontributor.model.entities.PoiTypeTag) Subscribe(org.greenrobot.eventbus.Subscribe)

Example 23 with PoiType

use of io.jawg.osmcontributor.model.entities.PoiType 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)

Example 24 with PoiType

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

the class PoiTypePickerAdapter method getView.

@Override
public View getView(int position, View view, ViewGroup parent) {
    ViewHolder holder = null;
    if (view != null) {
        holder = (ViewHolder) view.getTag();
        if (holder instanceof ExpertViewHolder ^ expertMode) {
            holder = null;
        }
    }
    if (holder == null) {
        if (expertMode) {
            view = inflater.inflate(R.layout.single_expert_poitype_autocomplete_layout, parent, false);
            holder = new ExpertViewHolder(view);
        } else {
            view = inflater.inflate(R.layout.single_poitype_autocomplete_layout, parent, false);
            holder = new ViewHolder(view);
        }
        view.setTag(holder);
    }
    final PoiType value = filteredValues.get(position);
    holder.onBind(value);
    view.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            eventBus.post(new NewPoiTypeSelected(value));
            closeKeyboard();
        }
    });
    return view;
}
Also used : PoiType(io.jawg.osmcontributor.model.entities.PoiType) NewPoiTypeSelected(io.jawg.osmcontributor.ui.events.map.NewPoiTypeSelected) ImageView(android.widget.ImageView) BindView(butterknife.BindView) TextView(android.widget.TextView) View(android.view.View)

Example 25 with PoiType

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

the class PoiTypeMapper method convert.

private PoiType convert(PoiTypeDto dto) {
    PoiType type = new PoiType();
    type.setName(getTranslationFormJson(dto.getLabel(), getName(dto.getName())));
    type.setTechnicalName(dto.getName());
    type.setDescription(getTranslationFormJson(dto.getDescription(), ""));
    type.setKeyWords(getKeywordsFormJson(dto.getKeywords()));
    type.setIcon(getName(dto.getName()));
    // When creating a new PoiType from file, put the same date of last use to all new PoiTypes : 1970-01-01T00:00:00Z
    type.setLastUse(dateTime);
    int ordinal = 0;
    if (dto.getTags() != null) {
        ArrayList<PoiTypeTag> tags = new ArrayList<>(dto.getTags().size());
        type.setTags(tags);
        type.setQuery(dto.getQuery());
        for (PoiTypeTagDto tagDto : dto.getTags()) {
            // If the tag is implied, do not keep it
            PoiTypeTag poiTypeTag = new PoiTypeTag();
            poiTypeTag.setPoiType(type);
            poiTypeTag.setKey(tagDto.getKey());
            poiTypeTag.setValue(tagDto.getValue());
            poiTypeTag.setMandatory(tagDto.getRequired());
            poiTypeTag.setOrdinal(ordinal++);
            poiTypeTag.setShow(tagDto.getShow());
            if (tagDto.getValues() != null && !tagDto.getValues().isEmpty()) {
                List<String> possibleValues = new ArrayList<>();
                for (Map<String, Map<String, String>> valuesMap : tagDto.getValues()) {
                    for (Map.Entry<String, Map<String, String>> value : valuesMap.entrySet()) {
                        possibleValues.add(value.getKey() + VALUE_SEPARATOR + getTranslationFormJson(value.getValue(), ""));
                    }
                }
                poiTypeTag.setPossibleValues(getPossibleValues(possibleValues));
            }
            poiTypeTag.setTagType(tagDto.getType());
            tags.add(poiTypeTag);
        }
    }
    ordinal = 0;
    if (dto.getConstraints() != null) {
        ArrayList<Constraint> constraints = new ArrayList<>();
        type.setConstraints(constraints);
        for (ConstraintDto constraintDto : dto.getConstraints()) {
            // Constraint's Source
            Source source = Source.builder().setType(constraintDto.getSource().getType()).setKey(constraintDto.getSource().getKey()).build();
            // Constraint's Condition
            Condition condition = Condition.builder().setType(constraintDto.getCondition().getType()).setValue(constraintDto.getCondition().getValue()).build();
            // Constraint's Action
            Action action = Action.builder().setType(constraintDto.getAction().getType()).setKey(constraintDto.getAction().getKey()).setValue(constraintDto.getAction().getValue()).build();
            // Complete constraint
            Constraint constraint = Constraint.builder().setPoiType(type).setSource(source).setCondition(condition).setAction(action).setOrdinal(ordinal++).build();
            // Add constraint to the list
            constraints.add(constraint);
        }
    }
    return type;
}
Also used : Condition(io.jawg.osmcontributor.model.entities.Condition) Action(io.jawg.osmcontributor.model.entities.Action) Constraint(io.jawg.osmcontributor.model.entities.Constraint) PoiTypeTagDto(io.jawg.osmcontributor.rest.dtos.dma.PoiTypeTagDto) PoiType(io.jawg.osmcontributor.model.entities.PoiType) ArrayList(java.util.ArrayList) ConstraintDto(io.jawg.osmcontributor.rest.dtos.dma.ConstraintDto) PoiTypeTag(io.jawg.osmcontributor.model.entities.PoiTypeTag) Constraint(io.jawg.osmcontributor.model.entities.Constraint) Source(io.jawg.osmcontributor.model.entities.Source) Map(java.util.Map)

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