Minor fixes
This commit is contained in:
parent
b5ff545647
commit
a70ad01304
2 changed files with 18 additions and 21 deletions
|
@ -33,6 +33,7 @@ public class UploadPhotoProgressBottomSheet extends MenuBottomSheetDialogFragmen
|
||||||
|
|
||||||
private int progress;
|
private int progress;
|
||||||
private int maxProgress;
|
private int maxProgress;
|
||||||
|
private boolean uploadingFinished;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void createMenuItems(Bundle savedInstanceState) {
|
public void createMenuItems(Bundle savedInstanceState) {
|
||||||
|
@ -44,17 +45,12 @@ public class UploadPhotoProgressBottomSheet extends MenuBottomSheetDialogFragmen
|
||||||
uploadedPhotosCounter = view.findViewById(R.id.description);
|
uploadedPhotosCounter = view.findViewById(R.id.description);
|
||||||
progressBar = view.findViewById(R.id.progress_bar);
|
progressBar = view.findViewById(R.id.progress_bar);
|
||||||
progressBar.setMax(maxProgress);
|
progressBar.setMax(maxProgress);
|
||||||
String titleProgress = getString(progress == maxProgress? R.string.upload_photo_completed: R.string.upload_photo);
|
|
||||||
String descriptionProgress;
|
int descriptionId = uploadingFinished ? R.string.uploaded_count : R.string.uploading_count;
|
||||||
if (progress == maxProgress) {
|
|
||||||
descriptionProgress = getString(R.string.uploaded_count, progress, maxProgress);
|
|
||||||
} else {
|
|
||||||
descriptionProgress = getString(R.string.uploading_count, progress, maxProgress);
|
|
||||||
}
|
|
||||||
|
|
||||||
BaseBottomSheetItem descriptionItem = new BottomSheetItemWithDescription.Builder()
|
BaseBottomSheetItem descriptionItem = new BottomSheetItemWithDescription.Builder()
|
||||||
.setDescription(descriptionProgress)
|
.setDescription(getString(descriptionId, progress, maxProgress))
|
||||||
.setTitle(titleProgress)
|
.setTitle(getString(uploadingFinished ? R.string.upload_photo_completed : R.string.upload_photo))
|
||||||
.setCustomView(view)
|
.setCustomView(view)
|
||||||
.create();
|
.create();
|
||||||
items.add(descriptionItem);
|
items.add(descriptionItem);
|
||||||
|
@ -74,9 +70,10 @@ public class UploadPhotoProgressBottomSheet extends MenuBottomSheetDialogFragmen
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateProgress(int progress) {
|
private void updateProgress(int progress) {
|
||||||
|
int descriptionId = uploadingFinished ? R.string.uploaded_count : R.string.uploading_count;
|
||||||
progressBar.setProgress(progress);
|
progressBar.setProgress(progress);
|
||||||
uploadedPhotosCounter.setText((getString(R.string.uploading_count, progress, maxProgress)));
|
uploadedPhotosCounter.setText(getString(descriptionId, progress, maxProgress));
|
||||||
uploadedPhotosTitle.setText(progress == maxProgress ? R.string.upload_photo_completed : R.string.upload_photo);
|
uploadedPhotosTitle.setText(uploadingFinished ? R.string.upload_photo_completed : R.string.upload_photo);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -87,12 +84,10 @@ public class UploadPhotoProgressBottomSheet extends MenuBottomSheetDialogFragmen
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void uploadPhotosFinished() {
|
public void uploadPhotosFinished() {
|
||||||
if (progress == maxProgress) {
|
uploadingFinished = true;
|
||||||
uploadedPhotosCounter.setText((getString(R.string.uploaded_count, progress, maxProgress)));
|
updateProgress(progress);
|
||||||
setDismissButtonTextId(R.string.shared_string_close);
|
|
||||||
UiUtilities.setupDialogButton(nightMode, dismissButton, getDismissButtonType(), getDismissButtonTextId());
|
UiUtilities.setupDialogButton(nightMode, dismissButton, getDismissButtonType(), getDismissButtonTextId());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDismiss(@NonNull DialogInterface dialog) {
|
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) {
|
public static UploadPhotosListener showInstance(@NonNull FragmentManager fragmentManager, int maxProgress, OnDismissListener listener) {
|
||||||
UploadPhotoProgressBottomSheet fragment = new UploadPhotoProgressBottomSheet();
|
UploadPhotoProgressBottomSheet fragment = new UploadPhotoProgressBottomSheet();
|
||||||
fragment.setRetainInstance(true);
|
fragment.setRetainInstance(true);
|
||||||
|
|
|
@ -128,7 +128,7 @@ public class UploadPhotosAsyncTask extends AsyncTask<Void, Integer, Void> {
|
||||||
private boolean uploadImageToPlace(InputStream image) {
|
private boolean uploadImageToPlace(InputStream image) {
|
||||||
boolean success = false;
|
boolean success = false;
|
||||||
InputStream serverData = new ByteArrayInputStream(compressImageToJpeg(image));
|
InputStream serverData = new ByteArrayInputStream(compressImageToJpeg(image));
|
||||||
final String baseUrl = OPRConstants.getBaseUrl(app);
|
String baseUrl = OPRConstants.getBaseUrl(app);
|
||||||
// all these should be constant
|
// all these should be constant
|
||||||
String url = baseUrl + "api/ipfs/image";
|
String url = baseUrl + "api/ipfs/image";
|
||||||
String response = NetworkUtils.sendPostDataRequest(url, "file", "compressed.jpeg", serverData);
|
String response = NetworkUtils.sendPostDataRequest(url, "file", "compressed.jpeg", serverData);
|
||||||
|
@ -146,18 +146,16 @@ public class UploadPhotosAsyncTask extends AsyncTask<Void, Integer, Void> {
|
||||||
response, error);
|
response, error);
|
||||||
if (res != 200) {
|
if (res != 200) {
|
||||||
app.showToastMessage(error.toString());
|
app.showToastMessage(error.toString());
|
||||||
} else {
|
|
||||||
//ok, continue
|
|
||||||
}
|
}
|
||||||
} catch (FailedVerificationException e) {
|
} catch (FailedVerificationException e) {
|
||||||
LOG.error(e);
|
LOG.error(e);
|
||||||
checkTokenAndShowScreen();
|
checkTokenAndShowScreen();
|
||||||
|
|
||||||
}
|
}
|
||||||
if (res != 200) {
|
if (res != 200) {
|
||||||
//image was uploaded but not added to blockchain
|
//image was uploaded but not added to blockchain
|
||||||
checkTokenAndShowScreen();
|
checkTokenAndShowScreen();
|
||||||
} else {
|
} else {
|
||||||
|
success = true;
|
||||||
String str = app.getString(R.string.successfully_uploaded_pattern, 1, 1);
|
String str = app.getString(R.string.successfully_uploaded_pattern, 1, 1);
|
||||||
app.showToastMessage(str);
|
app.showToastMessage(str);
|
||||||
//refresh the image
|
//refresh the image
|
||||||
|
@ -166,7 +164,6 @@ public class UploadPhotosAsyncTask extends AsyncTask<Void, Integer, Void> {
|
||||||
if (activity != null) {
|
if (activity != null) {
|
||||||
MenuBuilder.execute(new GetImageCardsTask(activity, latLon, params, imageCardListener));
|
MenuBuilder.execute(new GetImageCardsTask(activity, latLon, params, imageCardListener));
|
||||||
}
|
}
|
||||||
success = true;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
checkTokenAndShowScreen();
|
checkTokenAndShowScreen();
|
||||||
|
|
Loading…
Reference in a new issue