diff --git a/library/src/main/java/com/bumptech/glide/request/target/CustomViewTarget.java b/library/src/main/java/com/bumptech/glide/request/target/CustomViewTarget.java index 3932554ced..548af1521c 100644 --- a/library/src/main/java/com/bumptech/glide/request/target/CustomViewTarget.java +++ b/library/src/main/java/com/bumptech/glide/request/target/CustomViewTarget.java @@ -42,7 +42,6 @@ public abstract class CustomViewTarget implements Target { @Nullable private OnAttachStateChangeListener attachStateListener; private boolean isClearedByUs; private boolean isAttachStateListenerAdded; - @IdRes private int overrideTag; /** Constructor that defaults {@code waitForLayout} to {@code false}. */ public CustomViewTarget(@NonNull T view) { @@ -162,14 +161,14 @@ public void onViewDetachedFromWindow(View v) { * the same view, for example one foreground and one background view. * * @param tagId The android resource id to use. + * @deprecated Using this method prevents clearing the target from working properly. Glide uses + * its own internal tag id so this method should not be necessary. This method is currently a + * no-op. */ // Public API. @SuppressWarnings({"UnusedReturnValue", "WeakerAccess"}) + @Deprecated public final CustomViewTarget useTagId(@IdRes int tagId) { - if (this.overrideTag != 0) { - throw new IllegalArgumentException("You cannot change the tag id once it has been set."); - } - this.overrideTag = tagId; return this; } @@ -265,12 +264,12 @@ final void pauseMyRequest() { } private void setTag(@Nullable Object tag) { - view.setTag(overrideTag == 0 ? VIEW_TAG_ID : overrideTag, tag); + view.setTag(VIEW_TAG_ID, tag); } @Nullable private Object getTag() { - return view.getTag(overrideTag == 0 ? VIEW_TAG_ID : overrideTag); + return view.getTag(VIEW_TAG_ID); } private void maybeAddAttachStateListener() { diff --git a/library/src/test/java/com/bumptech/glide/request/target/CustomViewTargetTest.java b/library/src/test/java/com/bumptech/glide/request/target/CustomViewTargetTest.java index f10bd7fb1c..08ec0dbb92 100644 --- a/library/src/test/java/com/bumptech/glide/request/target/CustomViewTargetTest.java +++ b/library/src/test/java/com/bumptech/glide/request/target/CustomViewTargetTest.java @@ -584,7 +584,7 @@ public void clearOnDetach_onAttach_withClearedRequest_beginsRequest() { } @Test - public void clearOnDetach_afterLoadClearedAndRestarted_onAttach_beingsREquest() { + public void clearOnDetach_afterLoadClearedAndRestarted_onAttach_beginsRequest() { attachStateTarget.clearOnDetach(); attachStateTarget.setRequest(request); when(request.isCleared()).thenReturn(true);