Skip to content

Commit

Permalink
add
Browse files Browse the repository at this point in the history
  • Loading branch information
coderZsq committed Feb 27, 2019
1 parent 6b7abc4 commit c294f3d
Show file tree
Hide file tree
Showing 12 changed files with 46 additions and 94 deletions.
4 changes: 0 additions & 4 deletions SQFitnessProgram/SQFitnessProgram.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,6 @@
1496CBF9222635B500AE6A3F /* SQTrainingCapacityDataManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SQTrainingCapacityDataManager.m; sourceTree = "<group>"; };
1496CBFC222635CD00AE6A3F /* SQTrainingCapacityDataService.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SQTrainingCapacityDataService.h; sourceTree = "<group>"; };
1496CBFD22263BC800AE6A3F /* SQTrainingCapacityViewProtocol.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SQTrainingCapacityViewProtocol.h; sourceTree = "<group>"; };
1496CBFE2226510D00AE6A3F /* SQTrainingCapacityInteractorDataSource.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SQTrainingCapacityInteractorDataSource.h; sourceTree = "<group>"; };
1496CBFF2226559B00AE6A3F /* SQTrainingCapacityInteractorEventHandler.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SQTrainingCapacityInteractorEventHandler.h; sourceTree = "<group>"; };
14A8CF1022239C5B000A397B /* SQTrainingMusclesDataManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SQTrainingMusclesDataManager.h; sourceTree = "<group>"; };
14BDFFE521DC5A5400C52CEF /* SQTrainingCapacityModel.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SQTrainingCapacityModel.h; sourceTree = "<group>"; };
14BDFFE621DC5A5400C52CEF /* SQTrainingCapacityModel.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SQTrainingCapacityModel.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -717,8 +715,6 @@
14F93ACA222571E9007297D2 /* Interactor */ = {
isa = PBXGroup;
children = (
1496CBFF2226559B00AE6A3F /* SQTrainingCapacityInteractorEventHandler.h */,
1496CBFE2226510D00AE6A3F /* SQTrainingCapacityInteractorDataSource.h */,
1496CBF62226321600AE6A3F /* SQTrainingCapacityInteractorInput.h */,
14F93AC7222571E5007297D2 /* SQTrainingCapacityInteractor.h */,
14F93AC8222571E5007297D2 /* SQTrainingCapacityInteractor.m */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@
#import <Foundation/Foundation.h>
#import "SQTrainingCapacityMuscleType.h"

NS_ASSUME_NONNULL_BEGIN

@protocol SQTrainingCapacityDataService <NSObject>

@property (nonatomic, readonly, copy) NSString *totalCapacity;

@property (nonatomic, readonly, strong) NSArray *dataSource;

- (void)fetchDataSourceWithTitle:(NSString *)title type:(SQTrainingCapacityMuscleType)type completion:(void(^)(NSArray *dataSource))completion;
Expand All @@ -21,3 +24,5 @@
- (void)addTrainingAction;

@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

#import "SQTrainingCapacityInteractor.h"
#import "SQTrainingCapacityDataService.h"
#import "SQTrainingCapacityInteractorDataSource.h"

@interface SQTrainingCapacityInteractor ()

Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -63,36 +63,33 @@ - (void)handleCommitEditingAtIndexPath:(NSIndexPath *)indexPath {
self.view.footerView.totalCapacityLabel.text = self.totalCapacity;
}

- (NSString *)totalCapacity {
return self.interactor.totalCapacity;
}

- (NSArray *)fetchDataSourceFromDB {
return self.interactor.fetchDataSource;
}

- (void)didTouchNavigationBarAddButton {
[self.interactor addTrainingAction];
[self.view fetchDataSource];
[self.view.tableView insertRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:self.fetchDataSourceFromDB.count - 1 inSection:0]] withRowAnimation:(UITableViewRowAnimationLeft)];
}

- (void)didTouchNavigationBarDoneButton {
[self.view.tableView endEditing:YES];
[[NSNotificationCenter defaultCenter]postNotificationName:SQTrainingCapacityBindToModelNotification object:nil];
self.view.footerView.totalCapacityLabel.text = self.totalCapacity;
[self.view.tableView reloadData];
}

- (void)keyboardWillShow:(NSNotification *)sender {
[self.view setRightBarButtonItem:(UIBarButtonSystemItemDone) target:self action:@selector(doneAction)];
[self.view setRightBarButtonItem:(UIBarButtonSystemItemDone) target:self action:@selector(didTouchNavigationBarDoneButton)];
}

- (void)keyboardWillHide:(NSNotification *)sender {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wundeclared-selector"
[self.view setRightBarButtonItem:(UIBarButtonSystemItemAdd) target:self.view action:@selector(addTraningAction)];
#pragma clang diagnostic pop
[self.view setRightBarButtonItem:(UIBarButtonSystemItemAdd) target:self action:@selector(didTouchNavigationBarAddButton)];
}

- (void)doneAction {
[self.view.tableView endEditing:YES];
[[NSNotificationCenter defaultCenter]postNotificationName:SQTrainingCapacityBindToModelNotification object:nil];
self.view.footerView.totalCapacityLabel.text = self.totalCapacity;
[self.view.tableView reloadData];
- (NSString *)totalCapacity {
return self.interactor.totalCapacity;
}

- (NSArray *)fetchDataSourceFromDB {
return self.interactor.fetchDataSource;
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ NS_ASSUME_NONNULL_BEGIN

@property (nonatomic, assign) SQTrainingCapacityMuscleType type;

@property (nonatomic, weak) SQTrainingCapacityFooterView * footerView;

@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
@interface SQTrainingCapacityViewController ()

@property (nonatomic, strong) NSMutableArray *dataSource;
@property (nonatomic, weak) SQTrainingCapacityFooterView * footerView;

@end

Expand All @@ -26,9 +27,14 @@ - (void)setupData {
_dataSource = [NSMutableArray array];
}

- (void)fetchDataSource {
NSArray *dataSource = [(id<SQTrainingCapacityDataSource>)self.viewDataSource fetchDataSourceFromDB];
[self.dataSource removeAllObjects];
[self.dataSource addObjectsFromArray:dataSource];
}

- (void)setupUI {
[self setupRightBarButtonItem];
[self setupTableViewContent];
[self setupTableView];
}

Expand All @@ -40,16 +46,13 @@ - (void)setRightBarButtonItem:(UIBarButtonSystemItem)item target:(nullable id)ta
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:item target:target action:action];
}

- (void)setupTableViewContent {
- (void)setupTableView {
self.tableView.tableHeaderView = [SQTrainingCapacityHeaderView headerView];
SQTrainingCapacityFooterView * footerView = [SQTrainingCapacityFooterView footerView];
footerView.totalCapacityLabel.text = [(id<SQTrainingCapacityDataSource>)self.viewDataSource totalCapacity];
self.tableView.tableFooterView = footerView;
self.footerView = footerView;
[self.tableView registerNib:[UINib nibWithNibName:@"SQTrainingCapacityCell" bundle:[NSBundle bundleForClass:self.class]] forCellReuseIdentifier:@"TrainingCapacity"];
}

- (void)setupTableView {
[self setupDataSource:self.dataSource loadCell:^UITableViewCell *(UITableView * _Nonnull tableView, NSIndexPath * _Nonnull indexPath) {
return [tableView dequeueReusableCellWithIdentifier:@"TrainingCapacity" forIndexPath:indexPath];
} loadCellHeight:^CGFloat(id _Nonnull model) {
Expand All @@ -61,12 +64,6 @@ - (void)setupTableView {
}];
}

- (void)fetchDataSource {
NSArray *dataSource = [(id<SQTrainingCapacityDataSource>)self.viewDataSource fetchDataSourceFromDB];
[self.dataSource removeAllObjects];
[self.dataSource addObjectsFromArray:dataSource];
}

- (void)addTraningAction {
[(id<SQTrainingCapacityViewEventHandler>)self.eventHandler didTouchNavigationBarAddButton];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ NS_ASSUME_NONNULL_BEGIN

@protocol SQTrainingCapacityViewProtocol <SQViperView>

@property (nonatomic, copy) NSString *title;
@property (nonatomic, readonly, copy) NSString *title;

@property (nonatomic, assign) SQTrainingCapacityMuscleType type;
@property (nonatomic, readonly, assign) SQTrainingCapacityMuscleType type;

@property (nonatomic, weak) UITableView *tableView;
@property (nonatomic, readonly, weak) UITableView *tableView;

@property (nonatomic, weak) SQTrainingCapacityFooterView *footerView;
@property (nonatomic, readonly, weak) SQTrainingCapacityFooterView *footerView;

- (void)fetchDataSource;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ - (void)handleViewRemoved {
NSLog(@"%s", __func__);
}

- (void)handleDidSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSString * text = self.fetchDataSourceFromDB[indexPath.row];
NSString * title = [NSString stringWithFormat:@"Training Date: %@", text];
[self.wireframe pushTrainingCapacityWithTitle:title type:self.view.type];
}

- (void)didTouchNavigationBarAddButton {
NSDate *date = [NSDate date];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
Expand All @@ -74,12 +80,6 @@ - (void)didTouchNavigationBarAddButton {
}];
}

- (void)handleDidSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSString * text = self.fetchDataSourceFromDB[indexPath.row];
NSString * title = [NSString stringWithFormat:@"Training Date: %@", text];
[self.wireframe pushTrainingCapacityWithTitle:title type:self.view.type];
}

- (nonnull NSArray *)fetchDataSourceFromDB {
return [self.interactor fetchDataSource];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ - (void)setupData {
_dataSource = [NSMutableArray array];
}

- (void)setupUI {
self.title = @"Training Date";
[self setupTableView];
- (void)fetchDataSource {
NSArray *dataSource = [(id<SQTrainingDateListDataSource>)self.viewDataSource fetchDataSourceFromDB];
[self.dataSource removeAllObjects];
[self.dataSource addObjectsFromArray:dataSource];
}

- (void)setupTableView {
- (void)setupUI {
self.title = @"Training Date";
[self setupDataSource:self.dataSource loadCell:^UITableViewCell *(UITableView * _Nonnull tableView, NSIndexPath * _Nonnull indexPath) {
return [tableView dequeueReusableCellWithIdentifier:@"TrainingDate" forIndexPath:indexPath];
} loadCellHeight:^CGFloat(id _Nonnull model) {
Expand All @@ -37,12 +39,6 @@ - (void)setupTableView {
}];
}

- (void)fetchDataSource {
NSArray *dataSource = [(id<SQTrainingDateListDataSource>)self.viewDataSource fetchDataSourceFromDB];
[self.dataSource removeAllObjects];
[self.dataSource addObjectsFromArray:dataSource];
}

- (IBAction)addTraningDate:(UIBarButtonItem *)sender {
[(id<SQTrainingDateListViewEventHandler>)self.eventHandler didTouchNavigationBarAddButton];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ NS_ASSUME_NONNULL_BEGIN

@protocol SQTrainingDateListViewProtocol <SQViperView>

@property (nonatomic, assign) SQTrainingCapacityMuscleType type;
@property (nonatomic, readonly, assign) SQTrainingCapacityMuscleType type;

@property (nonatomic, weak) UITableView *tableView;
@property (nonatomic, readonly, weak) UITableView *tableView;

- (void)fetchDataSource;

Expand Down

0 comments on commit c294f3d

Please sign in to comment.