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
Proper support for GIFs when using a RetainingDataSource #2185
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,11 +7,10 @@ | |
|
||
package com.facebook.drawee.controller; | ||
|
||
import static com.facebook.drawee.components.DraweeEventTracker.Event; | ||
|
||
import android.graphics.drawable.Animatable; | ||
import android.graphics.drawable.Drawable; | ||
import android.view.MotionEvent; | ||
|
||
import com.facebook.common.internal.Objects; | ||
import com.facebook.common.internal.Preconditions; | ||
import com.facebook.common.logging.FLog; | ||
|
@@ -27,10 +26,14 @@ | |
import com.facebook.drawee.interfaces.SettableDraweeHierarchy; | ||
import com.facebook.imagepipeline.systrace.FrescoSystrace; | ||
import com.facebook.infer.annotation.ReturnsOwnership; | ||
|
||
import java.util.concurrent.Executor; | ||
|
||
import javax.annotation.Nullable; | ||
import javax.annotation.concurrent.NotThreadSafe; | ||
|
||
import static com.facebook.drawee.components.DraweeEventTracker.Event; | ||
|
||
/** | ||
* Abstract Drawee controller that implements common functionality | ||
* regardless of the backend used to fetch the image. | ||
|
@@ -443,7 +446,7 @@ protected void submitRequest() { | |
mEventTracker.recordEvent(Event.ON_SUBMIT_CACHE_HIT); | ||
getControllerListener().onSubmit(mId, mCallerContext); | ||
onImageLoadedFromCacheImmediately(mId, closeableImage); | ||
onNewResultInternal(mId, mDataSource, closeableImage, 1.0f, true, true); | ||
onNewResultInternal(mId, mDataSource, closeableImage, 1.0f, true, true, true); | ||
FrescoSystrace.endSection(); | ||
return; | ||
} | ||
|
@@ -470,10 +473,11 @@ public void onNewResultImpl(DataSource<T> dataSource) { | |
// isFinished must be obtained before image, otherwise we might set intermediate result | ||
// as final image. | ||
boolean isFinished = dataSource.isFinished(); | ||
boolean isReadyToPlay = dataSource.isReadyToPlay(); | ||
float progress = dataSource.getProgress(); | ||
T image = dataSource.getResult(); | ||
if (image != null) { | ||
onNewResultInternal(id, dataSource, image, progress, isFinished, wasImmediate); | ||
onNewResultInternal(id, dataSource, image, progress, isFinished, wasImmediate, isReadyToPlay); | ||
} else if (isFinished) { | ||
onFailureInternal(id, dataSource, new NullPointerException(), /* isFinished */ true); | ||
} | ||
|
@@ -499,7 +503,8 @@ private void onNewResultInternal( | |
@Nullable T image, | ||
float progress, | ||
boolean isFinished, | ||
boolean wasImmediate) { | ||
boolean wasImmediate, | ||
boolean isReadyToPlay) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The naming here is confusing if you don't have context. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I renamed it to |
||
try { | ||
FrescoSystrace.beginSection("AbstractDraweeController#onNewResultInternal"); | ||
// ignore late callbacks (data source that returned the new result is not the one we expected) | ||
|
@@ -532,7 +537,10 @@ private void onNewResultInternal( | |
mDataSource = null; | ||
mSettableDraweeHierarchy.setImage(drawable, 1f, wasImmediate); | ||
getControllerListener().onFinalImageSet(id, getImageInfo(image), getAnimatable()); | ||
// IMPORTANT: do not execute any instance-specific code after this point | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This warning shouldn't be removed since it is important :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok, I'll add it |
||
} else if (isReadyToPlay) { | ||
logMessageAndImage("set_temporary_result @ onNewResult", image); | ||
mSettableDraweeHierarchy.setImage(drawable, 1f, wasImmediate); | ||
getControllerListener().onFinalImageSet(id, getImageInfo(image), getAnimatable()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The problem here is that this is not true. It's not the final image but one in a series. I guess in this case it makes sense though since each image could be considered as an image on its own. |
||
} else { | ||
logMessageAndImage("set_intermediate_result @ onNewResult", image); | ||
mSettableDraweeHierarchy.setImage(drawable, progress, wasImmediate); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -319,4 +319,9 @@ public void run() { | |
}); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean isReadyToPlay() { | ||
return false; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,6 +49,13 @@ public interface DataSource<T> { | |
*/ | ||
boolean hasResult(); | ||
|
||
/** | ||
* | ||
* @return true if any resources poured in the datasource should be sent to controllers. Usefull | ||
* with a RetainingDataSource to loaded resources are displayed correctly. | ||
*/ | ||
boolean isReadyToPlay(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Data source is, as the javadoc mentions, "An alternative to Java Futures for the image pipeline". It shouldn't have any animation-related logic in the interface. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suggest renaming this to something like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
|
||
/** | ||
* @return true if request is finished, false otherwise | ||
*/ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The imports shouldn't be re-ordered. We deleted our code style settings
.intellij/codeStyleSettings.idea
by accident but they will be re-added shortly (cdbd6ea). Sorry for that.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AndroidStudio did that, imports optimisation was active. Will check for changes and revert them.