Improved separators presentation.

This commit is contained in:
Timur Bernikowich 2014-10-27 11:53:37 +03:00 committed by Alex Zolotarev
parent 0ca8735f17
commit 7720f8706e
5 changed files with 92 additions and 9 deletions

View file

@ -208,7 +208,7 @@
if (group == ActiveMapsLayout::TGroup::EOutOfDate)
{
BadgeView * badge = [[BadgeView alloc] init];
badge.value = self.mapsLayout.GetOutOfDateCount() + 25;
badge.value = self.mapsLayout.GetOutOfDateCount();
badge.center = CGPointMake(label.maxX + badge.width - 3, label.midY - 1.0 / [UIScreen mainScreen].scale);
[view addSubview:badge];
self.outOfDateBadge = badge;
@ -251,12 +251,19 @@
TStatus const status = self.mapsLayout.GetCountryStatus(group, position);
TMapOptions const options = self.mapsLayout.GetCountryOptions(group, position);
NSInteger const numberOfRows = [self tableView:tableView numberOfRowsInSection:indexPath.section];
BOOL const isLast = (indexPath.row == numberOfRows - 1);
BOOL const isFirst = (indexPath.row == 0);
cell.titleLabel.text = [NSString stringWithUTF8String:self.mapsLayout.GetCountryName(group, position).c_str()];
cell.parentMode = NO;
cell.status = status;
cell.options = options;
cell.delegate = self;
cell.badgeView.value = 0;
cell.separatorTop.hidden = !isFirst;
cell.separatorBottom.hidden = !isLast;
cell.separator.hidden = isLast;
if (status == TStatus::EOutOfMemFailed || status == TStatus::EDownloadFailed || status == TStatus::EDownloading || status == TStatus::EInQueue)
{
@ -268,6 +275,31 @@
return cell;
}
- (void)updateAllCellsSeprators
{
NSInteger numberOfSection = [self numberOfSectionsInTableView:self.tableView];
for (NSInteger section = 0; section < numberOfSection; section++)
{
NSInteger numberOfRows = [self tableView:self.tableView numberOfRowsInSection:section];
for (NSInteger row = 0; row < numberOfRows; row++)
{
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:row inSection:section];
[self updateSeparatorsForCellAtIndexPath:indexPath];
}
}
}
- (void)updateSeparatorsForCellAtIndexPath:(NSIndexPath *)indexPath
{
MapCell * cell = (MapCell *)[self.tableView cellForRowAtIndexPath:indexPath];
NSInteger const numberOfRows = [self tableView:self.tableView numberOfRowsInSection:indexPath.section];
BOOL const isLast = (indexPath.row == numberOfRows - 1);
BOOL const isFirst = (indexPath.row == 0);
cell.separatorTop.hidden = !isFirst;
cell.separatorBottom.hidden = !isLast;
cell.separator.hidden = isLast;
}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
TStatus const status = self.mapsLayout.GetCountryStatus([self groupWithSection:indexPath.section], indexPath.row);
@ -283,6 +315,7 @@
TMapOptions const options = self.mapsLayout.GetCountryOptions(group, position);
self.mapsLayout.DeleteMap(group, position, options);
[tableView setEditing:NO animated:YES];
[self updateAllCellsSeprators];
}
}
@ -366,6 +399,7 @@
NSIndexPath * newIndexPath = [NSIndexPath indexPathForRow:newPosition inSection:(NSInteger)newGroup];
[self.tableView moveRowAtIndexPath:oldIndexPath toIndexPath:newIndexPath];
}
[self updateAllCellsSeprators];
}
- (void)countryDownloadingProgressChanged:(LocalAndRemoteSizeT const &)progress atPosition:(int)position inGroup:(ActiveMapsLayout::TGroup const &)group

View file

@ -8,6 +8,7 @@
#define L(str) NSLocalizedString(str, nil)
#define INTEGRAL(f) ([UIScreen mainScreen].scale == 1 ? floor(f) : f)
#define PIXEL 1.0 / [UIScreen mainScreen].scale
@interface NSObject (Optimized)

View file

@ -23,6 +23,10 @@ using namespace storage;
@property (nonatomic, readonly) UILabel * sizeLabel;
@property (nonatomic, readonly) BadgeView * badgeView;
@property (nonatomic, readonly) UIView *separatorTop;
@property (nonatomic, readonly) UIView *separator;
@property (nonatomic, readonly) UIView *separatorBottom;
@property (nonatomic) BOOL parentMode;
@property (nonatomic) TStatus status;

View file

@ -12,7 +12,10 @@
@property (nonatomic) UIImageView * arrowView;
@property (nonatomic) BadgeView * badgeView;
@property (nonatomic) UIImageView * routingImageView;
@property (nonatomic) UIImageView * separator;
@property (nonatomic) UIView *separatorTop;
@property (nonatomic) UIView *separator;
@property (nonatomic) UIView *separatorBottom;
@property (nonatomic, readonly) BOOL progressMode;
@ -24,7 +27,7 @@
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
NSArray * subviews = @[self.titleLabel, self.subtitleLabel, self.statusLabel, self.sizeLabel, self.progressView, self.arrowView, self.badgeView, self.routingImageView, self.separator];
NSArray * subviews = @[self.titleLabel, self.subtitleLabel, self.statusLabel, self.sizeLabel, self.progressView, self.arrowView, self.badgeView, self.routingImageView, self.separator, self.separatorTop, self.separatorBottom];
for (UIView * subview in subviews)
[self.contentView addSubview:subview];
@ -162,6 +165,19 @@
self.routingImageView.center = CGPointMake(self.width - 25, self.height / 2 - 1);
self.routingImageView.alpha = [self shouldShowRoutingView];
self.separatorTop.frame = CGRectMake(0, 0, self.width, PIXEL);
self.separatorTop.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleBottomMargin;
self.separatorBottom.frame = CGRectMake(0, self.height - PIXEL, self.width, PIXEL);
self.separatorBottom.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleTopMargin;
}
- (void)prepareForReuse
{
self.separatorTop.hidden = YES;
self.separatorBottom.hidden = YES;
self.separator.hidden = NO;
}
- (void)layoutSubviews
@ -177,8 +193,8 @@
self.badgeView.minY = self.titleLabel.minY - 5;
self.separator.minX = self.titleLabel.minX;
self.separator.size = CGSizeMake(self.width - 2 * self.separator.minX, 1);
self.separator.maxY = self.height + 0.5;
self.separator.size = CGSizeMake(self.width - 2 * self.separator.minX, PIXEL);
self.separator.maxY = self.height;
}
@ -306,15 +322,34 @@
return _badgeView;
}
- (UIImageView *)separator
- (UIView *)separatorTop
{
if (!_separatorTop)
{
_separatorTop = [[UIView alloc] initWithFrame:CGRectZero];
_separatorTop.backgroundColor = [UIColor colorWithColorCode:@"cecece"];
}
return _separatorTop;
}
- (UIView *)separator
{
if (!_separator)
{
UIImage * separatorImage = [[UIImage imageNamed:@"MapCellSeparator"] resizableImageWithCapInsets:UIEdgeInsetsZero];
_separator = [[UIImageView alloc] initWithFrame:CGRectZero];
_separator.image = separatorImage;
_separator = [[UIView alloc] initWithFrame:CGRectZero];
_separator.backgroundColor = [UIColor colorWithColorCode:@"cecece"];
}
return _separator;
}
- (UIView *)separatorBottom
{
if (!_separatorBottom)
{
_separatorBottom = [[UIView alloc] initWithFrame:CGRectZero];
_separatorBottom.backgroundColor = [UIColor colorWithColorCode:@"cecece"];
}
return _separatorBottom;
}
@end

View file

@ -224,17 +224,26 @@
cell.subtitleLabel.text = nil;
cell.parentMode = YES;
cell.badgeView.value = self.tree.GetActiveMapLayout().GetOutOfDateCount();
cell.separatorTop.hidden = NO;
cell.separatorBottom.hidden = NO;
cell.separator.hidden = YES;
}
else
{
int const position = indexPath.row;
bool const isLeaf = self.tree.IsLeaf(position);
NSInteger const numberOfRows = [self tableView:tableView numberOfRowsInSection:indexPath.section];
BOOL const isLast = (indexPath.row == numberOfRows - 1);
BOOL const isFirst = (indexPath.row == 0);
cell.titleLabel.text = [NSString stringWithUTF8String:self.tree.GetChildName(position).c_str()];
cell.subtitleLabel.text = [self parentTitle];
cell.delegate = self;
cell.badgeView.value = 0;
cell.parentMode = !isLeaf;
cell.separatorTop.hidden = !isFirst;
cell.separatorBottom.hidden = !isLast;
cell.separator.hidden = isLast;
if (isLeaf)
{
TMapOptions const options = self.tree.GetLeafOptions(position);