forked from organicmaps/organicmaps
[cleanup] [ios] Code cleanup.
This commit is contained in:
parent
f0c5c39a26
commit
c627c38b21
7 changed files with 84 additions and 72 deletions
13
iphone/Maps/Categories/UITableView+Updates.swift
Normal file
13
iphone/Maps/Categories/UITableView+Updates.swift
Normal file
|
@ -0,0 +1,13 @@
|
|||
extension UITableView {
|
||||
typealias Updates = () -> Void
|
||||
|
||||
func update(_ updates: Updates) {
|
||||
beginUpdates()
|
||||
updates()
|
||||
endUpdates()
|
||||
}
|
||||
|
||||
func refresh() {
|
||||
update {}
|
||||
}
|
||||
}
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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 = "<group>"; };
|
||||
34D15BA61BD8F93C00C8BCBE /* AddSetTableViewCell.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = AddSetTableViewCell.mm; sourceTree = "<group>"; };
|
||||
34D15BA71BD8F93C00C8BCBE /* AddSetTableViewCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = AddSetTableViewCell.xib; sourceTree = "<group>"; };
|
||||
34D3AFE01E376F7E004100F9 /* UITableView+Updates.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UITableView+Updates.swift"; sourceTree = "<group>"; };
|
||||
34D4FA611E26572D003F53EF /* FirstLaunchController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FirstLaunchController.swift; sourceTree = "<group>"; };
|
||||
34D4FA651E265749003F53EF /* WhatsNewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WhatsNewController.swift; sourceTree = "<group>"; };
|
||||
34F73F601E082FF700AC1FD6 /* ar */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ar; path = ar.lproj/InfoPlist.strings; sourceTree = "<group>"; };
|
||||
|
@ -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 */,
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -823,8 +823,7 @@ void registerCellsForTableView(vector<MWMPlacePageCellType> 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<MWMPlacePageCellType> 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
|
||||
|
|
|
@ -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<NSIndexPath *> * 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<MWMOpeningHoursSectionProtocol> 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];
|
||||
}
|
||||
|
||||
|
|
|
@ -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<NSString *, 1> const kButtonsCells = {{@"MWMPlacePageButtonCell"}};
|
|||
|
||||
- (void)update
|
||||
{
|
||||
auto tableView = self.placePageView.tableView;
|
||||
[tableView beginUpdates];
|
||||
[tableView endUpdates];
|
||||
[self.placePageView.tableView refresh];
|
||||
}
|
||||
|
||||
#pragma mark - MWMPlacePageViewUpdateProtocol
|
||||
|
|
Loading…
Add table
Reference in a new issue