Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(95)

Unified Diff: ios/chrome/browser/ui/content_suggestions/content_suggestions_view_controller.mm

Issue 2775593002: Add a message to empty ContentSuggestions sections (Closed)
Patch Set: Change tests Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ios/chrome/browser/ui/content_suggestions/content_suggestions_view_controller.mm
diff --git a/ios/chrome/browser/ui/content_suggestions/content_suggestions_view_controller.mm b/ios/chrome/browser/ui/content_suggestions/content_suggestions_view_controller.mm
index 4447d4ad793506e02321ee92df81ab1afe255477..bea4610b3f01378aee9f95451d9c242bc4274d53 100644
--- a/ios/chrome/browser/ui/content_suggestions/content_suggestions_view_controller.mm
+++ b/ios/chrome/browser/ui/content_suggestions/content_suggestions_view_controller.mm
@@ -65,6 +65,9 @@ const NSTimeInterval kAnimationDuration = 0.35;
willDeleteItemsAtIndexPaths:@[ indexPath ]];
[self.collectionView deleteItemsAtIndexPaths:@[ indexPath ]];
+
+ // Check if the section is now empty.
+ [self addEmptySectionPlaceholderIfNeeded:indexPath.section];
}
completion:^(BOOL) {
// The context menu could be displayed for the deleted entry.
@@ -140,6 +143,8 @@ const NSTimeInterval kAnimationDuration = 0.35;
case ContentSuggestionTypeArticle:
[self openArticle:item];
break;
+ case ContentSuggestionTypeEmpty:
+ break;
}
}
@@ -267,4 +272,15 @@ const NSTimeInterval kAnimationDuration = 0.35;
atIndexPath:touchedItemIndexPath];
}
+// Checks if the |section| is empty and add an empty element if it is the case.
+// Must be called from inside a performBatchUpdates: block.
+- (void)addEmptySectionPlaceholderIfNeeded:(NSInteger)section {
+ if ([self.collectionViewModel numberOfItemsInSection:section] > 0)
+ return;
+
+ NSIndexPath* emptyItem =
+ [self.collectionUpdater addEmptyItemForSection:section];
+ [self.collectionView insertItemsAtIndexPaths:@[ emptyItem ]];
+}
+
@end

Powered by Google App Engine
This is Rietveld 408576698