Fix for null pointer exception
This commit is contained in:
parent
fe6bdfb51a
commit
af569a00cc
3 changed files with 27 additions and 31 deletions
|
@ -133,7 +133,7 @@ public class DashOsmEditsFragment extends DashBaseFragment {
|
||||||
ProgressDialog dialog = ProgressImplementation.createProgressDialog(getActivity(),
|
ProgressDialog dialog = ProgressImplementation.createProgressDialog(getActivity(),
|
||||||
getString(R.string.uploading), getString(R.string.local_openstreetmap_uploading),
|
getString(R.string.uploading), getString(R.string.local_openstreetmap_uploading),
|
||||||
ProgressDialog.STYLE_HORIZONTAL).getDialog();
|
ProgressDialog.STYLE_HORIZONTAL).getDialog();
|
||||||
OsmEditsUploadListener listener = new OsmEditUploadListenerHelper(getActivity(),
|
OsmEditsUploadListener listener = new OsmEditsUploadListenerHelper(getActivity(),
|
||||||
getString(R.string.local_openstreetmap_were_uploaded)) {
|
getString(R.string.local_openstreetmap_were_uploaded)) {
|
||||||
@Override
|
@Override
|
||||||
public void uploadUpdated(OsmPoint point) {
|
public void uploadUpdated(OsmPoint point) {
|
||||||
|
|
|
@ -500,7 +500,7 @@ public class OsmEditsFragment extends OsmAndListFragment {
|
||||||
getString(R.string.uploading),
|
getString(R.string.uploading),
|
||||||
getString(R.string.local_openstreetmap_uploading),
|
getString(R.string.local_openstreetmap_uploading),
|
||||||
ProgressDialog.STYLE_HORIZONTAL).getDialog();
|
ProgressDialog.STYLE_HORIZONTAL).getDialog();
|
||||||
OsmEditsUploadListener listener = new OsmEditUploadListenerHelper(getActivity(),
|
OsmEditsUploadListener listener = new OsmEditsUploadListenerHelper(getActivity(),
|
||||||
getString(R.string.local_openstreetmap_were_uploaded));
|
getString(R.string.local_openstreetmap_were_uploaded));
|
||||||
UploadOpenstreetmapPointAsyncTask uploadTask = new UploadOpenstreetmapPointAsyncTask(
|
UploadOpenstreetmapPointAsyncTask uploadTask = new UploadOpenstreetmapPointAsyncTask(
|
||||||
dialog, listener, plugin, remotepoi, remotebug, toUpload.length);
|
dialog, listener, plugin, remotepoi, remotebug, toUpload.length);
|
||||||
|
|
|
@ -71,27 +71,8 @@ public class OsmEditsUploadListenerHelper implements OsmEditsUploadListener {
|
||||||
UploadingErrorDialogFragment.getInstance(message, point);
|
UploadingErrorDialogFragment.getInstance(message, point);
|
||||||
dialogFragment.show(activity.getSupportFragmentManager(), "error_loading");
|
dialogFragment.show(activity.getSupportFragmentManager(), "error_loading");
|
||||||
} else {
|
} else {
|
||||||
Log.v(TAG, "in if2");
|
|
||||||
String[] pointNames = new String[loadErrorsMap.keySet().size()];
|
|
||||||
boolean[] hasErrors = new boolean[loadErrorsMap.keySet().size()];
|
|
||||||
ArrayList<OsmPoint> pointsWithErrors = new ArrayList<>();
|
|
||||||
int i = 0;
|
|
||||||
for (OsmPoint point : loadErrorsMap.keySet()) {
|
|
||||||
pointNames[i] = point.getGroup() == OsmPoint.Group.BUG ?
|
|
||||||
((OsmNotesPoint) point).getText() :
|
|
||||||
((OpenstreetmapPoint) point).getName();
|
|
||||||
pointNames[i] = TextUtils.isEmpty(pointNames[i]) ?
|
|
||||||
"id:" + point.getId() : pointNames[i];
|
|
||||||
hasErrors[i] = loadErrorsMap.get(point) != null;
|
|
||||||
if (hasErrors[i]) {
|
|
||||||
pointsWithErrors.add(point);
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
UploadingMultipleErrorDialogFragment dialogFragment =
|
UploadingMultipleErrorDialogFragment dialogFragment =
|
||||||
UploadingMultipleErrorDialogFragment.getInstance(pointNames, hasErrors);
|
UploadingMultipleErrorDialogFragment.createInstance(loadErrorsMap);
|
||||||
dialogFragment.setPointsToUpload(
|
|
||||||
pointsWithErrors.toArray(new OsmPoint[pointsWithErrors.size()]));
|
|
||||||
dialogFragment.show(activity.getSupportFragmentManager(), "multiple_error_loading");
|
dialogFragment.show(activity.getSupportFragmentManager(), "multiple_error_loading");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -164,8 +145,7 @@ public class OsmEditsUploadListenerHelper implements OsmEditsUploadListener {
|
||||||
public static final class UploadingMultipleErrorDialogFragment extends DialogFragment {
|
public static final class UploadingMultipleErrorDialogFragment extends DialogFragment {
|
||||||
private static final String HAS_ERROR = "has_error";
|
private static final String HAS_ERROR = "has_error";
|
||||||
private static final String POINT_NAMES = "point_names";
|
private static final String POINT_NAMES = "point_names";
|
||||||
|
private static final String POINTS_WITH_ERRORS = "points_with_errors";
|
||||||
OsmPoint[] points;
|
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
|
@ -173,6 +153,7 @@ public class OsmEditsUploadListenerHelper implements OsmEditsUploadListener {
|
||||||
Bundle arguments = getArguments();
|
Bundle arguments = getArguments();
|
||||||
String[] pointNames = arguments.getStringArray(POINT_NAMES);
|
String[] pointNames = arguments.getStringArray(POINT_NAMES);
|
||||||
boolean[] hasErrors = arguments.getBooleanArray(HAS_ERROR);
|
boolean[] hasErrors = arguments.getBooleanArray(HAS_ERROR);
|
||||||
|
final OsmPoint[] points = (OsmPoint[]) arguments.getSerializable(POINTS_WITH_ERRORS);
|
||||||
int successfulUploads = 0;
|
int successfulUploads = 0;
|
||||||
for (boolean hasError : hasErrors) {
|
for (boolean hasError : hasErrors) {
|
||||||
if (!hasError) {
|
if (!hasError) {
|
||||||
|
@ -200,21 +181,36 @@ public class OsmEditsUploadListenerHelper implements OsmEditsUploadListener {
|
||||||
return builder.create();
|
return builder.create();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPointsToUpload(OsmPoint[] points) {
|
public static UploadingMultipleErrorDialogFragment createInstance(
|
||||||
this.points = points;
|
Map<OsmPoint, String> loadErrorsMap) {
|
||||||
|
String[] pointNames = new String[loadErrorsMap.keySet().size()];
|
||||||
|
boolean[] hasErrors = new boolean[loadErrorsMap.keySet().size()];
|
||||||
|
ArrayList<OsmPoint> pointsWithErrors = new ArrayList<>();
|
||||||
|
int i = 0;
|
||||||
|
for (OsmPoint point : loadErrorsMap.keySet()) {
|
||||||
|
pointNames[i] = point.getGroup() == OsmPoint.Group.BUG ?
|
||||||
|
((OsmNotesPoint) point).getText() :
|
||||||
|
((OpenstreetmapPoint) point).getName();
|
||||||
|
pointNames[i] = TextUtils.isEmpty(pointNames[i]) ?
|
||||||
|
"id:" + point.getId() : pointNames[i];
|
||||||
|
hasErrors[i] = loadErrorsMap.get(point) != null;
|
||||||
|
if (hasErrors[i]) {
|
||||||
|
pointsWithErrors.add(point);
|
||||||
|
}
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static UploadingMultipleErrorDialogFragment getInstance(String[] pointNames,
|
if (pointNames.length != hasErrors.length) {
|
||||||
boolean[] hasError) {
|
|
||||||
if (pointNames.length != hasError.length) {
|
|
||||||
throw new IllegalArgumentException("pointNames and hasError arrays " +
|
throw new IllegalArgumentException("pointNames and hasError arrays " +
|
||||||
"must me of equal length");
|
"must me of equal length");
|
||||||
}
|
}
|
||||||
UploadingMultipleErrorDialogFragment fragment =
|
UploadingMultipleErrorDialogFragment fragment =
|
||||||
new UploadingMultipleErrorDialogFragment();
|
new UploadingMultipleErrorDialogFragment();
|
||||||
Bundle bundle = new Bundle();
|
Bundle bundle = new Bundle();
|
||||||
|
bundle.putSerializable(POINTS_WITH_ERRORS,
|
||||||
|
pointsWithErrors.toArray(new OsmPoint[pointsWithErrors.size()]));
|
||||||
bundle.putStringArray(POINT_NAMES, pointNames);
|
bundle.putStringArray(POINT_NAMES, pointNames);
|
||||||
bundle.putBooleanArray(HAS_ERROR, hasError);
|
bundle.putBooleanArray(HAS_ERROR, hasErrors);
|
||||||
fragment.setArguments(bundle);
|
fragment.setArguments(bundle);
|
||||||
return fragment;
|
return fragment;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue