* panoramic images fixed

* made requested changes

* Minor refactoring

Co-authored-by: Aditya Srivastava <iamaditya2009@gmail.com>
This commit is contained in:
Nicolas Raoul 2021-06-21 13:05:46 +09:00 committed by GitHub
parent 810c797be2
commit c8a31a32ea
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -29,6 +29,16 @@ public class ImageInfo implements Serializable {
@Nullable private String user;
@Nullable private String timestamp;
/**
* Query width, default width parameter of the API query in pixels.
*/
final private static int QUERY_WIDTH = 640;
/**
* Threshold height, the minimum height of the image in pixels.
*/
final private static int THRESHOLD_HEIGHT = 220;
@NonNull
public String getSource() {
return StringUtils.defaultString(source);
@ -50,11 +60,24 @@ public class ImageInfo implements Serializable {
return height;
}
/**
* Get the thumbnail width.
* @return
*/
public int getThumbWidth() { return thumbWidth; }
/**
* Get the thumbnail height.
* @return
*/
public int getThumbHeight() { return thumbHeight; }
@NonNull public String getMimeType() {
return StringUtils.defaultString(mimeType, "*/*");
}
@NonNull public String getThumbUrl() {
updateThumbUrl();
return StringUtils.defaultString(thumbUrl);
}
@ -73,4 +96,26 @@ public class ImageInfo implements Serializable {
@Nullable public ExtMetadata getMetadata() {
return metadata;
}
/**
* Updates the ThumbUrl if image dimensions are not sufficient.
* Specifically, in panoramic images the height retrieved is less than required due to large width to height ratio,
* so we update the thumb url keeping a minimum height threshold.
*/
private void updateThumbUrl() {
// If thumbHeight retrieved from API is less than THRESHOLD_HEIGHT
if(getThumbHeight() < THRESHOLD_HEIGHT){
// If thumbWidthRetrieved is same as queried width ( If not tells us that the image has no larger dimensions. )
if(getThumbWidth() == QUERY_WIDTH){
// Calculate new width depending on the aspect ratio.
final int finalWidth = (int)(THRESHOLD_HEIGHT * getThumbWidth() * 1.0 / getThumbHeight());
thumbHeight = THRESHOLD_HEIGHT;
thumbWidth = finalWidth;
final String toReplace = "/" + QUERY_WIDTH + "px";
final int position = thumbUrl.lastIndexOf(toReplace);
thumbUrl = (new StringBuilder(thumbUrl)).replace(position, position + toReplace.length(), "/" + thumbWidth + "px").toString();
}
}
}
}