OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/bookmarks/bookmark_collection_view.h" | 5 #import "ios/chrome/browser/ui/bookmarks/bookmark_collection_view.h" |
6 | 6 |
7 #import <UIKit/UIGestureRecognizerSubclass.h> | 7 #import <UIKit/UIGestureRecognizerSubclass.h> |
8 #include <algorithm> | 8 #include <algorithm> |
9 #include <map> | 9 #include <map> |
10 #include <memory> | 10 #include <memory> |
11 | 11 |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/mac/bind_objc_block.h" | 13 #include "base/mac/bind_objc_block.h" |
14 #include "base/mac/foundation_util.h" | 14 #include "base/mac/foundation_util.h" |
15 #include "base/strings/sys_string_conversions.h" | 15 #include "base/strings/sys_string_conversions.h" |
16 #include "components/bookmarks/browser/bookmark_model.h" | 16 #include "components/bookmarks/browser/bookmark_model.h" |
17 #include "components/bookmarks/browser/bookmark_model_observer.h" | 17 #include "components/bookmarks/browser/bookmark_model_observer.h" |
18 #include "components/favicon/core/fallback_url_util.h" | 18 #include "components/favicon/core/fallback_url_util.h" |
19 #include "components/favicon/core/large_icon_service.h" | 19 #include "components/favicon/core/large_icon_service.h" |
20 #include "components/favicon_base/fallback_icon_style.h" | 20 #include "components/favicon_base/fallback_icon_style.h" |
21 #include "components/favicon_base/favicon_types.h" | 21 #include "components/favicon_base/favicon_types.h" |
| 22 #include "components/pref_registry/pref_registry_syncable.h" |
22 #include "ios/chrome/browser/bookmarks/bookmark_model_factory.h" | 23 #include "ios/chrome/browser/bookmarks/bookmark_model_factory.h" |
23 #include "ios/chrome/browser/bookmarks/bookmarks_utils.h" | 24 #include "ios/chrome/browser/bookmarks/bookmarks_utils.h" |
24 #include "ios/chrome/browser/experimental_flags.h" | 25 #include "ios/chrome/browser/experimental_flags.h" |
25 #include "ios/chrome/browser/favicon/ios_chrome_large_icon_service_factory.h" | 26 #include "ios/chrome/browser/favicon/ios_chrome_large_icon_service_factory.h" |
| 27 #include "ios/chrome/browser/pref_names.h" |
26 #import "ios/chrome/browser/ui/authentication/signin_promo_view.h" | 28 #import "ios/chrome/browser/ui/authentication/signin_promo_view.h" |
27 #import "ios/chrome/browser/ui/authentication/signin_promo_view_configurator.h" | 29 #import "ios/chrome/browser/ui/authentication/signin_promo_view_configurator.h" |
28 #import "ios/chrome/browser/ui/authentication/signin_promo_view_consumer.h" | 30 #import "ios/chrome/browser/ui/authentication/signin_promo_view_consumer.h" |
29 #import "ios/chrome/browser/ui/authentication/signin_promo_view_mediator.h" | 31 #import "ios/chrome/browser/ui/authentication/signin_promo_view_mediator.h" |
30 #import "ios/chrome/browser/ui/bookmarks/bookmark_collection_cells.h" | 32 #import "ios/chrome/browser/ui/bookmarks/bookmark_collection_cells.h" |
31 #import "ios/chrome/browser/ui/bookmarks/bookmark_collection_view_background.h" | 33 #import "ios/chrome/browser/ui/bookmarks/bookmark_collection_view_background.h" |
32 #import "ios/chrome/browser/ui/bookmarks/bookmark_promo_cell.h" | 34 #import "ios/chrome/browser/ui/bookmarks/bookmark_promo_cell.h" |
33 #import "ios/chrome/browser/ui/bookmarks/bookmark_signin_promo_cell.h" | 35 #import "ios/chrome/browser/ui/bookmarks/bookmark_signin_promo_cell.h" |
34 #import "ios/chrome/browser/ui/bookmarks/bookmark_utils_ios.h" | 36 #import "ios/chrome/browser/ui/bookmarks/bookmark_utils_ios.h" |
35 #include "ios/chrome/browser/ui/ui_util.h" | 37 #include "ios/chrome/browser/ui/ui_util.h" |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 @synthesize folder = _folder; | 137 @synthesize folder = _folder; |
136 @synthesize bookmarkModel = _bookmarkModel; | 138 @synthesize bookmarkModel = _bookmarkModel; |
137 @synthesize collectionView = _collectionView; | 139 @synthesize collectionView = _collectionView; |
138 @synthesize editing = _editing; | 140 @synthesize editing = _editing; |
139 @synthesize emptyCollectionBackgroundView = _emptyCollectionBackgroundView; | 141 @synthesize emptyCollectionBackgroundView = _emptyCollectionBackgroundView; |
140 @synthesize loader = _loader; | 142 @synthesize loader = _loader; |
141 @synthesize longPressRecognizer = _longPressRecognizer; | 143 @synthesize longPressRecognizer = _longPressRecognizer; |
142 @synthesize browserState = _browserState; | 144 @synthesize browserState = _browserState; |
143 @synthesize shadow = _shadow; | 145 @synthesize shadow = _shadow; |
144 | 146 |
| 147 + (void)registerBrowserStatePrefs:(user_prefs::PrefRegistrySyncable*)registry { |
| 148 registry->RegisterIntegerPref(prefs::kIosBookmarkSigninPromoDisplayedCount, |
| 149 0); |
| 150 } |
| 151 |
145 #pragma mark - Initialization | 152 #pragma mark - Initialization |
146 | 153 |
147 - (void)setupViews { | 154 - (void)setupViews { |
148 self.backgroundColor = bookmark_utils_ios::mainBackgroundColor(); | 155 self.backgroundColor = bookmark_utils_ios::mainBackgroundColor(); |
149 UICollectionViewFlowLayout* layout = | 156 UICollectionViewFlowLayout* layout = |
150 [[UICollectionViewFlowLayout alloc] init]; | 157 [[UICollectionViewFlowLayout alloc] init]; |
151 | 158 |
152 UICollectionView* collectionView = | 159 UICollectionView* collectionView = |
153 [[UICollectionView alloc] initWithFrame:self.bounds | 160 [[UICollectionView alloc] initWithFrame:self.bounds |
154 collectionViewLayout:layout]; | 161 collectionViewLayout:layout]; |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 if (newPromoState != _promoVisible) { | 335 if (newPromoState != _promoVisible) { |
329 // This is awful, but until the old code to do the refresh when switching | 336 // This is awful, but until the old code to do the refresh when switching |
330 // in and out of edit mode is fixed, this is probably the cleanest thing to | 337 // in and out of edit mode is fixed, this is probably the cleanest thing to |
331 // do. | 338 // do. |
332 _promoVisible = newPromoState; | 339 _promoVisible = newPromoState; |
333 if (experimental_flags::IsSigninPromoEnabled()) { | 340 if (experimental_flags::IsSigninPromoEnabled()) { |
334 if (!_promoVisible) { | 341 if (!_promoVisible) { |
335 _signinPromoViewMediator.consumer = nil; | 342 _signinPromoViewMediator.consumer = nil; |
336 _signinPromoViewMediator = nil; | 343 _signinPromoViewMediator = nil; |
337 } else { | 344 } else { |
338 _signinPromoViewMediator = [[SigninPromoViewMediator alloc] init]; | 345 _signinPromoViewMediator = [[SigninPromoViewMediator alloc] |
| 346 initWithBrowserState:_browserState]; |
339 _signinPromoViewMediator.consumer = self; | 347 _signinPromoViewMediator.consumer = self; |
| 348 _signinPromoViewMediator.displayedCountPreferenceKey = |
| 349 prefs::kIosBookmarkSigninPromoDisplayedCount; |
| 350 _signinPromoViewMediator.alreadySeenSigninViewPreferenceKey = |
| 351 prefs::kIosBookmarkPromoAlreadySeen; |
| 352 _signinPromoViewMediator.histograms = |
| 353 ios::SigninPromoViewHistograms::Bookmarks; |
340 _signinPromoViewMediator.accessPoint = | 354 _signinPromoViewMediator.accessPoint = |
341 signin_metrics::AccessPoint::ACCESS_POINT_BOOKMARK_MANAGER; | 355 signin_metrics::AccessPoint::ACCESS_POINT_BOOKMARK_MANAGER; |
| 356 [_signinPromoViewMediator signinPromoViewVisible]; |
342 } | 357 } |
343 } | 358 } |
344 [self.collectionView reloadData]; | 359 [self.collectionView reloadData]; |
345 } | 360 } |
346 } | 361 } |
347 | 362 |
| 363 - (void)wasShown { |
| 364 [_signinPromoViewMediator signinPromoViewVisible]; |
| 365 } |
| 366 |
| 367 - (void)wasHidden { |
| 368 [_signinPromoViewMediator signinPromoViewHidden]; |
| 369 } |
| 370 |
348 #pragma mark - Sections | 371 #pragma mark - Sections |
349 | 372 |
350 - (NSInteger)promoSection { | 373 - (NSInteger)promoSection { |
351 return [self shouldShowPromoCell] ? 0 : -1; | 374 return [self shouldShowPromoCell] ? 0 : -1; |
352 } | 375 } |
353 | 376 |
354 - (NSInteger)folderSection { | 377 - (NSInteger)folderSection { |
355 return [self shouldShowPromoCell] ? 1 : 0; | 378 return [self shouldShowPromoCell] ? 1 : 0; |
356 } | 379 } |
357 | 380 |
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
766 if (experimental_flags::IsSigninPromoEnabled()) { | 789 if (experimental_flags::IsSigninPromoEnabled()) { |
767 BookmarkSigninPromoCell* signinPromoCell = [self.collectionView | 790 BookmarkSigninPromoCell* signinPromoCell = [self.collectionView |
768 dequeueReusableCellWithReuseIdentifier:[BookmarkSigninPromoCell | 791 dequeueReusableCellWithReuseIdentifier:[BookmarkSigninPromoCell |
769 reuseIdentifier] | 792 reuseIdentifier] |
770 forIndexPath:indexPath]; | 793 forIndexPath:indexPath]; |
771 signinPromoCell.signinPromoView.delegate = _signinPromoViewMediator; | 794 signinPromoCell.signinPromoView.delegate = _signinPromoViewMediator; |
772 [[_signinPromoViewMediator createConfigurator] | 795 [[_signinPromoViewMediator createConfigurator] |
773 configureSigninPromoView:signinPromoCell.signinPromoView]; | 796 configureSigninPromoView:signinPromoCell.signinPromoView]; |
774 __weak BookmarkCollectionView* weakSelf = self; | 797 __weak BookmarkCollectionView* weakSelf = self; |
775 signinPromoCell.closeButtonAction = ^() { | 798 signinPromoCell.closeButtonAction = ^() { |
776 [weakSelf.delegate bookmarkCollectionViewDismissPromo:self]; | 799 [weakSelf signinPromoCloseButtonAction]; |
777 }; | 800 }; |
778 return signinPromoCell; | 801 return signinPromoCell; |
779 } else { | 802 } else { |
780 BookmarkPromoCell* promoCell = [self.collectionView | 803 BookmarkPromoCell* promoCell = [self.collectionView |
781 dequeueReusableCellWithReuseIdentifier:[BookmarkPromoCell | 804 dequeueReusableCellWithReuseIdentifier:[BookmarkPromoCell |
782 reuseIdentifier] | 805 reuseIdentifier] |
783 forIndexPath:indexPath]; | 806 forIndexPath:indexPath]; |
784 promoCell.delegate = self; | 807 promoCell.delegate = self; |
785 return promoCell; | 808 return promoCell; |
786 } | 809 } |
787 } | 810 } |
788 const BookmarkNode* node = [self nodeAtIndexPath:indexPath]; | 811 const BookmarkNode* node = [self nodeAtIndexPath:indexPath]; |
789 | 812 |
790 if (indexPath.section == self.folderSection) | 813 if (indexPath.section == self.folderSection) |
791 return [self cellForFolder:node indexPath:indexPath]; | 814 return [self cellForFolder:node indexPath:indexPath]; |
792 | 815 |
793 BookmarkItemCell* cell = [self cellForBookmark:node indexPath:indexPath]; | 816 BookmarkItemCell* cell = [self cellForBookmark:node indexPath:indexPath]; |
794 return cell; | 817 return cell; |
795 } | 818 } |
796 | 819 |
| 820 // Removes the sign-in promo view. |
| 821 - (void)signinPromoCloseButtonAction { |
| 822 [_signinPromoViewMediator signinPromoViewDismissed]; |
| 823 [_delegate bookmarkCollectionViewDismissPromo:self]; |
| 824 } |
| 825 |
797 // Create a header view for the element at |indexPath|. | 826 // Create a header view for the element at |indexPath|. |
798 - (UICollectionReusableView*)headerAtIndexPath:(NSIndexPath*)indexPath { | 827 - (UICollectionReusableView*)headerAtIndexPath:(NSIndexPath*)indexPath { |
799 if (![self needsSectionHeaderForSection:indexPath.section]) | 828 if (![self needsSectionHeaderForSection:indexPath.section]) |
800 return nil; | 829 return nil; |
801 | 830 |
802 BookmarkHeaderSeparatorView* view = [self.collectionView | 831 BookmarkHeaderSeparatorView* view = [self.collectionView |
803 dequeueReusableSupplementaryViewOfKind: | 832 dequeueReusableSupplementaryViewOfKind: |
804 UICollectionElementKindSectionHeader | 833 UICollectionElementKindSectionHeader |
805 withReuseIdentifier:[BookmarkHeaderSeparatorView | 834 withReuseIdentifier:[BookmarkHeaderSeparatorView |
806 reuseIdentifier] | 835 reuseIdentifier] |
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1247 | 1276 |
1248 - (BOOL)shouldShowPromoCell { | 1277 - (BOOL)shouldShowPromoCell { |
1249 return _promoVisible; | 1278 return _promoVisible; |
1250 } | 1279 } |
1251 | 1280 |
1252 - (BOOL)isPromoActive { | 1281 - (BOOL)isPromoActive { |
1253 return NO; | 1282 return NO; |
1254 } | 1283 } |
1255 | 1284 |
1256 @end | 1285 @end |
OLD | NEW |