POI creation dialog with close changeset option

This commit is contained in:
Victor Shcherb 2012-10-29 00:59:17 +01:00
parent d52363eaf6
commit 47abeecd19
7 changed files with 53 additions and 18 deletions

View file

@ -74,7 +74,6 @@
android:layout_marginLeft="5dp" android:layout_marginLeft="5dp"
android:layout_marginRight="5dp" android:layout_marginRight="5dp"
android:hint="http://osmand.net" /> android:hint="http://osmand.net" />
</TableRow> </TableRow>
<TableRow> <TableRow>
@ -82,6 +81,12 @@
<EditText android:text="@string/poi_dialog_comment_default" android:id="@+id/Comment" android:layout_marginLeft="5dp" android:layout_width ="100dp" android:layout_marginRight="5dp" android:layout_height="wrap_content"></EditText> <EditText android:text="@string/poi_dialog_comment_default" android:id="@+id/Comment" android:layout_marginLeft="5dp" android:layout_width ="100dp" android:layout_marginRight="5dp" android:layout_height="wrap_content"></EditText>
</TableRow> </TableRow>
<TableRow >
<CheckBox android:layout_width="wrap_content" android:layout_marginLeft="5dp" android:layout_span="2"
android:layout_marginRight="5dp" android:text="@string/close_changeset" android:id="@+id/CloseChangeset"/>
</TableRow>
</TableLayout> </TableLayout>
<Button <Button

View file

@ -9,6 +9,7 @@
1. All your modified/created strings are in the top of the file (to make easier find what\'s translated). 1. All your modified/created strings are in the top of the file (to make easier find what\'s translated).
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
--> -->
<string name="close_changeset">Close changeset</string>
<string name="zxing_barcode_scanner_not_found">ZXing Barcode Scanner application not installed. Search in Market?</string> <string name="zxing_barcode_scanner_not_found">ZXing Barcode Scanner application not installed. Search in Market?</string>
<string name="rendering_attr_roadColors_description">Select a road color scheme:</string> <string name="rendering_attr_roadColors_description">Select a road color scheme:</string>
<string name="rendering_attr_roadColors_name">Road color scheme</string> <string name="rendering_attr_roadColors_name">Road color scheme</string>

View file

@ -44,7 +44,9 @@ import android.view.View;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView; import android.widget.AutoCompleteTextView;
import android.widget.Button; import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText; import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TableLayout; import android.widget.TableLayout;
import android.widget.TableRow; import android.widget.TableRow;
import android.widget.TextView; import android.widget.TextView;
@ -63,6 +65,7 @@ public class EditingPOIActivity implements DialogProvider {
private EditText commentText; private EditText commentText;
private EditText websiteText; private EditText websiteText;
private EditText phoneText; private EditText phoneText;
private CheckBox closeChange;
// private final static Log log = LogUtil.getLog(EditingPOIActivity.class); // private final static Log log = LogUtil.getLog(EditingPOIActivity.class);
@ -80,6 +83,7 @@ public class EditingPOIActivity implements DialogProvider {
private Bundle dialogBundle = new Bundle(); private Bundle dialogBundle = new Bundle();
private OsmandSettings settings; private OsmandSettings settings;
public EditingPOIActivity(MapActivity uiContext){ public EditingPOIActivity(MapActivity uiContext){
this.ctx = uiContext; this.ctx = uiContext;
@ -139,16 +143,23 @@ public class EditingPOIActivity implements DialogProvider {
private Dialog createDeleteDialog(final Bundle args) { private Dialog createDeleteDialog(final Bundle args) {
Builder builder = new AlertDialog.Builder(ctx); Builder builder = new AlertDialog.Builder(ctx);
builder.setTitle(R.string.poi_remove_title); builder.setTitle(R.string.poi_remove_title);
LinearLayout ll = new LinearLayout(ctx);
ll.setPadding(4, 2, 4, 0);
ll.setOrientation(LinearLayout.VERTICAL);
final EditText comment = new EditText(ctx); final EditText comment = new EditText(ctx);
comment.setText(R.string.poi_remove_title); comment.setText(R.string.poi_remove_title);
builder.setView(comment); ll.addView(comment);
final CheckBox closeChangeset = new CheckBox(ctx);
closeChangeset.setText(R.string.close_changeset);
ll.addView(closeChangeset);
builder.setView(ll);
builder.setNegativeButton(R.string.default_buttons_cancel, null); builder.setNegativeButton(R.string.default_buttons_cancel, null);
builder.setPositiveButton(R.string.default_buttons_delete, new DialogInterface.OnClickListener(){ builder.setPositiveButton(R.string.default_buttons_delete, new DialogInterface.OnClickListener(){
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
Node n = (Node) args.getSerializable(KEY_AMENITY_NODE); Node n = (Node) args.getSerializable(KEY_AMENITY_NODE);
String c = comment.getText().toString(); String c = comment.getText().toString();
commitNode(OsmPoint.Action.DELETE, n, openstreetmapUtil.getEntityInfo(), c, new Runnable(){ commitNode(OsmPoint.Action.DELETE, n, openstreetmapUtil.getEntityInfo(), c, closeChangeset.isSelected(), new Runnable(){
@Override @Override
public void run() { public void run() {
AccessibleToast.makeText(ctx, ctx.getResources().getString(R.string.poi_remove_success), Toast.LENGTH_LONG).show(); AccessibleToast.makeText(ctx, ctx.getResources().getString(R.string.poi_remove_success), Toast.LENGTH_LONG).show();
@ -164,6 +175,9 @@ public class EditingPOIActivity implements DialogProvider {
private void preparePOIDialog(Dialog dlg, Bundle args, int title) { private void preparePOIDialog(Dialog dlg, Bundle args, int title) {
Amenity a = (Amenity) args.getSerializable(KEY_AMENITY); Amenity a = (Amenity) args.getSerializable(KEY_AMENITY);
if(a == null){
a = new Amenity();
}
dlg.setTitle(title); dlg.setTitle(title);
EditText nameText = ((EditText)dlg.findViewById(R.id.Name)); EditText nameText = ((EditText)dlg.findViewById(R.id.Name));
nameText.setText(a.getName()); nameText.setText(a.getName());
@ -285,7 +299,7 @@ public class EditingPOIActivity implements DialogProvider {
commentText = ((EditText)dlg.findViewById(R.id.Comment)); commentText = ((EditText)dlg.findViewById(R.id.Comment));
phoneText = ((EditText)dlg.findViewById(R.id.Phone)); phoneText = ((EditText)dlg.findViewById(R.id.Phone));
websiteText = ((EditText)dlg.findViewById(R.id.Website)); websiteText = ((EditText)dlg.findViewById(R.id.Website));
closeChange = ((CheckBox) dlg.findViewById(R.id.CloseChangeset));
TextView linkToOsmDoc = (TextView) dlg.findViewById(R.id.LinkToOsmDoc); TextView linkToOsmDoc = (TextView) dlg.findViewById(R.id.LinkToOsmDoc);
linkToOsmDoc.setOnClickListener(new View.OnClickListener() { linkToOsmDoc.setOnClickListener(new View.OnClickListener() {
@ -441,7 +455,8 @@ public class EditingPOIActivity implements DialogProvider {
if (phone.length() > 0 ){ if (phone.length() > 0 ){
n.putTag(OSMTagKey.PHONE.getValue(),phone); n.putTag(OSMTagKey.PHONE.getValue(),phone);
} }
commitNode(action, n, openstreetmapUtil.getEntityInfo(), commentText.getText().toString(), new Runnable() { commitNode(action, n, openstreetmapUtil.getEntityInfo(), commentText.getText().toString(), closeChange.isSelected(),
new Runnable() {
@Override @Override
public void run() { public void run() {
AccessibleToast.makeText(ctx, MessageFormat.format(ctx.getResources().getString(R.string.poi_action_succeded_template), msg), AccessibleToast.makeText(ctx, MessageFormat.format(ctx.getResources().getString(R.string.poi_action_succeded_template), msg),
@ -525,7 +540,9 @@ public class EditingPOIActivity implements DialogProvider {
} }
public void commitNode(final OsmPoint.Action action, final Node n, final EntityInfo info, final String comment, final Runnable successAction) { public void commitNode(final OsmPoint.Action action, final Node n, final EntityInfo info, final String comment,
final boolean closeChangeSet,
final Runnable successAction) {
if (info == null && OsmPoint.Action.CREATE != action) { if (info == null && OsmPoint.Action.CREATE != action) {
AccessibleToast.makeText(ctx, ctx.getResources().getString(R.string.poi_error_info_not_loaded), Toast.LENGTH_LONG).show(); AccessibleToast.makeText(ctx, ctx.getResources().getString(R.string.poi_error_info_not_loaded), Toast.LENGTH_LONG).show();
return; return;
@ -540,7 +557,7 @@ public class EditingPOIActivity implements DialogProvider {
@Override @Override
protected Node doInBackground(Void... params) { protected Node doInBackground(Void... params) {
Node node = null; Node node = null;
if ((node = openstreetmapUtil.commitNodeImpl(action, n, info, comment)) != null) { if ((node = openstreetmapUtil.commitNodeImpl(action, n, info, comment, closeChangeSet)) != null) {
openstreetmapUtil.updateNodeInIndexes(ctx, action, node, n); openstreetmapUtil.updateNodeInIndexes(ctx, action, node, n);
} }
return node; return node;

View file

@ -209,7 +209,7 @@ public class LocalOpenstreetmapActivity extends ListActivity {
entityInfo = remotepoi.loadNode(p.getEntity()); entityInfo = remotepoi.loadNode(p.getEntity());
} }
Node n; Node n;
if ((n = remotepoi.commitNodeImpl(p.getAction(), p.getEntity(), entityInfo, p.getComment())) != null) { if ((n = remotepoi.commitNodeImpl(p.getAction(), p.getEntity(), entityInfo, p.getComment(), false)) != null) {
remotepoi.updateNodeInIndexes(LocalOpenstreetmapActivity.this, p.getAction(), n, p.getEntity()); remotepoi.updateNodeInIndexes(LocalOpenstreetmapActivity.this, p.getAction(), n, p.getEntity());
dbpoi.deletePOI(p); dbpoi.deletePOI(p);
publishProgress(p); publishProgress(p);

View file

@ -43,7 +43,7 @@ public class OpenstreetmapLocalUtil extends AbstractOpenstreetmapUtil {
} }
@Override @Override
public Node commitNodeImpl(OsmPoint.Action action, Node n, EntityInfo info, String comment){ public Node commitNodeImpl(OsmPoint.Action action, Node n, EntityInfo info, String comment, boolean closeChangeSet){
Node newNode = n; Node newNode = n;
if (n.getId() == -1) { if (n.getId() == -1) {
newNode = new Node(n, --nextid); // generate local id for the created node newNode = new Node(n, --nextid); // generate local id for the created node
@ -119,4 +119,8 @@ public class OpenstreetmapLocalUtil extends AbstractOpenstreetmapUtil {
return null; return null;
} }
@Override
public void closeChangeSet() {
}
} }

View file

@ -277,11 +277,6 @@ public class OpenstreetmapRemoteUtil extends AbstractOpenstreetmapUtil {
return id; return id;
} }
public void closeChangeSet(long id){
String response = sendRequest(SITE_API+"api/0.6/changeset/"+id+"/close", "PUT", "", ctx.getString(R.string.closing_changeset), true); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
log.info("Response : " + response); //$NON-NLS-1$
}
private void writeNode(Node n, EntityInfo i, XmlSerializer ser, long changeSetId, String user) throws IllegalArgumentException, IllegalStateException, IOException{ private void writeNode(Node n, EntityInfo i, XmlSerializer ser, long changeSetId, String user) throws IllegalArgumentException, IllegalStateException, IOException{
ser.startTag(null, "node"); //$NON-NLS-1$ ser.startTag(null, "node"); //$NON-NLS-1$
ser.attribute(null, "id", n.getId()+""); //$NON-NLS-1$ //$NON-NLS-2$ ser.attribute(null, "id", n.getId()+""); //$NON-NLS-1$ //$NON-NLS-2$
@ -323,7 +318,7 @@ public class OpenstreetmapRemoteUtil extends AbstractOpenstreetmapUtil {
} }
@Override @Override
public Node commitNodeImpl(OsmPoint.Action action, final Node n, EntityInfo info, String comment){ public Node commitNodeImpl(OsmPoint.Action action, final Node n, EntityInfo info, String comment, boolean closeChangeSet){
if (isNewChangesetRequired()){ if (isNewChangesetRequired()){
changeSetId = openChangeSet(comment); changeSetId = openChangeSet(comment);
changeSetTimeStamp = System.currentTimeMillis(); changeSetTimeStamp = System.currentTimeMillis();
@ -373,11 +368,22 @@ public class OpenstreetmapRemoteUtil extends AbstractOpenstreetmapUtil {
} }
return null; return null;
} finally { } finally {
// reuse changeset, do not close if(closeChangeSet) {
//closeChangeSet(changeSetId); closeChangeSet();
}
} }
} }
@Override
public void closeChangeSet() {
if (changeSetId != NO_CHANGESET_ID) {
String response = sendRequest(SITE_API+"api/0.6/changeset/"+changeSetId+"/close", "PUT", "", ctx.getString(R.string.closing_changeset), true); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
log.info("Response : " + response); //$NON-NLS-1$
changeSetId = NO_CHANGESET_ID;
}
}
public EntityInfo loadNode(Node n) { public EntityInfo loadNode(Node n) {
long nodeId = n.getId(); // >> 1; long nodeId = n.getId(); // >> 1;
try { try {

View file

@ -9,7 +9,9 @@ public interface OpenstreetmapUtil {
public EntityInfo getEntityInfo(); public EntityInfo getEntityInfo();
public Node commitNodeImpl(OsmPoint.Action action, Node n, EntityInfo info, String comment); public Node commitNodeImpl(OsmPoint.Action action, Node n, EntityInfo info, String comment, boolean closeChangeSet);
public void closeChangeSet();
public Node loadNode(Amenity n); public Node loadNode(Amenity n);