[bookmarks][iOS] Refactoring.

This commit is contained in:
Daria Volvenkova 2019-08-07 20:03:35 +03:00 committed by Aleksey Belousov
parent cf5325423b
commit 63176abb8e
10 changed files with 833 additions and 771 deletions

View file

@ -1,67 +1,24 @@
#import "MWMTypes.h"
#include "platform/location.hpp"
#import "TableSectionDataSource.h"
#include "kml/type_utils.hpp"
@protocol TableSectionDelegate <NSObject>
- (NSInteger)numberOfRows;
- (NSString *)title;
- (BOOL)canEdit;
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRow:(NSInteger)row;
- (BOOL)didSelectRow:(NSInteger)row;
- (void)deleteRow:(NSInteger)row;
@optional
-(void)updateCell:(UITableViewCell *)cell forRow:(NSInteger)row withNewLocation:(location::GpsInfo const &)gpsInfo;
@end
@class BookmarksSection;
@protocol BookmarksSectionDelegate <NSObject>
- (NSInteger)numberOfBookmarksInSection:(BookmarksSection *)bookmarkSection;
- (NSString *)titleOfBookmarksSection:(BookmarksSection *)bookmarkSection;
- (BOOL)canEditBookmarksSection:(BookmarksSection *)bookmarkSection;
- (kml::MarkId)bookmarkSection:(BookmarksSection *)bookmarkSection getBookmarkIdByRow:(NSInteger)row;
- (void)bookmarkSection:(BookmarksSection *)bookmarkSection onDeleteBookmarkInRow:(NSInteger)row;
- (BOOL)bookmarkSection:(BookmarksSection *)bookmarkSection onDeleteBookmarkInRow:(NSInteger)row;
@end
@class TracksSection;
@protocol TracksSectionDelegate <NSObject>
- (NSInteger)numberOfTracksInSection:(TracksSection *)tracksSection;
- (NSString *)titleOfTracksSection:(TracksSection *)tracksSection;
- (BOOL)canEditTracksSection:(TracksSection *)tracksSection;
- (kml::MarkId)tracksSection:(TracksSection *)tracksSection getTrackIdByRow:(NSInteger)row;
- (void)tracksSection:(TracksSection *)tracksSection onDeleteTrackInRow:(NSInteger)row;
@end
@protocol InfoSectionDelegate <NSObject>
- (UITableViewCell *)infoCellForTableView:(UITableView *)tableView;
@end
@interface BookmarksSection : NSObject <TableSectionDelegate>
@interface BookmarksSection : NSObject <TableSectionDataSource>
@property (nullable, nonatomic) NSNumber * blockIndex;
- (instancetype)initWithDelegate:(id<BookmarksSectionDelegate>)delegate;
- (instancetype)initWithBlockIndex:(NSNumber *)blockIndex delegate:(id<BookmarksSectionDelegate>)delegate;
@end
@interface TracksSection : NSObject <TableSectionDelegate>
@property (nullable, nonatomic) NSNumber * blockIndex;
- (instancetype)initWithDelegate:(id<TracksSectionDelegate>)delegate;
- (instancetype)initWithBlockIndex:(NSNumber *)blockIndex delegate: (id<TracksSectionDelegate>)delegate;
@end
@interface InfoSection : NSObject <TableSectionDelegate>
- (instancetype)initWithDelegate:(id<InfoSectionDelegate>)delegate;
@end

View file

@ -2,7 +2,6 @@
#import "CircleView.h"
#import "ColorPickerView.h"
#import "MWMBookmarksManager.h"
#import "MWMCategoryInfoCell.h"
#import "MWMLocationHelpers.h"
#import "MWMSearchManager.h"
#include "Framework.h"
@ -80,8 +79,10 @@ CGFloat const kPinDiameter = 22.0f;
{
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"BookmarksVCBookmarkItemCell"];
if (!cell)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:@"BookmarksVCBookmarkItemCell"];
}
CHECK(cell, ("Invalid bookmark cell."));
kml::MarkId const bmId = [self.delegate bookmarkSection:self getBookmarkIdByRow:row];
@ -119,149 +120,11 @@ CGFloat const kPinDiameter = 22.0f;
return YES;
}
- (void)deleteRow: (NSInteger)row
- (BOOL)deleteRow: (NSInteger)row
{
kml::MarkId const bmId = [self.delegate bookmarkSection:self getBookmarkIdByRow:row];
[[MWMBookmarksManager sharedManager] deleteBookmark:bmId];
[self.delegate bookmarkSection:self onDeleteBookmarkInRow:row];
}
@end
////////////////////////////////////////////////////////
@interface TracksSection()
@property (weak, nonatomic) id<TracksSectionDelegate> delegate;
@end
@implementation TracksSection
- (instancetype)initWithDelegate:(id<TracksSectionDelegate>)delegate
{
return [self initWithBlockIndex:nil delegate:delegate];
}
- (instancetype)initWithBlockIndex:(NSNumber *)blockIndex delegate: (id<TracksSectionDelegate>)delegate
{
self = [super init];
if (self)
{
_blockIndex = blockIndex;
_delegate = delegate;
}
return self;
}
- (NSInteger)numberOfRows
{
return [self.delegate numberOfTracksInSection:self];
}
- (NSString *)title
{
return [self.delegate titleOfTracksSection:self];
}
- (BOOL)canEdit
{
return [self.delegate canEditTracksSection:self];
}
- (UITableViewCell *)tableView: (UITableView *)tableView cellForRow: (NSInteger)row
{
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"TrackCell"];
if (!cell)
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"TrackCell"];
CHECK(cell, ("Invalid track cell."));
auto const & bm = GetFramework().GetBookmarkManager();
kml::TrackId const trackId = [self.delegate tracksSection:self getTrackIdByRow:row];
Track const * track = bm.GetTrack(trackId);
cell.textLabel.text = @(track->GetName().c_str());
string dist;
if (measurement_utils::FormatDistance(track->GetLengthMeters(), dist))
//Change Length before release!!!
cell.detailTextLabel.text = [NSString stringWithFormat:@"%@ %@", L(@"length"), @(dist.c_str())];
else
cell.detailTextLabel.text = nil;
dp::Color const c = track->GetColor(0);
cell.imageView.image = [CircleView createCircleImageWith:kPinDiameter
andColor:[UIColor colorWithRed:c.GetRed()/255.f
green:c.GetGreen()/255.f
blue:c.GetBlue()/255.f
alpha:1.f]];
return cell;
}
- (BOOL)didSelectRow: (NSInteger)row
{
kml::TrackId const trackId = [self.delegate tracksSection:self getTrackIdByRow:row];
GetFramework().ShowTrack(trackId);
return YES;
}
- (void)deleteRow: (NSInteger)row
{
// TODO(@darina): [[MWMBookmarksManager sharedManager] deleteTrack:bmId];?
kml::TrackId const trackId = [self.delegate tracksSection:self getTrackIdByRow:row];
auto & bm = GetFramework().GetBookmarkManager();
bm.GetEditSession().DeleteTrack(trackId);
[self.delegate tracksSection:self onDeleteTrackInRow:row];
}
@end
////////////////////////////////////////////////////////
@interface InfoSection()
@property (weak, nonatomic) id<InfoSectionDelegate> delegate;
@end
@implementation InfoSection
- (instancetype)initWithDelegate: (id<InfoSectionDelegate>)delegate
{
self = [super init];
if (self)
{
_delegate = delegate;
}
return self;
}
- (NSInteger)numberOfRows
{
return 1;
}
- (NSString *)title
{
return L(@"placepage_place_description");
}
- (BOOL)canEdit
{
return NO;
}
- (UITableViewCell *)tableView: (UITableView *)tableView cellForRow: (NSInteger)row
{
return [self.delegate infoCellForTableView:tableView];
}
- (BOOL)didSelectRow: (NSInteger)row
{
return NO;
}
- (void)deleteRow: (NSInteger)row
{
return [self.delegate bookmarkSection:self onDeleteBookmarkInRow:row];
}
@end

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,14 @@
#import "TableSectionDataSource.h"
@protocol InfoSectionDelegate <NSObject>
- (UITableViewCell *)infoCellForTableView:(UITableView *)tableView;
@end
@interface InfoSection : NSObject <TableSectionDataSource>
- (instancetype)initWithDelegate:(id<InfoSectionDelegate>)delegate;
@end

View file

@ -0,0 +1,51 @@
#import "InfoSection.h"
@interface InfoSection()
@property (weak, nonatomic) id<InfoSectionDelegate> delegate;
@end
@implementation InfoSection
- (instancetype)initWithDelegate: (id<InfoSectionDelegate>)delegate
{
self = [super init];
if (self)
{
_delegate = delegate;
}
return self;
}
- (NSInteger)numberOfRows
{
return 1;
}
- (NSString *)title
{
return L(@"placepage_place_description");
}
- (BOOL)canEdit
{
return NO;
}
- (UITableViewCell *)tableView: (UITableView *)tableView cellForRow: (NSInteger)row
{
return [self.delegate infoCellForTableView:tableView];
}
- (BOOL)didSelectRow: (NSInteger)row
{
return NO;
}
- (BOOL)deleteRow: (NSInteger)row
{
return YES;
}
@end

View file

@ -1,5 +1,5 @@
#import "MWMTableViewCell.h"
#import "BookmarksSection.h"
#import "InfoSection.h"
namespace kml
{

View file

@ -0,0 +1,21 @@
#include "platform/location.hpp"
@protocol TableSectionDataSource <NSObject>
- (NSInteger)numberOfRows;
- (NSString *)title;
- (BOOL)canEdit;
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRow:(NSInteger)row;
- (BOOL)didSelectRow:(NSInteger)row;
- (BOOL)deleteRow:(NSInteger)row;
@optional
-(void)updateCell:(UITableViewCell *)cell
forRow:(NSInteger)row
withNewLocation:(location::GpsInfo const &)gpsInfo;
@end

View file

@ -0,0 +1,26 @@
#import "TableSectionDataSource.h"
#include "kml/type_utils.hpp"
@class TracksSection;
@protocol TracksSectionDelegate <NSObject>
- (NSInteger)numberOfTracksInSection:(TracksSection *)tracksSection;
- (NSString *)titleOfTracksSection:(TracksSection *)tracksSection;
- (BOOL)canEditTracksSection:(TracksSection *)tracksSection;
- (kml::MarkId)tracksSection:(TracksSection *)tracksSection getTrackIdByRow:(NSInteger)row;
- (BOOL)tracksSection:(TracksSection *)tracksSection onDeleteTrackInRow:(NSInteger)row;
@end
@interface TracksSection : NSObject <TableSectionDataSource>
@property (nullable, nonatomic) NSNumber * blockIndex;
- (instancetype)initWithDelegate:(id<TracksSectionDelegate>)delegate;
- (instancetype)initWithBlockIndex:(NSNumber *)blockIndex
delegate:(id<TracksSectionDelegate>)delegate;
@end

View file

@ -0,0 +1,90 @@
#import "TracksSection.h"
#import "CircleView.h"
#include "Framework.h"
namespace
{
CGFloat const kPinDiameter = 22.0f;
} // namespace
@interface TracksSection()
@property (weak, nonatomic) id<TracksSectionDelegate> delegate;
@end
@implementation TracksSection
- (instancetype)initWithDelegate:(id<TracksSectionDelegate>)delegate
{
return [self initWithBlockIndex:nil delegate:delegate];
}
- (instancetype)initWithBlockIndex:(NSNumber *)blockIndex delegate: (id<TracksSectionDelegate>)delegate
{
self = [super init];
if (self)
{
_blockIndex = blockIndex;
_delegate = delegate;
}
return self;
}
- (NSInteger)numberOfRows
{
return [self.delegate numberOfTracksInSection:self];
}
- (NSString *)title
{
return [self.delegate titleOfTracksSection:self];
}
- (BOOL)canEdit
{
return [self.delegate canEditTracksSection:self];
}
- (UITableViewCell *)tableView: (UITableView *)tableView cellForRow: (NSInteger)row
{
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"TrackCell"];
if (!cell)
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"TrackCell"];
CHECK(cell, ("Invalid track cell."));
auto const & bm = GetFramework().GetBookmarkManager();
kml::TrackId const trackId = [self.delegate tracksSection:self getTrackIdByRow:row];
Track const * track = bm.GetTrack(trackId);
cell.textLabel.text = @(track->GetName().c_str());
string dist;
if (measurement_utils::FormatDistance(track->GetLengthMeters(), dist))
cell.detailTextLabel.text = [NSString stringWithFormat:@"%@ %@", L(@"length"), @(dist.c_str())];
else
cell.detailTextLabel.text = nil;
dp::Color const c = track->GetColor(0);
cell.imageView.image = [CircleView createCircleImageWith:kPinDiameter
andColor:[UIColor colorWithRed:c.GetRedF()
green:c.GetGreenF()
blue:c.GetBlueF()
alpha:1.f]];
return cell;
}
- (BOOL)didSelectRow: (NSInteger)row
{
kml::TrackId const trackId = [self.delegate tracksSection:self getTrackIdByRow:row];
GetFramework().ShowTrack(trackId);
return YES;
}
- (BOOL)deleteRow: (NSInteger)row
{
kml::TrackId const trackId = [self.delegate tracksSection:self getTrackIdByRow:row];
auto & bm = GetFramework().GetBookmarkManager();
bm.GetEditSession().DeleteTrack(trackId);
return [self.delegate tracksSection:self onDeleteTrackInRow:row];
}
@end

View file

@ -589,6 +589,8 @@
BB8123CF212C264700ADE512 /* Metal.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BB8123CD212C264700ADE512 /* Metal.framework */; settings = {ATTRIBUTES = (Weak, ); }; };
BB8123D0212C264700ADE512 /* MetalKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BB8123CE212C264700ADE512 /* MetalKit.framework */; settings = {ATTRIBUTES = (Weak, ); }; };
BB8123D62130427E00ADE512 /* MetalContextFactory.mm in Sources */ = {isa = PBXBuildFile; fileRef = BB8123D52130427E00ADE512 /* MetalContextFactory.mm */; };
BB87BF8A22FAF1CA008A8A72 /* TracksSection.mm in Sources */ = {isa = PBXBuildFile; fileRef = BB87BF8922FAF1CA008A8A72 /* TracksSection.mm */; };
BB87BF8D22FAF435008A8A72 /* InfoSection.mm in Sources */ = {isa = PBXBuildFile; fileRef = BB87BF8C22FAF435008A8A72 /* InfoSection.mm */; };
BBED27022292F6C000788143 /* BookmarksSection.mm in Sources */ = {isa = PBXBuildFile; fileRef = BBED27012292F6C000788143 /* BookmarksSection.mm */; };
CD08887422B7ABB400C1368D /* MWMDiscoveryCollectionView.mm in Sources */ = {isa = PBXBuildFile; fileRef = CD08887322B7ABB400C1368D /* MWMDiscoveryCollectionView.mm */; };
CD4A1F132305872700F2A6B6 /* PromoBookingPresentationController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD4A1F122305872700F2A6B6 /* PromoBookingPresentationController.swift */; };
@ -1679,6 +1681,11 @@
BB8123CE212C264700ADE512 /* MetalKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MetalKit.framework; path = System/Library/Frameworks/MetalKit.framework; sourceTree = SDKROOT; };
BB8123D42130427E00ADE512 /* MetalContextFactory.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MetalContextFactory.h; sourceTree = "<group>"; };
BB8123D52130427E00ADE512 /* MetalContextFactory.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = MetalContextFactory.mm; sourceTree = "<group>"; };
BB87BF8722FAEC82008A8A72 /* TableSectionDataSource.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TableSectionDataSource.h; sourceTree = "<group>"; };
BB87BF8822FAF125008A8A72 /* TracksSection.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TracksSection.h; sourceTree = "<group>"; };
BB87BF8922FAF1CA008A8A72 /* TracksSection.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = TracksSection.mm; sourceTree = "<group>"; };
BB87BF8B22FAF3B8008A8A72 /* InfoSection.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = InfoSection.h; sourceTree = "<group>"; };
BB87BF8C22FAF435008A8A72 /* InfoSection.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = InfoSection.mm; sourceTree = "<group>"; };
BBED27002292F42000788143 /* BookmarksSection.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BookmarksSection.h; sourceTree = "<group>"; };
BBED27012292F6C000788143 /* BookmarksSection.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = BookmarksSection.mm; sourceTree = "<group>"; };
CD08887222B7ABB400C1368D /* MWMDiscoveryCollectionView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MWMDiscoveryCollectionView.h; sourceTree = "<group>"; };
@ -4735,6 +4742,11 @@
B33D21B720E130D000BAD749 /* BookmarksTabViewController.swift */,
BBED27002292F42000788143 /* BookmarksSection.h */,
BBED27012292F6C000788143 /* BookmarksSection.mm */,
BB87BF8722FAEC82008A8A72 /* TableSectionDataSource.h */,
BB87BF8822FAF125008A8A72 /* TracksSection.h */,
BB87BF8922FAF1CA008A8A72 /* TracksSection.mm */,
BB87BF8B22FAF3B8008A8A72 /* InfoSection.h */,
BB87BF8C22FAF435008A8A72 /* InfoSection.mm */,
);
path = Bookmarks;
sourceTree = "<group>";
@ -5420,6 +5432,7 @@
CDCA2745223FCFD200167D87 /* SearchResultInfo.swift in Sources */,
349A13831DEC138C00C7DB60 /* MWMMobileInternetAlert.mm in Sources */,
349D1ADE1E2E325C004A2006 /* MWMBottomMenuViewController.mm in Sources */,
BB87BF8A22FAF1CA008A8A72 /* TracksSection.mm in Sources */,
6741A9EC1BF340DE002C974C /* MWMCircularProgress.mm in Sources */,
470A89FD21342A9D00D72FBF /* TutorialBlurView.swift in Sources */,
342CC5F21C2D7730005F3FE5 /* MWMAuthorizationLoginViewController.mm in Sources */,
@ -5454,6 +5467,7 @@
3358607E217632A2006D11F2 /* BookmarksSharingViewController.swift in Sources */,
CDB92CF1229EB8A800EC757C /* MWMDiscoverySearchViewModel.m in Sources */,
34AB662F1FC5AA330078E451 /* RouteManageriPhonePresentationController.swift in Sources */,
BB87BF8D22FAF435008A8A72 /* InfoSection.mm in Sources */,
4797A4DC226F4B2900D3A984 /* DeepLinkHandler.swift in Sources */,
34AB66201FC5AA330078E451 /* RouteStartButton.swift in Sources */,
34F4072C1E9E1AFF00E57AC0 /* Banner.swift in Sources */,