Skip to content

Commit

Permalink
Disable custom tags in CustomViewTarget
Browse files Browse the repository at this point in the history
Setting custom tags will prevent Glide.with().clear() from working properly.

PiperOrigin-RevId: 251273595
  • Loading branch information
sjudd authored and glide-copybara-robot committed Jun 3, 2019
1 parent 6d833d9 commit c8d646e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ public abstract class CustomViewTarget<T extends View, Z> implements Target<Z> {
@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) {
Expand Down Expand Up @@ -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<T, Z> 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;
}

Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit c8d646e

Please sign in to comment.