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

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

Issue 2720423003: Get Suggestions image only if it is not empty (Closed)
Patch Set: Fix 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 unified diff | Download patch
« no previous file with comments | « ios/chrome/browser/ui/content_suggestions/content_suggestions_article_item_unittest.mm ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/time/time.h" 9 #include "base/time/time.h"
10 #import "ios/chrome/browser/ui/collection_view/collection_view_controller.h" 10 #import "ios/chrome/browser/ui/collection_view/collection_view_controller.h"
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 146
147 #pragma mark - ContentSuggestionsArticleItemDelegate 147 #pragma mark - ContentSuggestionsArticleItemDelegate
148 148
149 - (void)loadImageForArticleItem:(ContentSuggestionsArticleItem*)articleItem { 149 - (void)loadImageForArticleItem:(ContentSuggestionsArticleItem*)articleItem {
150 NSInteger sectionIdentifier = 150 NSInteger sectionIdentifier =
151 SectionIdentifierForInfo(articleItem.suggestionIdentifier.sectionInfo); 151 SectionIdentifierForInfo(articleItem.suggestionIdentifier.sectionInfo);
152 152
153 __weak ContentSuggestionsCollectionUpdater* weakSelf = self; 153 __weak ContentSuggestionsCollectionUpdater* weakSelf = self;
154 __weak ContentSuggestionsArticleItem* weakArticle = articleItem; 154 __weak ContentSuggestionsArticleItem* weakArticle = articleItem;
155 void (^imageFetchedCallback)(const gfx::Image&) = ^(const gfx::Image& image) { 155 void (^imageFetchedCallback)(const gfx::Image&) = ^(const gfx::Image& image) {
156 if (image.IsEmpty()) {
157 return;
158 }
159
156 ContentSuggestionsCollectionUpdater* strongSelf = weakSelf; 160 ContentSuggestionsCollectionUpdater* strongSelf = weakSelf;
157 ContentSuggestionsArticleItem* strongArticle = weakArticle; 161 ContentSuggestionsArticleItem* strongArticle = weakArticle;
158 if (!strongSelf || !strongArticle) { 162 if (!strongSelf || !strongArticle) {
159 return; 163 return;
160 } 164 }
161 165
162 strongArticle.imageBeingFetched = NO;
163 strongArticle.image = image.CopyUIImage(); 166 strongArticle.image = image.CopyUIImage();
164 [strongSelf.collectionViewController 167 [strongSelf.collectionViewController
165 reconfigureCellsForItems:@[ strongArticle ] 168 reconfigureCellsForItems:@[ strongArticle ]
166 inSectionWithIdentifier:sectionIdentifier]; 169 inSectionWithIdentifier:sectionIdentifier];
167 }; 170 };
168 171
169 articleItem.imageBeingFetched = YES;
170
171 [self.dataSource.imageFetcher 172 [self.dataSource.imageFetcher
172 fetchImageForSuggestion:articleItem.suggestionIdentifier 173 fetchImageForSuggestion:articleItem.suggestionIdentifier
173 callback:imageFetchedCallback]; 174 callback:imageFetchedCallback];
174 } 175 }
175 176
176 #pragma mark - Private methods 177 #pragma mark - Private methods
177 178
178 - (void)reloadData { 179 - (void)reloadData {
179 [self resetModels]; 180 [self resetModels];
180 CollectionViewModel* model = 181 CollectionViewModel* model =
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 } 222 }
222 return sectionIdentifier; 223 return sectionIdentifier;
223 } 224 }
224 225
225 - (void)resetModels { 226 - (void)resetModels {
226 [self.collectionViewController loadModel]; 227 [self.collectionViewController loadModel];
227 self.sectionInfoBySectionIdentifier = [[NSMutableDictionary alloc] init]; 228 self.sectionInfoBySectionIdentifier = [[NSMutableDictionary alloc] init];
228 } 229 }
229 230
230 @end 231 @end
OLDNEW
« no previous file with comments | « ios/chrome/browser/ui/content_suggestions/content_suggestions_article_item_unittest.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698