use of androidx.recyclerview.widget.RecyclerView.AdapterDataObserver in project epoxy by airbnb.
the class OnModelBindListenerTest method nullBindListenerChangesHashCode.
@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());
}
use of androidx.recyclerview.widget.RecyclerView.AdapterDataObserver in project epoxy by airbnb.
the class OnModelBindListenerTest method newUnbindListenerDoesNotChangHashCode.
@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());
}
use of androidx.recyclerview.widget.RecyclerView.AdapterDataObserver in project epoxy by airbnb.
the class OnModelBindListenerTest method newBindListenerDoesNotChangeHashCode.
@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());
}
use of androidx.recyclerview.widget.RecyclerView.AdapterDataObserver in project epoxy by airbnb.
the class OnModelBindListenerTest method unbindListenerChangesHashCode.
@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());
}
use of androidx.recyclerview.widget.RecyclerView.AdapterDataObserver in project apps-android-commons by commons-app.
the class ContributionsListFragment method initRecyclerView.
private void initRecyclerView() {
final GridLayoutManager layoutManager = new GridLayoutManager(getContext(), getSpanCount(getResources().getConfiguration().orientation));
rvContributionsList.setLayoutManager(layoutManager);
// Setting flicker animation of recycler view to false.
final ItemAnimator animator = rvContributionsList.getItemAnimator();
if (animator instanceof SimpleItemAnimator) {
((SimpleItemAnimator) animator).setSupportsChangeAnimations(false);
}
contributionsListPresenter.setup(userName, Objects.equals(sessionManager.getUserName(), userName));
contributionsListPresenter.contributionList.observe(getViewLifecycleOwner(), list -> {
contributionsSize = list.size();
adapter.submitList(list);
if (callback != null) {
callback.notifyDataSetChanged();
}
});
rvContributionsList.setAdapter(adapter);
adapter.registerAdapterDataObserver(new AdapterDataObserver() {
@Override
public void onItemRangeInserted(int positionStart, int itemCount) {
super.onItemRangeInserted(positionStart, itemCount);
if (itemCount > 0 && positionStart == 0) {
if (adapter.getContributionForPosition(positionStart) != null) {
rvContributionsList.scrollToPosition(// Newly upload items are always added to the top
0);
}
}
}
/**
* Called whenever items in the list have changed
* Calls viewPagerNotifyDataSetChanged() that will notify the viewpager
*/
@Override
public void onItemRangeChanged(final int positionStart, final int itemCount) {
super.onItemRangeChanged(positionStart, itemCount);
if (callback != null) {
callback.viewPagerNotifyDataSetChanged();
}
}
});
// Fab close on touch outside (Scrolling or taping on item triggers this action).
rvContributionsList.addOnItemTouchListener(new OnItemTouchListener() {
/**
* Silently observe and/or take over touch events sent to the RecyclerView before
* they are handled by either the RecyclerView itself or its child views.
*/
@Override
public boolean onInterceptTouchEvent(@NonNull RecyclerView rv, @NonNull MotionEvent e) {
if (e.getAction() == MotionEvent.ACTION_DOWN) {
if (isFabOpen) {
animateFAB(isFabOpen);
}
}
return false;
}
/**
* Process a touch event as part of a gesture that was claimed by returning true
* from a previous call to {@link #onInterceptTouchEvent}.
*
* @param rv
* @param e MotionEvent describing the touch event. All coordinates are in the
* RecyclerView's coordinate system.
*/
@Override
public void onTouchEvent(@NonNull RecyclerView rv, @NonNull MotionEvent e) {
// required abstract method DO NOT DELETE
}
/**
* Called when a child of RecyclerView does not want RecyclerView and its ancestors
* to intercept touch events with {@link ViewGroup#onInterceptTouchEvent(MotionEvent)}.
*
* @param disallowIntercept True if the child does not want the parent to intercept
* touch events.
*/
@Override
public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {
// required abstract method DO NOT DELETE
}
});
}
Aggregations