diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java index 6b1a05748e..0e62a6e48f 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java @@ -106,6 +106,7 @@ public class MenuBuilder { private String preferredMapLang; private String preferredMapAppLang; private boolean transliterateNames; + private View view; private final OpenDBAPI openDBAPI = new OpenDBAPI(); private String[] placeId = new String[0]; @@ -226,6 +227,7 @@ public class MenuBuilder { } public void build(View view) { + this.view = view; firstRow = true; hidden = false; buildTopInternal(view); @@ -399,7 +401,7 @@ public class MenuBuilder { } }); //TODO This feature is under development - view.setVisibility(View.GONE); + view.setVisibility(View.VISIBLE); return view; } @@ -417,7 +419,9 @@ public class MenuBuilder { OnActivityResultListener() { @Override public void onResult(int resultCode, Intent resultData) { - handleSelectedImage(view, resultData.getData()); + if (resultData != null) { + handleSelectedImage(view, resultData.getData()); + } } })); } @@ -435,7 +439,7 @@ public class MenuBuilder { } catch (Exception e) { LOG.error(e); String str = app.getString(R.string.cannot_upload_image); - app.showToastMessage(str); + showToastMessage(str); } finally { Algorithms.closeStream(inputStream); } @@ -452,12 +456,18 @@ public class MenuBuilder { if (response != null) { int res = 0; try { + StringBuilder error = new StringBuilder(); res = openDBAPI.uploadImage( placeId, baseUrl, OPRWebviewActivity.getPrivateKeyFromCookie(app), OPRWebviewActivity.getUsernameFromCookie(app), - response); + response, error); + if (res != 200) { + showToastMessage(error.toString()); + } else { + //ok, continue + } } catch (FailedVerificationException e) { LOG.error(e); checkTokenAndShowScreen(); @@ -466,7 +476,8 @@ public class MenuBuilder { //image was uploaded but not added to blockchain checkTokenAndShowScreen(); } else { - app.showToastMessage(R.string.successfully_uploaded_pattern, 1, 1); + String str = app.getString(R.string.successfully_uploaded_pattern, 1, 1); + showToastMessage(str); //refresh the image execute(new GetImageCardsTask(mapActivity, getLatLon(), getAdditionalCardParams(), imageCardListener)); } @@ -475,13 +486,23 @@ public class MenuBuilder { } } + private void showToastMessage(final String str) { + app.runInUIThread(new Runnable() { + @Override + public void run() { + Toast.makeText(view.getContext(), str, Toast.LENGTH_LONG).show(); + } + }); + } + //This method runs on non main thread private void checkTokenAndShowScreen() { final String baseUrl = OPRWebviewActivity.getBaseUrl(app); final String name = OPRWebviewActivity.getUsernameFromCookie(app); final String privateKey = OPRWebviewActivity.getPrivateKeyFromCookie(app); if (openDBAPI.checkPrivateKeyValid(baseUrl, name, privateKey)) { - app.showToastMessage(R.string.cannot_upload_image); + String str = app.getString(R.string.cannot_upload_image); + showToastMessage(str); } else { app.runInUIThread(new Runnable() { @Override diff --git a/OsmAnd/src/net/osmand/plus/osmedit/opr/OpenDBAPI.java b/OsmAnd/src/net/osmand/plus/osmedit/opr/OpenDBAPI.java index f9e106e06d..4754346805 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/opr/OpenDBAPI.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/opr/OpenDBAPI.java @@ -68,7 +68,7 @@ public class OpenDBAPI { response.toString().contains(LOGIN_SUCCESS_MESSAGE); } - public int uploadImage(String[] placeId, String baseUrl, String privateKey, String username, String image) throws FailedVerificationException { + public int uploadImage(String[] placeId, String baseUrl, String privateKey, String username, String image, StringBuilder sb) throws FailedVerificationException { if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { Security.removeProvider("BC"); Security.addProvider(new BouncyCastleProvider()); @@ -93,7 +93,7 @@ public class OpenDBAPI { Map change = new TreeMap<>(); Map images = new TreeMap<>(); images.put("append", imageMap); - change.put("version", "increment"); + change.put("version", 25); change.put("images.review", images); edit.put("id", ids); edit.put("change", change); @@ -132,6 +132,7 @@ public class OpenDBAPI { String strCurrentLine; while ((strCurrentLine = br.readLine()) != null) { log.error(strCurrentLine); + sb.append(strCurrentLine); } } return rc;