From 4e1825a9945bd01c72e9d37bf8356c2ea08924da Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Tue, 25 Jul 2017 12:24:37 +0300 Subject: [PATCH] Refactor substring and fix NPE (cherry picked from commit 46f6b79) --- .../dialogs/SendPoiDialogFragment.java | 32 ++++++------------- 1 file changed, 10 insertions(+), 22 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendPoiDialogFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendPoiDialogFragment.java index 2b57460a71..b028f7495d 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendPoiDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendPoiDialogFragment.java @@ -137,6 +137,9 @@ public class SendPoiDialogFragment extends DialogFragment { private String createDefaultChangeSet() { Map allTranslatedSubTypes = getMyApplication().getPoiTypes().getAllTranslatedNames(true); + if (allTranslatedSubTypes == null) { + return ""; + } Map addGroup = new HashMap<>(); Map editGroup = new HashMap<>(); Map deleteGroup = new HashMap<>(); @@ -178,7 +181,6 @@ public class SendPoiDialogFragment extends DialogFragment { } } int modifiedItemsOutOfLimit = 0; - boolean stringModifiedIfExceeded = false; for (int i = 0; i < 4; i++) { String action; Map group; @@ -205,41 +207,27 @@ public class SendPoiDialogFragment extends DialogFragment { } if (!group.isEmpty()) { - if (modifiedItemsOutOfLimit == 0) { - comment = comment.concat(action).concat(" "); - } int pos = 0; for (Map.Entry entry : group.entrySet()) { String type = entry.getKey(); int quantity = entry.getValue(); if (comment.length() > 200) { modifiedItemsOutOfLimit += quantity; - if (!stringModifiedIfExceeded) { - if (pos == 0) { - if (comment.length() - action.length() - 3 >= 0) { - comment = comment.substring(0, comment.length() - action.length() - 3).concat("; "); - } else { - comment = comment.substring(0, comment.length() - action.length() - 1).concat("; "); - } - } else { - comment = comment.substring(0, comment.length() - 2).concat("; "); - } - stringModifiedIfExceeded = true; - } } else { - comment = comment.concat(quantity == 1 ? "" : quantity + " ").concat(type + ", "); + if (pos == 0) { + comment = comment.concat(comment.length() == 0 ? "" : "; ").concat(action).concat(" ").concat(quantity == 1 ? "" : quantity + "").concat(type); + } else { + comment = comment.concat(", ").concat(quantity == 1 ? "" : quantity + "").concat(type); + } } pos++; } - if (modifiedItemsOutOfLimit == 0) { - comment = comment.substring(0, comment.length() - 2).concat("; "); - } } } if (modifiedItemsOutOfLimit != 0) { - comment = comment.concat(modifiedItemsOutOfLimit + " ").concat(getString(R.string.items_modified)).concat("."); + comment = comment.concat("; ").concat(modifiedItemsOutOfLimit + " ").concat(getString(R.string.items_modified)).concat("."); } else if (!comment.equals("")){ - comment = comment.substring(0, comment.length() - 2).concat("."); + comment = comment.concat("."); } return comment; }