Add warning dialog and prevent saving of POI edits if any of fields exceed OSM limit of 255 chars per tag.
This commit is contained in:
parent
256ae885b5
commit
09b46bb3bb
2 changed files with 40 additions and 4 deletions
|
@ -10,7 +10,8 @@
|
|||
- For wording and consistency, please note https://osmand.net/help-online?id=technical-articles#Creating_a_Consistent_User_Experience
|
||||
Thx - Hardy
|
||||
|
||||
-->
|
||||
--> <string name="save_poi_value_exceed_length">Value of tag \"%s\" cannot exceed 255 chars. \nPlease edit it before continue.</string>
|
||||
<string name="save_poi_value_exceed_length_title">Length of \"%s\" value</string>
|
||||
<string name="public_transport_warning_descr_blog">Learn more about how OsmAnd calculates routes in our blog.</string>
|
||||
<string name="public_transport_warning_title">Public transport routes are now in the beta testing phase, so errors and inaccuracies may occur.</string>
|
||||
<string name="add_intermediate">Add intermediate point</string>
|
||||
|
|
|
@ -3,6 +3,7 @@ package net.osmand.plus.osmedit;
|
|||
import android.app.Activity;
|
||||
import android.app.Dialog;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Resources;
|
||||
|
@ -108,7 +109,7 @@ public class EditPoiDialogFragment extends BaseOsmAndDialogFragment {
|
|||
private View view;
|
||||
|
||||
@Override
|
||||
public void onAttach(Activity activity) {
|
||||
public void onAttach(Context activity) {
|
||||
super.onAttach(activity);
|
||||
OsmEditingPlugin plugin = OsmandPlugin.getPlugin(OsmEditingPlugin.class);
|
||||
if (getSettings().OFFLINE_EDITION.get()
|
||||
|
@ -400,7 +401,14 @@ public class EditPoiDialogFragment extends BaseOsmAndDialogFragment {
|
|||
}
|
||||
|
||||
private void trySave() {
|
||||
if (TextUtils.isEmpty(poiTypeEditText.getText())) {
|
||||
String tagWithExceedingValue = isTextLengthInRange();
|
||||
if (!Algorithms.isEmpty(tagWithExceedingValue)){
|
||||
ValueExceedLimitDialogFragment f = new ValueExceedLimitDialogFragment();
|
||||
Bundle args = new Bundle();
|
||||
args.putString("tag", tagWithExceedingValue);
|
||||
f.setArguments(args);
|
||||
f.show(getChildFragmentManager(), "exceedDialog");
|
||||
} else if (TextUtils.isEmpty(poiTypeEditText.getText())) {
|
||||
HashSet<String> tagsCopy = new HashSet<>();
|
||||
tagsCopy.addAll(editPoiData.getTagValues().keySet());
|
||||
if (Algorithms.isEmpty(editPoiData.getTag(OSMSettings.OSMTagKey.ADDR_HOUSE_NUMBER.getValue()))) {
|
||||
|
@ -422,12 +430,22 @@ public class EditPoiDialogFragment extends BaseOsmAndDialogFragment {
|
|||
} else if (editPoiData.getPoiCategory() == getMyApplication().getPoiTypes().getOtherPoiCategory()) {
|
||||
poiTypeEditText.setError(getResources().getString(R.string.please_specify_poi_type));
|
||||
} else if (editPoiData.getPoiTypeDefined() == null) {
|
||||
poiTypeEditText.setError(getResources().getString(R.string.please_specify_poi_type_only_from_list));
|
||||
poiTypeEditText.setError(
|
||||
getResources().getString(R.string.please_specify_poi_type_only_from_list));
|
||||
} else {
|
||||
save();
|
||||
}
|
||||
}
|
||||
|
||||
private String isTextLengthInRange() {
|
||||
for (String s: editPoiData.getChangedTags()) {
|
||||
if (editPoiData.getTag(s).length() > 255) {
|
||||
return s;
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
private boolean testTooManyCapitalLetters(String name) {
|
||||
if(name == null) {
|
||||
return false;
|
||||
|
@ -889,6 +907,23 @@ public class EditPoiDialogFragment extends BaseOsmAndDialogFragment {
|
|||
}
|
||||
}
|
||||
|
||||
public static class ValueExceedLimitDialogFragment extends DialogFragment {
|
||||
@NonNull
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||
String msg = getString(R.string.save_poi_value_exceed_length);
|
||||
String fieldTag = getArguments().getString("tag", "");
|
||||
if(!Algorithms.isEmpty(fieldTag)) {
|
||||
msg = String.format(msg, fieldTag);
|
||||
}
|
||||
builder.setTitle(String.format(getResources().getString(R.string.save_poi_value_exceed_length_title), fieldTag))
|
||||
.setMessage(msg)
|
||||
.setNegativeButton(R.string.shared_string_ok, null);
|
||||
return builder.create();
|
||||
}
|
||||
}
|
||||
|
||||
private TextView.OnEditorActionListener mOnEditorActionListener =
|
||||
new TextView.OnEditorActionListener() {
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue