Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
沉迷打码的小凳子
glide
提交
6fb87b35
G
glide
项目概览
沉迷打码的小凳子
/
glide
与 Fork 源项目一致
从无法访问的项目Fork
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
glide
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
6fb87b35
编写于
9月 21, 2017
作者:
S
Sam Judd
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Assert that into() and clear() are not called in callbacks.
Fixes #2413.
上级
1b4a99a7
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
53 addition
and
9 deletion
+53
-9
library/src/main/java/com/bumptech/glide/request/SingleRequest.java
...c/main/java/com/bumptech/glide/request/SingleRequest.java
+34
-9
library/src/main/java/com/bumptech/glide/request/target/PreloadTarget.java
...java/com/bumptech/glide/request/target/PreloadTarget.java
+19
-0
未找到文件。
library/src/main/java/com/bumptech/glide/request/SingleRequest.java
浏览文件 @
6fb87b35
...
...
@@ -45,6 +45,7 @@ public final class SingleRequest<R> implements Request,
return
new
SingleRequest
<
Object
>();
}
});
private
boolean
isCallingCallbacks
;
private
enum
Status
{
/**
...
...
@@ -182,6 +183,7 @@ public final class SingleRequest<R> implements Request,
@Override
public
void
recycle
()
{
assertNotCallingCallbacks
();
glideContext
=
null
;
model
=
null
;
transcodeClass
=
null
;
...
...
@@ -203,6 +205,7 @@ public final class SingleRequest<R> implements Request,
@Override
public
void
begin
()
{
assertNotCallingCallbacks
();
stateVerifier
.
throwIfRecycled
();
startTime
=
LogTime
.
getLogTime
();
if
(
model
==
null
)
{
...
...
@@ -260,6 +263,7 @@ public final class SingleRequest<R> implements Request,
* @see #clear()
*/
void
cancel
()
{
assertNotCallingCallbacks
();
stateVerifier
.
throwIfRecycled
();
target
.
removeCallback
(
this
);
status
=
Status
.
CANCELLED
;
...
...
@@ -269,6 +273,15 @@ public final class SingleRequest<R> implements Request,
}
}
// Avoids difficult to understand errors like #2413.
private
void
assertNotCallingCallbacks
()
{
if
(
isCallingCallbacks
)
{
throw
new
IllegalStateException
(
"You can't start or clear loads in RequestListener or"
+
" Target callbacks. If you must do so, consider posting your into() or clear() calls"
+
" to the main thread using a Handler instead."
);
}
}
/**
* Cancels the current load if it is in progress, clears any resources held onto by the request
* and replaces the loaded resource if the load completed with the placeholder.
...
...
@@ -280,6 +293,7 @@ public final class SingleRequest<R> implements Request,
@Override
public
void
clear
()
{
Util
.
assertMainThread
();
assertNotCallingCallbacks
();
if
(
status
==
Status
.
CLEARED
)
{
return
;
}
...
...
@@ -535,11 +549,16 @@ public final class SingleRequest<R> implements Request,
+
LogTime
.
getElapsedMillis
(
startTime
)
+
" ms"
);
}
if
(
requestListener
==
null
||
!
requestListener
.
onResourceReady
(
result
,
model
,
target
,
dataSource
,
isFirstResource
))
{
Transition
<?
super
R
>
animation
=
animationFactory
.
build
(
dataSource
,
isFirstResource
);
target
.
onResourceReady
(
result
,
animation
);
isCallingCallbacks
=
true
;
try
{
if
(
requestListener
==
null
||
!
requestListener
.
onResourceReady
(
result
,
model
,
target
,
dataSource
,
isFirstResource
))
{
Transition
<?
super
R
>
animation
=
animationFactory
.
build
(
dataSource
,
isFirstResource
);
target
.
onResourceReady
(
result
,
animation
);
}
}
finally
{
isCallingCallbacks
=
false
;
}
notifyLoadSuccess
();
...
...
@@ -565,10 +584,16 @@ public final class SingleRequest<R> implements Request,
loadStatus
=
null
;
status
=
Status
.
FAILED
;
//TODO: what if this is a thumbnail request?
if
(
requestListener
==
null
||
!
requestListener
.
onLoadFailed
(
e
,
model
,
target
,
isFirstReadyResource
()))
{
setErrorPlaceholder
();
isCallingCallbacks
=
true
;
try
{
//TODO: what if this is a thumbnail request?
if
(
requestListener
==
null
||
!
requestListener
.
onLoadFailed
(
e
,
model
,
target
,
isFirstReadyResource
()))
{
setErrorPlaceholder
();
}
}
finally
{
isCallingCallbacks
=
false
;
}
}
...
...
library/src/main/java/com/bumptech/glide/request/target/PreloadTarget.java
浏览文件 @
6fb87b35
package
com.bumptech.glide.request.target
;
import
android.os.Handler
;
import
android.os.Handler.Callback
;
import
android.os.Looper
;
import
android.os.Message
;
import
com.bumptech.glide.RequestManager
;
import
com.bumptech.glide.request.transition.Transition
;
...
...
@@ -10,6 +14,17 @@ import com.bumptech.glide.request.transition.Transition;
* @param <Z> The type of resource that will be loaded into memory.
*/
public
final
class
PreloadTarget
<
Z
>
extends
SimpleTarget
<
Z
>
{
private
static
final
int
MESSAGE_CLEAR
=
1
;
private
static
final
Handler
HANDLER
=
new
Handler
(
Looper
.
getMainLooper
(),
new
Callback
()
{
@Override
public
boolean
handleMessage
(
Message
message
)
{
if
(
message
.
what
==
MESSAGE_CLEAR
)
{
((
PreloadTarget
<?>)
message
.
obj
).
clear
();
return
true
;
}
return
false
;
}
});
private
final
RequestManager
requestManager
;
...
...
@@ -31,6 +46,10 @@ public final class PreloadTarget<Z> extends SimpleTarget<Z> {
@Override
public
void
onResourceReady
(
Z
resource
,
Transition
<?
super
Z
>
transition
)
{
HANDLER
.
obtainMessage
(
MESSAGE_CLEAR
,
this
).
sendToTarget
();
}
private
void
clear
()
{
requestManager
.
clear
(
this
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录