Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow onlyScaleDown() with fit() method #1600

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

kwangsu61
Copy link

onlyScaleDown() method is so useful to avoid useless bitmap scale up for memory usage and performance.

This PR allows that onlyScaleDown() works with fit() method like centerCrop()/centerInside().

Refer to #941

@magneticflux-
Copy link

It seems like an arbitrary restriction, I'd love this change! .fit() just uses .resize() behind the scenes, so I don't seen any problems using .onlyScaleDown() with it.

Copy link

@magneticflux- magneticflux- left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some confusing wording in the error and possible mistype.

@@ -500,6 +497,10 @@ public Request build() {
throw new IllegalStateException(
"Center inside requires calling resize with positive width and height.");
}
if (onlyScaleDown && (targetWidth == 0 && targetHeight == 0)) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be if(deferred || (targetWidth == 0 && targetHeight == 0))?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And this check should be moved back to the onlyScaleDown method.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JakeWharton This method is in the Request class, which seems to be in line with the other checks such as for null lists, invalid properties, and center[Crop|Inside] checks.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh, the Request class has no knowledge of fitting, which is done in the RequestCreator class. I'm going to make my own pull request that will hopefully fix these issues cleanly.

@@ -555,6 +565,11 @@ public void intoTargetNoResizeWithCenterInsideOrCenterCropThrows() {
fail("Center inside with unknown height should throw exception.");
} catch (IllegalStateException ignored) {
}
try {
new RequestCreator(picasso, URI_1, 0).onlyScaleDown().into(mockTarget());
fail("onlyScaleDown with unknown height should throw exception.");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this fail when .onlyScaleDown() is called without a call to .fit() or .resize(int, int)?

@@ -544,7 +554,7 @@ public void intoRemoteViewsNotificationWithFitThrows() {
}

@Test
public void intoTargetNoResizeWithCenterInsideOrCenterCropThrows() {
public void intoTargetNoResizeWithCenterInsideOrCenterCropOrOnlyScaleDownThrows() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably also be named intoTargetNoResizeOrFitWithCenterInsideOrCenterCropOrOnlyScaleDownThrows.

@magneticflux-
Copy link

@JakeWharton I have an alternative pull request, #1623, that I believe fixes the issues with this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants