From a70ad01304e2440fd1c8bfca426927afbd528e0e Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Mon, 1 Feb 2021 04:05:51 +0200 Subject: [PATCH] Minor fixes --- .../UploadPhotoProgressBottomSheet.java | 32 +++++++++---------- .../mapcontextmenu/UploadPhotosAsyncTask.java | 7 ++-- 2 files changed, 18 insertions(+), 21 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/dialogs/UploadPhotoProgressBottomSheet.java b/OsmAnd/src/net/osmand/plus/dialogs/UploadPhotoProgressBottomSheet.java index 46483ffc9b..05e4bcc468 100644 --- a/OsmAnd/src/net/osmand/plus/dialogs/UploadPhotoProgressBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/dialogs/UploadPhotoProgressBottomSheet.java @@ -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,11 +84,9 @@ 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); - UiUtilities.setupDialogButton(nightMode, dismissButton, getDismissButtonType(), getDismissButtonTextId()); - } + uploadingFinished = true; + updateProgress(progress); + UiUtilities.setupDialogButton(nightMode, dismissButton, getDismissButtonType(), getDismissButtonTextId()); } @Override @@ -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); diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/UploadPhotosAsyncTask.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/UploadPhotosAsyncTask.java index 24d70a83dc..afe492af6f 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/UploadPhotosAsyncTask.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/UploadPhotosAsyncTask.java @@ -128,7 +128,7 @@ public class UploadPhotosAsyncTask extends AsyncTask { 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 { 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 { if (activity != null) { MenuBuilder.execute(new GetImageCardsTask(activity, latLon, params, imageCardListener)); } - success = true; } } else { checkTokenAndShowScreen();