Minor fixes

This commit is contained in:
Vitaliy 2021-02-01 04:05:51 +02:00
parent b5ff545647
commit a70ad01304
2 changed files with 18 additions and 21 deletions

View file

@ -33,6 +33,7 @@ public class UploadPhotoProgressBottomSheet extends MenuBottomSheetDialogFragmen
private int progress;
private int maxProgress;
private boolean uploadingFinished;
@Override
public void createMenuItems(Bundle savedInstanceState) {
@ -44,17 +45,12 @@ public class UploadPhotoProgressBottomSheet extends MenuBottomSheetDialogFragmen
uploadedPhotosCounter = view.findViewById(R.id.description);
progressBar = view.findViewById(R.id.progress_bar);
progressBar.setMax(maxProgress);
String titleProgress = getString(progress == maxProgress? R.string.upload_photo_completed: R.string.upload_photo);
String descriptionProgress;
if (progress == maxProgress) {
descriptionProgress = getString(R.string.uploaded_count, progress, maxProgress);
} else {
descriptionProgress = getString(R.string.uploading_count, progress, maxProgress);
}
int descriptionId = uploadingFinished ? R.string.uploaded_count : R.string.uploading_count;
BaseBottomSheetItem descriptionItem = new BottomSheetItemWithDescription.Builder()
.setDescription(descriptionProgress)
.setTitle(titleProgress)
.setDescription(getString(descriptionId, progress, maxProgress))
.setTitle(getString(uploadingFinished ? R.string.upload_photo_completed : R.string.upload_photo))
.setCustomView(view)
.create();
items.add(descriptionItem);
@ -74,9 +70,10 @@ public class UploadPhotoProgressBottomSheet extends MenuBottomSheetDialogFragmen
}
private void updateProgress(int progress) {
int descriptionId = uploadingFinished ? R.string.uploaded_count : R.string.uploading_count;
progressBar.setProgress(progress);
uploadedPhotosCounter.setText((getString(R.string.uploading_count, progress, maxProgress)));
uploadedPhotosTitle.setText(progress == maxProgress ? R.string.upload_photo_completed : R.string.upload_photo);
uploadedPhotosCounter.setText(getString(descriptionId, progress, maxProgress));
uploadedPhotosTitle.setText(uploadingFinished ? R.string.upload_photo_completed : R.string.upload_photo);
}
@Override
@ -87,12 +84,10 @@ public class UploadPhotoProgressBottomSheet extends MenuBottomSheetDialogFragmen
@Override
public void uploadPhotosFinished() {
if (progress == maxProgress) {
uploadedPhotosCounter.setText((getString(R.string.uploaded_count, progress, maxProgress)));
setDismissButtonTextId(R.string.shared_string_close);
uploadingFinished = true;
updateProgress(progress);
UiUtilities.setupDialogButton(nightMode, dismissButton, getDismissButtonType(), getDismissButtonTextId());
}
}
@Override
public void onDismiss(@NonNull DialogInterface dialog) {
@ -103,6 +98,11 @@ public class UploadPhotoProgressBottomSheet extends MenuBottomSheetDialogFragmen
}
}
@Override
protected int getDismissButtonTextId() {
return uploadingFinished ? R.string.shared_string_close : R.string.shared_string_cancel;
}
public static UploadPhotosListener showInstance(@NonNull FragmentManager fragmentManager, int maxProgress, OnDismissListener listener) {
UploadPhotoProgressBottomSheet fragment = new UploadPhotoProgressBottomSheet();
fragment.setRetainInstance(true);

View file

@ -128,7 +128,7 @@ public class UploadPhotosAsyncTask extends AsyncTask<Void, Integer, Void> {
private boolean uploadImageToPlace(InputStream image) {
boolean success = false;
InputStream serverData = new ByteArrayInputStream(compressImageToJpeg(image));
final String baseUrl = OPRConstants.getBaseUrl(app);
String baseUrl = OPRConstants.getBaseUrl(app);
// all these should be constant
String url = baseUrl + "api/ipfs/image";
String response = NetworkUtils.sendPostDataRequest(url, "file", "compressed.jpeg", serverData);
@ -146,18 +146,16 @@ public class UploadPhotosAsyncTask extends AsyncTask<Void, Integer, Void> {
response, error);
if (res != 200) {
app.showToastMessage(error.toString());
} else {
//ok, continue
}
} catch (FailedVerificationException e) {
LOG.error(e);
checkTokenAndShowScreen();
}
if (res != 200) {
//image was uploaded but not added to blockchain
checkTokenAndShowScreen();
} else {
success = true;
String str = app.getString(R.string.successfully_uploaded_pattern, 1, 1);
app.showToastMessage(str);
//refresh the image
@ -166,7 +164,6 @@ public class UploadPhotosAsyncTask extends AsyncTask<Void, Integer, Void> {
if (activity != null) {
MenuBuilder.execute(new GetImageCardsTask(activity, latLon, params, imageCardListener));
}
success = true;
}
} else {
checkTokenAndShowScreen();