This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test public void testBatchedCallbacks() throws Exception { | |
SortedList<Article> articleSortedList = new SortedList<>(Article.class, | |
new SortedList.BatchedCallback<>(fixture.callbackRecorder())); | |
articleSortedList.beginBatchedUpdates(); | |
for (int i = 0; i < fixture.shuffledArticles().size(); i++) { | |
Article articleToAdd = fixture.shuffledArticles().get(i).dupe(); | |
articleSortedList.add(articleToAdd); | |
assertThat(fixture.callbackRecorder().insertions().size()).isEqualTo(0); | |
} | |
articleSortedList.endBatchedUpdates(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test public void testMoves() throws Exception { | |
assertThat(fixture.sortedList().size()).isEqualTo(0); | |
addArticles(); | |
fixture.callbackRecorder().clear(); | |
int index1 = 2; | |
Article articleOne = fixture.sortedList().get(index1); | |
assertThat(fixture.sortedList().indexOf(articleOne)).isEqualTo(index1); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test public void testDeletions() throws Exception { | |
assertThat(fixture.sortedList().size()).isEqualTo(0); | |
addArticles(); | |
fixture.callbackRecorder().clear(); | |
int index = Article.Utils.randomWithRange(0, fixture.sortedList().size() - 1); | |
Article articleToDelete = fixture.sortedList().get(index).dupe(); | |
boolean deleted = fixture.sortedList().remove(articleToDelete); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test public void testChanges() throws Exception { | |
assertThat(fixture.sortedList().size()).isEqualTo(0); | |
addArticles(); | |
assertThat(fixture.callbackRecorder().insertions().size()).isEqualTo( | |
fixture.shuffledArticles().size()); | |
assertThat(fixture.callbackRecorder().deletions().size()).isEqualTo(0); | |
assertThat(fixture.callbackRecorder().moves().size()).isEqualTo(0); | |
assertThat(fixture.callbackRecorder().changes().size()).isEqualTo(0); | |
fixture.callbackRecorder().clear(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test public void testInsertions() throws Exception { | |
assertThat(fixture.sortedList().size()).isEqualTo(0); | |
for (int i = 0; i < fixture.shuffledArticles().size(); i++) { | |
Article articleToAdd = fixture.shuffledArticles().get(i).dupe(); | |
int positionTobeInserted = -1; | |
for (int j = 0; j < fixture.sortedList().size(); j++) { | |
Article jth = fixture.sortedList().get(j); | |
if (jth.compare(articleToAdd) >= 0) { | |
positionTobeInserted = j; | |
break; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test public void testAdditionOfSameObjectShouldNotChangeSortedList() throws Exception { | |
assertThat(fixture.sortedList().size()).isEqualTo(0); | |
Article article = fixture.orderedArticleList() | |
.get(Article.Utils.randomWithRange(0, fixture.orderedArticleList().size() - 1)); | |
fixture.sortedList().add(article); | |
assertThat(fixture.callbackRecorder().insertions().size()).isEqualTo(1); | |
assertThat(fixture.callbackRecorder().deletions().size()).isEqualTo(0); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test public void testAddShouldSortListIrrespectiveOfOrder() throws Exception { | |
addArticles(); | |
for (int i = 0; i < fixture.orderedArticleList().size(); i++) { | |
assertThat(fixture.sortedList().get(i)) | |
.isEqualTo(fixture.orderedArticleList().get(i)); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func remove(item: ListItem, on collectionView: UICollectionView) { | |
let foundIndex = items.index { (given) -> Bool in | |
return given.id == item.id | |
} | |
if let index = foundIndex { | |
items.remove(at: index) | |
collectionView.deleteItems(at: [IndexPath(item: index, section: 0)]) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cell.deletedClosure = { listItem in | |
UIView.animate(withDuration: 0.3, delay: 0.0, usingSpringWithDamping: 1, initialSpringVelocity: 0.5, options: .curveEaseIn, animations: { | |
self.decorateReadyToMove(for: cell, andAngle: 0) | |
cell.transform = CGAffineTransform(scaleX: 0.01, y: 1) | |
}, completion: { (_) in | |
cell.transform = CGAffineTransform(scaleX: 0.01, y: 0.01) | |
cell.alpha = 0 | |
self.listItemDataset.remove(item: listItem, on: self.collectionView) | |
}) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func toggleCompleted(forItem listItem: ListItem, on collectionView: UICollectionView) { | |
let foundIndex = items.index { (given) -> Bool in | |
return given.id == listItem.id | |
} | |
if(listItem.isCompleted) { | |
if let index = foundIndex { | |
let item = items.remove(at: index) | |
items.insert(item, at: 0) | |
item.isCompleted = false | |
collectionView.moveItem(at: IndexPath(item: index, section: 0), to: IndexPath(item: 0, section: 0)) |
NewerOlder