OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #import "ios/chrome/browser/ui/tab_switcher/tab_switcher_session_cell_data.h" |
| 6 #include "ios/chrome/grit/ios_strings.h" |
| 7 #include "ui/base/l10n/l10n_util.h" |
| 8 |
| 9 @implementation SessionCellData |
| 10 |
| 11 @synthesize type = _type; |
| 12 @synthesize title = _title; |
| 13 @synthesize image = _image; |
| 14 |
| 15 + (instancetype)incognitoSessionCellData { |
| 16 static SessionCellData* incognitoSessionCellData = nil; |
| 17 static dispatch_once_t onceToken; |
| 18 dispatch_once(&onceToken, ^{ |
| 19 incognitoSessionCellData = [[self alloc] |
| 20 initWithSessionCellType:ios_internal::kIncognitoSessionCell]; |
| 21 }); |
| 22 return incognitoSessionCellData; |
| 23 } |
| 24 |
| 25 + (instancetype)openTabSessionCellData { |
| 26 static SessionCellData* openTabSessionCellData = nil; |
| 27 static dispatch_once_t onceToken; |
| 28 dispatch_once(&onceToken, ^{ |
| 29 openTabSessionCellData = [[self alloc] |
| 30 initWithSessionCellType:ios_internal::kOpenTabSessionCell]; |
| 31 }); |
| 32 return openTabSessionCellData; |
| 33 } |
| 34 |
| 35 + (instancetype)otherDevicesSessionCellData { |
| 36 static SessionCellData* otherDevicesSessionCellData = nil; |
| 37 static dispatch_once_t onceToken; |
| 38 dispatch_once(&onceToken, ^{ |
| 39 otherDevicesSessionCellData = [[self alloc] |
| 40 initWithSessionCellType:ios_internal::kGenericRemoteSessionCell]; |
| 41 }); |
| 42 return otherDevicesSessionCellData; |
| 43 } |
| 44 |
| 45 - (instancetype)initWithSessionCellType:(ios_internal::SessionCellType)type { |
| 46 self = [super init]; |
| 47 if (self) { |
| 48 _type = type; |
| 49 [self loadDefaultsForType]; |
| 50 } |
| 51 return self; |
| 52 } |
| 53 |
| 54 #pragma mark - Private |
| 55 |
| 56 - (void)loadDefaultsForType { |
| 57 NSString* imageName = nil; |
| 58 int messageId = 0; |
| 59 switch (self.type) { |
| 60 case ios_internal::kIncognitoSessionCell: |
| 61 imageName = @"tabswitcher_incognito"; |
| 62 messageId = IDS_IOS_TAB_SWITCHER_HEADER_INCOGNITO_TABS; |
| 63 break; |
| 64 case ios_internal::kOpenTabSessionCell: |
| 65 imageName = @"tabswitcher_open_tabs"; |
| 66 messageId = IDS_IOS_TAB_SWITCHER_HEADER_NON_INCOGNITO_TABS; |
| 67 break; |
| 68 case ios_internal::kGenericRemoteSessionCell: |
| 69 imageName = @"tabswitcher_other_devices"; |
| 70 messageId = IDS_IOS_TAB_SWITCHER_HEADER_OTHER_DEVICES_TABS; |
| 71 break; |
| 72 case ios_internal::kPhoneRemoteSessionCell: |
| 73 imageName = @"ntp_opentabs_phone"; |
| 74 messageId = IDS_IOS_TAB_SWITCHER_HEADER_OTHER_DEVICES_TABS; |
| 75 break; |
| 76 case ios_internal::kTabletRemoteSessionCell: |
| 77 imageName = @"ntp_opentabs_tablet"; |
| 78 messageId = IDS_IOS_TAB_SWITCHER_HEADER_OTHER_DEVICES_TABS; |
| 79 break; |
| 80 case ios_internal::kLaptopRemoteSessionCell: |
| 81 imageName = @"ntp_opentabs_laptop"; |
| 82 messageId = IDS_IOS_TAB_SWITCHER_HEADER_OTHER_DEVICES_TABS; |
| 83 break; |
| 84 } |
| 85 [self setTitle:l10n_util::GetNSString(messageId)]; |
| 86 UIImage* image = [UIImage imageNamed:imageName]; |
| 87 image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; |
| 88 [self setImage:image]; |
| 89 } |
| 90 |
| 91 @end |
OLD | NEW |