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

Side by Side Diff: ios/chrome/browser/ui/content_suggestions/content_suggestions_collection_updater.mm

Issue 2888533002: Identify MostVisited by item instead of URL (Closed)
Patch Set: Reviewable Created 3 years, 7 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_collectio n_updater.h" 5 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_collectio n_updater.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/mac/foundation_util.h" 8 #include "base/mac/foundation_util.h"
9 #include "base/strings/sys_string_conversions.h" 9 #include "base/strings/sys_string_conversions.h"
10 #include "base/time/time.h" 10 #include "base/time/time.h"
11 #include "components/strings/grit/components_strings.h" 11 #include "components/strings/grit/components_strings.h"
12 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_item+collec tion_view_controller.h" 12 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_item+collec tion_view_controller.h"
13 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_item.h " 13 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_item.h "
14 #import "ios/chrome/browser/ui/collection_view/collection_view_controller.h" 14 #import "ios/chrome/browser/ui/collection_view/collection_view_controller.h"
15 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" 15 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h"
16 #import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_foo ter_item.h" 16 #import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_foo ter_item.h"
17 #import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_tex t_item.h" 17 #import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_tex t_item.h"
18 #import "ios/chrome/browser/ui/content_suggestions/cells/suggested_content.h" 18 #import "ios/chrome/browser/ui/content_suggestions/cells/suggested_content.h"
19 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_data_sink .h" 19 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_data_sink .h"
20 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_data_sour ce.h" 20 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_data_sour ce.h"
21 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_image_fet cher.h" 21 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_image_fet cher.h"
22 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_view_cont roller.h" 22 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_view_cont roller.h"
23 #import "ios/chrome/browser/ui/content_suggestions/identifier/content_suggestion _identifier.h" 23 #import "ios/chrome/browser/ui/content_suggestions/identifier/content_suggestion _identifier.h"
24 #import "ios/chrome/browser/ui/content_suggestions/identifier/content_suggestion s_section_information.h" 24 #import "ios/chrome/browser/ui/content_suggestions/identifier/content_suggestion s_section_information.h"
25 #import "ios/chrome/browser/ui/favicon/favicon_attributes.h" 25 #import "ios/chrome/browser/ui/favicon/favicon_attributes.h"
26 #include "ui/base/l10n/l10n_util.h" 26 #include "ui/base/l10n/l10n_util.h"
27 #include "url/gurl.h"
28 27
29 #if !defined(__has_feature) || !__has_feature(objc_arc) 28 #if !defined(__has_feature) || !__has_feature(objc_arc)
30 #error "This file requires ARC support." 29 #error "This file requires ARC support."
31 #endif 30 #endif
32 31
33 namespace { 32 namespace {
34 33
35 using CSCollectionViewItem = CollectionViewItem<SuggestedContent>; 34 using CSCollectionViewItem = CollectionViewItem<SuggestedContent>;
36 using CSCollectionViewModel = CollectionViewModel<CSCollectionViewItem*>; 35 using CSCollectionViewModel = CollectionViewModel<CSCollectionViewItem*>;
37 36
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 NSInteger section = [self.collectionViewController.collectionViewModel 209 NSInteger section = [self.collectionViewController.collectionViewModel
211 sectionIdentifierForSection:sectionIdentifier]; 210 sectionIdentifierForSection:sectionIdentifier];
212 211
213 [self.collectionViewController dismissSection:section]; 212 [self.collectionViewController dismissSection:section];
214 } 213 }
215 214
216 - (void)reloadSection:(ContentSuggestionsSectionInformation*)sectionInfo { 215 - (void)reloadSection:(ContentSuggestionsSectionInformation*)sectionInfo {
217 // TODO(crbug.com/707754): implement this method. 216 // TODO(crbug.com/707754): implement this method.
218 } 217 }
219 218
220 - (void)faviconAvailableForURL:(const GURL&)URL { 219 - (void)faviconAvailableForItem:(CollectionViewItem<SuggestedContent>*)item {
221 // TODO(crbug.com/707754): implement this method. 220 if ([self.collectionViewController.collectionViewModel hasItem:item]) {
221 [self fetchFaviconForItem:item];
222 }
222 } 223 }
223 224
224 #pragma mark - Public methods 225 #pragma mark - Public methods
225 226
226 - (BOOL)shouldUseCustomStyleForSection:(NSInteger)section { 227 - (BOOL)shouldUseCustomStyleForSection:(NSInteger)section {
227 NSNumber* identifier = @([self.collectionViewController.collectionViewModel 228 NSNumber* identifier = @([self.collectionViewController.collectionViewModel
228 sectionIdentifierForSection:section]); 229 sectionIdentifierForSection:section]);
229 ContentSuggestionsSectionInformation* sectionInformation = 230 ContentSuggestionsSectionInformation* sectionInformation =
230 self.sectionInfoBySectionIdentifier[identifier]; 231 self.sectionInfoBySectionIdentifier[identifier];
231 return sectionInformation.layout == ContentSuggestionsSectionLayoutCustom; 232 return sectionInformation.layout == ContentSuggestionsSectionLayoutCustom;
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 - (void)fetchFaviconForItem:(CSCollectionViewItem*)item { 417 - (void)fetchFaviconForItem:(CSCollectionViewItem*)item {
417 __weak ContentSuggestionsCollectionUpdater* weakSelf = self; 418 __weak ContentSuggestionsCollectionUpdater* weakSelf = self;
418 __weak CSCollectionViewItem* weakItem = item; 419 __weak CSCollectionViewItem* weakItem = item;
419 420
420 [self.dataSource 421 [self.dataSource
421 fetchFaviconAttributesForItem:item 422 fetchFaviconAttributesForItem:item
422 completion:^(FaviconAttributes* attributes) { 423 completion:^(FaviconAttributes* attributes) {
423 ContentSuggestionsCollectionUpdater* strongSelf = 424 ContentSuggestionsCollectionUpdater* strongSelf =
424 weakSelf; 425 weakSelf;
425 CSCollectionViewItem* strongItem = weakItem; 426 CSCollectionViewItem* strongItem = weakItem;
426 if (!strongSelf || !strongItem) { 427 if (!strongSelf || !strongItem)
427 return; 428 return;
428 }
429 429
430 strongItem.attributes = attributes; 430 [strongSelf reconfigure:strongItem
431 [strongSelf.collectionViewController 431 withAttributes:attributes];
432 reconfigureCellsForItems:@[ strongItem ]];
433 432
434 [strongSelf fetchFaviconImageForItem:strongItem]; 433 [strongSelf fetchFaviconImageForItem:strongItem];
435 }]; 434 }];
436 } 435 }
437 436
438 // Fetches the favicon image for the |item|. 437 // Fetches the favicon image for the |item|.
439 - (void)fetchFaviconImageForItem:(CSCollectionViewItem*)item { 438 - (void)fetchFaviconImageForItem:(CSCollectionViewItem*)item {
440 __weak ContentSuggestionsCollectionUpdater* weakSelf = self; 439 __weak ContentSuggestionsCollectionUpdater* weakSelf = self;
441 __weak CSCollectionViewItem* weakItem = item; 440 __weak CSCollectionViewItem* weakItem = item;
442 441
443 [self.dataSource 442 [self.dataSource
444 fetchFaviconImageForItem:item 443 fetchFaviconImageForItem:item
445 completion:^(UIImage* image) { 444 completion:^(UIImage* image) {
446 ContentSuggestionsCollectionUpdater* strongSelf = 445 [weakSelf reconfigure:weakItem
447 weakSelf; 446 withAttributes:[FaviconAttributes
448 CSCollectionViewItem* strongItem = weakItem; 447 attributesWithImage:image]];
449 if (!strongSelf || !strongItem || !image) { 448 }];
450 return; 449 }
451 }
452 450
453 strongItem.attributes = 451 // Sets the attributes of |item| to |attributes| and reconfigure it.
jif 2017/05/17 13:13:28 and reconfigures
gambard 2017/05/17 14:13:32 Done.
454 [FaviconAttributes attributesWithImage:image]; 452 - (void)reconfigure:(CSCollectionViewItem*)item
455 [strongSelf.collectionViewController 453 withAttributes:(FaviconAttributes*)attributes {
456 reconfigureCellsForItems:@[ strongItem ]]; 454 if (!item || !attributes ||
457 }]; 455 ![self.collectionViewController.collectionViewModel hasItem:item]) {
456 return;
457 }
458
459 item.attributes = attributes;
460 [self.collectionViewController reconfigureCellsForItems:@[ item ]];
458 } 461 }
459 462
460 // Runs the additional action for the section identified by |sectionInfo|. 463 // Runs the additional action for the section identified by |sectionInfo|.
461 - (void)runAdditionalActionForSection: 464 - (void)runAdditionalActionForSection:
462 (ContentSuggestionsSectionInformation*)sectionInfo { 465 (ContentSuggestionsSectionInformation*)sectionInfo {
463 SectionIdentifier sectionIdentifier = SectionIdentifierForInfo(sectionInfo); 466 SectionIdentifier sectionIdentifier = SectionIdentifierForInfo(sectionInfo);
464 467
465 // TODO(crbug.com/721229): Start spinner. 468 // TODO(crbug.com/721229): Start spinner.
466 469
467 NSMutableArray<ContentSuggestionIdentifier*>* knownSuggestionIdentifiers = 470 NSMutableArray<ContentSuggestionIdentifier*>* knownSuggestionIdentifiers =
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 CSCollectionViewModel* model = 521 CSCollectionViewModel* model =
519 self.collectionViewController.collectionViewModel; 522 self.collectionViewController.collectionViewModel;
520 NSInteger section = [model sectionForSectionIdentifier:sectionIdentifier]; 523 NSInteger section = [model sectionForSectionIdentifier:sectionIdentifier];
521 NSInteger itemNumber = [model numberOfItemsInSection:section]; 524 NSInteger itemNumber = [model numberOfItemsInSection:section];
522 [model addItem:item toSectionWithIdentifier:sectionIdentifier]; 525 [model addItem:item toSectionWithIdentifier:sectionIdentifier];
523 526
524 return [NSIndexPath indexPathForItem:itemNumber inSection:section]; 527 return [NSIndexPath indexPathForItem:itemNumber inSection:section];
525 } 528 }
526 529
527 @end 530 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698