1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
//
// ICRPatrolDetailViewController.m
// XFFruit
//
// Created by Xummer on 4/11/15.
// Copyright (c) 2015 Xummer. All rights reserved.
//
#import "ICRPatrolDetailViewController.h"
#import "IBTTableViewInfo.h"
#import "IBTTableView.h"
#import "ICRQuestionBaseViewController.h"
#import "ICRQuestionManager.h"
#import "ICRPatrolPlan.h"
#import "ICRStore.h"
#define PATROL_DETAIL_CELL_CONTENT_LABEL_HORIZON_MARGIN (15)
#define PATROL_DETAIL_CELL_CONTENT_LABEL_VERTICAL_MARGIN (10)
#define PATROL_DETAIL_CELL_CONTENT_LABEL_FONT [UIFont systemFontOfSize:15]
@interface ICRPatrolDetailViewController ()
@property (strong, nonatomic) IBTTableViewInfo *m_tableViewInfo;
@property (strong, nonatomic) ICRPatrolPlan *m_plan;
@property (copy, nonatomic) NSString* m_storeID;
@end
@implementation ICRPatrolDetailViewController
#pragma mark - Life Cycle
- (instancetype)initWithPatrolPlan:(id)plan storeID:(NSString *)storeID {
self = [super init];
if (!self) {
return nil;
}
if ([plan isKindOfClass:[ICRPatrolPlan class]]) {
self.m_plan = plan;
}
self.m_storeID = storeID;
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.title = [IBTCommon localizableString:@"Patrol Detail"];
[self initTableViewInfo];
[self updateContent];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Private Method
- (void)initTableViewInfo {
self.m_tableViewInfo = [[IBTTableViewInfo alloc] initWithFrame:self.view.bounds
style:UITableViewStylePlain];
IBTTableView *tableV = [_m_tableViewInfo getTableView];
// Footer
UIButton *btn = nil;
UIView *tableFooter =
[tableV buttonViewWithTitle:@"开始"
color:ICR_ORANGE_BTN_COLOR
topGap:25
pointer:&btn
target:self
action:@selector(startButtonAction:)];
tableV.tableFooterView = tableFooter;
[self.view addSubview:tableV];
// # Section 0
IBTTableViewSectionInfo *sec0Info = [IBTTableViewSectionInfo sectionInfoDefaut];
// User ID
IBTTableViewCellInfo *titleCellInfo =
[IBTTableViewCellInfo normalCellForSel:nil target:nil
title:[IBTCommon localizableString:@"Title"]
rightValue:@""
accessoryType:UITableViewCellAccessoryNone];
titleCellInfo.selectionStyle = UITableViewCellSelectionStyleNone;
[sec0Info addCell:titleCellInfo];
IBTTableViewCellInfo *typeCellInfo =
[IBTTableViewCellInfo normalCellForSel:nil target:nil
title:[IBTCommon localizableString:@"Type"]
rightValue:@""
accessoryType:UITableViewCellAccessoryNone];
typeCellInfo.selectionStyle = UITableViewCellSelectionStyleNone;
[sec0Info addCell:typeCellInfo];
IBTTableViewCellInfo *planTimeCellInfo =
[IBTTableViewCellInfo normalCellForSel:nil target:nil
title:[IBTCommon localizableString:@"Scheduled Time"]
rightValue:@""
accessoryType:UITableViewCellAccessoryNone];
planTimeCellInfo.selectionStyle = UITableViewCellSelectionStyleNone;
[sec0Info addCell:planTimeCellInfo];
IBTTableViewCellInfo *startTimeCellInfo =
[IBTTableViewCellInfo normalCellForSel:nil target:nil
title:[IBTCommon localizableString:@"Start Time"]
rightValue:@""
accessoryType:UITableViewCellAccessoryNone];
startTimeCellInfo.selectionStyle = UITableViewCellSelectionStyleNone;
[sec0Info addCell:startTimeCellInfo];
IBTTableViewCellInfo *contentCellInfo =
[[IBTTableViewCellInfo alloc] init];
contentCellInfo.makeTarget = self;
contentCellInfo.makeSel = @selector(makeContentCell:);
contentCellInfo.calHeightTarget = self;
contentCellInfo.calHeightSel = @selector(calContentCellHeight:);
contentCellInfo.selectionStyle = UITableViewCellSelectionStyleNone;
[sec0Info addCell:contentCellInfo];
[_m_tableViewInfo addSection:sec0Info];
}
- (void)makeContentCell:(IBTTableViewCellInfo*)cellInfo {
IBTTableViewCell *cell = cellInfo.cell;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
[cell.contentView removeAllSubViews];
UIView *contentView = cell.contentView;
IBTUILabel *titleLabel = [[IBTUILabel alloc] init];
NSString *rightValue = [cellInfo getUserInfoValueForKey:CInfoDetailKey];
titleLabel.text = rightValue;
titleLabel.textColor = [UIColor colorWithW:135.0f a:1];
titleLabel.font = PATROL_DETAIL_CELL_CONTENT_LABEL_FONT;
titleLabel.numberOfLines = 0;
CGSize titleLabelSize = [titleLabel sizeThatFits:CGSizeMake(contentView.width - PATROL_DETAIL_CELL_CONTENT_LABEL_HORIZON_MARGIN * 2, MAXFLOAT)];
titleLabel.frame = ((CGRect){
.origin.x = PATROL_DETAIL_CELL_CONTENT_LABEL_HORIZON_MARGIN,
.origin.y = PATROL_DETAIL_CELL_CONTENT_LABEL_VERTICAL_MARGIN,
.size = titleLabelSize
});
// cellInfo.fCellHeight = titleLabel.height + PATROL_DETAIL_CELL_CONTENT_LABEL_VERTICAL_MARGIN * 2;
[contentView addSubview:titleLabel];
}
- (CGFloat)calContentCellHeight:(IBTTableViewCellInfo*)cellInfo {
NSString *rightValue = [cellInfo getUserInfoValueForKey:CInfoDetailKey];
IBTTableView *tableV = [_m_tableViewInfo getTableView];
return [UILabel getHeightWithText:rightValue font:PATROL_DETAIL_CELL_CONTENT_LABEL_FONT
andWidth:tableV.width - PATROL_DETAIL_CELL_CONTENT_LABEL_HORIZON_MARGIN * 2] + PATROL_DETAIL_CELL_CONTENT_LABEL_VERTICAL_MARGIN * 2;
}
- (void)updateContent {
IBTTableViewCellInfo *cellInfo =
[self.m_tableViewInfo getCellAtSection:0 row:0];
[cellInfo addUserInfoValue:_m_plan.name
forKey:CInfoRightValueKey];
cellInfo =
[self.m_tableViewInfo getCellAtSection:0 row:1];
[cellInfo addUserInfoValue:_m_plan.category
forKey:CInfoRightValueKey];
NSString *nsStart = [[_m_plan.beginDate componentsSeparatedByString:@" "] firstObject];
NSString *nsEnd = [[_m_plan.endDate componentsSeparatedByString:@" "] firstObject];
cellInfo =
[self.m_tableViewInfo getCellAtSection:0 row:2];
[cellInfo addUserInfoValue:[NSString stringWithFormat:@"%@~%@", nsStart, nsEnd]
forKey:CInfoRightValueKey];
cellInfo =
[self.m_tableViewInfo getCellAtSection:0 row:3];
[cellInfo addUserInfoValue:[[NSDate date] httpParameterString]
forKey:CInfoRightValueKey];
cellInfo =
[self.m_tableViewInfo getCellAtSection:0 row:4];
[cellInfo addUserInfoValue:_m_plan.remark
forKey:CInfoDetailKey];
[[_m_tableViewInfo getTableView] reloadData];
}
#pragma mark - Button Actions
- (void)startButtonAction:(id)sender {
ICRDatabaseFetchBlock fetchBlk = ^FMResultSet *(FMDatabase *db) {
NSString * sql = [NSString stringWithFormat:@"SELECT * FROM %@ WHERE %@ == ?", [ICRStore TableName], @"uuid"];
return [db executeQuery:sql, _m_storeID];
};
__weak typeof(self)weakSelf = self;
ICRDatabaseFetchResultsBlock fetchResultsBlk = ^(NSArray *fetchedObjects) {
__strong __typeof(weakSelf)strongSelf = weakSelf;
ICRQuestionManager *mgr = [ICRQuestionManager sharedManager];
mgr.m_storeID = _m_storeID;
mgr.m_store = [fetchedObjects firstObject];
[mgr openQuestionVCFromViewControler:strongSelf withPlan:_m_plan];
};
ICRDataBaseController *dbCtrl = [ICRDataBaseController sharedController];
[dbCtrl runFetchForClass:[ICRStore class]
fetchBlock:fetchBlk
fetchResultsBlock:fetchResultsBlk];
}
@end