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 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

View file

@ -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<String, Object> change = new TreeMap<>();
Map<String, Object> 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;