Skip to content

Commit

Permalink
Add missing social sharing icons
Browse files Browse the repository at this point in the history
  • Loading branch information
kean committed Dec 20, 2024
1 parent cc26fec commit 0fd6957
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 52 deletions.
1 change: 1 addition & 0 deletions WordPress/Classes/Models/PublicizeService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ extension PublicizeService {
case linkedin
case instagram = "instagram-business"
case mastodon
case threads
case unknown

/// Returns the local image for the icon representing the social network.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import UIKit
import WordPressUI

final class PublicizeServiceCell: UITableViewCell {
let iconView = AsyncImageView()
let titleLabel = UILabel()
let detailsLabel = UILabel()

@objc class var cellId: String { "PublicizeServiceCell" }

override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)

detailsLabel.font = .preferredFont(forTextStyle: .footnote)
detailsLabel.textColor = .secondaryLabel

let stackView = UIStackView(alignment: .center, spacing: 12, [
iconView,
UIStackView(axis: .vertical, alignment: .leading, spacing: 2, [titleLabel, detailsLabel])
])
contentView.addSubview(stackView)
stackView.pinEdges(to: contentView.layoutMarginsGuide)

NSLayoutConstraint.activate([
iconView.widthAnchor.constraint(equalToConstant: 28),
iconView.heightAnchor.constraint(equalToConstant: 28),
])
iconView.layer.cornerRadius = 8
iconView.layer.masksToBounds = true
iconView.backgroundColor = UIColor.white

iconView.contentMode = .scaleAspectFit
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

override func prepareForReuse() {
super.prepareForReuse()

accessoryView = .none
iconView.prepareForReuse()
}

@objc func configure(with service: PublicizeService, connections: [PublicizeConnection]) {
let name = service.name
if name != .unknown && !name.hasModernRemoteLogo {
iconView.image = name.localIconImage
} else if let imageURL = URL(string: service.icon) {
iconView.setImage(with: imageURL)
} else {
iconView.image = UIImage(named: "social-default")
}

titleLabel.text = service.label

detailsLabel.isHidden = connections.isEmpty
if connections.count > 2 {
detailsLabel.text = String(format: Strings.numberOfAccounts, connections.count)
} else {
detailsLabel.text = connections
.map(\.externalDisplay)
.joined(separator: ", ")
}

if service.isSupported {
if connections.contains(where: { $0.requiresUserAction() }) {
accessoryView = WPStyleGuide.sharingCellWarningAccessoryImageView()
}
} else {
accessoryView = WPStyleGuide.sharingCellErrorAccessoryImageView()
}
}
}

private extension PublicizeService.ServiceName {
/// We no longer need to provide local overrides for these on this screen
/// as the remote images are good.
var hasModernRemoteLogo: Bool {
[
PublicizeService.ServiceName.instagram,
PublicizeService.ServiceName.mastodon
].contains(self)
}
}

private enum Strings {
static let numberOfAccounts = NSLocalizedString("socialSharing.connectionDetails.nAccount", value: "%d accounts", comment: "The number of connected accounts on a third party sharing service connected to the user's blog. The '%d' is a placeholder for the number of accounts.")
}
74 changes: 23 additions & 51 deletions WordPress/Classes/ViewRelated/Blog/Sharing/SharingViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ - (void)viewDidLoad
action:@selector(doneButtonTapped)];
}

[self.tableView registerClass:[PublicizeServiceCell class] forCellReuseIdentifier:PublicizeServiceCell.cellId];
self.tableView.cellLayoutMarginsFollowReadableWidth = YES;
[WPStyleGuide configureColorsForView:self.view andTableView:self.tableView];
[self.publicizeServicesState addInitialConnections:[self allConnections]];
Expand Down Expand Up @@ -237,32 +238,16 @@ - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPa

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
WPTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (!cell) {
cell = [[WPTableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier];
}

[WPStyleGuide configureTableViewCell:cell];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

SharingSectionType sectionType = [self sectionTypeForIndex:indexPath.section];
switch (sectionType) {
case SharingSectionAvailableServices: // fallthrough
case SharingSectionUnsupported:
[self configurePublicizeCell:cell atIndexPath:indexPath];
break;

return [self makePublicizeCellAtIndexPath:indexPath];
case SharingSectionSharingButtons:
cell.textLabel.text = NSLocalizedString(@"Manage", @"Verb. Text label. Tapping displays a screen where the user can configure 'share' buttons for third-party services.");
cell.detailTextLabel.text = nil;
cell.imageView.image = nil;
break;

return [self makeManageButtonCell];
default:
return [UITableViewCell new];
}

return cell;
}

- (PublicizeService *)publicizeServiceForIndexPath:(NSIndexPath *)indexPath
Expand All @@ -278,51 +263,38 @@ - (PublicizeService *)publicizeServiceForIndexPath:(NSIndexPath *)indexPath
}
}

- (void)configurePublicizeCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath
- (UITableViewCell *)makePublicizeCellAtIndexPath:(NSIndexPath *)indexPath
{
PublicizeServiceCell *cell = [self.tableView dequeueReusableCellWithIdentifier:PublicizeServiceCell.cellId];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

PublicizeService *publicizer = [self publicizeServiceForIndexPath:indexPath];
NSArray *connections = [self connectionsForService:publicizer];

// TODO: Remove?
if ([publicizer.serviceID isEqualToString:PublicizeService.googlePlusServiceID] && [connections count] == 0) { // Temporarily hiding Google+
cell.hidden = YES;
return;
}

// Configure the image
UIImage *image = [WPStyleGuide socialIconFor:publicizer.serviceID];
[cell.imageView setImage:image];

// Configure the text
cell.textLabel.text = publicizer.label;

// Show the name(s) or number of connections.
NSString *str = @"";
if ([connections count] > 2) {
NSString *format = NSLocalizedString(@"%d accounts", @"The number of connected accounts on a third party sharing service connected to the user's blog. The '%d' is a placeholder for the number of accounts.");
str = [NSString stringWithFormat:format, [connections count]];
} else {
NSMutableArray *names = [NSMutableArray array];
for (PublicizeConnection *pubConn in connections) {
[names addObject:pubConn.externalDisplay];
}
str = [names componentsJoinedByString:@", "];
return cell;
}

cell.detailTextLabel.text = str;
[cell configureWith:publicizer connections:connections];
return cell;
}

if (![publicizer isSupported]) {
cell.accessoryView = [WPStyleGuide sharingCellErrorAccessoryImageView];
return;
- (UITableViewCell *)makeManageButtonCell
{
WPTableViewCell *cell = [self.
tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (!cell) {
cell = [[WPTableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier];
}

// Check if any of the connections are broken.
for (PublicizeConnection *pubConn in connections) {
if ([pubConn requiresUserAction]) {
cell.accessoryView = [WPStyleGuide sharingCellWarningAccessoryImageView];
break;
}
}
[WPStyleGuide configureTableViewCell:cell];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.textLabel.text = NSLocalizedString(@"Manage", @"Verb. Text label. Tapping displays a screen where the user can configure 'share' buttons for third-party services.");
cell.detailTextLabel.text = nil;
cell.imageView.image = nil;
return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ struct JetpackSocialNoConnectionView: View {
}

func iconImage(image: UIImage, url: URL?) -> some View {
AsyncImage(url: url) { image in
CachedAsyncImage(url: url) { image in
image
.icon(backgroundColor: viewModel.preferredBackgroundColor)
} placeholder: {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"images" : [
{
"filename" : "361591942_304761532104096_2740029438399114184_n-2.png",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

0 comments on commit 0fd6957

Please sign in to comment.