-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathCommits.m
76 lines (70 loc) · 2.28 KB
/
Commits.m
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
//
// Commits.m
// Coding_iOS
//
// Created by Ease on 15/6/5.
// Copyright (c) 2015年 Coding. All rights reserved.
//
#import "Commits.h"
@implementation Commits
- (instancetype)init
{
self = [super init];
if (self) {
_canLoadMore = NO;
_isLoading = NO;
_willLoadMore = NO;
_pageSize = [NSNumber numberWithInteger:20];
_propertyArrayMap = [NSDictionary dictionaryWithObjectsAndKeys:
@"Commit", @"list", nil];
_listGroups = [[NSMutableArray alloc] init];
_list = [[NSMutableArray alloc] init];
}
return self;
}
+ (Commits *)commitsWithRef:(NSString *)ref Path:(NSString *)path{
Commits *commits = [Commits new];
commits.ref = ref;
commits.path = path;
return commits;
}
- (NSDictionary *)toParams{
return @{@"page" : [NSNumber numberWithInteger:_willLoadMore? self.page.integerValue+1 : 1],
@"pageSize" : self.pageSize};
}
- (void)configWithCommits:(Commits *)responseCommits{
self.page = responseCommits.page;
self.totalRow = responseCommits.totalRow;
self.totalPage = responseCommits.totalPage;
if (responseCommits.list.count > 0) {
self.canLoadMore = YES;
if (_willLoadMore) {
[self.list addObjectsFromArray:responseCommits.list];
}else{
self.list = [NSMutableArray arrayWithArray:responseCommits.list];
}
[self refreshListGroupWithCommits:responseCommits isAdd:self.willLoadMore];
}else{
self.canLoadMore = NO;
}
}
- (void)refreshListGroupWithCommits:(Commits *)responseCommits isAdd:(BOOL)isAdd{
if (!isAdd) {
[_listGroups removeAllObjects];
}
for (NSUInteger i = 0; i< [responseCommits.list count]; i++) {
Commit *curCommit = [responseCommits.list objectAtIndex:i];
NSUInteger location = [_list indexOfObject:curCommit];
if (location != NSNotFound) {
ListGroupItem *item = _listGroups.lastObject;
if (item && [item.date isSameDay:curCommit.commitTime]) {
[item addOneItem];
}else{
item = [ListGroupItem itemWithDate:curCommit.commitTime andLocation:location];
[item addOneItem];
[_listGroups addObject:item];
}
}
}
}
@end