本文整理汇总了Java中android.support.v7.util.ListUpdateCallback类的典型用法代码示例。如果您正苦于以下问题:Java ListUpdateCallback类的具体用法?Java ListUpdateCallback怎么用?Java ListUpdateCallback使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ListUpdateCallback类属于android.support.v7.util包,在下文中一共展示了ListUpdateCallback类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setItems
import android.support.v7.util.ListUpdateCallback; //导入依赖的package包/类
/**
* This method is used to transform the current dataset ({@link #items}) into the passed in list of items, performing
* logic to remove, add and rearrange items in a way that allows the RecyclerView to animate properly.
*
* @param items the new dataset ({@link List<ViewModel>})
* @param callback an optional {@link ListUpdateCallback}
*/
public synchronized void setItems(List<ViewModel> items, @Nullable ListUpdateCallback callback) {
if (this.items == items) {
return;
}
new DiffResultTask(this.items, items, diffResult -> {
ViewModelAdapter.this.items = items;
diffResult.dispatchUpdatesTo(ViewModelAdapter.this);
if (BuildConfig.DEBUG) {
logDiffResult(diffResult);
}
if (callback != null) {
diffResult.dispatchUpdatesTo(callback);
}
}).execute();
}
示例2: shouldNotApplyPresenter1ChangesWhenNotObservedUntilGetItemCount
import android.support.v7.util.ListUpdateCallback; //导入依赖的package包/类
@Test
public void shouldNotApplyPresenter1ChangesWhenNotObservedUntilGetItemCount() {
when(mockPresenter1.getItemId(REPOSITORY_VALUE_B, 2)).thenReturn(10L);
repositoryAdapter.unregisterAdapterDataObserver(redirectingObserver);
repository1.accept(REPOSITORY_VALUE_B);
runUiThreadTasksIncludingDelayedTasks();
verify(mockPresenter1, never()).getItemCount(any());
final int itemCount = repositoryAdapter.getItemCount();
verify(mockPresenter1, never()).getItemCount(REPOSITORY_VALUE_A);
verify(mockPresenter1).getItemCount(REPOSITORY_VALUE_B);
assertThat(itemCount, is(
PRESENTER_1_B_ITEM_COUNT + STATIC_ITEM_COUNT + PRESENTER_2_A_ITEM_COUNT));
assertThat(repositoryAdapter.getItemId(2), is(10L + STATIC_ITEM_COUNT));
verify(mockPresenter1, never()).getUpdates(any(), any(), any(ListUpdateCallback.class));
}
示例3: shouldNotApplyPresenter2ChangesEvenWhenObservedUntilGetItemCount
import android.support.v7.util.ListUpdateCallback; //导入依赖的package包/类
@Test
public void shouldNotApplyPresenter2ChangesEvenWhenObservedUntilGetItemCount() {
when(mockPresenter2.getItemId(REPOSITORY_VALUE_B, 4)).thenReturn(100L);
repository2.accept(REPOSITORY_VALUE_B);
runUiThreadTasksIncludingDelayedTasks();
verify(mockPresenter1, never()).getItemCount(any());
final int itemCount = repositoryAdapter.getItemCount();
verify(mockPresenter2, never()).getItemCount(REPOSITORY_VALUE_A);
verify(mockPresenter2).getItemCount(REPOSITORY_VALUE_B);
assertThat(itemCount, is(
PRESENTER_1_A_ITEM_COUNT + STATIC_ITEM_COUNT + PRESENTER_2_B_ITEM_COUNT));
assertThat(repositoryAdapter.getItemId(PRESENTER_1_A_ITEM_COUNT + STATIC_ITEM_COUNT + 4),
is(100L + STATIC_ITEM_COUNT));
verify(mockPresenter2, never()).getUpdates(any(), any(), any(ListUpdateCallback.class));
}
示例4: shouldApplyPresenter1ChangesWithEventsWhenObserved
import android.support.v7.util.ListUpdateCallback; //导入依赖的package包/类
@Test
public void shouldApplyPresenter1ChangesWithEventsWhenObserved() {
repositoryAdapter.getItemCount(); // usage
when(mockPresenter1.getItemId(REPOSITORY_VALUE_B, 2)).thenReturn(10L);
repository1.accept(REPOSITORY_VALUE_B);
runUiThreadTasksIncludingDelayedTasks();
assertThat(repositoryAdapter.getItemCount(), is(
PRESENTER_1_B_ITEM_COUNT + STATIC_ITEM_COUNT + PRESENTER_2_A_ITEM_COUNT));
assertThat(repositoryAdapter.getItemId(2), is(10L + STATIC_ITEM_COUNT));
verify(mockPresenter1).getUpdates(eq(REPOSITORY_VALUE_A), eq(REPOSITORY_VALUE_B),
any(ListUpdateCallback.class));
applyPresenter1FromAToBChanges(verifyingWrapper(fineGrainedEvents));
verifyNoMoreInteractions(fineGrainedEvents);
verify(onChangeEvent, never()).run();
}
示例5: shouldApplyPresenter2ChangesWithEventsWhenObserved
import android.support.v7.util.ListUpdateCallback; //导入依赖的package包/类
@Test
public void shouldApplyPresenter2ChangesWithEventsWhenObserved() {
repositoryAdapter.getItemCount(); // usage
when(mockPresenter2.getItemId(REPOSITORY_VALUE_B, 4)).thenReturn(100L);
repository2.accept(REPOSITORY_VALUE_B);
runUiThreadTasksIncludingDelayedTasks();
assertThat(repositoryAdapter.getItemCount(), is(
PRESENTER_1_A_ITEM_COUNT + STATIC_ITEM_COUNT + PRESENTER_2_B_ITEM_COUNT));
assertThat(repositoryAdapter.getItemId(PRESENTER_1_A_ITEM_COUNT + STATIC_ITEM_COUNT + 4),
is(100L + STATIC_ITEM_COUNT));
verify(mockPresenter2).getUpdates(eq(REPOSITORY_VALUE_A), eq(REPOSITORY_VALUE_B),
any(ListUpdateCallback.class));
applyPresenter2FromAToBChanges(PRESENTER_1_A_ITEM_COUNT + STATIC_ITEM_COUNT,
verifyingWrapper(fineGrainedEvents));
verifyNoMoreInteractions(fineGrainedEvents);
verify(onChangeEvent, never()).run();
}
示例6: shouldAskBothPresentersOnAdditionalObservableUpdate
import android.support.v7.util.ListUpdateCallback; //导入依赖的package包/类
@Test
public void shouldAskBothPresentersOnAdditionalObservableUpdate() {
repository1.accept(REPOSITORY_VALUE_B);
repository2.accept(REPOSITORY_VALUE_B);
runUiThreadTasksIncludingDelayedTasks();
repositoryAdapter.getItemCount(); // usage
verify(mockPresenter1).getItemCount(REPOSITORY_VALUE_B); // consume method call
verify(mockPresenter2).getItemCount(REPOSITORY_VALUE_B); // consume method call
updateDispatcher.update();
runUiThreadTasksIncludingDelayedTasks();
repositoryAdapter.getItemCount();
verify(mockPresenter1).getUpdates(eq(REPOSITORY_VALUE_B), eq(REPOSITORY_VALUE_B),
any(ListUpdateCallback.class));
verifyNoMoreInteractions(mockPresenter1); // should not have called getItemCount() again
verify(mockPresenter2).getUpdates(eq(REPOSITORY_VALUE_B), eq(REPOSITORY_VALUE_B),
any(ListUpdateCallback.class));
verifyNoMoreInteractions(mockPresenter2); // should not have called getItemCount() again
applyPresenter1RefreshBChanges(verifyingWrapper(fineGrainedEvents));
applyPresenter2RefreshBChanges(PRESENTER_1_B_ITEM_COUNT + STATIC_ITEM_COUNT,
verifyingWrapper(fineGrainedEvents));
verifyNoMoreInteractions(fineGrainedEvents);
verify(onChangeEvent, never()).run();
}
示例7: getUpdates
import android.support.v7.util.ListUpdateCallback; //导入依赖的package包/类
@Override
boolean getUpdates(final boolean reloadData,
@NonNull final ListUpdateCallback listUpdateCallback) {
final Object oldData = data;
final Object newData = reloadData ? repository.get() : oldData;
if (presenter.getUpdates(oldData, newData, listUpdateCallback)) {
data = newData;
return true;
}
return false;
}
示例8: applyPresenter1FromAToBChanges
import android.support.v7.util.ListUpdateCallback; //导入依赖的package包/类
private static void applyPresenter1FromAToBChanges(@NonNull final ListUpdateCallback callback) {
// From count 1 to count 3:
// [X] -> [Y, X]
callback.onInserted(0, 1);
// [Y, X] -> [Y, X']
callback.onChanged(1, 1, PAYLOAD_PRESENTER_1_VALUE_A_TO_B);
// [Y, X] -> [Y, X', Z]
callback.onInserted(2, 1);
}
示例9: applyPresenter1FromBToAChanges
import android.support.v7.util.ListUpdateCallback; //导入依赖的package包/类
private static void applyPresenter1FromBToAChanges(@NonNull final ListUpdateCallback callback) {
// From count 3 to count 1:
// [Y, X', Z] -> [Y, Z]
callback.onRemoved(1, 1);
// [Y, Z] -> []
callback.onRemoved(0, 2);
// [] -> [X]
callback.onInserted(0, 1);
}
示例10: applyPresenter2FromAToBChanges
import android.support.v7.util.ListUpdateCallback; //导入依赖的package包/类
private static void applyPresenter2FromAToBChanges(
final int offset, @NonNull final ListUpdateCallback callback) {
// From count 4 to count 5:
// [M, N, O, P] -> [P, M, N, O]
callback.onMoved(3 + offset, offset);
// [P, M, N, O] -> [P, M]
callback.onRemoved(2 + offset, 2);
// [P, M] -> [P, X, Y, Z, M]
callback.onInserted(1 + offset, 3);
}
示例11: applyPresenter2FromBToAChanges
import android.support.v7.util.ListUpdateCallback; //导入依赖的package包/类
private static void applyPresenter2FromBToAChanges(
final int offset, @NonNull final ListUpdateCallback callback) {
// From count 5 to count 4:
// [P, X, Y, Z, M] -> [M, P, X, Y, Z]
callback.onMoved(4 + offset, offset);
// [M, P, X, Y, Z] -> [M, P]
callback.onRemoved(2 + offset, 3);
// [M, P] -> [M, N, O, P]
callback.onInserted(1 + offset, 2);
}
示例12: tearDown
import android.support.v7.util.ListUpdateCallback; //导入依赖的package包/类
@After
public void tearDown() {
verify(mockStaticItemPresenter, never()).getUpdates(
any(), any(), any(ListUpdateCallback.class));
repositoryAdapter.stopObserving();
if (repositoryAdapter.hasObservers()) {
repositoryAdapter.unregisterAdapterDataObserver(redirectingObserver);
}
}
示例13: shouldSendDataChangeEventAndDisableUpdatesUntilGetItemCount
import android.support.v7.util.ListUpdateCallback; //导入依赖的package包/类
@Test
public void shouldSendDataChangeEventAndDisableUpdatesUntilGetItemCount() {
when(mockPresenter1.getUpdates(any(), any(), any(ListUpdateCallback.class))).thenReturn(false);
repositoryAdapter.getItemCount(); // usage
repository1.accept(REPOSITORY_VALUE_B);
runUiThreadTasksIncludingDelayedTasks();
verify(mockPresenter1).getUpdates(eq(REPOSITORY_VALUE_A), eq(REPOSITORY_VALUE_B),
any(ListUpdateCallback.class));
verifyZeroInteractions(fineGrainedEvents);
verify(onChangeEvent).run();
updateDispatcher.update();
runUiThreadTasksIncludingDelayedTasks();
verifyZeroInteractions(fineGrainedEvents);
verifyNoMoreInteractions(onChangeEvent);
repository2.accept(REPOSITORY_VALUE_B);
runUiThreadTasksIncludingDelayedTasks();
verifyZeroInteractions(fineGrainedEvents);
verifyNoMoreInteractions(onChangeEvent);
repositoryAdapter.getItemCount(); // usage
repository2.accept(REPOSITORY_VALUE_A);
runUiThreadTasksIncludingDelayedTasks();
verifyNoMoreInteractions(onChangeEvent);
applyPresenter2FromBToAChanges(PRESENTER_1_B_ITEM_COUNT + STATIC_ITEM_COUNT,
verifyingWrapper(fineGrainedEvents));
verifyNoMoreInteractions(fineGrainedEvents);
}
示例14: setUpdateCallback
import android.support.v7.util.ListUpdateCallback; //导入依赖的package包/类
public void setUpdateCallback(@NonNull final ListUpdateCallback updateCallback) {
mUpdateCallback = updateCallback;
}
示例15: setUpdatedCallback
import android.support.v7.util.ListUpdateCallback; //导入依赖的package包/类
void setUpdatedCallback(@Nullable ListUpdateCallback listUpdatedCallback) {
mListUpdateCallback = listUpdatedCallback;
}