forked from organicmaps/organicmaps
[ios] Code cleanup.
This commit is contained in:
parent
779c030722
commit
7e0fc7ea18
4 changed files with 66 additions and 69 deletions
|
@ -1,5 +1,7 @@
|
|||
#import "MWMButton.h"
|
||||
|
||||
#include "std/vector.hpp"
|
||||
|
||||
typedef NS_ENUM(NSInteger, MWMCircularProgressState)
|
||||
{
|
||||
MWMCircularProgressStateNormal,
|
||||
|
@ -10,6 +12,8 @@ typedef NS_ENUM(NSInteger, MWMCircularProgressState)
|
|||
MWMCircularProgressStateCompleted
|
||||
};
|
||||
|
||||
using MWMCircularProgressStateVec = vector<MWMCircularProgressState>;
|
||||
|
||||
@class MWMCircularProgress;
|
||||
|
||||
@protocol MWMCircularProgressProtocol <NSObject>
|
||||
|
@ -26,9 +30,9 @@ typedef NS_ENUM(NSInteger, MWMCircularProgressState)
|
|||
@property (nonatomic) MWMCircularProgressState state;
|
||||
@property (weak, nonatomic) id<MWMCircularProgressProtocol> delegate;
|
||||
|
||||
- (void)setImage:(nonnull UIImage *)image forState:(MWMCircularProgressState)state;
|
||||
- (void)setColor:(nonnull UIColor *)color forState:(MWMCircularProgressState)state;
|
||||
- (void)setColoring:(MWMButtonColoring)coloring forState:(MWMCircularProgressState)state;
|
||||
- (void)setImage:(nonnull UIImage *)image forStates:(MWMCircularProgressStateVec const &)states;
|
||||
- (void)setColor:(nonnull UIColor *)color forStates:(MWMCircularProgressStateVec const &)states;
|
||||
- (void)setColoring:(MWMButtonColoring)coloring forStates:(MWMCircularProgressStateVec const &)states;
|
||||
- (void)setInvertColor:(BOOL)invertColor;
|
||||
|
||||
- (nonnull instancetype)init __attribute__((unavailable("init is not available")));
|
||||
|
|
|
@ -14,23 +14,21 @@
|
|||
{
|
||||
MWMCircularProgress * progress = [[MWMCircularProgress alloc] initWithParentView:parentView];
|
||||
|
||||
UIImage * downloadImage = [UIImage imageNamed:@"ic_download"];
|
||||
[progress setImage:downloadImage forState:MWMCircularProgressStateNormal];
|
||||
[progress setImage:downloadImage forState:MWMCircularProgressStateSelected];
|
||||
[progress setImage:[UIImage imageNamed:@"ic_download"]
|
||||
forStates:{MWMCircularProgressStateNormal, MWMCircularProgressStateSelected}];
|
||||
[progress setImage:[UIImage imageNamed:@"ic_close_spinner"]
|
||||
forStates:{MWMCircularProgressStateProgress, MWMCircularProgressStateSpinner}];
|
||||
[progress setImage:[UIImage imageNamed:@"ic_download_error"]
|
||||
forStates:{MWMCircularProgressStateFailed}];
|
||||
[progress setImage:[UIImage imageNamed:@"ic_check"]
|
||||
forStates:{MWMCircularProgressStateCompleted}];
|
||||
|
||||
UIImage * spinnerImage = [UIImage imageNamed:@"ic_close_spinner"];
|
||||
[progress setImage:spinnerImage forState:MWMCircularProgressStateProgress];
|
||||
[progress setImage:spinnerImage forState:MWMCircularProgressStateSpinner];
|
||||
[progress setColoring:MWMButtonColoringBlack
|
||||
forStates:{MWMCircularProgressStateNormal, MWMCircularProgressStateSelected,
|
||||
MWMCircularProgressStateProgress, MWMCircularProgressStateSpinner}];
|
||||
[progress setColoring:MWMButtonColoringOther forStates:{MWMCircularProgressStateFailed}];
|
||||
[progress setColoring:MWMButtonColoringBlue forStates:{MWMCircularProgressStateCompleted}];
|
||||
|
||||
[progress setImage:[UIImage imageNamed:@"ic_download_error"] forState:MWMCircularProgressStateFailed];
|
||||
[progress setImage:[UIImage imageNamed:@"ic_check"] forState:MWMCircularProgressStateCompleted];
|
||||
|
||||
[progress setColoring:MWMButtonColoringBlack forState:MWMCircularProgressStateNormal];
|
||||
[progress setColoring:MWMButtonColoringBlack forState:MWMCircularProgressStateSelected];
|
||||
[progress setColoring:MWMButtonColoringBlack forState:MWMCircularProgressStateProgress];
|
||||
[progress setColoring:MWMButtonColoringBlack forState:MWMCircularProgressStateSpinner];
|
||||
[progress setColoring:MWMButtonColoringOther forState:MWMCircularProgressStateFailed];
|
||||
[progress setColoring:MWMButtonColoringBlue forState:MWMCircularProgressStateCompleted];
|
||||
return progress;
|
||||
}
|
||||
|
||||
|
@ -59,19 +57,22 @@
|
|||
self.nextProgressToAnimate = nil;
|
||||
}
|
||||
|
||||
- (void)setImage:(nonnull UIImage *)image forState:(MWMCircularProgressState)state
|
||||
- (void)setImage:(nonnull UIImage *)image forStates:(MWMCircularProgressStateVec const &)states
|
||||
{
|
||||
[self.rootView setImage:image forState:state];
|
||||
for (auto const & state : states)
|
||||
[self.rootView setImage:image forState:state];
|
||||
}
|
||||
|
||||
- (void)setColor:(nonnull UIColor *)color forState:(MWMCircularProgressState)state
|
||||
- (void)setColor:(nonnull UIColor *)color forStates:(MWMCircularProgressStateVec const &)states
|
||||
{
|
||||
[self.rootView setColor:color forState:state];
|
||||
for (auto const & state : states)
|
||||
[self.rootView setColor:color forState:state];
|
||||
}
|
||||
|
||||
- (void)setColoring:(MWMButtonColoring)coloring forState:(MWMCircularProgressState)state
|
||||
- (void)setColoring:(MWMButtonColoring)coloring forStates:(MWMCircularProgressStateVec const &)states
|
||||
{
|
||||
[self.rootView setColoring:coloring forState:state];
|
||||
for (auto const & state : states)
|
||||
[self.rootView setColoring:coloring forState:state];
|
||||
}
|
||||
|
||||
- (void)setInvertColor:(BOOL)invertColor
|
||||
|
|
|
@ -36,8 +36,8 @@ static CGFloat const kAdditionalHeight = 20.;
|
|||
@property (nonatomic) BOOL isNeedToMove;
|
||||
@property (nonatomic) NSIndexPath * indexPathOfMovingCell;
|
||||
|
||||
@property (nonatomic, readwrite) MWMCircularProgress * pedestrianProgressView;
|
||||
@property (nonatomic, readwrite) MWMCircularProgress * vehicleProgressView;
|
||||
@property (nonatomic, readwrite) MWMCircularProgress * pedestrianProgress;
|
||||
@property (nonatomic, readwrite) MWMCircularProgress * vehicleProgress;
|
||||
|
||||
@end
|
||||
|
||||
|
@ -87,8 +87,8 @@ static CGFloat const kAdditionalHeight = 20.;
|
|||
|
||||
- (void)statePrepare
|
||||
{
|
||||
self.pedestrianProgressView.state = MWMCircularProgressStateNormal;
|
||||
self.vehicleProgressView.state = MWMCircularProgressStateNormal;
|
||||
self.pedestrianProgress.state = MWMCircularProgressStateNormal;
|
||||
self.vehicleProgress.state = MWMCircularProgressStateNormal;
|
||||
self.arrowImageView.transform = CGAffineTransformMakeRotation(M_PI);
|
||||
self.goButton.hidden = NO;
|
||||
self.goButton.enabled = NO;
|
||||
|
@ -180,26 +180,26 @@ static CGFloat const kAdditionalHeight = 20.;
|
|||
|
||||
- (void)deselectPedestrian
|
||||
{
|
||||
self.pedestrianProgressView.state = MWMCircularProgressStateNormal;
|
||||
self.pedestrianProgress.state = MWMCircularProgressStateNormal;
|
||||
}
|
||||
|
||||
- (void)selectProgress:(MWMCircularProgress *)progress;
|
||||
{
|
||||
if ([progress isEqual:self.pedestrianProgressView])
|
||||
if ([progress isEqual:self.pedestrianProgress])
|
||||
{
|
||||
self.vehicleProgressView.state = MWMCircularProgressStateNormal;
|
||||
self.pedestrianProgressView.state = MWMCircularProgressStateSelected;
|
||||
self.vehicleProgress.state = MWMCircularProgressStateNormal;
|
||||
self.pedestrianProgress.state = MWMCircularProgressStateSelected;
|
||||
}
|
||||
else
|
||||
{
|
||||
self.pedestrianProgressView.state = MWMCircularProgressStateNormal;
|
||||
self.vehicleProgressView.state = MWMCircularProgressStateSelected;
|
||||
self.pedestrianProgress.state = MWMCircularProgressStateNormal;
|
||||
self.vehicleProgress.state = MWMCircularProgressStateSelected;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)deselectVehicle
|
||||
{
|
||||
self.vehicleProgressView.state = MWMCircularProgressStateNormal;
|
||||
self.vehicleProgress.state = MWMCircularProgressStateNormal;
|
||||
}
|
||||
|
||||
- (void)layoutSubviews
|
||||
|
@ -409,38 +409,34 @@ static CGFloat const kAdditionalHeight = 20.;
|
|||
|
||||
#pragma mark - Properties
|
||||
|
||||
- (MWMCircularProgress *)pedestrianProgressView
|
||||
- (MWMCircularProgress *)pedestrianProgress
|
||||
{
|
||||
if (!_pedestrianProgressView)
|
||||
if (!_pedestrianProgress)
|
||||
{
|
||||
UIImage * image = [UIImage imageNamed:@"ic_walk"];
|
||||
_pedestrianProgressView = [[MWMCircularProgress alloc] initWithParentView:self.pedestrian];
|
||||
[_pedestrianProgressView setImage:image forState:MWMCircularProgressStateNormal];
|
||||
[_pedestrianProgressView setImage:image forState:MWMCircularProgressStateFailed];
|
||||
[_pedestrianProgressView setImage:image forState:MWMCircularProgressStateSelected];
|
||||
[_pedestrianProgressView setImage:image forState:MWMCircularProgressStateProgress];
|
||||
[_pedestrianProgressView setImage:image forState:MWMCircularProgressStateSpinner];
|
||||
[_pedestrianProgressView setImage:image forState:MWMCircularProgressStateCompleted];
|
||||
_pedestrianProgressView.delegate = self.dashboardManager;
|
||||
_pedestrianProgress = [[MWMCircularProgress alloc] initWithParentView:self.pedestrian];
|
||||
[_pedestrianProgress
|
||||
setImage:[UIImage imageNamed:@"ic_walk"]
|
||||
forStates:{MWMCircularProgressStateNormal, MWMCircularProgressStateFailed,
|
||||
MWMCircularProgressStateSelected, MWMCircularProgressStateProgress,
|
||||
MWMCircularProgressStateSpinner, MWMCircularProgressStateCompleted}];
|
||||
_pedestrianProgress.delegate = self.dashboardManager;
|
||||
}
|
||||
return _pedestrianProgressView;
|
||||
return _pedestrianProgress;
|
||||
}
|
||||
|
||||
- (MWMCircularProgress *)vehicleProgressView
|
||||
- (MWMCircularProgress *)vehicleProgress
|
||||
{
|
||||
if (!_vehicleProgressView)
|
||||
if (!_vehicleProgress)
|
||||
{
|
||||
UIImage * image = [UIImage imageNamed:@"ic_drive"];
|
||||
_vehicleProgressView = [[MWMCircularProgress alloc] initWithParentView:self.vehicle];
|
||||
[_vehicleProgressView setImage:image forState:MWMCircularProgressStateNormal];
|
||||
[_vehicleProgressView setImage:image forState:MWMCircularProgressStateFailed];
|
||||
[_vehicleProgressView setImage:image forState:MWMCircularProgressStateSelected];
|
||||
[_vehicleProgressView setImage:image forState:MWMCircularProgressStateProgress];
|
||||
[_vehicleProgressView setImage:image forState:MWMCircularProgressStateSpinner];
|
||||
[_vehicleProgressView setImage:image forState:MWMCircularProgressStateCompleted];
|
||||
_vehicleProgressView.delegate = self.dashboardManager;
|
||||
_vehicleProgress = [[MWMCircularProgress alloc] initWithParentView:self.vehicle];
|
||||
[_vehicleProgress
|
||||
setImage:[UIImage imageNamed:@"ic_drive"]
|
||||
forStates:{MWMCircularProgressStateNormal, MWMCircularProgressStateFailed,
|
||||
MWMCircularProgressStateSelected, MWMCircularProgressStateProgress,
|
||||
MWMCircularProgressStateSpinner, MWMCircularProgressStateCompleted}];
|
||||
_vehicleProgress.delegate = self.dashboardManager;
|
||||
}
|
||||
return _vehicleProgressView;
|
||||
return _vehicleProgress;
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -63,11 +63,9 @@
|
|||
case NodeStatus::NotDownloaded:
|
||||
case NodeStatus::Partly:
|
||||
{
|
||||
UIImage * downloadImage = [UIImage imageNamed:@"ic_download"];
|
||||
[progress setImage:downloadImage forState:MWMCircularProgressStateNormal];
|
||||
[progress setImage:downloadImage forState:MWMCircularProgressStateSelected];
|
||||
[progress setColoring:MWMButtonColoringBlack forState:MWMCircularProgressStateNormal];
|
||||
[progress setColoring:MWMButtonColoringBlack forState:MWMCircularProgressStateSelected];
|
||||
auto const affectedStates = {MWMCircularProgressStateNormal, MWMCircularProgressStateSelected};
|
||||
[progress setImage:[UIImage imageNamed:@"ic_download"] forStates:affectedStates];
|
||||
[progress setColoring:MWMButtonColoringBlack forStates:affectedStates];
|
||||
progress.state = MWMCircularProgressStateNormal;
|
||||
break;
|
||||
}
|
||||
|
@ -89,11 +87,9 @@
|
|||
break;
|
||||
case NodeStatus::OnDiskOutOfDate:
|
||||
{
|
||||
UIImage * downloadImage = [UIImage imageNamed:@"ic_update"];
|
||||
[progress setImage:downloadImage forState:MWMCircularProgressStateNormal];
|
||||
[progress setImage:downloadImage forState:MWMCircularProgressStateSelected];
|
||||
[progress setColoring:MWMButtonColoringOther forState:MWMCircularProgressStateNormal];
|
||||
[progress setColoring:MWMButtonColoringOther forState:MWMCircularProgressStateSelected];
|
||||
auto const affectedStates = {MWMCircularProgressStateNormal, MWMCircularProgressStateSelected};
|
||||
[progress setImage:[UIImage imageNamed:@"ic_update"] forStates:affectedStates];
|
||||
[progress setColoring:MWMButtonColoringOther forStates:affectedStates];
|
||||
progress.state = MWMCircularProgressStateNormal;
|
||||
break;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue