Search in sources :

Example 26 with PoiType

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

the class PoiTypeAdapter method notifyTagRemoved.

public void notifyTagRemoved(PoiTypeTag poiTypeTag) {
    PoiType poiType = poiTypeTag.getPoiType();
    Long id = poiType != null ? poiType.getId() : null;
    if (id == null) {
        return;
    }
    poiType = getItemById(id);
    if (poiType != null) {
        poiType.getTags().remove(poiTypeTag);
        int position = filteredValues.indexOf(poiType);
        if (position != -1) {
            notifyItemChanged(position);
        }
    }
}
Also used : PoiType(io.jawg.osmcontributor.model.entities.PoiType)

Example 27 with PoiType

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

the class PoiTypeAdapter method undoLastRemoval.

public void undoLastRemoval() {
    final PoiType item = lastRemovedItem;
    if (item != null) {
        lastRemovedItem = null;
        addItem(item);
    }
}
Also used : PoiType(io.jawg.osmcontributor.model.entities.PoiType)

Example 28 with PoiType

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

the class PoiManagerTest method testBulkSaveAndBulkUpdate.

@Test
public void testBulkSaveAndBulkUpdate() {
    PoiManager poiManager = component.getPoiManager();
    PoiType poiType = poiManager.savePoiType(getPoiType());
    // try to save and then update 1000 pois.
    // 1000 because it can happen in real life and pose problems if we try to do an "IN" sql clause
    List<Poi> pois = new ArrayList<>(1000);
    for (int i = 0; i < 1000; i++) {
        pois.add(getPoi(poiType, i));
    }
    poiManager.savePois(pois);
    for (Poi poi : pois) {
        assertThat(poi.getId()).isNotNull();
    }
    for (Poi poi : pois) {
        Map<String, String> tags = new HashMap<>();
        tags.put("tag2", "value2");
        poi.getTags().clear();
        poi.applyChanges(tags);
    }
    List<Poi> savedPois = poiManager.savePois(pois);
    for (Poi poi : savedPois) {
        assertThat(poi.getTags()).hasSize(1);
        PoiTag tag = poi.getTags().iterator().next();
        assertThat(tag.getKey()).isEqualTo("tag2");
        assertThat(tag.getValue()).isEqualTo("value2");
    }
}
Also used : PoiTag(io.jawg.osmcontributor.model.entities.PoiTag) HashMap(java.util.HashMap) PoiType(io.jawg.osmcontributor.model.entities.PoiType) ArrayList(java.util.ArrayList) Poi(io.jawg.osmcontributor.model.entities.Poi) PoiManager(io.jawg.osmcontributor.ui.managers.PoiManager) Test(org.junit.Test)

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