diff --git a/docs/wiki/listener.md b/docs/wiki/listener.md index c2cc6b2a4f..2cce2c9066 100644 --- a/docs/wiki/listener.md +++ b/docs/wiki/listener.md @@ -4,7 +4,7 @@ Sketch 支持对 `准备加载`、`完成`、`失败`、`取消` 以及 `下载 注意: * listener 默认在主线程回调,但是当 Sketch.load() 和 Sketch.download() 开启了同步后其 listener 就在运行线程回调,可能是主线程,也可能是非主线程 -* onReadyLoad() 方法只有在需要进入非主线程加载图片时才会被回调,因此有可能不回调 onReadyLoad() 方法而直接回调其它方法 +* onStarted() 方法只有在需要进入非主线程加载或下载图片时才会被回调,因此有可能不回调 onStarted() 方法而直接回调其它方法 #### SketchImageView @@ -14,8 +14,8 @@ SketchImageView sketchImageView = ...; // setDisplayListener() 一定要在 displayImage() 之前 sketchImageView.setDisplayListener(new DisplayListener() { @Override - public void onReadyLoad() { - // 只有在需要进入非主线程加载图片时才会回调 onReadyLoad() 方法 + public void onStarted() { + // 只有在需要进入非主线程加载图片时才会回调 onStarted() 方法 } @Override @@ -52,8 +52,8 @@ sketchImageView.displayImage("http://b.zol-img.com.cn/desk/bizhi/image/4/1366x76 ```java Sketch.with(context).load("http://t.cn/RShdS1f", new LoadListener() { @Override - public void onReadyLoad() { - // 只有在需要进入非主线程加载图片时才会回调 onReadyLoad() 方法 + public void onStarted() { + // 只有在需要进入非主线程加载图片时才会回调 onStarted() 方法 } @Override @@ -83,8 +83,8 @@ Sketch.with(context).load("http://t.cn/RShdS1f", new LoadListener() { ```java Sketch.with(context).download("http://t.cn/RShdS1f", new DownloadListener() { @Override - public void onReadyLoad() { - // 只有在需要进入非主线程加载图片时才会回调 onReadyLoad() 方法 + public void onStarted() { + // 只有在需要进入非主线程下载图片时才会回调 onStarted() 方法 } @Override diff --git a/sample/src/main/java/me/xiaopan/sketchsample/fragment/ImageFragment.java b/sample/src/main/java/me/xiaopan/sketchsample/fragment/ImageFragment.java index 058881bba4..9e4428208f 100644 --- a/sample/src/main/java/me/xiaopan/sketchsample/fragment/ImageFragment.java +++ b/sample/src/main/java/me/xiaopan/sketchsample/fragment/ImageFragment.java @@ -197,7 +197,7 @@ private void initOptions() { } @Override - public void onReadyLoad() { + public void onStarted() { hintView.loading(null); } diff --git a/sketch/src/main/java/me/xiaopan/sketch/request/CallbackHandler.java b/sketch/src/main/java/me/xiaopan/sketch/request/CallbackHandler.java index 9e9f7741e4..4a3d0e45a5 100644 --- a/sketch/src/main/java/me/xiaopan/sketch/request/CallbackHandler.java +++ b/sketch/src/main/java/me/xiaopan/sketch/request/CallbackHandler.java @@ -59,7 +59,7 @@ public boolean handleMessage(Message msg) { break; case WHAT_CALLBACK_STARTED: - ((Listener) msg.obj).onReadyLoad(); + ((Listener) msg.obj).onStarted(); break; case WHAT_CALLBACK_FAILED: ((Listener) msg.obj).onError(ErrorCause.valueOf(msg.getData().getString(PARAM_FAILED_CAUSE))); @@ -124,7 +124,7 @@ static void postRunUpdateProgress(@NonNull AsyncRequest request, int totalLength static void postCallbackStarted(@Nullable Listener listener, boolean sync) { if (listener != null) { if (sync || SketchUtils.isMainThread()) { - listener.onReadyLoad(); + listener.onStarted(); } else { handler.obtainMessage(WHAT_CALLBACK_STARTED, listener).sendToTarget(); } diff --git a/sketch/src/main/java/me/xiaopan/sketch/request/DisplayListener.java b/sketch/src/main/java/me/xiaopan/sketch/request/DisplayListener.java index 6ecccfa97e..0747efbf61 100644 --- a/sketch/src/main/java/me/xiaopan/sketch/request/DisplayListener.java +++ b/sketch/src/main/java/me/xiaopan/sketch/request/DisplayListener.java @@ -25,5 +25,11 @@ * 显示监听器,值的注意的是DisplayListener中所有的方法都会在主线中执行,所以实现着不必考虑异步线程中刷新UI的问题 */ public interface DisplayListener extends Listener { + /** + * 开始转入异步线程加载图片 + */ + @Override + void onStarted(); + void onCompleted(@NonNull Drawable drawable, @NonNull ImageFrom imageFrom, @NonNull ImageAttrs imageAttrs); } \ No newline at end of file diff --git a/sketch/src/main/java/me/xiaopan/sketch/request/DownloadListener.java b/sketch/src/main/java/me/xiaopan/sketch/request/DownloadListener.java index 475e1b52da..0a7a84857b 100644 --- a/sketch/src/main/java/me/xiaopan/sketch/request/DownloadListener.java +++ b/sketch/src/main/java/me/xiaopan/sketch/request/DownloadListener.java @@ -22,5 +22,11 @@ * 下载监听器 */ public interface DownloadListener extends Listener { + /** + * 开始转入异步线程下载图片 + */ + @Override + void onStarted(); + void onCompleted(@NonNull DownloadResult result); } \ No newline at end of file diff --git a/sketch/src/main/java/me/xiaopan/sketch/request/Listener.java b/sketch/src/main/java/me/xiaopan/sketch/request/Listener.java index a4cbc8dc52..13b548a103 100644 --- a/sketch/src/main/java/me/xiaopan/sketch/request/Listener.java +++ b/sketch/src/main/java/me/xiaopan/sketch/request/Listener.java @@ -22,10 +22,7 @@ * 请求监听器,可监听准备加载、失败、取消 */ public interface Listener { - /** - * 准备转入异步线程加载图片 - */ - void onReadyLoad(); + void onStarted(); /** * 失败 diff --git a/sketch/src/main/java/me/xiaopan/sketch/request/LoadListener.java b/sketch/src/main/java/me/xiaopan/sketch/request/LoadListener.java index a91c3217df..be5c08b0d6 100644 --- a/sketch/src/main/java/me/xiaopan/sketch/request/LoadListener.java +++ b/sketch/src/main/java/me/xiaopan/sketch/request/LoadListener.java @@ -19,5 +19,11 @@ import android.support.annotation.NonNull; public interface LoadListener extends Listener { + /** + * 开始转入异步线程加载图片 + */ + @Override + void onStarted(); + void onCompleted(@NonNull LoadResult result); } \ No newline at end of file diff --git a/sketch/src/main/java/me/xiaopan/sketch/viewfun/DisplayListenerProxy.java b/sketch/src/main/java/me/xiaopan/sketch/viewfun/DisplayListenerProxy.java index 7f0585992c..50c92a58c1 100644 --- a/sketch/src/main/java/me/xiaopan/sketch/viewfun/DisplayListenerProxy.java +++ b/sketch/src/main/java/me/xiaopan/sketch/viewfun/DisplayListenerProxy.java @@ -35,19 +35,19 @@ public DisplayListenerProxy(FunctionCallbackView view) { } @Override - public void onReadyLoad() { + public void onStarted() { FunctionCallbackView view = viewWeakReference.get(); if (view == null) { return; } - boolean needInvokeInvalidate = view.getFunctions().onDisplayReadyLoad(); + boolean needInvokeInvalidate = view.getFunctions().onDisplayStarted(); if (needInvokeInvalidate) { view.invalidate(); } if (view.wrappedDisplayListener != null) { - view.wrappedDisplayListener.onReadyLoad(); + view.wrappedDisplayListener.onStarted(); } } diff --git a/sketch/src/main/java/me/xiaopan/sketch/viewfun/ViewFunction.java b/sketch/src/main/java/me/xiaopan/sketch/viewfun/ViewFunction.java index 93650ccc86..d8618195ca 100644 --- a/sketch/src/main/java/me/xiaopan/sketch/viewfun/ViewFunction.java +++ b/sketch/src/main/java/me/xiaopan/sketch/viewfun/ViewFunction.java @@ -100,7 +100,7 @@ public boolean onReadyDisplay(@Nullable UriModel uriModel) { * * @return 是否需要调用 invalidate() 刷新 ImageView */ - public boolean onDisplayReadyLoad() { + public boolean onDisplayStarted() { return false; } diff --git a/sketch/src/main/java/me/xiaopan/sketch/viewfun/ViewFunctions.java b/sketch/src/main/java/me/xiaopan/sketch/viewfun/ViewFunctions.java index 6df599fbb6..98206a1631 100644 --- a/sketch/src/main/java/me/xiaopan/sketch/viewfun/ViewFunctions.java +++ b/sketch/src/main/java/me/xiaopan/sketch/viewfun/ViewFunctions.java @@ -342,39 +342,39 @@ boolean onReadyDisplay(@Nullable UriModel uriModel) { /** * @return true:需要调用invalidate()刷新view */ - boolean onDisplayReadyLoad() { + boolean onDisplayStarted() { boolean needInvokeInvalidate = false; if (showImageFromFunction != null) { //noinspection ConstantConditions - needInvokeInvalidate |= showImageFromFunction.onDisplayReadyLoad(); + needInvokeInvalidate |= showImageFromFunction.onDisplayStarted(); } if (showDownloadProgressFunction != null) { - needInvokeInvalidate |= showDownloadProgressFunction.onDisplayReadyLoad(); + needInvokeInvalidate |= showDownloadProgressFunction.onDisplayStarted(); } if (showGifFlagFunction != null) { - needInvokeInvalidate |= showGifFlagFunction.onDisplayReadyLoad(); + needInvokeInvalidate |= showGifFlagFunction.onDisplayStarted(); } if (showPressedFunction != null) { - needInvokeInvalidate |= showPressedFunction.onDisplayReadyLoad(); + needInvokeInvalidate |= showPressedFunction.onDisplayStarted(); } if (clickRetryFunction != null) { - needInvokeInvalidate |= clickRetryFunction.onDisplayReadyLoad(); + needInvokeInvalidate |= clickRetryFunction.onDisplayStarted(); } if (requestFunction != null) { - needInvokeInvalidate |= requestFunction.onDisplayReadyLoad(); + needInvokeInvalidate |= requestFunction.onDisplayStarted(); } if (recyclerCompatFunction != null) { - needInvokeInvalidate |= recyclerCompatFunction.onDisplayReadyLoad(); + needInvokeInvalidate |= recyclerCompatFunction.onDisplayStarted(); } if (zoomFunction != null) { - needInvokeInvalidate |= zoomFunction.onDisplayReadyLoad(); + needInvokeInvalidate |= zoomFunction.onDisplayStarted(); } if (hugeImageFunction != null) { - needInvokeInvalidate |= hugeImageFunction.onDisplayReadyLoad(); + needInvokeInvalidate |= hugeImageFunction.onDisplayStarted(); } if (clickPlayGifFunction != null) { - needInvokeInvalidate |= clickPlayGifFunction.onDisplayReadyLoad(); + needInvokeInvalidate |= clickPlayGifFunction.onDisplayStarted(); } return needInvokeInvalidate;