Check upload success
This commit is contained in:
parent
3782fbeb57
commit
1c904641e0
2 changed files with 16 additions and 8 deletions
|
@ -87,7 +87,6 @@ public class UploadPhotoProgressBottomSheet extends MenuBottomSheetDialogFragmen
|
|||
|
||||
@Override
|
||||
public void uploadPhotosFinished() {
|
||||
updateProgress(maxProgress);
|
||||
if (progress == maxProgress) {
|
||||
uploadedPhotosCounter.setText((getString(R.string.uploaded_count, progress, maxProgress)));
|
||||
setDismissButtonTextId(R.string.shared_string_close);
|
||||
|
|
|
@ -34,6 +34,7 @@ import java.io.ByteArrayInputStream;
|
|||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -45,14 +46,13 @@ public class UploadPhotosAsyncTask extends AsyncTask<Void, Integer, Void> {
|
|||
|
||||
private final OsmandApplication app;
|
||||
private final WeakReference<MapActivity> activityRef;
|
||||
private UploadPhotosListener listener;
|
||||
|
||||
private final OpenDBAPI openDBAPI = new OpenDBAPI();
|
||||
private final LatLon latLon;
|
||||
private final List<Uri> data;
|
||||
private final String[] placeId;
|
||||
private final Map<String, String> params;
|
||||
private final GetImageCardsListener imageCardListener;
|
||||
private UploadPhotosListener listener;
|
||||
|
||||
public UploadPhotosAsyncTask(MapActivity activity, List<Uri> data, LatLon latLon, String[] placeId,
|
||||
Map<String, String> params, GetImageCardsListener imageCardListener) {
|
||||
|
@ -87,13 +87,16 @@ public class UploadPhotosAsyncTask extends AsyncTask<Void, Integer, Void> {
|
|||
}
|
||||
|
||||
protected Void doInBackground(Void... uris) {
|
||||
List<Uri> uploadedPhotoUris = new ArrayList<>();
|
||||
for (int i = 0; i < data.size(); i++) {
|
||||
if (isCancelled()) {
|
||||
break;
|
||||
}
|
||||
Uri uri = data.get(i);
|
||||
handleSelectedImage(uri);
|
||||
publishProgress(i + 1);
|
||||
if (handleSelectedImage(uri)) {
|
||||
uploadedPhotoUris.add(uri);
|
||||
publishProgress(uploadedPhotoUris.size());
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -105,12 +108,13 @@ public class UploadPhotosAsyncTask extends AsyncTask<Void, Integer, Void> {
|
|||
}
|
||||
}
|
||||
|
||||
private void handleSelectedImage(final Uri uri) {
|
||||
private boolean handleSelectedImage(final Uri uri) {
|
||||
boolean success = false;
|
||||
InputStream inputStream = null;
|
||||
try {
|
||||
inputStream = app.getContentResolver().openInputStream(uri);
|
||||
if (inputStream != null) {
|
||||
uploadImageToPlace(inputStream);
|
||||
success = uploadImageToPlace(inputStream);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOG.error(e);
|
||||
|
@ -118,9 +122,11 @@ public class UploadPhotosAsyncTask extends AsyncTask<Void, Integer, Void> {
|
|||
} finally {
|
||||
Algorithms.closeStream(inputStream);
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
private void uploadImageToPlace(InputStream image) {
|
||||
private boolean uploadImageToPlace(InputStream image) {
|
||||
boolean success = false;
|
||||
InputStream serverData = new ByteArrayInputStream(compressImageToJpeg(image));
|
||||
final String baseUrl = OPRConstants.getBaseUrl(app);
|
||||
// all these should be constant
|
||||
|
@ -146,6 +152,7 @@ public class UploadPhotosAsyncTask extends AsyncTask<Void, Integer, Void> {
|
|||
} catch (FailedVerificationException e) {
|
||||
LOG.error(e);
|
||||
checkTokenAndShowScreen();
|
||||
|
||||
}
|
||||
if (res != 200) {
|
||||
//image was uploaded but not added to blockchain
|
||||
|
@ -159,10 +166,12 @@ public class UploadPhotosAsyncTask extends AsyncTask<Void, Integer, Void> {
|
|||
if (activity != null) {
|
||||
MenuBuilder.execute(new GetImageCardsTask(activity, latLon, params, imageCardListener));
|
||||
}
|
||||
success = true;
|
||||
}
|
||||
} else {
|
||||
checkTokenAndShowScreen();
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
//This method runs on non main thread
|
||||
|
|
Loading…
Reference in a new issue