androidx.recyclerview.widget.RecyclerView.AdapterDataObserver Java Examples
The following examples show how to use
androidx.recyclerview.widget.RecyclerView.AdapterDataObserver.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EpoxyControllerTest.java From epoxy with Apache License 2.0 | 6 votes |
@Test public void basicBuildModels() { AdapterDataObserver observer = mock(AdapterDataObserver.class); EpoxyController controller = new EpoxyController() { @Override protected void buildModels() { new TestModel() .addTo(this); } @Override protected void onExceptionSwallowed(RuntimeException exception) { noExceptionsDuringBasicBuildModels = false; } }; controller.getAdapter().registerAdapterDataObserver(observer); controller.requestModelBuild(); assertTrue(noExceptionsDuringBasicBuildModels); assertEquals(1, controller.getAdapter().getItemCount()); verify(observer).onItemRangeInserted(0, 1); verifyNoMoreInteractions(observer); }
Example #2
Source File: DiffPayloadTest.java From epoxy with Apache License 2.0 | 6 votes |
@Before public void before() { adapter = new BaseEpoxyAdapter() { @Override List<EpoxyModel<?>> getCurrentModels() { return models; } }; observer = spy(new AdapterDataObserver() { @Override public void onItemRangeChanged(int positionStart, int itemCount, Object payload) { } }); adapter.registerAdapterDataObserver(observer); }
Example #3
Source File: DataBindingModelIntegrationTest.java From epoxy with Apache License 2.0 | 6 votes |
@Test public void typesWithHashCodeAreDiffed() { SimpleEpoxyController controller = new SimpleEpoxyController(); AdapterDataObserver observerMock = mock(AdapterDataObserver.class); controller.getAdapter().registerAdapterDataObserver(observerMock); ModelWithDataBindingBindingModel_ firstModel = new ModelWithDataBindingBindingModel_() .stringValue("value1") .id(1); controller.setModels(Collections.singletonList(firstModel)); verify(observerMock).onItemRangeInserted(0, 1); ModelWithDataBindingBindingModel_ secondModel = new ModelWithDataBindingBindingModel_() .stringValue("value2") .id(1); controller.setModels(Collections.singletonList(secondModel)); verify(observerMock).onItemRangeChanged(eq(0), eq(1), any()); verifyNoMoreInteractions(observerMock); }
Example #4
Source File: OnModelBindListenerTest.java From epoxy with Apache License 2.0 | 6 votes |
@Test public void nullBindListenerChangesHashCode() { TestController controller = new TestController(); AdapterDataObserver observerMock = mock(AdapterDataObserver.class); controller.getAdapter().registerAdapterDataObserver(observerMock); ModelWithClickListener_ model = new ModelWithClickListener_(); controller.buildWithModel(model); verify(observerMock).onItemRangeInserted(eq(0), eq(1)); model = new ModelWithClickListener_(); model.onBind(new BindListener()); controller.buildWithModel(model); model = new ModelWithClickListener_(); model.onBind(null); controller.buildWithModel(model); verify(observerMock, times(2)).onItemRangeChanged(eq(0), eq(1), any()); }
Example #5
Source File: OnModelBindListenerTest.java From epoxy with Apache License 2.0 | 6 votes |
@Test public void newBindListenerDoesNotChangeHashCode() { TestController controller = new TestController(); AdapterDataObserver observerMock = mock(AdapterDataObserver.class); controller.getAdapter().registerAdapterDataObserver(observerMock); ModelWithClickListener_ model = new ModelWithClickListener_(); controller.buildWithModel(model); verify(observerMock).onItemRangeInserted(eq(0), eq(1)); model = new ModelWithClickListener_(); model.onBind(new BindListener()); controller.buildWithModel(model); model = new ModelWithClickListener_(); model.onBind(new BindListener()); controller.buildWithModel(model); verify(observerMock).onItemRangeChanged(eq(0), eq(1), any()); }
Example #6
Source File: OnModelBindListenerTest.java From epoxy with Apache License 2.0 | 6 votes |
@Test public void nullUnbindListenerChangesHashCode() { TestController controller = new TestController(); AdapterDataObserver observerMock = mock(AdapterDataObserver.class); controller.getAdapter().registerAdapterDataObserver(observerMock); ModelWithClickListener_ model = new ModelWithClickListener_(); controller.buildWithModel(model); verify(observerMock).onItemRangeInserted(eq(0), eq(1)); model = new ModelWithClickListener_(); model.onUnbind(new UnbindListener()); controller.buildWithModel(model); model = new ModelWithClickListener_(); model.onUnbind(null); controller.buildWithModel(model); verify(observerMock, times(2)).onItemRangeChanged(eq(0), eq(1), any()); }
Example #7
Source File: OnModelBindListenerTest.java From epoxy with Apache License 2.0 | 6 votes |
@Test public void newUnbindListenerDoesNotChangHashCode() { TestController controller = new TestController(); AdapterDataObserver observerMock = mock(AdapterDataObserver.class); controller.getAdapter().registerAdapterDataObserver(observerMock); ModelWithClickListener_ model = new ModelWithClickListener_(); controller.buildWithModel(model); verify(observerMock).onItemRangeInserted(eq(0), eq(1)); model = new ModelWithClickListener_(); model.onUnbind(new UnbindListener()); controller.buildWithModel(model); model = new ModelWithClickListener_(); model.onUnbind(new UnbindListener()); controller.buildWithModel(model); verify(observerMock).onItemRangeChanged(eq(0), eq(1), any()); }
Example #8
Source File: EpoxyControllerTest.java From epoxy with Apache License 2.0 | 5 votes |
@Test public void moveModel() { AdapterDataObserver observer = mock(AdapterDataObserver.class); final List<TestModel> testModels = new ArrayList<>(); testModels.add(new TestModel(1)); testModels.add(new TestModel(2)); testModels.add(new TestModel(3)); EpoxyController controller = new EpoxyController() { @Override protected void buildModels() { add(testModels); } }; EpoxyControllerAdapter adapter = controller.getAdapter(); adapter.registerAdapterDataObserver(observer); controller.requestModelBuild(); verify(observer).onItemRangeInserted(0, 3); testModels.add(0, testModels.remove(1)); controller.moveModel(1, 0); verify(observer).onItemRangeMoved(1, 0, 1); assertEquals(testModels, adapter.getCurrentModels()); controller.requestModelBuild(); assertEquals(testModels, adapter.getCurrentModels()); verifyNoMoreInteractions(observer); }
Example #9
Source File: EpoxyControllerTest.java From epoxy with Apache License 2.0 | 5 votes |
@Test public void moveModelOtherWay() { AdapterDataObserver observer = mock(AdapterDataObserver.class); final List<TestModel> testModels = new ArrayList<>(); testModels.add(new TestModel(1)); testModels.add(new TestModel(2)); testModels.add(new TestModel(3)); EpoxyController controller = new EpoxyController() { @Override protected void buildModels() { add(testModels); } }; EpoxyControllerAdapter adapter = controller.getAdapter(); adapter.registerAdapterDataObserver(observer); controller.requestModelBuild(); verify(observer).onItemRangeInserted(0, 3); testModels.add(2, testModels.remove(1)); controller.moveModel(1, 2); verify(observer).onItemRangeMoved(1, 2, 1); assertEquals(testModels, adapter.getCurrentModels()); controller.requestModelBuild(); assertEquals(testModels, adapter.getCurrentModels()); verifyNoMoreInteractions(observer); }
Example #10
Source File: EpoxyControllerTest.java From epoxy with Apache License 2.0 | 5 votes |
@Test public void multipleMoves() { AdapterDataObserver observer = mock(AdapterDataObserver.class); final List<TestModel> testModels = new ArrayList<>(); testModels.add(new TestModel(1)); testModels.add(new TestModel(2)); testModels.add(new TestModel(3)); EpoxyController controller = new EpoxyController() { @Override protected void buildModels() { add(testModels); } }; EpoxyControllerAdapter adapter = controller.getAdapter(); adapter.registerAdapterDataObserver(observer); controller.requestModelBuild(); testModels.add(0, testModels.remove(1)); controller.moveModel(1, 0); verify(observer).onItemRangeMoved(1, 0, 1); testModels.add(2, testModels.remove(1)); controller.moveModel(1, 2); verify(observer).onItemRangeMoved(1, 2, 1); assertEquals(testModels, adapter.getCurrentModels()); controller.requestModelBuild(); assertEquals(testModels, adapter.getCurrentModels()); }
Example #11
Source File: OnModelBindListenerTest.java From epoxy with Apache License 2.0 | 5 votes |
@Test public void bindListenerChangesHashCode() { TestController controller = new TestController(); AdapterDataObserver observerMock = mock(AdapterDataObserver.class); controller.getAdapter().registerAdapterDataObserver(observerMock); ModelWithClickListener_ model = new ModelWithClickListener_(); controller.buildWithModel(model); verify(observerMock).onItemRangeInserted(eq(0), eq(1)); // shouldn't change model = new ModelWithClickListener_(); model.onBind(null); controller.buildWithModel(model); verify(observerMock, never()).onItemRangeChanged(eq(0), eq(1), any()); model = new ModelWithClickListener_(); BindListener listener1 = new BindListener(); model.onBind(listener1); controller.buildWithModel(model); verify(observerMock, times(1)).onItemRangeChanged(eq(0), eq(1), any()); model = new ModelWithClickListener_(); model.onBind(listener1); controller.buildWithModel(model); verify(observerMock, times(1)).onItemRangeChanged(eq(0), eq(1), any()); }
Example #12
Source File: OnModelBindListenerTest.java From epoxy with Apache License 2.0 | 5 votes |
@Test public void unbindListenerChangesHashCode() { TestController controller = new TestController(); AdapterDataObserver observerMock = mock(AdapterDataObserver.class); controller.getAdapter().registerAdapterDataObserver(observerMock); ModelWithClickListener_ model = new ModelWithClickListener_(); controller.buildWithModel(model); verify(observerMock).onItemRangeInserted(eq(0), eq(1)); // shouldn't change model = new ModelWithClickListener_(); model.onUnbind(null); controller.buildWithModel(model); verify(observerMock, never()).onItemRangeChanged(eq(0), eq(1), any()); model = new ModelWithClickListener_(); UnbindListener listener1 = new UnbindListener(); model.onUnbind(listener1); controller.buildWithModel(model); verify(observerMock, times(1)).onItemRangeChanged(eq(0), eq(1), any()); model = new ModelWithClickListener_(); model.onUnbind(listener1); controller.buildWithModel(model); verify(observerMock, times(1)).onItemRangeChanged(eq(0), eq(1), any()); }
Example #13
Source File: ModelClickListenerTest.java From epoxy with Apache License 2.0 | 5 votes |
@Test public void modelClickListenerIsDiffed() { // Internally we wrap the model click listener with an anonymous click listener. We can't hash // the anonymous click listener since that changes the model state, instead our anonymous // click listener should use the hashCode of the user's click listener ModelClickListener modelClickListener = new ModelClickListener(); ViewClickListener viewClickListener = new ViewClickListener(); TestController controller = new TestController(); AdapterDataObserver observerMock = mock(AdapterDataObserver.class); controller.getAdapter().registerAdapterDataObserver(observerMock); ModelWithClickListener_ model = new ModelWithClickListener_(); controller.setModel(model); controller.requestModelBuild(); verify(observerMock).onItemRangeInserted(eq(0), eq(1)); model = new ModelWithClickListener_(); model.clickListener(modelClickListener); controller.setModel(model); lifecycleHelper.buildModelsAndBind(controller); // The second update shouldn't cause a item change model = new ModelWithClickListener_(); model.clickListener(modelClickListener); controller.setModel(model); lifecycleHelper.buildModelsAndBind(controller); model = new ModelWithClickListener_(); model.clickListener(viewClickListener); controller.setModel(model); lifecycleHelper.buildModelsAndBind(controller); verify(observerMock, times(2)).onItemRangeChanged(eq(0), eq(1), any()); verifyNoMoreInteractions(observerMock); }
Example #14
Source File: ModelClickListenerTest.java From epoxy with Apache License 2.0 | 5 votes |
@Test public void viewClickListenerIsDiffed() { TestController controller = new TestController(); AdapterDataObserver observerMock = mock(AdapterDataObserver.class); controller.getAdapter().registerAdapterDataObserver(observerMock); ModelWithClickListener_ model = new ModelWithClickListener_(); controller.setModel(model); controller.requestModelBuild(); verify(observerMock).onItemRangeInserted(eq(0), eq(1)); ViewClickListener viewClickListener = new ViewClickListener(); model = new ModelWithClickListener_(); model.clickListener(viewClickListener); controller.setModel(model); controller.requestModelBuild(); // The second update shouldn't cause a item change model = new ModelWithClickListener_(); model.clickListener(viewClickListener); controller.setModel(model); controller.requestModelBuild(); ModelClickListener modelClickListener = new ModelClickListener(); model = new ModelWithClickListener_(); model.clickListener(modelClickListener); controller.setModel(model); controller.requestModelBuild(); verify(observerMock, times(2)).onItemRangeChanged(eq(0), eq(1), any()); verifyNoMoreInteractions(observerMock); }
Example #15
Source File: RecyclerConverterAdapter.java From power-adapters with Apache License 2.0 | 4 votes |
@Override public final void unregisterAdapterDataObserver(RecyclerView.AdapterDataObserver observer) { super.unregisterAdapterDataObserver(observer); mAdapterDataObservers.remove(observer); updateObserver(); }
Example #16
Source File: SelectionTracker.java From FairEmail with GNU General Public License v3.0 | 4 votes |
/** @hide */ @RestrictTo(LIBRARY) protected abstract @NonNull AdapterDataObserver getAdapterDataObserver();
Example #17
Source File: RecyclerConverterAdapter.java From power-adapters with Apache License 2.0 | 4 votes |
@Override public final void registerAdapterDataObserver(RecyclerView.AdapterDataObserver observer) { super.registerAdapterDataObserver(observer); mAdapterDataObservers.add(observer); updateObserver(); }
Example #18
Source File: DefaultSelectionTracker.java From FairEmail with GNU General Public License v3.0 | 4 votes |
@Override protected @NonNull AdapterDataObserver getAdapterDataObserver() { return mAdapterObserver; }