POI creation dialog with close changeset option
This commit is contained in:
parent
d52363eaf6
commit
47abeecd19
7 changed files with 53 additions and 18 deletions
|
@ -74,7 +74,6 @@
|
|||
android:layout_marginLeft="5dp"
|
||||
android:layout_marginRight="5dp"
|
||||
android:hint="http://osmand.net" />
|
||||
|
||||
</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>
|
||||
</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>
|
||||
|
||||
<Button
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
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
|
||||
-->
|
||||
<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="rendering_attr_roadColors_description">Select a road color scheme:</string>
|
||||
<string name="rendering_attr_roadColors_name">Road color scheme</string>
|
||||
|
|
|
@ -44,7 +44,9 @@ import android.view.View;
|
|||
import android.widget.ArrayAdapter;
|
||||
import android.widget.AutoCompleteTextView;
|
||||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.EditText;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TableLayout;
|
||||
import android.widget.TableRow;
|
||||
import android.widget.TextView;
|
||||
|
@ -63,6 +65,7 @@ public class EditingPOIActivity implements DialogProvider {
|
|||
private EditText commentText;
|
||||
private EditText websiteText;
|
||||
private EditText phoneText;
|
||||
private CheckBox closeChange;
|
||||
|
||||
// private final static Log log = LogUtil.getLog(EditingPOIActivity.class);
|
||||
|
||||
|
@ -80,6 +83,7 @@ public class EditingPOIActivity implements DialogProvider {
|
|||
private Bundle dialogBundle = new Bundle();
|
||||
private OsmandSettings settings;
|
||||
|
||||
|
||||
public EditingPOIActivity(MapActivity uiContext){
|
||||
this.ctx = uiContext;
|
||||
|
||||
|
@ -139,16 +143,23 @@ public class EditingPOIActivity implements DialogProvider {
|
|||
private Dialog createDeleteDialog(final Bundle args) {
|
||||
Builder builder = new AlertDialog.Builder(ctx);
|
||||
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);
|
||||
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.setPositiveButton(R.string.default_buttons_delete, new DialogInterface.OnClickListener(){
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
Node n = (Node) args.getSerializable(KEY_AMENITY_NODE);
|
||||
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
|
||||
public void run() {
|
||||
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) {
|
||||
Amenity a = (Amenity) args.getSerializable(KEY_AMENITY);
|
||||
if(a == null){
|
||||
a = new Amenity();
|
||||
}
|
||||
dlg.setTitle(title);
|
||||
EditText nameText = ((EditText)dlg.findViewById(R.id.Name));
|
||||
nameText.setText(a.getName());
|
||||
|
@ -285,7 +299,7 @@ public class EditingPOIActivity implements DialogProvider {
|
|||
commentText = ((EditText)dlg.findViewById(R.id.Comment));
|
||||
phoneText = ((EditText)dlg.findViewById(R.id.Phone));
|
||||
websiteText = ((EditText)dlg.findViewById(R.id.Website));
|
||||
|
||||
closeChange = ((CheckBox) dlg.findViewById(R.id.CloseChangeset));
|
||||
|
||||
TextView linkToOsmDoc = (TextView) dlg.findViewById(R.id.LinkToOsmDoc);
|
||||
linkToOsmDoc.setOnClickListener(new View.OnClickListener() {
|
||||
|
@ -441,7 +455,8 @@ public class EditingPOIActivity implements DialogProvider {
|
|||
if (phone.length() > 0 ){
|
||||
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
|
||||
public void run() {
|
||||
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) {
|
||||
AccessibleToast.makeText(ctx, ctx.getResources().getString(R.string.poi_error_info_not_loaded), Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
|
@ -540,7 +557,7 @@ public class EditingPOIActivity implements DialogProvider {
|
|||
@Override
|
||||
protected Node doInBackground(Void... params) {
|
||||
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);
|
||||
}
|
||||
return node;
|
||||
|
|
|
@ -209,7 +209,7 @@ public class LocalOpenstreetmapActivity extends ListActivity {
|
|||
entityInfo = remotepoi.loadNode(p.getEntity());
|
||||
}
|
||||
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());
|
||||
dbpoi.deletePOI(p);
|
||||
publishProgress(p);
|
||||
|
|
|
@ -43,7 +43,7 @@ public class OpenstreetmapLocalUtil extends AbstractOpenstreetmapUtil {
|
|||
}
|
||||
|
||||
@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;
|
||||
if (n.getId() == -1) {
|
||||
newNode = new Node(n, --nextid); // generate local id for the created node
|
||||
|
@ -119,4 +119,8 @@ public class OpenstreetmapLocalUtil extends AbstractOpenstreetmapUtil {
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeChangeSet() {
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -277,11 +277,6 @@ public class OpenstreetmapRemoteUtil extends AbstractOpenstreetmapUtil {
|
|||
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{
|
||||
ser.startTag(null, "node"); //$NON-NLS-1$
|
||||
ser.attribute(null, "id", n.getId()+""); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
|
@ -323,7 +318,7 @@ public class OpenstreetmapRemoteUtil extends AbstractOpenstreetmapUtil {
|
|||
}
|
||||
|
||||
@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()){
|
||||
changeSetId = openChangeSet(comment);
|
||||
changeSetTimeStamp = System.currentTimeMillis();
|
||||
|
@ -373,11 +368,22 @@ public class OpenstreetmapRemoteUtil extends AbstractOpenstreetmapUtil {
|
|||
}
|
||||
return null;
|
||||
} finally {
|
||||
// reuse changeset, do not close
|
||||
//closeChangeSet(changeSetId);
|
||||
if(closeChangeSet) {
|
||||
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) {
|
||||
long nodeId = n.getId(); // >> 1;
|
||||
try {
|
||||
|
|
|
@ -9,7 +9,9 @@ public interface OpenstreetmapUtil {
|
|||
|
||||
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);
|
||||
|
||||
|
|
Loading…
Reference in a new issue