Skip to content

Commit 03d1f37

Browse files
committed
Merge branch 'use_double_colon_as_count_sep_for_keys'
2 parents ff96742 + 764d8fa commit 03d1f37

File tree

1 file changed

+62
-51
lines changed

1 file changed

+62
-51
lines changed

src/main/java/de/blau/android/listener/UploadListener.java

Lines changed: 62 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -59,32 +59,32 @@
5959
*/
6060
public class UploadListener implements DialogInterface.OnShowListener, View.OnClickListener {
6161

62-
private static final int TAG_LEN = Math.min(LOG_TAG_LEN, UploadListener.class.getSimpleName().length());
63-
private static final String DEBUG_TAG = UploadListener.class.getSimpleName().substring(0, TAG_LEN);
62+
private static final int TAG_LEN = Math.min(LOG_TAG_LEN, UploadListener.class.getSimpleName().length());
63+
private static final String DEBUG_TAG = UploadListener.class.getSimpleName().substring(0, TAG_LEN);
6464

6565
// auto summary tags
66-
public static final String V_DELETED = "v:deleted";
67-
public static final String V_MODIFIED_MEMBERS = "v:modified_members";
68-
public static final String V_MODIFIED_GEOMETRY = "v:modified_geometry";
69-
public static final String V_MODIFIED = "v:modified";
70-
public static final String V_CREATED = "v:created";
71-
72-
private static final long DEBOUNCE_TIME = 1000;
73-
74-
private final FragmentActivity caller;
75-
private final EditText commentField;
76-
private final EditText sourceField;
77-
private final CheckBox closeOpenChangeset;
78-
private final CheckBox closeChangeset;
79-
private final CheckBox requestReview;
80-
private LinearLayout persistentCustomTagLayout;
81-
private LinearLayout transientCustomTagLayout;
66+
public static final String V_DELETED = "v:deleted";
67+
public static final String V_MODIFIED_MEMBERS = "v:modified_members";
68+
public static final String V_MODIFIED_GEOMETRY = "v:modified_geometry";
69+
public static final String V_MODIFIED = "v:modified";
70+
public static final String V_CREATED = "v:created";
71+
72+
private static final long DEBOUNCE_TIME = 1000;
73+
74+
private final FragmentActivity caller;
75+
private final EditText commentField;
76+
private final EditText sourceField;
77+
private final CheckBox closeOpenChangeset;
78+
private final CheckBox closeChangeset;
79+
private final CheckBox requestReview;
80+
private LinearLayout persistentCustomTagLayout;
81+
private LinearLayout transientCustomTagLayout;
8282

8383
private final List<FormValidation> validations;
8484
private final List<OsmElement> elements;
85-
private Long lastClickTime = null;
85+
private Long lastClickTime = null;
8686

87-
private boolean tagsShown = false;
87+
private boolean tagsShown = false;
8888

8989
public static class UploadArguments {
9090

@@ -129,7 +129,7 @@ public UploadListener(@NonNull final FragmentActivity caller, @NonNull final Edi
129129
this.requestReview = requestReview;
130130
this.elements = elements;
131131
FormValidation commentValidator = new NotEmptyValidator(commentField, caller.getString(R.string.upload_validation_error_empty_comment));
132-
FormValidation sourceValidator = new NotEmptyValidator(sourceField, caller.getString(R.string.upload_validation_error_empty_source));
132+
FormValidation sourceValidator = new NotEmptyValidator(sourceField, caller.getString(R.string.upload_validation_error_empty_source));
133133
this.validations = Arrays.asList(commentValidator, sourceValidator);
134134
}
135135

@@ -149,8 +149,8 @@ public void onClick(View view) {
149149
validateFields();
150150
}
151151
if (!emptyCommentWarning || tagsShown || ReviewAndUpload.getPage(caller) == ReviewAndUpload.TAGS_PAGE) {
152-
FragmentManager fm = caller.getSupportFragmentManager();
153-
Fragment fragment = fm.findFragmentByTag(ReviewAndUpload.TAG);
152+
FragmentManager fm = caller.getSupportFragmentManager();
153+
Fragment fragment = fm.findFragmentByTag(ReviewAndUpload.TAG);
154154
if (fragment instanceof ReviewAndUpload) {
155155
((ReviewAndUpload) fragment).removeTransientCustomTags();
156156
}
@@ -178,14 +178,14 @@ private void upload() {
178178
addCustomTags(transientCustomTagLayout, extraTags);
179179
}
180180
extraTags.putAll(generateAutoSummary(elements != null ? elements : App.getDelegator().listChangedElements()));
181-
final Logic logic = App.getLogic();
181+
final Logic logic = App.getLogic();
182182
final Server server = logic.getPrefs().getServer();
183183
if (!server.isLoginSet()) {
184184
ErrorAlert.showDialog(caller, ErrorCodes.NO_LOGIN_DATA);
185185
return;
186186
}
187187
boolean hasDataChanges = logic.hasChanges();
188-
boolean hasBugChanges = !App.getTaskStorage().isEmpty() && App.getTaskStorage().hasChanges();
188+
boolean hasBugChanges = !App.getTaskStorage().isEmpty() && App.getTaskStorage().hasChanges();
189189
if (hasDataChanges || hasBugChanges) {
190190
if (hasDataChanges) {
191191
UploadArguments arguments = new UploadArguments(getTrimmedString(commentField), getTrimmedString(sourceField),
@@ -214,7 +214,7 @@ public static void addCustomTags(@Nullable LinearLayout customTagLayout, @NonNul
214214
for (int i = 0; i < customTagLayout.getChildCount(); i++) {
215215
View v = customTagLayout.getChildAt(i);
216216
if (v instanceof CustomTagRow) {
217-
String key = ((CustomTagRow) v).getKey();
217+
String key = ((CustomTagRow) v).getKey();
218218
String value = ((CustomTagRow) v).getValue();
219219
if (!"".equals(key) && !"".equals(value)) {
220220
tags.put(key, value);
@@ -241,20 +241,20 @@ private final class Actions {
241241
* @return a Map containing the tags
242242
*/
243243
private Map<String, String> generateAutoSummary(@NonNull List<OsmElement> elements) {
244-
Map<String, String> result = new HashMap<>();
245-
UndoStorage undoStorage = App.getDelegator().getUndo();
246-
Preset[] presets = App.getCurrentPresets(caller);
247-
List<Node> movedNodes = new ArrayList<>();
248-
Actions actions = new Actions();
249-
for (OsmElement current : elements) {
244+
Map<String, String> result = new HashMap<>();
245+
UndoStorage undoStorage = App.getDelegator().getUndo();
246+
Preset[] presets = App.getCurrentPresets(caller);
247+
List<Node> movedNodes = new ArrayList<>();
248+
Actions actions = new Actions();
249+
for (OsmElement current:elements) {
250250
addActionsForElement(actions, movedNodes, undoStorage, presets, current);
251251
}
252252
if (!movedNodes.isEmpty()) {
253253
Set<Way> modifiedGeometryWays = new HashSet<>();
254-
for (Node n : movedNodes) {
254+
for (Node n:movedNodes) {
255255
modifiedGeometryWays.addAll(App.getLogic().getWaysForNode(n));
256256
}
257-
for (Way w : modifiedGeometryWays) {
257+
for (Way w:modifiedGeometryWays) {
258258
PresetItem match = Preset.findBestMatch(caller, presets, w.getTags(), null, w, true);
259259
actions.geometryModified.add(getPresetName(match));
260260
}
@@ -281,11 +281,11 @@ private Map<String, String> generateAutoSummary(@NonNull List<OsmElement> elemen
281281
private void addActionsForElement(@NonNull Actions actions, @NonNull List<Node> movedNodes, @NonNull UndoStorage undoStorage, @NonNull Preset[] presets,
282282
@NonNull OsmElement element) {
283283

284-
final boolean hasTags = element.hasTags();
285-
final Map<String, String> currentTags = element.getTags();
286-
PresetItem matchCurrent = Preset.findBestMatch(caller, presets, currentTags, null, element, true);
287-
final String currentPresetName = getPresetName(matchCurrent);
288-
final boolean currentHasMatch = matchCurrent != null;
284+
final boolean hasTags = element.hasTags();
285+
final Map<String, String> currentTags = element.getTags();
286+
PresetItem matchCurrent = Preset.findBestMatch(caller, presets, currentTags, null, element, true);
287+
final String currentPresetName = getPresetName(matchCurrent);
288+
final boolean currentHasMatch = matchCurrent != null;
289289

290290
if (element.isNew()) {
291291
// created
@@ -297,10 +297,10 @@ private void addActionsForElement(@NonNull Actions actions, @NonNull List<Node>
297297
return;
298298
}
299299
// note original can be null if data was loaded from a JOSM OSM file
300-
UndoElement original = undoStorage.getOriginal(element);
301-
final Map<String, String> originalTags = original != null ? original.getTags() : new HashMap<>();
300+
UndoElement original = undoStorage.getOriginal(element);
301+
final Map<String, String> originalTags = original != null ? original.getTags() : new HashMap<>();
302302
// element type should be the same as current element here
303-
PresetItem matchOriginal = Preset.findBestMatch(presets, originalTags, null, element.getType(), true, null);
303+
PresetItem matchOriginal = Preset.findBestMatch(presets, originalTags, null, element.getType(), true, null);
304304
if (OsmElement.STATE_DELETED == element.getState()) {
305305
// deleted
306306
actions.deleted.add(!originalTags.isEmpty() ? getPresetName(matchOriginal) : getUntaggedString(element));
@@ -389,11 +389,11 @@ private boolean moved(@NonNull Node current, @NonNull UndoNode original) {
389389
*/
390390
private void putSummary(@NonNull String key, @NonNull Collection<String> actions, @NonNull Map<String, String> result) {
391391
actions = addCounts(actions);
392-
int summaryCount = 0;
393-
StringBuilder summary = new StringBuilder();
394-
for (String s : actions) {
392+
int summaryCount = 0;
393+
StringBuilder summary = new StringBuilder();
394+
for (String s:actions) {
395395
if (summary.length() + s.length() + 1 > Capabilities.DEFAULT_MAX_STRING_LENGTH) {
396-
result.put(key + (summaryCount > 0 ? summaryCount : ""), summary.toString());
396+
result.put(keyWithCount(key, summaryCount), summary.toString());
397397
summaryCount++;
398398
summary.setLength(0);
399399
}
@@ -403,10 +403,21 @@ private void putSummary(@NonNull String key, @NonNull Collection<String> actions
403403
summary.append(s);
404404
}
405405
if (summary.length() > 0) {
406-
result.put(key + (summaryCount > 0 ? summaryCount : ""), summary.toString());
406+
result.put(keyWithCount(key, summaryCount), summary.toString());
407407
}
408408
}
409409

410+
/**
411+
* Add a count to a key if necessary
412+
*
413+
* @param key the key
414+
* @param count count to add (if not 0
415+
* @return the key with a count
416+
*/
417+
private String keyWithCount(@NonNull String key, int count) {
418+
return key + (count > 0 ? ":" + count : "");
419+
}
420+
410421
/**
411422
* Generate a List of actions with counts from the original actions
412423
*
@@ -415,17 +426,17 @@ private void putSummary(@NonNull String key, @NonNull Collection<String> actions
415426
*/
416427
@NonNull
417428
List<String> addCounts(@NonNull Collection<String> actions) {
418-
List<String> result = new ArrayList<>();
429+
List<String> result = new ArrayList<>();
419430
Map<String, Integer> counts = new HashMap<>();
420-
for (String action : actions) {
431+
for (String action:actions) {
421432
Integer count = counts.get(action);
422433
if (count == null) {
423434
counts.put(action, 1);
424435
continue;
425436
}
426437
counts.put(action, count + 1);
427438
}
428-
for (Entry<String, Integer> entry : counts.entrySet()) {
439+
for (Entry<String, Integer> entry:counts.entrySet()) {
429440
result.add(Integer.toString(entry.getValue()) + " " + entry.getKey());
430441
}
431442
return result;
@@ -460,7 +471,7 @@ private String getTrimmedString(@NonNull EditText editText) {
460471
* Run all supplied validators
461472
*/
462473
private void validateFields() {
463-
for (FormValidation validation : validations) {
474+
for (FormValidation validation:validations) {
464475
validation.validate();
465476
}
466477
}

0 commit comments

Comments
 (0)