Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add removeAllModels() to EpoxyAdapter #94

Merged
merged 1 commit into from
Jan 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions epoxy-adapter/src/main/java/com/airbnb/epoxy/EpoxyAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,19 @@ protected void removeModel(EpoxyModel<?> model) {
}
}

/**
* Removes all models
*/
protected void removeAllModels() {
int numModelsRemoved = models.size();

pauseModelListNotifications();
models.clear();
resumeModelListNotifications();

notifyItemRangeRemoved(0, numModelsRemoved);
}

/**
* Removes all models after the given model, which must have already been added. An example use
* case is you want to keep a header but clear everything else, like in the case of refreshing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ public void removeModel(EpoxyModel<?> model) {
super.removeModel(model);
}

@Override
public void removeAllModels() {
super.removeAllModels();
}

@Override
public void removeAllAfterModel(EpoxyModel<?> model) {
super.removeAllAfterModel(model);
Expand Down
14 changes: 14 additions & 0 deletions epoxy-adapter/src/test/java/com/airbnb/epoxy/EpoxyAdapterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,20 @@ public void testRemoveModels() {
checkDifferState();
}

@Test
public void testRemoveAllModels() {
for (int i = 0; i < 10; i++) {
TestModel model = new TestModel();
testAdapter.addModels(model);
}

testAdapter.removeAllModels();
verify(observer).onItemRangeRemoved(0, 10);
assertEquals(0, testAdapter.models.size());

checkDifferState();
}

@Test
public void testRemoveAllAfterModels() {
List<TestModel> models = new ArrayList<>();
Expand Down