Skip to content

Commit 1428099

Browse files
d0iasmpull[bot]
authored andcommitted
[ios][STG] Fetch user's icon and set it to RecentActivityLogItem
This CL fetches an avatar image via ShareKitService and set it to RecentActivityLogItem. The property in RecentActivityLogItem is updated accordingly. Also `numberOfLines` is updated to have 2 lines at maximum when the title is long (see the screenshot below). screenshot with placeholder data: https://drive.google.com/file/d/1E_0y5nPU73tS4ZVI2npEy3u33UEJlrAI/view?usp=sharing Bug: 370897655 Change-Id: I2d38d07fc437ac1e0f0cf1a43f1ea9d6a536c040 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6037873 Reviewed-by: Gauthier Ambard <gambard@chromium.org> Commit-Queue: Asami Doi <asamidoi@chromium.org> Cr-Commit-Position: refs/heads/main@{#1387554}
1 parent df8701d commit 1428099

8 files changed

+59
-23
lines changed

ios/chrome/browser/ui/tab_switcher/tab_grid/tab_groups/BUILD.gn

+1
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ source_set("tab_groups_ui") {
147147
"//ios/chrome/browser/keyboard/ui_bundled",
148148
"//ios/chrome/browser/menu/ui_bundled",
149149
"//ios/chrome/browser/saved_tab_groups/favicon/ui",
150+
"//ios/chrome/browser/share_kit/model",
150151
"//ios/chrome/browser/shared/model/web_state_list",
151152
"//ios/chrome/browser/shared/public/commands",
152153
"//ios/chrome/browser/shared/public/features",

ios/chrome/browser/ui/tab_switcher/tab_grid/tab_groups/recent_activity_coordinator.mm

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#import "ios/chrome/browser/collaboration/model/messaging/messaging_backend_service_factory.h"
99
#import "ios/chrome/browser/favicon/model/ios_chrome_favicon_loader_factory.h"
1010
#import "ios/chrome/browser/saved_tab_groups/model/tab_group_sync_service_factory.h"
11+
#import "ios/chrome/browser/share_kit/model/share_kit_service_factory.h"
1112
#import "ios/chrome/browser/shared/model/browser/browser.h"
1213
#import "ios/chrome/browser/shared/model/web_state_list/tab_group.h"
1314
#import "ios/chrome/browser/ui/tab_switcher/tab_grid/tab_groups/recent_activity_mediator.h"
@@ -47,7 +48,8 @@ - (void)start {
4748
profile)
4849
faviconLoader:IOSChromeFaviconLoaderFactory::GetForProfile(profile)
4950
syncService:tab_groups::TabGroupSyncServiceFactory::GetForProfile(
50-
profile)];
51+
profile)
52+
shareKitService:ShareKitServiceFactory::GetForProfile(profile)];
5153
_mediator.consumer = _viewController;
5254

5355
UINavigationController* navigationController = [[UINavigationController alloc]

ios/chrome/browser/ui/tab_switcher/tab_grid/tab_groups/recent_activity_log_cell.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
// Represents a log in the recent activity in a shared tab group.
1111
@interface RecentActivityLogCell : UITableViewCell
1212

13-
// The cell user's icon imageView on the left end.
14-
@property(nonatomic, readonly, strong) UIImageView* iconImageView;
13+
// The cell user's avatar view on the left end.
14+
@property(nonatomic, readonly, strong) UIView* avatarView;
1515
// The cell favicon imageView on the right end.
1616
@property(nonatomic, readonly, strong) UIImageView* faviconImageView;
1717
// The cell title.

ios/chrome/browser/ui/tab_switcher/tab_grid/tab_groups/recent_activity_log_cell.mm

+6-8
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,7 @@ - (instancetype)initWithStyle:(UITableViewCellStyle)style
1313
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
1414
if (self) {
1515
self.isAccessibilityElement = YES;
16-
_iconImageView = [[UIImageView alloc] init];
17-
// The user's icon is smaller than its UIImageView's bounds, so center it.
18-
_iconImageView.contentMode = UIViewContentModeCenter;
19-
[_iconImageView setContentHuggingPriority:UILayoutPriorityRequired
20-
forAxis:UILayoutConstraintAxisHorizontal];
16+
_avatarView = [[UIView alloc] init];
2117

2218
// The favicon image is smaller than its UIImageView's bounds, so center
2319
// it.
@@ -31,7 +27,7 @@ - (instancetype)initWithStyle:(UITableViewCellStyle)style
3127
_titleLabel = [[UILabel alloc] init];
3228
_titleLabel.font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody];
3329
_titleLabel.adjustsFontForContentSizeCategory = YES;
34-
_titleLabel.numberOfLines = 1;
30+
_titleLabel.numberOfLines = 2;
3531
[_titleLabel
3632
setContentCompressionResistancePriority:UILayoutPriorityDefaultLow
3733
forAxis:
@@ -53,7 +49,7 @@ - (instancetype)initWithStyle:(UITableViewCellStyle)style
5349

5450
UIStackView* horizontalStack =
5551
[[UIStackView alloc] initWithArrangedSubviews:@[
56-
_iconImageView, verticalStack, _faviconImageView
52+
_avatarView, verticalStack, _faviconImageView
5753
]];
5854
horizontalStack.translatesAutoresizingMaskIntoConstraints = NO;
5955
horizontalStack.axis = UILayoutConstraintAxisHorizontal;
@@ -95,8 +91,10 @@ - (void)prepareForReuse {
9591
[super prepareForReuse];
9692
_titleLabel.text = nil;
9793
_descriptionLabel.text = nil;
98-
_iconImageView.image = nil;
9994
_faviconImageView.image = nil;
95+
for (UIView* subview in _avatarView.subviews) {
96+
[subview removeFromSuperview];
97+
}
10098
}
10199

102100
@end

ios/chrome/browser/ui/tab_switcher/tab_grid/tab_groups/recent_activity_log_item.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
#import <UIKit/UIKit.h>
99

10+
@protocol ShareKitAvatarPrimitive;
11+
1012
// Different type used for RecentActivityLogItem.
1113
enum class ActivityLogType : NSUInteger {
1214
kTabAdded,
@@ -30,8 +32,8 @@ enum class ActivityLogType : NSUInteger {
3032
// The image of a favicon of a page.
3133
@property(nonatomic, strong) UIImage* favicon;
3234

33-
// The image of a user icon.
34-
@property(nonatomic, strong) UIImage* userIcon;
35+
// The object to provide an avatar image.
36+
@property(nonatomic, strong) id<ShareKitAvatarPrimitive> avatarPrimitive;
3537

3638
// The string of a title.
3739
@property(nonatomic, strong) NSString* title;

ios/chrome/browser/ui/tab_switcher/tab_grid/tab_groups/recent_activity_mediator.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010
#import "base/memory/weak_ptr.h"
1111

1212
class FaviconLoader;
13-
class TabGroup;
1413
@protocol RecentActivityConsumer;
14+
class ShareKitService;
15+
class TabGroup;
1516
namespace collaboration::messaging {
1617
class MessagingBackendService;
1718
} // namespace collaboration::messaging
@@ -32,6 +33,7 @@ class TabGroupSyncService;
3233
messagingService
3334
faviconLoader:(FaviconLoader*)faviconLoader
3435
syncService:(tab_groups::TabGroupSyncService*)syncService
36+
shareKitService:(ShareKitService*)shareKitService
3537
NS_DESIGNATED_INITIALIZER;
3638

3739
- (instancetype)init NS_UNAVAILABLE;

ios/chrome/browser/ui/tab_switcher/tab_grid/tab_groups/recent_activity_mediator.mm

+31-8
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,24 @@
66

77
#import "base/strings/sys_string_conversions.h"
88
#import "components/collaboration/public/messaging/messaging_backend_service.h"
9+
#import "components/data_sharing/public/group_data.h"
910
#import "components/saved_tab_groups/public/saved_tab_group.h"
1011
#import "components/saved_tab_groups/public/tab_group_sync_service.h"
1112
#import "ios/chrome/browser/favicon/model/favicon_loader.h"
1213
#import "ios/chrome/browser/saved_tab_groups/model/ios_tab_group_sync_util.h"
14+
#import "ios/chrome/browser/share_kit/model/share_kit_avatar_configuration.h"
15+
#import "ios/chrome/browser/share_kit/model/share_kit_service.h"
1316
#import "ios/chrome/browser/shared/model/web_state_list/tab_group.h"
14-
#import "ios/chrome/browser/shared/ui/symbols/symbols.h"
1517
#import "ios/chrome/browser/ui/tab_switcher/tab_grid/tab_groups/recent_activity_consumer.h"
1618
#import "ios/chrome/browser/ui/tab_switcher/tab_grid/tab_groups/recent_activity_log_item.h"
1719
#import "ios/chrome/common/ui/favicon/favicon_attributes.h"
1820

1921
namespace {
2022

21-
// The size of image of a user's icon and a favicon.
22-
const CGFloat kImageSize = 22;
23+
// The size of a favicon image.
24+
const CGFloat kFaviconSize = 20;
25+
// The size of an avatar image.
26+
const CGFloat kAvatarSize = 30;
2327

2428
ActivityLogType ConvertCollaborationEvent(
2529
collaboration::messaging::CollaborationEvent collaboration_event) {
@@ -53,21 +57,26 @@ @implementation RecentActivityMediator {
5357
raw_ptr<FaviconLoader> _faviconLoader;
5458
// A service to get the information of a tab group.
5559
raw_ptr<tab_groups::TabGroupSyncService> _syncService;
60+
// A service to get the information of a shared tab group.
61+
raw_ptr<ShareKitService> _shareKitService;
5662
}
5763

5864
- (instancetype)initWithtabGroup:(base::WeakPtr<const TabGroup>)tabGroup
5965
messagingService:
6066
(collaboration::messaging::MessagingBackendService*)
6167
messagingService
6268
faviconLoader:(FaviconLoader*)faviconLoader
63-
syncService:(tab_groups::TabGroupSyncService*)syncService {
69+
syncService:(tab_groups::TabGroupSyncService*)syncService
70+
shareKitService:(ShareKitService*)shareKitService {
6471
CHECK(messagingService);
6572
CHECK(faviconLoader);
6673
CHECK(syncService);
74+
CHECK(shareKitService);
6775
if ((self = [super init])) {
6876
_messagingService = messagingService;
6977
_faviconLoader = faviconLoader;
7078
_syncService = syncService;
79+
_shareKitService = shareKitService;
7180
}
7281
return self;
7382
}
@@ -103,14 +112,28 @@ - (void)populateItemsFromService {
103112
_faviconLoader->FaviconForPageUrlOrHost(
104113
GURL(log.activity_metadata.tab_metadata.value()
105114
.last_known_url.value()),
106-
kImageSize, ^(FaviconAttributes* attributes) {
115+
kFaviconSize, ^(FaviconAttributes* attributes) {
107116
item.favicon = attributes.faviconImage;
108117
});
109118
}
110119

111-
// TODO(crbug.com/370897655): Get a correct user icon.
112-
item.userIcon =
113-
DefaultSymbolTemplateWithPointSize(kXMarkCircleFillSymbol, 20);
120+
// Get a user's icon from the avatar URL and set it to `item`.
121+
// The image is asynchronously loaded.
122+
if (_shareKitService->IsSupported() &&
123+
log.activity_metadata.triggering_user.has_value()) {
124+
ShareKitAvatarConfiguration* config =
125+
[[ShareKitAvatarConfiguration alloc] init];
126+
data_sharing::GroupMember user =
127+
log.activity_metadata.triggering_user.value();
128+
config.avatarUrl =
129+
[NSURL URLWithString:base::SysUTF8ToNSString(user.avatar_url.spec())];
130+
// Use email intead when the display name is empty.
131+
config.displayName = user.display_name.empty()
132+
? base::SysUTF8ToNSString(user.email)
133+
: base::SysUTF8ToNSString(user.display_name);
134+
config.avatarSize = CGSizeMake(kAvatarSize, kAvatarSize);
135+
item.avatarPrimitive = _shareKitService->AvatarImage(config);
136+
}
114137

115138
[items addObject:item];
116139
}

ios/chrome/browser/ui/tab_switcher/tab_grid/tab_groups/recent_activity_view_controller.mm

+9-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#import "ios/chrome/browser/ui/tab_switcher/tab_grid/tab_groups/recent_activity_view_controller.h"
66

77
#import "base/check.h"
8+
#import "ios/chrome/browser/share_kit/model/share_kit_avatar_primitive.h"
89
#import "ios/chrome/browser/shared/ui/symbols/symbols.h"
910
#import "ios/chrome/browser/shared/ui/table_view/table_view_utils.h"
1011
#import "ios/chrome/browser/ui/tab_switcher/tab_grid/tab_groups/recent_activity_log_cell.h"
@@ -116,8 +117,15 @@ - (UITableViewCell*)cellForTableView:(UITableView*)tableView
116117
DequeueTableViewCell<RecentActivityLogCell>(tableView);
117118
cell.titleLabel.text = itemIdentifier.title;
118119
cell.descriptionLabel.text = itemIdentifier.actionDescription;
119-
cell.iconImageView.image = itemIdentifier.userIcon;
120120
cell.faviconImageView.image = itemIdentifier.favicon;
121+
122+
UIView* view = [itemIdentifier.avatarPrimitive view];
123+
[cell.avatarView addSubview:view];
124+
[NSLayoutConstraint activateConstraints:@[
125+
[view.centerXAnchor constraintEqualToAnchor:cell.avatarView.centerXAnchor],
126+
[view.centerYAnchor constraintEqualToAnchor:cell.avatarView.centerYAnchor],
127+
]];
128+
[itemIdentifier.avatarPrimitive resolve];
121129
return cell;
122130
}
123131

0 commit comments

Comments
 (0)