@Before public void setUp() { MockitoAnnotations.initMocks(this); mResult1 = new Object(); mResult2 = new Object(); mResult3 = new Object(); mException = mock(Exception.class); mDataSubscriber1 = mock(DataSubscriber.class); mDataSubscriber2 = mock(DataSubscriber.class); mSettableProducerContext = mock(SettableProducerContext.class); when(mSettableProducerContext.getId()).thenReturn(mRequestId); when(mSettableProducerContext.isPrefetch()).thenReturn(true); mProducer = mock(Producer.class); mDataSource = ProducerToDataSourceAdapter.create( mProducer, mSettableProducerContext, mRequestListener); ArgumentCaptor<Consumer> captor = ArgumentCaptor.forClass(Consumer.class); verify(mRequestListener).onRequestStart( mSettableProducerContext.getImageRequest(), mSettableProducerContext.getCallerContext(), mRequestId, mSettableProducerContext.isPrefetch()); verify(mProducer).produceResults(captor.capture(), any(SettableProducerContext.class)); mInternalConsumer = captor.getValue(); mDataSource.subscribe(mDataSubscriber1, CallerThreadExecutor.getInstance()); }
@Before public void setUp() { MockitoAnnotations.initMocks(this); mResourceReleaser = mock(ResourceReleaser.class); mResultRef1 = CloseableReference.of(new Object(), mResourceReleaser); mResultRef2 = CloseableReference.of(new Object(), mResourceReleaser); mResultRef3 = CloseableReference.of(new Object(), mResourceReleaser); mException = mock(Exception.class); mDataSubscriber1 = mock(DataSubscriber.class); mDataSubscriber2 = mock(DataSubscriber.class); mSettableProducerContext = mock(SettableProducerContext.class); when(mSettableProducerContext.getId()).thenReturn(mRequestId); when(mSettableProducerContext.isPrefetch()).thenReturn(false); mProducer = mock(Producer.class); mDataSource = CloseableProducerToDataSourceAdapter.create( mProducer, mSettableProducerContext, mRequestListener); ArgumentCaptor<Consumer> captor = ArgumentCaptor.forClass(Consumer.class); verify(mRequestListener).onRequestStart( mSettableProducerContext.getImageRequest(), mSettableProducerContext.getCallerContext(), mRequestId, mSettableProducerContext.isPrefetch()); verify(mProducer).produceResults(captor.capture(), any(SettableProducerContext.class)); mInternalConsumer = captor.getValue(); mDataSource.subscribe(mDataSubscriber1, CallerThreadExecutor.getInstance()); }
@Override public View instantiateItem(ViewGroup container, int position) { View view = LayoutInflater.from(ImageViewActivity.this).inflate(R.layout.item_imagepage, container, false); final PhotoView photoView = (PhotoView) view.findViewById(R.id.photoview); final View wheel = view.findViewById(R.id.wheel); photoView.setOnPhotoTapListener((view1, v, v1) -> finish()); ImagePipeline imagePipeline = Fresco.getImagePipeline(); ImageRequest request = ImageRequestBuilder.newBuilderWithSource(urls.get(position)) .setResizeOptions(new ResizeOptions(768, 768)) .build(); DataSource<CloseableReference<CloseableImage>> dataSource = imagePipeline.fetchDecodedImage(request,this); DataSubscriber dataSubscriber = new BaseBitmapDataSubscriber() { @Override protected void onNewResultImpl(Bitmap bitmap) { photoView.setImageBitmap(bitmap); wheel.setVisibility(View.GONE); } @Override protected void onFailureImpl(DataSource<CloseableReference<CloseableImage>> closeableReferenceDataSource) { } }; dataSource.subscribe(dataSubscriber, new Executor() { @Override public void execute(Runnable command) { handler.post(command); } }); container.addView(view); return view; }