Commit 75ce234e authored by adamta's avatar adamta Committed by Commit Bot

[iOS] Show/Hide feed from setting + Change setting title to Discover

Immediately shows or hides Discover feed from NTP when setting is
toggled in the settings menu. Changes setting title from "Article
Suggestions" to "Discover" (this may change eventually and the icon
will change as well).

Bug: 1085419, 1105624
Change-Id: I560b7af4aa41b18493f7853a5b44b504d9c1ad53
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2302809
Commit-Queue: Adam Trudeau-Arcaro <adamta@google.com>
Reviewed-by: default avatarRohit Rao <rohitrao@chromium.org>
Reviewed-by: default avatarSergio Collazos <sczs@chromium.org>
Cr-Commit-Position: refs/heads/master@{#790537}
parent 36b7dd54
......@@ -698,6 +698,9 @@ Because your account is managed by <ph name="HOSTED_DOMAIN">$1<ex>google.com</ex
<message name="IDS_IOS_DISCONNECT_DIALOG_TITLE_UNITY" desc="The title of the disconnect dialog [Length: 30em].">
Sign out and turn off sync?
</message>
<message name="IDS_IOS_DISCOVER_SETTING_TITLE" desc="The title of the settings to toggle the Discover feed on the NTP on/off">
Discover
</message>
<message name="IDS_IOS_DOWNLOAD_MANAGER_CANNOT_DETERMINE_FILE_SIZE" desc="Message displayed when the size of the file to be downloaded is unknown. [Length: 30em] [iOS only]">
Cannot determine file size.
</message>
......
15330c0a1e5640cab9b6bd5223c6bbda7f26a44b
\ No newline at end of file
......@@ -34,6 +34,8 @@ source_set("content_suggestions") {
"//components/feed/core/shared_prefs:feed_shared_prefs",
"//components/ntp_snippets",
"//components/ntp_tiles",
"//components/prefs",
"//components/prefs/ios",
"//components/reading_list/core",
"//components/reading_list/ios:ios",
"//components/signin/public/identity_manager",
......
......@@ -249,6 +249,7 @@
- (void)stop {
[self.NTPMediator shutdown];
self.NTPMediator = nil;
[self.contentSuggestionsMediator disconnect];
self.contentSuggestionsMediator = nil;
self.headerController = nil;
_visible = NO;
......
......@@ -75,6 +75,9 @@ class ReadingListModel;
// ViewController created by the Discover provider containing the Discover feed.
@property(nonatomic, strong) UIViewController* discoverFeed;
// Disconnects the mediator.
- (void)disconnect;
// The notification promo owned by this mediator.
- (NotificationPromoWhatsNew*)notificationPromo;
......
......@@ -14,6 +14,8 @@
#include "components/ntp_tiles/metrics.h"
#include "components/ntp_tiles/most_visited_sites.h"
#include "components/ntp_tiles/ntp_tile.h"
#import "components/prefs/ios/pref_observer_bridge.h"
#include "components/prefs/pref_change_registrar.h"
#include "components/reading_list/core/reading_list_model.h"
#import "components/reading_list/ios/reading_list_model_bridge_observer.h"
#include "ios/chrome/browser/application_context.h"
......@@ -60,6 +62,7 @@ const NSInteger kMaxNumMostVisitedTiles = 4;
ContentSuggestionsItemDelegate,
ContentSuggestionsServiceObserver,
MostVisitedSitesObserving,
PrefObserverDelegate,
ReadingListModelBridgeObserver> {
// Bridge for this class to become an observer of a ContentSuggestionsService.
std::unique_ptr<ContentSuggestionsServiceBridge> _suggestionBridge;
......@@ -67,6 +70,10 @@ const NSInteger kMaxNumMostVisitedTiles = 4;
std::unique_ptr<ntp_tiles::MostVisitedSitesObserverBridge> _mostVisitedBridge;
std::unique_ptr<NotificationPromoWhatsNew> _notificationPromo;
std::unique_ptr<ReadingListModelBridge> _readingListModelBridge;
// Pref observer to track changes to prefs.
std::unique_ptr<PrefObserverBridge> _prefObserverBridge;
// Registrar for pref changes notifications.
std::unique_ptr<PrefChangeRegistrar> _prefChangeRegistrar;
}
// Whether the contents section should be hidden completely.
......@@ -174,12 +181,24 @@ const NSInteger kMaxNumMostVisitedTiles = 4;
std::make_unique<ntp_tiles::MostVisitedSitesObserverBridge>(self);
_mostVisitedSites->SetMostVisitedURLsObserver(_mostVisitedBridge.get(),
kMaxNumMostVisitedTiles);
_prefChangeRegistrar = std::make_unique<PrefChangeRegistrar>();
_prefChangeRegistrar->Init(prefService);
_prefObserverBridge.reset(new PrefObserverBridge(self));
_prefObserverBridge->ObserveChangesForPreference(
prefs::kArticlesForYouEnabled, _prefChangeRegistrar.get());
_readingListModelBridge =
std::make_unique<ReadingListModelBridge>(self, readingListModel);
}
return self;
}
- (void)disconnect {
_prefChangeRegistrar.reset();
_prefObserverBridge.reset();
}
- (void)blockMostVisitedURL:(GURL)URL {
_mostVisitedSites->AddOrRemoveBlacklistedUrl(URL, true);
[self useFreshMostVisited];
......@@ -722,6 +741,14 @@ const NSInteger kMaxNumMostVisitedTiles = 4;
[contentArticlesExpanded setObserver:self];
}
#pragma mark - PrefObserverDelegate
- (void)onPreferenceChanged:(const std::string&)preferenceName {
if (preferenceName == prefs::kArticlesForYouEnabled) {
[self.dataSink reloadAllData];
}
}
#pragma mark - ReadingListModelBridgeObserver
- (void)readingListModelLoaded:(const ReadingListModel*)model {
......
......@@ -145,6 +145,7 @@ source_set("settings") {
"//ios/chrome/browser/ui/autofill/cells",
"//ios/chrome/browser/ui/colors",
"//ios/chrome/browser/ui/commands",
"//ios/chrome/browser/ui/content_suggestions:feature_flags",
"//ios/chrome/browser/ui/content_suggestions/cells",
"//ios/chrome/browser/ui/content_suggestions/cells:cells_ui",
"//ios/chrome/browser/ui/coordinators:chrome_coordinators",
......
......@@ -45,6 +45,7 @@
#import "ios/chrome/browser/ui/authentication/cells/table_view_account_item.h"
#import "ios/chrome/browser/ui/authentication/cells/table_view_signin_promo_item.h"
#import "ios/chrome/browser/ui/authentication/signin_promo_view_mediator.h"
#import "ios/chrome/browser/ui/content_suggestions/content_suggestions_feature.h"
#import "ios/chrome/browser/ui/settings/about_chrome_table_view_controller.h"
#import "ios/chrome/browser/ui/settings/autofill/autofill_credit_card_table_view_controller.h"
#import "ios/chrome/browser/ui/settings/autofill/autofill_profile_table_view_controller.h"
......@@ -683,10 +684,14 @@ NSString* kDevViewSourceKey = @"DevViewSource";
}
- (SettingsSwitchItem*)articlesForYouSwitchItem {
NSString* settingTitle =
IsDiscoverFeedEnabled()
? l10n_util::GetNSString(IDS_IOS_DISCOVER_SETTING_TITLE)
: l10n_util::GetNSString(IDS_IOS_CONTENT_SUGGESTIONS_SETTING_TITLE);
SettingsSwitchItem* articlesForYouSwitchItem =
[self switchItemWithType:ItemTypeArticlesForYou
title:l10n_util::GetNSString(
IDS_IOS_CONTENT_SUGGESTIONS_SETTING_TITLE)
title:settingTitle
iconImageName:kSettingsArticleSuggestionsImageName
withDefaultsKey:nil
accessibilityIdentifier:kSettingsArticleSuggestionsCellId];
......
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