Search in sources :

Example 1 with PoiUpdateWrapper

use of io.jawg.osmcontributor.utils.upload.PoiUpdateWrapper in project osm-contributor by jawg.

the class PoiManager method onPleaseLoadPoisToUpdateEvent.

@Subscribe(threadMode = ThreadMode.ASYNC)
public void onPleaseLoadPoisToUpdateEvent(PleaseLoadPoisToUpdateEvent event) {
    List<Poi> updatedPois = poiDao.queryForAllUpdated();
    List<Poi> newPois = poiDao.queryForAllNew();
    List<Poi> toDeletePois = poiDao.queryToDelete();
    List<PoiNodeRef> wayPoiNodeRef = poiNodeRefDao.queryAllToUpdate();
    List<PoiUpdateWrapper> allPois = new ArrayList<>();
    for (Poi p : updatedPois) {
        Long oldPoiId = p.getOldPoiId();
        if (oldPoiId != null) {
            allPois.add(new PoiUpdateWrapper(true, p, poiDao.queryForId(oldPoiId), null, PoiUpdateWrapper.PoiAction.UPDATE));
        }
    }
    for (Poi p : newPois) {
        allPois.add(new PoiUpdateWrapper(true, p, null, null, PoiUpdateWrapper.PoiAction.CREATE));
    }
    for (Poi p : toDeletePois) {
        allPois.add(new PoiUpdateWrapper(true, p, poiDao.queryForId(p.getOldPoiId()), null, PoiUpdateWrapper.PoiAction.DELETED));
    }
    for (PoiNodeRef p : wayPoiNodeRef) {
        allPois.add(new PoiUpdateWrapper(false, null, null, p, PoiUpdateWrapper.PoiAction.UPDATE));
    }
    bus.post(new PoisToUpdateLoadedEvent(allPois));
}
Also used : PoisToUpdateLoadedEvent(io.jawg.osmcontributor.model.events.PoisToUpdateLoadedEvent) ArrayList(java.util.ArrayList) Poi(io.jawg.osmcontributor.model.entities.Poi) PoiNodeRef(io.jawg.osmcontributor.model.entities.PoiNodeRef) PoiUpdateWrapper(io.jawg.osmcontributor.utils.upload.PoiUpdateWrapper) Subscribe(org.greenrobot.eventbus.Subscribe)

Example 2 with PoiUpdateWrapper

use of io.jawg.osmcontributor.utils.upload.PoiUpdateWrapper in project osm-contributor by jawg.

the class PoisAdapter method remove.

public void remove(int position) {
    PoiUpdateWrapper wrapper = poisWrapper.remove(position);
    if (OnRemoveListener != null) {
        OnRemoveListener.onItemRemoved(wrapper, position);
    }
    notifyItemRemoved(position);
}
Also used : PoiUpdateWrapper(io.jawg.osmcontributor.utils.upload.PoiUpdateWrapper)

Example 3 with PoiUpdateWrapper

use of io.jawg.osmcontributor.utils.upload.PoiUpdateWrapper in project osm-contributor by jawg.

the class PoisAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final PoiViewHolder holder, final int position) {
    final PoiUpdateWrapper poiWrapper = poisWrapper.get(position);
    switch(poiWrapper.getAction()) {
        case CREATE:
            holder.getPoiAction().setText(context.getString(R.string.created));
            break;
        case DELETED:
            holder.getPoiAction().setText(context.getString(R.string.deleted));
            break;
        case UPDATE:
            holder.getPoiAction().setText(context.getString(R.string.updated));
            break;
    }
    final LinearLayout wrapper = holder.getDetailsWrapper();
    if (poiWrapper.getIsPoi()) {
        holder.getPoiType().setText(poiWrapper.getPoiType());
        holder.getPoiName().setText(poiWrapper.getName());
        holder.getExpandBtn().setVisibility(View.VISIBLE);
        populateDiffs(holder, holder.getDetailsWrapper(), poiWrapper);
        View.OnClickListener expendCardnew = new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                poiWrapper.setOpen(!poiWrapper.isOpen());
                ViewAnimation.animate(wrapper, poiWrapper.isOpen());
                if (poiWrapper.isOpen()) {
                    holder.getExpandBtn().setImageResource(R.drawable.chevron_up);
                } else {
                    holder.getExpandBtn().setImageResource(R.drawable.chevron_down);
                }
            }
        };
        holder.getExpandBtn().setOnClickListener(expendCardnew);
        holder.getHeader().setOnClickListener(expendCardnew);
        if (poiWrapper.isOpen()) {
            wrapper.setVisibility(View.VISIBLE);
            holder.getExpandBtn().setImageResource(R.drawable.chevron_up);
        } else {
            wrapper.setVisibility(View.GONE);
            holder.getExpandBtn().setImageResource(R.drawable.chevron_down);
        }
    } else {
        holder.getExpandBtn().setVisibility(View.GONE);
        wrapper.setVisibility(View.GONE);
        holder.getPoiType().setText(context.getString(R.string.node_ref_title));
        holder.getPoiName().setText("");
    }
    holder.getRevertBtn().setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            remove(poisWrapper.indexOf(poiWrapper));
        }
    });
    holder.getCheckbox().setChecked(poiWrapper.isSelected());
    holder.getCheckbox().setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            poiWrapper.setSelected(isChecked);
        }
    });
}
Also used : BindView(butterknife.BindView) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) View(android.view.View) PoiUpdateWrapper(io.jawg.osmcontributor.utils.upload.PoiUpdateWrapper) LinearLayout(android.widget.LinearLayout) CompoundButton(android.widget.CompoundButton)

Aggregations

PoiUpdateWrapper (io.jawg.osmcontributor.utils.upload.PoiUpdateWrapper)3 RecyclerView (android.support.v7.widget.RecyclerView)1 View (android.view.View)1 CompoundButton (android.widget.CompoundButton)1 LinearLayout (android.widget.LinearLayout)1 TextView (android.widget.TextView)1 BindView (butterknife.BindView)1 Poi (io.jawg.osmcontributor.model.entities.Poi)1 PoiNodeRef (io.jawg.osmcontributor.model.entities.PoiNodeRef)1 PoisToUpdateLoadedEvent (io.jawg.osmcontributor.model.events.PoisToUpdateLoadedEvent)1 ArrayList (java.util.ArrayList)1 Subscribe (org.greenrobot.eventbus.Subscribe)1