Search in sources :

Example 1 with OsmBugResult

use of net.osmand.plus.osmedit.OsmBugsUtil.OsmBugResult in project Osmand by osmandapp.

the class OsmBugsLayer method asyncActionTask.

private void asyncActionTask(final OpenStreetNote bug, final OsmNotesPoint point, final String text, final Action action) {
    AsyncTask<Void, Void, OsmBugResult> task = new AsyncTask<Void, Void, OsmBugResult>() {

        private OsmBugsUtil osmbugsUtil;

        @Override
        protected OsmBugResult doInBackground(Void... params) {
            if (bug != null) {
                osmbugsUtil = getOsmbugsUtil(bug);
                OsmNotesPoint pnt = new OsmNotesPoint();
                pnt.setId(bug.getId());
                pnt.setLatitude(bug.getLatitude());
                pnt.setLongitude(bug.getLongitude());
                return osmbugsUtil.commit(pnt, text, action);
            } else if (point != null) {
                osmbugsUtil = local;
                return osmbugsUtil.modify(point, text);
            }
            return null;
        }

        protected void onPostExecute(OsmBugResult obj) {
            if (obj != null && obj.warning == null) {
                if (local == osmbugsUtil) {
                    Toast.makeText(activity, R.string.osm_changes_added_to_local_edits, Toast.LENGTH_LONG).show();
                    if (obj.local != null) {
                        PointDescription pd = new PointDescription(PointDescription.POINT_TYPE_OSM_BUG, obj.local.getText());
                        activity.getContextMenu().show(new LatLon(obj.local.getLatitude(), obj.local.getLongitude()), pd, obj.local);
                    }
                } else {
                    if (action == Action.REOPEN) {
                        Toast.makeText(activity, R.string.osn_add_dialog_success, Toast.LENGTH_LONG).show();
                    } else if (action == Action.MODIFY) {
                        Toast.makeText(activity, R.string.osb_comment_dialog_success, Toast.LENGTH_LONG).show();
                    } else if (action == Action.DELETE) {
                        Toast.makeText(activity, R.string.osn_close_dialog_success, Toast.LENGTH_LONG).show();
                    } else if (action == Action.CREATE) {
                        Toast.makeText(activity, R.string.osn_add_dialog_success, Toast.LENGTH_LONG).show();
                    }
                }
                clearCache();
            } else {
                int r = R.string.osb_comment_dialog_error;
                if (action == Action.REOPEN) {
                    r = R.string.osn_add_dialog_error;
                    reopenBug(bug, text);
                } else if (action == Action.DELETE) {
                    r = R.string.osn_close_dialog_error;
                    closeBug(bug, text);
                } else if (action == Action.CREATE) {
                    r = R.string.osn_add_dialog_error;
                    openBug(bug.getLatitude(), bug.getLongitude(), text);
                } else if (action == null) {
                    r = R.string.osn_modify_dialog_error;
                    modifyBug(point);
                } else {
                    commentBug(bug, text);
                }
                Toast.makeText(activity, activity.getResources().getString(r) + "\n" + obj, Toast.LENGTH_LONG).show();
            }
        }
    };
    executeTaskInBackground(task);
}
Also used : LatLon(net.osmand.data.LatLon) PointDescription(net.osmand.data.PointDescription) AsyncTask(android.os.AsyncTask) OsmBugResult(net.osmand.plus.osmedit.OsmBugsUtil.OsmBugResult) SuppressLint(android.annotation.SuppressLint) Paint(android.graphics.Paint)

Aggregations

SuppressLint (android.annotation.SuppressLint)1 Paint (android.graphics.Paint)1 AsyncTask (android.os.AsyncTask)1 LatLon (net.osmand.data.LatLon)1 PointDescription (net.osmand.data.PointDescription)1 OsmBugResult (net.osmand.plus.osmedit.OsmBugsUtil.OsmBugResult)1