This commit is contained in:
simon 2020-11-27 12:22:28 +02:00
parent 18134d5087
commit 868222d872
2 changed files with 30 additions and 8 deletions

View file

@ -106,6 +106,7 @@ public class MenuBuilder {
private String preferredMapLang; private String preferredMapLang;
private String preferredMapAppLang; private String preferredMapAppLang;
private boolean transliterateNames; private boolean transliterateNames;
private View view;
private final OpenDBAPI openDBAPI = new OpenDBAPI(); private final OpenDBAPI openDBAPI = new OpenDBAPI();
private String[] placeId = new String[0]; private String[] placeId = new String[0];
@ -226,6 +227,7 @@ public class MenuBuilder {
} }
public void build(View view) { public void build(View view) {
this.view = view;
firstRow = true; firstRow = true;
hidden = false; hidden = false;
buildTopInternal(view); buildTopInternal(view);
@ -399,7 +401,7 @@ public class MenuBuilder {
} }
}); });
//TODO This feature is under development //TODO This feature is under development
view.setVisibility(View.GONE); view.setVisibility(View.VISIBLE);
return view; return view;
} }
@ -417,7 +419,9 @@ public class MenuBuilder {
OnActivityResultListener() { OnActivityResultListener() {
@Override @Override
public void onResult(int resultCode, Intent resultData) { 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) { } catch (Exception e) {
LOG.error(e); LOG.error(e);
String str = app.getString(R.string.cannot_upload_image); String str = app.getString(R.string.cannot_upload_image);
app.showToastMessage(str); showToastMessage(str);
} finally { } finally {
Algorithms.closeStream(inputStream); Algorithms.closeStream(inputStream);
} }
@ -452,12 +456,18 @@ public class MenuBuilder {
if (response != null) { if (response != null) {
int res = 0; int res = 0;
try { try {
StringBuilder error = new StringBuilder();
res = openDBAPI.uploadImage( res = openDBAPI.uploadImage(
placeId, placeId,
baseUrl, baseUrl,
OPRWebviewActivity.getPrivateKeyFromCookie(app), OPRWebviewActivity.getPrivateKeyFromCookie(app),
OPRWebviewActivity.getUsernameFromCookie(app), OPRWebviewActivity.getUsernameFromCookie(app),
response); response, error);
if (res != 200) {
showToastMessage(error.toString());
} else {
//ok, continue
}
} catch (FailedVerificationException e) { } catch (FailedVerificationException e) {
LOG.error(e); LOG.error(e);
checkTokenAndShowScreen(); checkTokenAndShowScreen();
@ -466,7 +476,8 @@ public class MenuBuilder {
//image was uploaded but not added to blockchain //image was uploaded but not added to blockchain
checkTokenAndShowScreen(); checkTokenAndShowScreen();
} else { } 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 //refresh the image
execute(new GetImageCardsTask(mapActivity, getLatLon(), getAdditionalCardParams(), imageCardListener)); 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 //This method runs on non main thread
private void checkTokenAndShowScreen() { private void checkTokenAndShowScreen() {
final String baseUrl = OPRWebviewActivity.getBaseUrl(app); final String baseUrl = OPRWebviewActivity.getBaseUrl(app);
final String name = OPRWebviewActivity.getUsernameFromCookie(app); final String name = OPRWebviewActivity.getUsernameFromCookie(app);
final String privateKey = OPRWebviewActivity.getPrivateKeyFromCookie(app); final String privateKey = OPRWebviewActivity.getPrivateKeyFromCookie(app);
if (openDBAPI.checkPrivateKeyValid(baseUrl, name, privateKey)) { 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 { } else {
app.runInUIThread(new Runnable() { app.runInUIThread(new Runnable() {
@Override @Override

View file

@ -68,7 +68,7 @@ public class OpenDBAPI {
response.toString().contains(LOGIN_SUCCESS_MESSAGE); 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) { if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
Security.removeProvider("BC"); Security.removeProvider("BC");
Security.addProvider(new BouncyCastleProvider()); Security.addProvider(new BouncyCastleProvider());
@ -93,7 +93,7 @@ public class OpenDBAPI {
Map<String, Object> change = new TreeMap<>(); Map<String, Object> change = new TreeMap<>();
Map<String, Object> images = new TreeMap<>(); Map<String, Object> images = new TreeMap<>();
images.put("append", imageMap); images.put("append", imageMap);
change.put("version", "increment"); change.put("version", 25);
change.put("images.review", images); change.put("images.review", images);
edit.put("id", ids); edit.put("id", ids);
edit.put("change", change); edit.put("change", change);
@ -132,6 +132,7 @@ public class OpenDBAPI {
String strCurrentLine; String strCurrentLine;
while ((strCurrentLine = br.readLine()) != null) { while ((strCurrentLine = br.readLine()) != null) {
log.error(strCurrentLine); log.error(strCurrentLine);
sb.append(strCurrentLine);
} }
} }
return rc; return rc;