Skip to content

Commit 329f1ef

Browse files
author
Momo Ozawa
committed
Refactor: remove table header view from BlogDetailsVC
We can now remove the table header view from BlogDetailsViewController, because we have extracted the code to SitePickerViewController and we are showing SitePickerVC regardless of the MSD feature flag state. As such, we can also removed the BlogDetailHeaderViewDelegate implementation as well as the Remove Site Icon Update Management related code, since these have been implemented on the SitePickerViewController.
1 parent 21e9761 commit 329f1ef

File tree

2 files changed

+4
-322
lines changed

2 files changed

+4
-322
lines changed

WordPress/Classes/ViewRelated/Blog/Blog Details/BlogDetailsViewController+FancyAlerts.swift

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ extension BlogDetailsViewController {
1212
guard self?.blog.managedObjectContext != nil else {
1313
return
1414
}
15-
self?.toggleSpotlightForSiteTitle()
16-
self?.refreshSiteIcon()
1715
self?.configureTableViewData()
1816
self?.reloadTableViewPreservingSelection()
1917

@@ -114,9 +112,7 @@ extension BlogDetailsViewController {
114112
private func showQuickStart(with type: QuickStartType) {
115113
let checklist = QuickStartChecklistViewController(blog: blog, type: type)
116114
let navigationViewController = UINavigationController(rootViewController: checklist)
117-
present(navigationViewController, animated: true) { [weak self] in
118-
self?.toggleSpotlightOnHeaderView()
119-
}
115+
present(navigationViewController, animated: true)
120116

121117
QuickStartTourGuide.shared.visited(.checklist)
122118

WordPress/Classes/ViewRelated/Blog/Blog Details/BlogDetailsViewController.m

Lines changed: 3 additions & 317 deletions
Original file line numberDiff line numberDiff line change
@@ -327,13 +327,8 @@ - (void)viewDidLoad
327327
{
328328
[super viewDidLoad];
329329

330-
if ([Feature enabled:FeatureFlagMySiteDashboard]) {
331-
_tableView = [[IntrinsicTableView alloc] initWithFrame:CGRectZero style:UITableViewStyleInsetGrouped];
332-
self.tableView.scrollEnabled = false;
333-
} else {
334-
_tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleInsetGrouped];
335-
}
336-
330+
_tableView = [[IntrinsicTableView alloc] initWithFrame:CGRectZero style:UITableViewStyleInsetGrouped];
331+
self.tableView.scrollEnabled = false;
337332
self.tableView.delegate = self;
338333
self.tableView.dataSource = self;
339334
self.tableView.translatesAutoresizingMaskIntoConstraints = false;
@@ -377,8 +372,6 @@ - (void)viewDidLoad
377372
name:NSManagedObjectContextObjectsDidChangeNotification
378373
object:context];
379374

380-
[self configureBlogDetailHeader];
381-
[self.headerView setBlog:_blog];
382375
[self startObservingQuickStart];
383376
[self addMeButtonToNavigationBarWithEmail:self.blog.account.email meScenePresenter:self.meScenePresenter];
384377

@@ -390,24 +383,10 @@ - (void)viewDidLoad
390383

391384
}
392385

393-
/// Resizes the `tableHeaderView` as necessary whenever its size changes.
394386
- (void)viewDidLayoutSubviews {
395387
[super viewDidLayoutSubviews];
396388

397389
[self.createButtonCoordinator presentingTraitCollectionWillChange:self.traitCollection newTraitCollection:self.traitCollection];
398-
399-
if ([Feature enabled:FeatureFlagMySiteDashboard]) {
400-
return;
401-
}
402-
403-
UIView *headerView = self.tableView.tableHeaderView;
404-
405-
CGSize size = [self.tableView.tableHeaderView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize];
406-
if (headerView.frame.size.height != size.height) {
407-
headerView.frame = CGRectMake(headerView.frame.origin.x, headerView.frame.origin.y, headerView.frame.size.width, size.height);
408-
409-
self.tableView.tableHeaderView = headerView;
410-
}
411390
}
412391

413392
- (void)viewWillAppear:(BOOL)animated
@@ -1094,98 +1073,6 @@ - (BOOL)shouldDisplayLinkToWPAdmin
10941073
return [defaultAccount.dateCreated compare:hideWPAdminDate] == NSOrderedAscending;
10951074
}
10961075

1097-
#pragma mark - Configuration
1098-
1099-
- (void)configureBlogDetailHeader
1100-
{
1101-
if ([Feature enabled:FeatureFlagMySiteDashboard]) {
1102-
return;
1103-
}
1104-
1105-
BlogDetailHeaderView *headerView = [self configureHeaderView];
1106-
headerView.delegate = self;
1107-
1108-
self.headerView = headerView;
1109-
1110-
self.tableView.tableHeaderView = headerView;
1111-
1112-
[self.headerView setTranslatesAutoresizingMaskIntoConstraints:NO];
1113-
[NSLayoutConstraint activateConstraints:@[
1114-
[self.headerView.leadingAnchor constraintEqualToAnchor:self.view.leadingAnchor],
1115-
[self.headerView.trailingAnchor constraintEqualToAnchor:self.view.trailingAnchor]
1116-
]];
1117-
}
1118-
1119-
#pragma mark BlogDetailHeaderViewDelegate
1120-
1121-
- (void)siteIconTapped
1122-
{
1123-
if (![self siteIconShouldAllowDroppedImages]) {
1124-
// Gracefully ignore the tap for users that can not upload files or
1125-
// blogs that do not have capabilities since those will not support the REST API icon update
1126-
return;
1127-
}
1128-
[WPAnalytics track:WPAnalyticsStatSiteSettingsSiteIconTapped];
1129-
1130-
[NoticesDispatch lock];
1131-
1132-
if (![Feature enabled:FeatureFlagSiteIconCreator]) {
1133-
[self showUpdateSiteIconAlert];
1134-
}
1135-
1136-
if (@available(iOS 14.0, *)) {
1137-
[self showSiteIconSelectionAlert];
1138-
} else {
1139-
[self showUpdateSiteIconAlert];
1140-
}
1141-
}
1142-
1143-
- (void)siteIconReceivedDroppedImage:(UIImage *)image
1144-
{
1145-
if (![self siteIconShouldAllowDroppedImages]) {
1146-
// Gracefully ignore the drop for users that can not upload files or
1147-
// blogs that do not have capabilities since those will not support the REST API icon update
1148-
self.headerView.updatingIcon = NO;
1149-
return;
1150-
}
1151-
[self presentCropViewControllerForDroppedSiteIcon:image];
1152-
}
1153-
1154-
- (BOOL)siteIconShouldAllowDroppedImages
1155-
{
1156-
if (!self.blog.isAdmin || !self.blog.isUploadingFilesAllowed) {
1157-
return NO;
1158-
}
1159-
1160-
return YES;
1161-
}
1162-
1163-
- (void)siteTitleTapped
1164-
{
1165-
[self showSiteTitleSettings];
1166-
}
1167-
1168-
- (void)siteSwitcherTapped
1169-
{
1170-
BlogListViewController* blogListViewController = [[BlogListViewController alloc] initWithMeScenePresenter:self.meScenePresenter];
1171-
__weak __typeof(self) weakSelf = self;
1172-
blogListViewController.blogSelected = ^(BlogListViewController* blogListViewController, Blog *blog) {
1173-
[weakSelf switchToBlog:blog];
1174-
[blogListViewController dismissViewControllerAnimated:true completion:nil];
1175-
};
1176-
1177-
UINavigationController* navigationController = [[UINavigationController alloc] initWithRootViewController:blogListViewController];
1178-
navigationController.modalPresentationStyle = UIModalPresentationFormSheet;
1179-
[self presentViewController:navigationController animated:true completion:nil];
1180-
1181-
[WPAnalytics trackEvent:WPAnalyticsEventMySiteSiteSwitcherTapped];
1182-
}
1183-
1184-
- (void)visitSiteTapped
1185-
{
1186-
[self showViewSiteFromSource:BlogDetailsNavigationSourceButton];
1187-
}
1188-
11891076
#pragma mark Site Switching
11901077

11911078
- (void)switchToBlog:(Blog*)blog
@@ -1206,205 +1093,6 @@ - (void)showInitialDetailsForBlog
12061093
[self showDetailViewForSubsection:BlogDetailsSubsectionStats];
12071094
}
12081095

1209-
#pragma mark Site Icon Update Management
1210-
1211-
- (void)showUpdateSiteIconAlert
1212-
{
1213-
UIAlertController *updateIconAlertController = [UIAlertController alertControllerWithTitle:nil
1214-
message:nil
1215-
preferredStyle:UIAlertControllerStyleActionSheet];
1216-
1217-
updateIconAlertController.popoverPresentationController.sourceView = self.headerView.blavatarImageView.superview;
1218-
updateIconAlertController.popoverPresentationController.sourceRect = self.headerView.blavatarImageView.frame;
1219-
updateIconAlertController.popoverPresentationController.permittedArrowDirections = UIPopoverArrowDirectionAny;
1220-
1221-
[updateIconAlertController addDefaultActionWithTitle:NSLocalizedString(@"Change Site Icon", @"Change site icon button")
1222-
handler:^(UIAlertAction *action) {
1223-
[NoticesDispatch unlock];
1224-
[self updateSiteIcon];
1225-
}];
1226-
if (self.blog.hasIcon) {
1227-
[updateIconAlertController addDestructiveActionWithTitle:NSLocalizedString(@"Remove Site Icon", @"Remove site icon button")
1228-
handler:^(UIAlertAction *action) {
1229-
[NoticesDispatch unlock];
1230-
[self removeSiteIcon];
1231-
}];
1232-
}
1233-
[updateIconAlertController addCancelActionWithTitle:NSLocalizedString(@"Cancel", @"Cancel button")
1234-
handler:^(UIAlertAction *action) {
1235-
[NoticesDispatch unlock];
1236-
[self startAlertTimer];
1237-
}];
1238-
1239-
[self presentViewController:updateIconAlertController animated:YES completion:nil];
1240-
}
1241-
1242-
- (void)showSiteIconSelectionAlert
1243-
{
1244-
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil
1245-
message:nil
1246-
preferredStyle:UIAlertControllerStyleActionSheet];
1247-
1248-
alertController.popoverPresentationController.sourceView = self.headerView.blavatarImageView.superview;
1249-
alertController.popoverPresentationController.sourceRect = self.headerView.blavatarImageView.frame;
1250-
alertController.popoverPresentationController.permittedArrowDirections = UIPopoverArrowDirectionAny;
1251-
1252-
[alertController setTitle:NSLocalizedString(@"Update Site Icon", @"Title for sheet displayed allowing user to update their site icon")];
1253-
1254-
[alertController addDefaultActionWithTitle:NSLocalizedString(@"Choose Image From My Device", @"Button allowing the user to choose an image from their device to use as their site icon")
1255-
handler:^(UIAlertAction *action) {
1256-
[NoticesDispatch unlock];
1257-
[self updateSiteIcon];
1258-
}];
1259-
1260-
[alertController addDefaultActionWithTitle:NSLocalizedString(@"Create With Emoji", @"Button allowing the user to create a site icon by choosing an emoji character")
1261-
handler:^(UIAlertAction *action) {
1262-
[NoticesDispatch unlock];
1263-
[self showEmojiPicker];
1264-
}];
1265-
1266-
[alertController addDestructiveActionWithTitle:NSLocalizedString(@"Remove Site Icon", @"Remove site icon button")
1267-
handler:^(UIAlertAction *action) {
1268-
[NoticesDispatch unlock];
1269-
[self removeSiteIcon];
1270-
}];
1271-
1272-
[alertController addCancelActionWithTitle:NSLocalizedString(@"Cancel", @"Cancel button")
1273-
handler:^(UIAlertAction *action) {
1274-
[NoticesDispatch unlock];
1275-
[self startAlertTimer];
1276-
}];
1277-
1278-
[self presentViewController:alertController animated:YES completion:nil];
1279-
}
1280-
1281-
- (void)presentCropViewControllerForDroppedSiteIcon:(UIImage *)image
1282-
{
1283-
self.imageCropViewController = [[ImageCropViewController alloc] initWithImage:image];
1284-
self.imageCropViewController.maskShape = ImageCropOverlayMaskShapeSquare;
1285-
self.imageCropViewController.shouldShowCancelButton = YES;
1286-
1287-
__weak __typeof(self) weakSelf = self;
1288-
self.imageCropViewController.onCancel = ^(void) {
1289-
[weakSelf dismissViewControllerAnimated:YES completion:nil];
1290-
weakSelf.headerView.updatingIcon = NO;
1291-
};
1292-
1293-
self.imageCropViewController.onCompletion = ^(UIImage *image, BOOL modified) {
1294-
[weakSelf dismissViewControllerAnimated:YES completion:nil];
1295-
[weakSelf uploadDroppedSiteIcon:image onCompletion:^{
1296-
weakSelf.headerView.blavatarImageView.image = image;
1297-
weakSelf.headerView.updatingIcon = NO;
1298-
}];
1299-
};
1300-
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:self.imageCropViewController];
1301-
navController.modalPresentationStyle = UIModalPresentationFormSheet;
1302-
[self presentViewController:navController animated:YES completion:nil];
1303-
}
1304-
1305-
- (void)uploadDroppedSiteIcon:(UIImage *)image onCompletion:(void(^)(void))completion
1306-
{
1307-
if (self.blog.objectID == nil) {
1308-
return;
1309-
}
1310-
1311-
__weak __typeof(self) weakSelf = self;
1312-
MediaService *mediaService = [[MediaService alloc] initWithManagedObjectContext:[ContextManager sharedInstance].mainContext];
1313-
NSProgress *mediaCreateProgress;
1314-
[mediaService createMediaWith:image blog:self.blog post:nil progress:&mediaCreateProgress thumbnailCallback:nil completion:^(Media *media, NSError *error) {
1315-
if (media == nil || error != nil) {
1316-
return;
1317-
}
1318-
NSProgress *uploadProgress;
1319-
[mediaService uploadMedia:media
1320-
automatedRetry:false
1321-
progress:&uploadProgress
1322-
success:^{
1323-
[weakSelf updateBlogIconWithMedia:media];
1324-
completion();
1325-
} failure:^(NSError * _Nonnull error) {
1326-
[weakSelf showErrorForSiteIconUpdate];
1327-
completion();
1328-
}];
1329-
}];
1330-
}
1331-
1332-
- (void)updateSiteIcon
1333-
{
1334-
self.siteIconPickerPresenter = [[SiteIconPickerPresenter alloc]initWithBlog:self.blog];
1335-
__weak __typeof(self) weakSelf = self;
1336-
self.siteIconPickerPresenter.onCompletion = ^(Media *media, NSError *error) {
1337-
if (error) {
1338-
[weakSelf showErrorForSiteIconUpdate];
1339-
} else if (media) {
1340-
[weakSelf updateBlogIconWithMedia:media];
1341-
} else {
1342-
// If no media and no error the picker was canceled
1343-
[weakSelf dismissViewControllerAnimated:YES completion:nil];
1344-
}
1345-
weakSelf.siteIconPickerPresenter = nil;
1346-
[weakSelf startAlertTimer];
1347-
};
1348-
self.siteIconPickerPresenter.onIconSelection = ^() {
1349-
weakSelf.headerView.updatingIcon = YES;
1350-
[weakSelf dismissViewControllerAnimated:YES completion:nil];
1351-
};
1352-
[self.siteIconPickerPresenter presentPickerFrom:self];
1353-
}
1354-
1355-
- (void)removeSiteIcon
1356-
{
1357-
self.headerView.updatingIcon = YES;
1358-
self.blog.settings.iconMediaID = @0;
1359-
[self updateBlogSettingsAndRefreshIcon];
1360-
[WPAnalytics track:WPAnalyticsStatSiteSettingsSiteIconRemoved];
1361-
}
1362-
1363-
- (void)refreshSiteIcon
1364-
{
1365-
[self.headerView refreshIconImage];
1366-
}
1367-
1368-
- (void)toggleSpotlightForSiteTitle
1369-
{
1370-
[self.headerView toggleSpotlightOnSiteTitle];
1371-
}
1372-
1373-
- (void)toggleSpotlightOnHeaderView
1374-
{
1375-
[self.headerView toggleSpotlightOnSiteTitle];
1376-
[self.headerView toggleSpotlightOnSiteIcon];
1377-
}
1378-
1379-
- (void)updateBlogIconWithMedia:(Media *)media
1380-
{
1381-
[[QuickStartTourGuide shared] completeSiteIconTourForBlog:self.blog];
1382-
1383-
self.blog.settings.iconMediaID = media.mediaID;
1384-
[self updateBlogSettingsAndRefreshIcon];
1385-
}
1386-
1387-
- (void)updateBlogSettingsAndRefreshIcon
1388-
{
1389-
BlogService *blogService = [[BlogService alloc] initWithManagedObjectContext:self.blog.managedObjectContext];
1390-
[blogService updateSettingsForBlog:self.blog
1391-
success:^{
1392-
[blogService syncBlog:self.blog
1393-
success:^{
1394-
self.headerView.updatingIcon = NO;
1395-
[self.headerView refreshIconImage];
1396-
} failure:nil];
1397-
} failure:^(NSError *error){
1398-
[self showErrorForSiteIconUpdate];
1399-
}];
1400-
}
1401-
1402-
- (void)showErrorForSiteIconUpdate
1403-
{
1404-
[SVProgressHUD showDismissibleErrorWithStatus:NSLocalizedString(@"Icon update failed", @"Message to show when site icon update failed")];
1405-
self.headerView.updatingIcon = NO;
1406-
}
1407-
14081096
#pragma mark - Table view data source
14091097

14101098
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
@@ -1908,9 +1596,7 @@ - (void)showViewSiteFromSource:(BlogDetailsNavigationSource)source
19081596

19091597
[self presentViewController:navController
19101598
animated:YES
1911-
completion:^(void) {
1912-
[self toggleSpotlightOnHeaderView];
1913-
}];
1599+
completion:nil];
19141600

19151601
QuickStartTourGuide *guide = [QuickStartTourGuide shared];
19161602

0 commit comments

Comments
 (0)