Commit 816a4d79 authored by David Jean's avatar David Jean Committed by Commit Bot

[ios] sync suggestions show/hide on ntps in multi-windows

Bug: 1106689
Change-Id: I9239398fc5ed9462d6c7fff4f08c2a718cfe5f56
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2303442Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Commit-Queue: David Jean <djean@chromium.org>
Cr-Commit-Position: refs/heads/master@{#790316}
parent 9ca607f9
...@@ -56,10 +56,11 @@ const NSInteger kMaxNumMostVisitedTiles = 4; ...@@ -56,10 +56,11 @@ const NSInteger kMaxNumMostVisitedTiles = 4;
} // namespace } // namespace
@interface ContentSuggestionsMediator ()<ContentSuggestionsItemDelegate, @interface ContentSuggestionsMediator () <BooleanObserver,
ContentSuggestionsServiceObserver, ContentSuggestionsItemDelegate,
MostVisitedSitesObserving, ContentSuggestionsServiceObserver,
ReadingListModelBridgeObserver> { MostVisitedSitesObserving,
ReadingListModelBridgeObserver> {
// Bridge for this class to become an observer of a ContentSuggestionsService. // Bridge for this class to become an observer of a ContentSuggestionsService.
std::unique_ptr<ContentSuggestionsServiceBridge> _suggestionBridge; std::unique_ptr<ContentSuggestionsServiceBridge> _suggestionBridge;
std::unique_ptr<ntp_tiles::MostVisitedSites> _mostVisitedSites; std::unique_ptr<ntp_tiles::MostVisitedSites> _mostVisitedSites;
...@@ -369,22 +370,13 @@ const NSInteger kMaxNumMostVisitedTiles = 4; ...@@ -369,22 +370,13 @@ const NSInteger kMaxNumMostVisitedTiles = 4;
- (void)toggleArticlesVisibility { - (void)toggleArticlesVisibility {
[self.contentArticlesExpanded setValue:![self.contentArticlesExpanded value]]; [self.contentArticlesExpanded setValue:![self.contentArticlesExpanded value]];
[self reloadArticleSection];
}
// Update the section information for new collapsed state. #pragma mark - BooleanObserver
ntp_snippets::Category category = ntp_snippets::Category::FromKnownCategory(
ntp_snippets::KnownCategories::ARTICLES);
ContentSuggestionsCategoryWrapper* wrapper =
[ContentSuggestionsCategoryWrapper wrapperWithCategory:category];
ContentSuggestionsSectionInformation* sectionInfo =
self.sectionInformationByCategory[wrapper];
sectionInfo.expanded = [self.contentArticlesExpanded value];
// Reloading the section with animations looks bad because the section - (void)booleanDidChange:(id<ObservableBoolean>)observableBoolean {
// border with the new collapsed height draws before the elements collapse. [self reloadArticleSection];
BOOL animationsWereEnabled = [UIView areAnimationsEnabled];
[UIView setAnimationsEnabled:NO];
[self.dataSink reloadSection:sectionInfo];
[UIView setAnimationsEnabled:animationsWereEnabled];
} }
#pragma mark - ContentSuggestionsServiceObserver #pragma mark - ContentSuggestionsServiceObserver
...@@ -563,6 +555,24 @@ const NSInteger kMaxNumMostVisitedTiles = 4; ...@@ -563,6 +555,24 @@ const NSInteger kMaxNumMostVisitedTiles = 4;
#pragma mark - Private #pragma mark - Private
- (void)reloadArticleSection {
// Update the section information for new collapsed state.
ntp_snippets::Category category = ntp_snippets::Category::FromKnownCategory(
ntp_snippets::KnownCategories::ARTICLES);
ContentSuggestionsCategoryWrapper* wrapper =
[ContentSuggestionsCategoryWrapper wrapperWithCategory:category];
ContentSuggestionsSectionInformation* sectionInfo =
self.sectionInformationByCategory[wrapper];
sectionInfo.expanded = [self.contentArticlesExpanded value];
// Reloading the section with animations looks bad because the section
// border with the new collapsed height draws before the elements collapse.
BOOL animationsWereEnabled = [UIView areAnimationsEnabled];
[UIView setAnimationsEnabled:NO];
[self.dataSink reloadSection:sectionInfo];
[UIView setAnimationsEnabled:animationsWereEnabled];
}
// Converts the |suggestions| from |category| to CSCollectionViewItem and adds // Converts the |suggestions| from |category| to CSCollectionViewItem and adds
// them to the |contentArray| if the category is available. // them to the |contentArray| if the category is available.
- (void)addSuggestions: - (void)addSuggestions:
...@@ -705,6 +715,13 @@ const NSInteger kMaxNumMostVisitedTiles = 4; ...@@ -705,6 +715,13 @@ const NSInteger kMaxNumMostVisitedTiles = 4;
} }
} }
- (void)setContentArticlesExpanded:(PrefBackedBoolean*)contentArticlesExpanded {
if (_contentArticlesExpanded == contentArticlesExpanded)
return;
_contentArticlesExpanded = contentArticlesExpanded;
[contentArticlesExpanded setObserver:self];
}
#pragma mark - ReadingListModelBridgeObserver #pragma mark - ReadingListModelBridgeObserver
- (void)readingListModelLoaded:(const ReadingListModel*)model { - (void)readingListModelLoaded:(const ReadingListModel*)model {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment