From c627c38b212a31693e1098dd302aee58badc3b2c Mon Sep 17 00:00:00 2001 From: Ilya Grechuhin Date: Tue, 24 Jan 2017 15:06:55 +0300 Subject: [PATCH] [cleanup] [ios] Code cleanup. --- .../Maps/Categories/UITableView+Updates.swift | 13 +++ .../MWMDownloadTransitMapAlert.mm | 8 +- iphone/Maps/Maps.xcodeproj/project.pbxproj | 8 ++ .../EditBookmark/MWMEditBookmarkController.mm | 6 +- .../Maps/UI/Editor/MWMEditorViewController.mm | 13 +-- .../OpeningHours/MWMOpeningHoursSection.mm | 97 +++++++++---------- .../PlacePageLayout/MWMPlacePageLayout.mm | 11 +-- 7 files changed, 84 insertions(+), 72 deletions(-) create mode 100644 iphone/Maps/Categories/UITableView+Updates.swift diff --git a/iphone/Maps/Categories/UITableView+Updates.swift b/iphone/Maps/Categories/UITableView+Updates.swift new file mode 100644 index 0000000000..40446ae096 --- /dev/null +++ b/iphone/Maps/Categories/UITableView+Updates.swift @@ -0,0 +1,13 @@ +extension UITableView { + typealias Updates = () -> Void + + func update(_ updates: Updates) { + beginUpdates() + updates() + endUpdates() + } + + func refresh() { + update {} + } +} diff --git a/iphone/Maps/Classes/CustomAlert/DownloadTransitMapsAlert/MWMDownloadTransitMapAlert.mm b/iphone/Maps/Classes/CustomAlert/DownloadTransitMapsAlert/MWMDownloadTransitMapAlert.mm index e7b71196ef..81f07963b7 100644 --- a/iphone/Maps/Classes/CustomAlert/DownloadTransitMapsAlert/MWMDownloadTransitMapAlert.mm +++ b/iphone/Maps/Classes/CustomAlert/DownloadTransitMapsAlert/MWMDownloadTransitMapAlert.mm @@ -1,12 +1,13 @@ -#import "MWMCommon.h" +#import "MWMDownloadTransitMapAlert.h" #import "MWMAlertViewController.h" #import "MWMCircularProgress.h" +#import "MWMCommon.h" #import "MWMDownloaderDialogCell.h" #import "MWMDownloaderDialogHeader.h" -#import "MWMDownloadTransitMapAlert.h" #import "MWMFrameworkListener.h" #import "MWMStorage.h" #import "Statistics.h" +#import "SwiftBridge.h" #import "UILabel+RuntimeAttributes.h" #include "Framework.h" @@ -234,8 +235,7 @@ CGFloat const kAnimationDuration = .05; { cell.titleLabel.alpha = show ? 1. : 0.; } - [self.dialogsTableView beginUpdates]; - [self.dialogsTableView endUpdates]; + [self.dialogsTableView refresh]; }; if (listExpanded) { diff --git a/iphone/Maps/Maps.xcodeproj/project.pbxproj b/iphone/Maps/Maps.xcodeproj/project.pbxproj index b9ad9d0964..5cf5de9d24 100644 --- a/iphone/Maps/Maps.xcodeproj/project.pbxproj +++ b/iphone/Maps/Maps.xcodeproj/project.pbxproj @@ -330,6 +330,9 @@ 34CA57191C292F50004D9C89 /* MediaPlayer.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 97C9864B186C5EAA00AF7E9E /* MediaPlayer.framework */; }; 34D15BA81BD8F93C00C8BCBE /* AddSetTableViewCell.mm in Sources */ = {isa = PBXBuildFile; fileRef = 34D15BA61BD8F93C00C8BCBE /* AddSetTableViewCell.mm */; }; 34D15BA91BD8F93C00C8BCBE /* AddSetTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 34D15BA71BD8F93C00C8BCBE /* AddSetTableViewCell.xib */; }; + 34D3AFE11E376F7E004100F9 /* UITableView+Updates.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34D3AFE01E376F7E004100F9 /* UITableView+Updates.swift */; }; + 34D3AFE21E376F7E004100F9 /* UITableView+Updates.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34D3AFE01E376F7E004100F9 /* UITableView+Updates.swift */; }; + 34D3AFE31E376F7E004100F9 /* UITableView+Updates.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34D3AFE01E376F7E004100F9 /* UITableView+Updates.swift */; }; 34D4FA621E26572D003F53EF /* FirstLaunchController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34D4FA611E26572D003F53EF /* FirstLaunchController.swift */; }; 34D4FA631E26572D003F53EF /* FirstLaunchController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34D4FA611E26572D003F53EF /* FirstLaunchController.swift */; }; 34D4FA641E26572D003F53EF /* FirstLaunchController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34D4FA611E26572D003F53EF /* FirstLaunchController.swift */; }; @@ -1617,6 +1620,7 @@ 34D15BA51BD8F93C00C8BCBE /* AddSetTableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AddSetTableViewCell.h; sourceTree = ""; }; 34D15BA61BD8F93C00C8BCBE /* AddSetTableViewCell.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = AddSetTableViewCell.mm; sourceTree = ""; }; 34D15BA71BD8F93C00C8BCBE /* AddSetTableViewCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = AddSetTableViewCell.xib; sourceTree = ""; }; + 34D3AFE01E376F7E004100F9 /* UITableView+Updates.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UITableView+Updates.swift"; sourceTree = ""; }; 34D4FA611E26572D003F53EF /* FirstLaunchController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FirstLaunchController.swift; sourceTree = ""; }; 34D4FA651E265749003F53EF /* WhatsNewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WhatsNewController.swift; sourceTree = ""; }; 34F73F601E082FF700AC1FD6 /* ar */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ar; path = ar.lproj/InfoPlist.strings; sourceTree = ""; }; @@ -2719,6 +2723,7 @@ 3454D7AF1E07F045004AF2AD /* UILabel+RuntimeAttributes.mm */, 3454D7B01E07F045004AF2AD /* UISwitch+RuntimeAttributes.h */, 3454D7B11E07F045004AF2AD /* UISwitch+RuntimeAttributes.m */, + 34D3AFE01E376F7E004100F9 /* UITableView+Updates.swift */, 3454D7B21E07F045004AF2AD /* UITextField+RuntimeAttributes.h */, 3454D7B31E07F045004AF2AD /* UITextField+RuntimeAttributes.mm */, 3454D7B41E07F045004AF2AD /* UITextView+RuntimeAttributes.h */, @@ -4869,6 +4874,7 @@ 34ABA6241C2D551900FE1BEC /* MWMInputValidatorFactory.mm in Sources */, 34943BBA1E2626B200B14F84 /* WelcomePageController.swift in Sources */, F6E2FEE11E097BA00083EBEC /* MWMSearchManager.mm in Sources */, + 34D3AFE11E376F7E004100F9 /* UITableView+Updates.swift in Sources */, F6E2FE211E097BA00083EBEC /* MWMOpeningHoursEditorViewController.mm in Sources */, 349D1ADA1E2E325C004A2006 /* MWMBottomMenuView.mm in Sources */, F6E2FD911E097BA00083EBEC /* MWMBookmarkColorViewController.mm in Sources */, @@ -5121,6 +5127,7 @@ F6E2FEE21E097BA00083EBEC /* MWMSearchManager.mm in Sources */, F6E2FE221E097BA00083EBEC /* MWMOpeningHoursEditorViewController.mm in Sources */, 34943BBB1E2626B200B14F84 /* WelcomePageController.swift in Sources */, + 34D3AFE21E376F7E004100F9 /* UITableView+Updates.swift in Sources */, 6741AA141BF340DE002C974C /* MWMMultilineLabel.mm in Sources */, 349D1ADB1E2E325C004A2006 /* MWMBottomMenuView.mm in Sources */, F6E2FD921E097BA00083EBEC /* MWMBookmarkColorViewController.mm in Sources */, @@ -5373,6 +5380,7 @@ F6E2FEE31E097BA00083EBEC /* MWMSearchManager.mm in Sources */, 34943BBC1E2626B200B14F84 /* WelcomePageController.swift in Sources */, F6E2FE231E097BA00083EBEC /* MWMOpeningHoursEditorViewController.mm in Sources */, + 34D3AFE31E376F7E004100F9 /* UITableView+Updates.swift in Sources */, 849CF72F1DE842290024A8A5 /* MWMInputValidator.mm in Sources */, 349D1ADC1E2E325C004A2006 /* MWMBottomMenuView.mm in Sources */, F6E2FD931E097BA00083EBEC /* MWMBookmarkColorViewController.mm in Sources */, diff --git a/iphone/Maps/UI/EditBookmark/MWMEditBookmarkController.mm b/iphone/Maps/UI/EditBookmark/MWMEditBookmarkController.mm index c322abd05b..4229527a83 100644 --- a/iphone/Maps/UI/EditBookmark/MWMEditBookmarkController.mm +++ b/iphone/Maps/UI/EditBookmark/MWMEditBookmarkController.mm @@ -1,11 +1,12 @@ #import "MWMEditBookmarkController.h" -#import "MWMCommon.h" #import "MWMBookmarkColorViewController.h" #import "MWMBookmarkTitleCell.h" #import "MWMButtonCell.h" +#import "MWMCommon.h" #import "MWMNoteCell.h" #import "MWMPlacePageData.h" #import "SelectSetVC.h" +#import "SwiftBridge.h" #import "UIImageView+Coloring.h" #import "UIViewController+Navigation.h" @@ -254,8 +255,7 @@ enum RowInMetaInfo - (void)cellShouldChangeSize:(MWMNoteCell *)cell text:(NSString *)text { self.cachedDescription = text; - [self.tableView beginUpdates]; - [self.tableView endUpdates]; + [self.tableView refresh]; NSIndexPath * ip = [self.tableView indexPathForCell:cell]; [self.tableView scrollToRowAtIndexPath:ip atScrollPosition:UITableViewScrollPositionBottom diff --git a/iphone/Maps/UI/Editor/MWMEditorViewController.mm b/iphone/Maps/UI/Editor/MWMEditorViewController.mm index 2a5f9d41f3..a8d2dfcb47 100644 --- a/iphone/Maps/UI/Editor/MWMEditorViewController.mm +++ b/iphone/Maps/UI/Editor/MWMEditorViewController.mm @@ -823,8 +823,7 @@ void registerCellsForTableView(vector const & cells, UITab { self.offscreenCells[reuseIdentifier(MWMPlacePageCellTypeNote)] = cell; self.note = text; - [self.tableView beginUpdates]; - [self.tableView endUpdates]; + [self.tableView refresh]; NSIndexPath * ip = [self.tableView indexPathForCell:cell]; [self.tableView scrollToRowAtIndexPath:ip atScrollPosition:UITableViewScrollPositionBottom @@ -861,12 +860,10 @@ void registerCellsForTableView(vector const & cells, UITab - (void)tryToChangeInvalidStateForCell:(MWMEditorTextTableViewCell *)cell { - [self.tableView beginUpdates]; - - NSIndexPath * indexPath = [self.tableView indexPathForCell:cell]; - [self.invalidCells removeObject:indexPath]; - - [self.tableView endUpdates]; + [self.tableView update:^{ + NSIndexPath * indexPath = [self.tableView indexPathForCell:cell]; + [self.invalidCells removeObject:indexPath]; + }]; } - (void)cell:(MWMTableViewCell *)cell changedText:(NSString *)changeText diff --git a/iphone/Maps/UI/Editor/OpeningHours/MWMOpeningHoursSection.mm b/iphone/Maps/UI/Editor/OpeningHours/MWMOpeningHoursSection.mm index 8cedd6f643..39376895a0 100644 --- a/iphone/Maps/UI/Editor/OpeningHours/MWMOpeningHoursSection.mm +++ b/iphone/Maps/UI/Editor/OpeningHours/MWMOpeningHoursSection.mm @@ -1,6 +1,7 @@ -#import "MWMOpeningHoursCommon.h" #import "MWMOpeningHoursSection.h" +#import "MWMOpeningHoursCommon.h" #import "MWMOpeningHoursTableViewCell.h" +#import "SwiftBridge.h" #include "3party/opening_hours/opening_hours.hpp" #include "editor/opening_hours_ui.hpp" @@ -202,13 +203,10 @@ using namespace osmoh; if (closedTimesCountAfterUpdate > closedTimesCountBeforeUpdate) { - UITableView * tableView = self.delegate.tableView; - [tableView beginUpdates]; - - [self insertRow:row]; - self.selectedRow = @(row); - - [tableView endUpdates]; + [self.delegate.tableView update:^{ + [self insertRow:row]; + self.selectedRow = @(row); + }]; } [self refresh:NO]; } @@ -219,16 +217,14 @@ using namespace osmoh; self.skipStoreCachedData = [self isRowSelected:row]; if (closedTimesCountBeforeUpdate == [self closedTimesCount]) { - UITableView * tableView = self.delegate.tableView; - [tableView beginUpdates]; + [self.delegate.tableView update:^{ + TTimeTableProxy timeTable = [self timeTableProxy]; + timeTable.RemoveExcludeTime([self closedTimeIndex:row]); + timeTable.Commit(); - TTimeTableProxy timeTable = [self timeTableProxy]; - timeTable.RemoveExcludeTime([self closedTimeIndex:row]); - timeTable.Commit(); - - self.selectedRow = nil; - [self deleteRow:row]; - [tableView endUpdates]; + self.selectedRow = nil; + [self deleteRow:row]; + }]; } [self refresh:NO]; } @@ -281,22 +277,23 @@ using namespace osmoh; - (void)refreshForNewRowCount:(NSUInteger)newRowCount oldRowCount:(NSUInteger)oldRowCount { NSAssert(newRowCount != oldRowCount, @"Invalid rows change"); - UITableView * tableView = self.delegate.tableView; - [tableView beginUpdates]; - BOOL const addRows = newRowCount > oldRowCount; NSUInteger const minRows = MIN(newRowCount, oldRowCount); NSUInteger const maxRows = MAX(newRowCount, oldRowCount); NSMutableArray * indexes = [NSMutableArray arrayWithCapacity:maxRows - minRows]; - for (NSUInteger row = minRows; row < maxRows; ++row) - [indexes addObject:[NSIndexPath indexPathForRow:row inSection:self.index]]; - if (addRows) - [tableView insertRowsAtIndexPaths:indexes withRowAnimation:kMWMOpeningHoursEditorRowAnimation]; - else - [tableView deleteRowsAtIndexPaths:indexes withRowAnimation:kMWMOpeningHoursEditorRowAnimation]; + UITableView * tableView = self.delegate.tableView; + [tableView update:^{ + for (NSUInteger row = minRows; row < maxRows; ++row) + [indexes addObject:[NSIndexPath indexPathForRow:row inSection:self.index]]; - [tableView endUpdates]; + if (addRows) + [tableView insertRowsAtIndexPaths:indexes + withRowAnimation:kMWMOpeningHoursEditorRowAnimation]; + else + [tableView deleteRowsAtIndexPaths:indexes + withRowAnimation:kMWMOpeningHoursEditorRowAnimation]; + }]; [self refresh:NO]; } @@ -347,36 +344,34 @@ using namespace osmoh; id delegate = self.delegate; UITableView * tableView = delegate.tableView; - [tableView beginUpdates]; - - if (!oldSelectedRow) - { - _selectedRow = selectedRow; - [self insertRow:newInd + 1]; - [delegate updateActiveSection:self.index]; - } - else if (selectedRow) - { - if (newInd < oldInd) + [tableView update:^{ + if (!oldSelectedRow) { - _selectedRow = selectedRow; + self->_selectedRow = selectedRow; [self insertRow:newInd + 1]; + [delegate updateActiveSection:self.index]; + } + else if (selectedRow) + { + if (newInd < oldInd) + { + self->_selectedRow = selectedRow; + [self insertRow:newInd + 1]; + } + else + { + self->_selectedRow = @(newInd - 1); + [self insertRow:newInd]; + } + + [self deleteRow:oldInd + 1]; } else { - _selectedRow = @(newInd - 1); - [self insertRow:newInd]; + self->_selectedRow = selectedRow; + [self deleteRow:oldInd + 1]; } - - [self deleteRow:oldInd + 1]; - } - else - { - _selectedRow = selectedRow; - [self deleteRow:oldInd + 1]; - } - - [tableView endUpdates]; + }]; [self scrollToSelection]; } diff --git a/iphone/Maps/UI/PlacePage/PlacePageLayout/MWMPlacePageLayout.mm b/iphone/Maps/UI/PlacePage/PlacePageLayout/MWMPlacePageLayout.mm index e24ec01608..42e6a2fb17 100644 --- a/iphone/Maps/UI/PlacePage/PlacePageLayout/MWMPlacePageLayout.mm +++ b/iphone/Maps/UI/PlacePage/PlacePageLayout/MWMPlacePageLayout.mm @@ -1,16 +1,17 @@ #import "MWMPlacePageLayout.h" #import "MWMBookmarkCell.h" #import "MWMCircularProgress.h" -#import "MWMiPadPlacePageLayoutImpl.h" -#import "MWMiPhonePlacePageLayoutImpl.h" #import "MWMOpeningHoursLayoutHelper.h" +#import "MWMPPPreviewLayoutHelper.h" #import "MWMPlacePageButtonCell.h" #import "MWMPlacePageCellUpdateProtocol.h" #import "MWMPlacePageData.h" #import "MWMPlacePageInfoCell.h" #import "MWMPlacePageLayoutImpl.h" #import "MWMPlacePageTaxiCell.h" -#import "MWMPPPreviewLayoutHelper.h" +#import "MWMiPadPlacePageLayoutImpl.h" +#import "MWMiPhonePlacePageLayoutImpl.h" +#import "SwiftBridge.h" #include "storage/storage.hpp" @@ -376,9 +377,7 @@ array const kButtonsCells = {{@"MWMPlacePageButtonCell"}}; - (void)update { - auto tableView = self.placePageView.tableView; - [tableView beginUpdates]; - [tableView endUpdates]; + [self.placePageView.tableView refresh]; } #pragma mark - MWMPlacePageViewUpdateProtocol