/** * Assign a tag to this request. Tags are an easy way to logically associate * related requests that can be managed together e.g. paused, resumed, * or canceled. * <p> * You can either use simple {@link String} tags or objects that naturally * define the scope of your requests within your app such as a * {@link android.content.Context}, an {@link android.app.Activity}, or a * {@link android.app.Fragment}. * * <strong>WARNING:</strong>: Picasso will keep a reference to the tag for * as long as this tag is paused and/or has active requests. Look out for * potential leaks. * * @see Picasso#cancelTag(Object) * @see Picasso#pauseTag(Object) * @see Picasso#resumeTag(Object) */ @NonNull public RequestCreator tag(@NonNull Object tag) { data.tag(tag); return this; }
@Test public void performCancelWithFetchActionWithCallback() { String pausedTag = "pausedTag"; dispatcher.pausedTags.add(pausedTag); assertThat(dispatcher.pausedActions).isEmpty(); Callback callback = mockCallback(); FetchAction fetchAction1 = new FetchAction(mockPicasso(), new Request.Builder(URI_1).tag(pausedTag).build(), callback); dispatcher.performCancel(fetchAction1); fetchAction1.cancel(); assertThat(dispatcher.pausedActions).isEmpty(); }
@Test public void performSubmitWithFetchAction() { String pausedTag = "pausedTag"; dispatcher.pausedTags.add(pausedTag); assertThat(dispatcher.pausedActions).isEmpty(); FetchAction fetchAction1 = new FetchAction(mockPicasso(), new Request.Builder(URI_1).tag(pausedTag).build(), null); FetchAction fetchAction2 = new FetchAction(mockPicasso(), new Request.Builder(URI_1).tag(pausedTag).build(), null); dispatcher.performSubmit(fetchAction1); dispatcher.performSubmit(fetchAction2); assertThat(dispatcher.pausedActions).hasSize(2); }