Skip to content

Commit c8d646e

Browse files
sjuddglide-copybara-robot
authored andcommittedJun 3, 2019
Disable custom tags in CustomViewTarget
Setting custom tags will prevent Glide.with().clear() from working properly. PiperOrigin-RevId: 251273595
1 parent 6d833d9 commit c8d646e

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed
 

‎library/src/main/java/com/bumptech/glide/request/target/CustomViewTarget.java

+6-7
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ public abstract class CustomViewTarget<T extends View, Z> implements Target<Z> {
4242
@Nullable private OnAttachStateChangeListener attachStateListener;
4343
private boolean isClearedByUs;
4444
private boolean isAttachStateListenerAdded;
45-
@IdRes private int overrideTag;
4645

4746
/** Constructor that defaults {@code waitForLayout} to {@code false}. */
4847
public CustomViewTarget(@NonNull T view) {
@@ -162,14 +161,14 @@ public void onViewDetachedFromWindow(View v) {
162161
* the same view, for example one foreground and one background view.
163162
*
164163
* @param tagId The android resource id to use.
164+
* @deprecated Using this method prevents clearing the target from working properly. Glide uses
165+
* its own internal tag id so this method should not be necessary. This method is currently a
166+
* no-op.
165167
*/
166168
// Public API.
167169
@SuppressWarnings({"UnusedReturnValue", "WeakerAccess"})
170+
@Deprecated
168171
public final CustomViewTarget<T, Z> useTagId(@IdRes int tagId) {
169-
if (this.overrideTag != 0) {
170-
throw new IllegalArgumentException("You cannot change the tag id once it has been set.");
171-
}
172-
this.overrideTag = tagId;
173172
return this;
174173
}
175174

@@ -265,12 +264,12 @@ final void pauseMyRequest() {
265264
}
266265

267266
private void setTag(@Nullable Object tag) {
268-
view.setTag(overrideTag == 0 ? VIEW_TAG_ID : overrideTag, tag);
267+
view.setTag(VIEW_TAG_ID, tag);
269268
}
270269

271270
@Nullable
272271
private Object getTag() {
273-
return view.getTag(overrideTag == 0 ? VIEW_TAG_ID : overrideTag);
272+
return view.getTag(VIEW_TAG_ID);
274273
}
275274

276275
private void maybeAddAttachStateListener() {

‎library/src/test/java/com/bumptech/glide/request/target/CustomViewTargetTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ public void clearOnDetach_onAttach_withClearedRequest_beginsRequest() {
584584
}
585585

586586
@Test
587-
public void clearOnDetach_afterLoadClearedAndRestarted_onAttach_beingsREquest() {
587+
public void clearOnDetach_afterLoadClearedAndRestarted_onAttach_beginsRequest() {
588588
attachStateTarget.clearOnDetach();
589589
attachStateTarget.setRequest(request);
590590
when(request.isCleared()).thenReturn(true);

0 commit comments

Comments
 (0)
Please sign in to comment.