[iOS] Add SharingState logic to tab group indicator
Bug: 395073160 Change-Id: I4a1d9da3decb94109ee38a490607d97dcf8f5ea6 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6244279 Reviewed-by: Louis Romero <lpromero@google.com> Commit-Queue: Ewann Pellé <ewannpv@chromium.org> Cr-Commit-Position: refs/heads/main@{#1418093}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
88ac5476c4
commit
adda3caec7
ios/chrome/browser/toolbar/ui_bundled/tab_groups
@ -26,6 +26,7 @@ source_set("coordinator") {
|
||||
"//ios/chrome/browser/feature_engagement/model",
|
||||
"//ios/chrome/browser/saved_tab_groups/model",
|
||||
"//ios/chrome/browser/share_kit/model",
|
||||
"//ios/chrome/browser/share_kit/model:constants",
|
||||
"//ios/chrome/browser/share_kit/model:factory",
|
||||
"//ios/chrome/browser/shared/coordinator/chrome_coordinator",
|
||||
"//ios/chrome/browser/shared/coordinator/scene:scene_state_header",
|
||||
|
@ -21,6 +21,7 @@
|
||||
#import "ios/chrome/browser/share_kit/model/share_kit_manage_configuration.h"
|
||||
#import "ios/chrome/browser/share_kit/model/share_kit_service.h"
|
||||
#import "ios/chrome/browser/share_kit/model/share_kit_share_group_configuration.h"
|
||||
#import "ios/chrome/browser/share_kit/model/sharing_state.h"
|
||||
#import "ios/chrome/browser/shared/model/url/chrome_url_constants.h"
|
||||
#import "ios/chrome/browser/shared/model/web_state_list/tab_group.h"
|
||||
#import "ios/chrome/browser/shared/model/web_state_list/web_state_list.h"
|
||||
@ -44,6 +45,7 @@ using ScopedTabGroupSyncObservation =
|
||||
using ScopedDataSharingSyncObservation =
|
||||
base::ScopedObservation<data_sharing::DataSharingService,
|
||||
data_sharing::DataSharingService::Observer>;
|
||||
using tab_groups::SharingState;
|
||||
|
||||
namespace {
|
||||
// The preferred size in points for the avatar icons.
|
||||
@ -172,10 +174,10 @@ constexpr CGFloat kFacePileAvatarSize = 20;
|
||||
HasTabGroupIndicatorVisible()) {
|
||||
[_consumer setTabGroupTitle:tabGroup->GetTitle()
|
||||
groupColor:tabGroup->GetColor()];
|
||||
[self updateTabGroupSharedState:tabGroup];
|
||||
[self updateTabGroupSharingState:tabGroup];
|
||||
} else {
|
||||
[_consumer setTabGroupTitle:nil groupColor:nil];
|
||||
[_consumer setShared:NO owner:NO];
|
||||
[_consumer setSharingState:SharingState::kNotShared];
|
||||
}
|
||||
[self updateFacePileUI];
|
||||
}
|
||||
@ -311,7 +313,7 @@ constexpr CGFloat kFacePileAvatarSize = 20;
|
||||
|
||||
- (void)tabGroupSyncServiceInitialized {
|
||||
[self presentForegroundIPHIfNeeded];
|
||||
[self updateTabGroupSharedState:[self currentTabGroup]];
|
||||
[self updateTabGroupSharingState:[self currentTabGroup]];
|
||||
[self updateFacePileUI];
|
||||
}
|
||||
|
||||
@ -323,7 +325,7 @@ constexpr CGFloat kFacePileAvatarSize = 20;
|
||||
if (!tabGroup || newGroup.local_group_id() != tabGroup->tab_group_id()) {
|
||||
return;
|
||||
}
|
||||
[self updateTabGroupSharedState:tabGroup];
|
||||
[self updateTabGroupSharingState:tabGroup];
|
||||
[self updateFacePileUI];
|
||||
}
|
||||
|
||||
@ -331,7 +333,7 @@ constexpr CGFloat kFacePileAvatarSize = 20;
|
||||
|
||||
- (void)dataSharingServiceInitialized {
|
||||
[self presentForegroundIPHIfNeeded];
|
||||
[self updateTabGroupSharedState:[self currentTabGroup]];
|
||||
[self updateTabGroupSharingState:[self currentTabGroup]];
|
||||
[self updateFacePileUI];
|
||||
}
|
||||
|
||||
@ -382,7 +384,7 @@ constexpr CGFloat kFacePileAvatarSize = 20;
|
||||
return;
|
||||
}
|
||||
|
||||
[self updateTabGroupSharedState:tabGroup];
|
||||
[self updateTabGroupSharingState:tabGroup];
|
||||
[self updateFacePileUI];
|
||||
}
|
||||
|
||||
@ -456,7 +458,7 @@ constexpr CGFloat kFacePileAvatarSize = 20;
|
||||
tab_groups::CollaborationId savedCollabID =
|
||||
tab_groups::utils::GetTabGroupCollabID(tabGroup, _tabGroupSyncService);
|
||||
BOOL isShared = !savedCollabID.value().empty();
|
||||
[self updateTabGroupSharedState:tabGroup];
|
||||
[self updateTabGroupSharingState:tabGroup];
|
||||
|
||||
// Prevent the face pile from being set up for tab groups that are not shared.
|
||||
if (!isShared) {
|
||||
@ -498,14 +500,22 @@ constexpr CGFloat kFacePileAvatarSize = 20;
|
||||
return _webStateList->GetGroupOfWebStateAt(_webStateList->active_index());
|
||||
}
|
||||
|
||||
// Updates the shared state of for the given `tabGroup`.
|
||||
- (void)updateTabGroupSharedState:(const TabGroup*)tabGroup {
|
||||
// Updates the sharing state for the given `tabGroup`.
|
||||
- (void)updateTabGroupSharingState:(const TabGroup*)tabGroup {
|
||||
BOOL shared =
|
||||
tab_groups::utils::IsTabGroupShared(tabGroup, _tabGroupSyncService);
|
||||
if (!shared) {
|
||||
[_consumer setSharingState:SharingState::kNotShared];
|
||||
return;
|
||||
}
|
||||
|
||||
data_sharing::MemberRole userRole = tab_groups::utils::GetUserRoleForGroup(
|
||||
tabGroup, _tabGroupSyncService, _collaborationService);
|
||||
[_consumer setShared:shared
|
||||
owner:userRole == data_sharing::MemberRole::kOwner];
|
||||
|
||||
SharingState state = userRole == data_sharing::MemberRole::kOwner
|
||||
? SharingState::kSharedAndOwned
|
||||
: SharingState::kShared;
|
||||
[_consumer setSharingState:state];
|
||||
}
|
||||
|
||||
@end
|
||||
|
@ -14,6 +14,7 @@ source_set("ui") {
|
||||
"//base",
|
||||
"//ios/chrome/app/strings",
|
||||
"//ios/chrome/browser/menu/ui_bundled",
|
||||
"//ios/chrome/browser/share_kit/model:constants",
|
||||
"//ios/chrome/browser/shared/public/features",
|
||||
"//ios/chrome/browser/toolbar/ui_bundled/public",
|
||||
"//ios/chrome/browser/toolbar/ui_bundled/public:constants",
|
||||
|
@ -7,6 +7,8 @@
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import "ios/chrome/browser/share_kit/model/sharing_state.h"
|
||||
|
||||
// TabGroupIndicator Consumer interface.
|
||||
@protocol TabGroupIndicatorConsumer <NSObject>
|
||||
|
||||
@ -16,10 +18,8 @@
|
||||
// Sets whether the group can be shared or not.
|
||||
- (void)setShareAvailable:(BOOL)shareAvailable;
|
||||
|
||||
// Sets the group shared state.
|
||||
// - `shared` is true when this group is shared with other users.
|
||||
// - `owner` is true when the user owns the shared group.
|
||||
- (void)setShared:(BOOL)shared owner:(BOOL)owner;
|
||||
// Sets the sharing state of a group.
|
||||
- (void)setSharingState:(tab_groups::SharingState)state;
|
||||
|
||||
// Sets the face pile view controller to display the share button or the face
|
||||
// pile.
|
||||
|
@ -8,6 +8,7 @@
|
||||
#import "base/metrics/user_metrics_action.h"
|
||||
#import "base/strings/sys_string_conversions.h"
|
||||
#import "ios/chrome/browser/menu/ui_bundled/action_factory.h"
|
||||
#import "ios/chrome/browser/share_kit/model/sharing_state.h"
|
||||
#import "ios/chrome/browser/shared/public/features/features.h"
|
||||
#import "ios/chrome/browser/toolbar/ui_bundled/public/toolbar_constants.h"
|
||||
#import "ios/chrome/browser/toolbar/ui_bundled/public/toolbar_height_delegate.h"
|
||||
@ -19,6 +20,8 @@
|
||||
#import "ui/base/l10n/l10n_util.h"
|
||||
#import "ui/gfx/ios/uikit_util.h"
|
||||
|
||||
using tab_groups::SharingState;
|
||||
|
||||
@implementation TabGroupIndicatorView {
|
||||
// Stores the tab group informations.
|
||||
NSString* _groupTitle;
|
||||
@ -42,11 +45,8 @@
|
||||
UIViewController* _facePileViewController;
|
||||
// Whether the share option is available.
|
||||
BOOL _shareAvailable;
|
||||
// Whether the group is shared.
|
||||
BOOL _shared;
|
||||
// Whether the user owns the shared group.
|
||||
// This should only be checked if `_shared` is true.
|
||||
BOOL _owner;
|
||||
// Sharing state of the saved tab group.
|
||||
SharingState _sharingState;
|
||||
}
|
||||
|
||||
- (instancetype)init {
|
||||
@ -93,9 +93,8 @@
|
||||
[self configureMenuButton];
|
||||
}
|
||||
|
||||
- (void)setShared:(BOOL)shared owner:(BOOL)owner {
|
||||
_shared = shared;
|
||||
_owner = owner;
|
||||
- (void)setSharingState:(SharingState)state {
|
||||
_sharingState = state;
|
||||
[self configureMenuButton];
|
||||
}
|
||||
|
||||
@ -216,7 +215,7 @@
|
||||
|
||||
// Shared actions.
|
||||
NSMutableArray<UIAction*>* sharedActions = [[NSMutableArray alloc] init];
|
||||
if (_shared) {
|
||||
if (_sharingState != SharingState::kNotShared) {
|
||||
[sharedActions addObject:[actionFactory actionToManageTabGroupWithBlock:^{
|
||||
[weakSelf.mutator manageGroup];
|
||||
}]];
|
||||
@ -244,7 +243,7 @@
|
||||
[editActions addObject:[actionFactory actionToAddNewTabInGroupWithBlock:^{
|
||||
[weakSelf.mutator addNewTabInGroup];
|
||||
}]];
|
||||
if (!_shared) {
|
||||
if (_sharingState == SharingState::kNotShared) {
|
||||
[editActions addObject:[actionFactory actionToUngroupTabGroupWithBlock:^{
|
||||
[weakSelf.mutator unGroupWithConfirmation:YES];
|
||||
}]];
|
||||
@ -263,23 +262,28 @@
|
||||
[weakSelf.mutator closeGroup];
|
||||
}]];
|
||||
if (!_incognito) {
|
||||
if (_shared) {
|
||||
if (_owner) {
|
||||
switch (_sharingState) {
|
||||
case SharingState::kNotShared: {
|
||||
[destructiveActions
|
||||
addObject:[actionFactory actionToDeleteSharedTabGroupWithBlock:^{
|
||||
[weakSelf.mutator deleteSharedGroupWithConfirmation:YES];
|
||||
addObject:[actionFactory actionToDeleteTabGroupWithBlock:^{
|
||||
[weakSelf.mutator deleteGroupWithConfirmation:YES];
|
||||
}]];
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
case SharingState::kShared: {
|
||||
[destructiveActions
|
||||
addObject:[actionFactory actionToLeaveSharedTabGroupWithBlock:^{
|
||||
[weakSelf.mutator leaveSharedGroupWithConfirmation:YES];
|
||||
}]];
|
||||
break;
|
||||
}
|
||||
case SharingState::kSharedAndOwned: {
|
||||
[destructiveActions
|
||||
addObject:[actionFactory actionToDeleteSharedTabGroupWithBlock:^{
|
||||
[weakSelf.mutator deleteSharedGroupWithConfirmation:YES];
|
||||
}]];
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
[destructiveActions
|
||||
addObject:[actionFactory actionToDeleteTabGroupWithBlock:^{
|
||||
[weakSelf.mutator deleteGroupWithConfirmation:YES];
|
||||
}]];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
Reference in New Issue
Block a user