Skip to content

Commit

Permalink
Drawee: support multiple controller listeners 2
Browse files Browse the repository at this point in the history
Reviewed By: oprisnik

Differential Revision: D21763220

fbshipit-source-id: 25745b235e9cd5e53c5f9a334fc9f71e16cbe851
  • Loading branch information
defHLT authored and facebook-github-bot committed Jun 5, 2020
1 parent e442337 commit 036605d
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.facebook.drawee.controller.AbstractDraweeControllerBuilder;
import com.facebook.drawee.controller.ControllerListener;
import com.facebook.drawee.interfaces.DraweeController;
import com.facebook.fresco.ui.common.ControllerListener2;
import com.facebook.imagepipeline.cache.CacheKeyFactory;
import com.facebook.imagepipeline.common.RotationOptions;
import com.facebook.imagepipeline.core.ImagePipeline;
Expand Down Expand Up @@ -56,8 +57,9 @@ public PipelineDraweeControllerBuilder(
Context context,
PipelineDraweeControllerFactory pipelineDraweeControllerFactory,
ImagePipeline imagePipeline,
Set<ControllerListener> boundControllerListeners) {
super(context, boundControllerListeners);
Set<ControllerListener> boundControllerListeners,
Set<ControllerListener2> boundControllerListeners2) {
super(context, boundControllerListeners, boundControllerListeners2);
mImagePipeline = imagePipeline;
mPipelineDraweeControllerFactory = pipelineDraweeControllerFactory;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.facebook.drawee.backends.pipeline.info.ImagePerfDataListener;
import com.facebook.drawee.components.DeferredReleaser;
import com.facebook.drawee.controller.ControllerListener;
import com.facebook.fresco.ui.common.ControllerListener2;
import com.facebook.imagepipeline.core.ImagePipeline;
import com.facebook.imagepipeline.core.ImagePipelineFactory;
import java.util.Set;
Expand All @@ -25,6 +26,7 @@ public class PipelineDraweeControllerBuilderSupplier
private final ImagePipeline mImagePipeline;
private final PipelineDraweeControllerFactory mPipelineDraweeControllerFactory;
private final Set<ControllerListener> mBoundControllerListeners;
private final Set<ControllerListener2> mBoundControllerListeners2;
private final @Nullable ImagePerfDataListener mDefaultImagePerfDataListener;

public PipelineDraweeControllerBuilderSupplier(Context context) {
Expand All @@ -40,13 +42,14 @@ public PipelineDraweeControllerBuilderSupplier(
Context context,
ImagePipelineFactory imagePipelineFactory,
@Nullable DraweeConfig draweeConfig) {
this(context, imagePipelineFactory, null, draweeConfig);
this(context, imagePipelineFactory, null, null, draweeConfig);
}

public PipelineDraweeControllerBuilderSupplier(
Context context,
ImagePipelineFactory imagePipelineFactory,
Set<ControllerListener> boundControllerListeners,
Set<ControllerListener2> boundControllerListeners2,
@Nullable DraweeConfig draweeConfig) {
mContext = context;
mImagePipeline = imagePipelineFactory.getImagePipeline();
Expand All @@ -65,6 +68,7 @@ public PipelineDraweeControllerBuilderSupplier(
draweeConfig != null ? draweeConfig.getCustomDrawableFactories() : null,
draweeConfig != null ? draweeConfig.getDebugOverlayEnabledSupplier() : null);
mBoundControllerListeners = boundControllerListeners;
mBoundControllerListeners2 = boundControllerListeners2;

mDefaultImagePerfDataListener =
draweeConfig != null ? draweeConfig.getImagePerfDataListener() : null;
Expand All @@ -74,7 +78,11 @@ public PipelineDraweeControllerBuilderSupplier(
public PipelineDraweeControllerBuilder get() {
PipelineDraweeControllerBuilder pipelineDraweeControllerBuilder =
new PipelineDraweeControllerBuilder(
mContext, mPipelineDraweeControllerFactory, mImagePipeline, mBoundControllerListeners);
mContext,
mPipelineDraweeControllerFactory,
mImagePipeline,
mBoundControllerListeners,
mBoundControllerListeners2);
return pipelineDraweeControllerBuilder.setPerfDataListener(mDefaultImagePerfDataListener);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public void setEnabled(boolean enabled) {
mPipelineDraweeController.removeImageOriginListener(mImageOriginListener);
}
if (mImagePerfControllerListener2 != null) {
mPipelineDraweeController.removeControllerListener2();
mPipelineDraweeController.removeControllerListener2(mImagePerfControllerListener2);
}
if (mForwardingRequestListener != null) {
mPipelineDraweeController.removeRequestListener(mForwardingRequestListener);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void testEnableDisable() {
verify(mController).addRequestListener(any(RequestListener.class));
verify(mController).getId();
verify(mController).removeImageOriginListener(any(ImagePerfImageOriginListener.class));
verify(mController).removeControllerListener2();
verify(mController).removeControllerListener2(any(ImagePerfControllerListener2.class));
verify(mController).removeRequestListener(any(RequestListener.class));
verifyNoMoreInteractions(mController);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.facebook.fresco.ui.common.BaseControllerListener2;
import com.facebook.fresco.ui.common.ControllerListener2;
import com.facebook.fresco.ui.common.ControllerListener2.Extras;
import com.facebook.fresco.ui.common.ForwardingControllerListener2;
import com.facebook.fresco.ui.common.LoggingListener;
import com.facebook.imagepipeline.systrace.FrescoSystrace;
import com.facebook.infer.annotation.ReturnsOwnership;
Expand Down Expand Up @@ -93,7 +94,8 @@ public static <INFO> InternalForwardingListener<INFO> createInternal(
private @Nullable GestureDetector mGestureDetector;
private @Nullable ControllerViewportVisibilityListener mControllerViewportVisibilityListener;
protected @Nullable ControllerListener<INFO> mControllerListener;
protected @Nullable ControllerListener2 mControllerListener2;
protected ForwardingControllerListener2<INFO> mControllerListener2 =
new ForwardingControllerListener2<>();
protected @Nullable LoggingListener mLoggingListener;

// Hierarchy
Expand Down Expand Up @@ -296,12 +298,12 @@ public void addControllerListener(ControllerListener<? super INFO> controllerLis
mControllerListener = (ControllerListener<INFO>) controllerListener;
}

public void addControllerListener2(ControllerListener2 controllerListener2) {
mControllerListener2 = controllerListener2;
public void addControllerListener2(ControllerListener2<INFO> controllerListener2) {
mControllerListener2.addListener(controllerListener2);
}

public void removeControllerListener2() {
mControllerListener2 = BaseControllerListener2.getNoOpListener();
public void removeControllerListener2(ControllerListener2<INFO> controllerListener2) {
mControllerListener2.removeListener(controllerListener2);
}

public void setLoggingListener(final LoggingListener loggingListener) {
Expand Down Expand Up @@ -333,9 +335,6 @@ protected ControllerListener<INFO> getControllerListener() {
}

protected ControllerListener2 getControllerListener2() {
if (mControllerListener2 == null) {
mControllerListener2 = BaseControllerListener2.getNoOpListener();
}
return mControllerListener2;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.facebook.drawee.gestures.GestureDetector;
import com.facebook.drawee.interfaces.DraweeController;
import com.facebook.drawee.interfaces.SimpleDraweeControllerBuilder;
import com.facebook.fresco.ui.common.ControllerListener2;
import com.facebook.fresco.ui.common.LoggingListener;
import com.facebook.imagepipeline.systrace.FrescoSystrace;
import com.facebook.infer.annotation.ReturnsOwnership;
Expand Down Expand Up @@ -52,6 +53,7 @@ public void onFinalImageSet(String id, @Nullable Object info, @Nullable Animatab
// components
private final Context mContext;
private final Set<ControllerListener> mBoundControllerListeners;
private final Set<ControllerListener2> mBoundControllerListeners2;

// builder parameters
private @Nullable Object mCallerContext;
Expand All @@ -73,9 +75,12 @@ public void onFinalImageSet(String id, @Nullable Object info, @Nullable Animatab
private static final AtomicLong sIdCounter = new AtomicLong();

protected AbstractDraweeControllerBuilder(
Context context, Set<ControllerListener> boundControllerListeners) {
Context context,
Set<ControllerListener> boundControllerListeners,
Set<ControllerListener2> boundControllerListeners2) {
mContext = context;
mBoundControllerListeners = boundControllerListeners;
mBoundControllerListeners2 = boundControllerListeners2;
init();
}

Expand Down Expand Up @@ -431,6 +436,11 @@ protected void maybeAttachListeners(AbstractDraweeController controller) {
controller.addControllerListener(listener);
}
}
if (mBoundControllerListeners2 != null) {
for (ControllerListener2<INFO> listener : mBoundControllerListeners2) {
controller.addControllerListener2(listener);
}
}
if (mControllerListener != null) {
controller.addControllerListener(mControllerListener);
}
Expand Down

0 comments on commit 036605d

Please sign in to comment.