Skip to content

Commit 80d9618

Browse files
committed
离线阅读代码
1 parent b351f78 commit 80d9618

23 files changed

+5107
-12
lines changed

Cartfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11

2-
github "libgit2/objective-git" "0.12.0"
2+
github "libgit2/objective-git"

Cartfile.resolved

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
github "libgit2/objective-git" "0.12.0"
1+
github "libgit2/objective-git" "0.13.0"

Coding_iOS.xcodeproj/project.pbxproj

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1273,6 +1273,10 @@
12731273
B1890C492015D92600F52ABA /* WikiHistoryListViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = B1890C442015D92500F52ABA /* WikiHistoryListViewController.m */; };
12741274
B1890C4A2015D92600F52ABA /* WikiViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = B1890C472015D92600F52ABA /* WikiViewController.m */; };
12751275
B1890C4D2019B29900F52ABA /* UINavigationBar+Common.m in Sources */ = {isa = PBXBuildFile; fileRef = B1890C4B2019B29800F52ABA /* UINavigationBar+Common.m */; };
1276+
B1944144206BB87F00147158 /* EALocalCodeListViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = B1944143206BB87F00147158 /* EALocalCodeListViewController.m */; };
1277+
B1944147206BB89100147158 /* EALocalCodeViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = B1944146206BB89100147158 /* EALocalCodeViewController.m */; };
1278+
B194414A206BB8BB00147158 /* EALocalCodeListCell.m in Sources */ = {isa = PBXBuildFile; fileRef = B1944149206BB8BB00147158 /* EALocalCodeListCell.m */; };
1279+
B1944154206CBE8C00147158 /* code_lang.plist in Resources */ = {isa = PBXBuildFile; fileRef = B1944153206CBE8C00147158 /* code_lang.plist */; };
12761280
B19D4EE11F690F5E00C598F3 /* file_activity_icon_rename@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = B19D4EDF1F690F5E00C598F3 /* file_activity_icon_rename@2x.png */; };
12771281
B19D4EE21F690F5E00C598F3 /* file_activity_icon_rename@3x.png in Resources */ = {isa = PBXBuildFile; fileRef = B19D4EE01F690F5E00C598F3 /* file_activity_icon_rename@3x.png */; };
12781282
B19D4EEA1F6FAA6000C598F3 /* AboutPointViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = B19D4EE81F6FAA6000C598F3 /* AboutPointViewController.m */; };
@@ -3383,6 +3387,13 @@
33833387
B1890C472015D92600F52ABA /* WikiViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WikiViewController.m; sourceTree = "<group>"; };
33843388
B1890C4B2019B29800F52ABA /* UINavigationBar+Common.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UINavigationBar+Common.m"; sourceTree = "<group>"; };
33853389
B1890C4C2019B29800F52ABA /* UINavigationBar+Common.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UINavigationBar+Common.h"; sourceTree = "<group>"; };
3390+
B1944142206BB87F00147158 /* EALocalCodeListViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = EALocalCodeListViewController.h; sourceTree = "<group>"; };
3391+
B1944143206BB87F00147158 /* EALocalCodeListViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = EALocalCodeListViewController.m; sourceTree = "<group>"; };
3392+
B1944145206BB89100147158 /* EALocalCodeViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = EALocalCodeViewController.h; sourceTree = "<group>"; };
3393+
B1944146206BB89100147158 /* EALocalCodeViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = EALocalCodeViewController.m; sourceTree = "<group>"; };
3394+
B1944148206BB8BB00147158 /* EALocalCodeListCell.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = EALocalCodeListCell.h; sourceTree = "<group>"; };
3395+
B1944149206BB8BB00147158 /* EALocalCodeListCell.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = EALocalCodeListCell.m; sourceTree = "<group>"; };
3396+
B1944153206CBE8C00147158 /* code_lang.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = code_lang.plist; sourceTree = "<group>"; };
33863397
B19D4EDF1F690F5E00C598F3 /* file_activity_icon_rename@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "file_activity_icon_rename@2x.png"; sourceTree = "<group>"; };
33873398
B19D4EE01F690F5E00C598F3 /* file_activity_icon_rename@3x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "file_activity_icon_rename@3x.png"; sourceTree = "<group>"; };
33883399
B19D4EE71F6FAA6000C598F3 /* AboutPointViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AboutPointViewController.h; sourceTree = "<group>"; };
@@ -5698,6 +5709,10 @@
56985709
B1817EE32064F92C00E9BAD1 /* EACodeReleaseViewController.m */,
56995710
B1817F042069F67700E9BAD1 /* EAEditCodeReleaseViewController.h */,
57005711
B1817F052069F67700E9BAD1 /* EAEditCodeReleaseViewController.m */,
5712+
B1944142206BB87F00147158 /* EALocalCodeListViewController.h */,
5713+
B1944143206BB87F00147158 /* EALocalCodeListViewController.m */,
5714+
B1944145206BB89100147158 /* EALocalCodeViewController.h */,
5715+
B1944146206BB89100147158 /* EALocalCodeViewController.m */,
57015716
);
57025717
path = Controllers;
57035718
sourceTree = "<group>";
@@ -6207,6 +6222,7 @@
62076222
4EE083DB1ADB736800CA342E /* service_terms.html */,
62086223
4ECEF9F61D1BB7FB002A27D3 /* diff-ios.html */,
62096224
4EBD7FB01CE482A400B3AF49 /* country_code.plist */,
6225+
B1944153206CBE8C00147158 /* code_lang.plist */,
62106226
8E1C3DF519E7F4CA00EF3032 /* address.json */,
62116227
);
62126228
path = Resources;
@@ -6718,6 +6734,8 @@
67186734
B1817EE92064FC7300E9BAD1 /* EACodeReleaseBodyCell.m */,
67196735
B1817EEB2064FD9400E9BAD1 /* EACodeReleaseAttachmentsOrReferencesCell.h */,
67206736
B1817EEC2064FD9400E9BAD1 /* EACodeReleaseAttachmentsOrReferencesCell.m */,
6737+
B1944148206BB8BB00147158 /* EALocalCodeListCell.h */,
6738+
B1944149206BB8BB00147158 /* EALocalCodeListCell.m */,
67216739
);
67226740
path = Cell;
67236741
sourceTree = "<group>";
@@ -7212,6 +7230,7 @@
72127230
927AFF4F1BFF6DAD00AAE593 /* shop_coding_coin_icon@3x.png in Resources */,
72137231
4EF17EDA1B3C3112003CDD2D /* intro_icon_5@3x.png in Resources */,
72147232
B1C871BC1EB338FD003DACF0 /* project_tag_icon@3x.png in Resources */,
7233+
B1944154206CBE8C00147158 /* code_lang.plist in Resources */,
72157234
B10341292024633900853447 /* logo_coding@2x.png in Resources */,
72167235
4ED4B48D1D82646100EED8C6 /* user_info_project@2x.png in Resources */,
72177236
B1AB5CBB202D7D500075A669 /* button_file_createFolder_unable@3x.png in Resources */,
@@ -8040,6 +8059,7 @@
80408059
8EF643CD19FF7E2900F7EEB0 /* TweetCommentMoreCell.m in Sources */,
80418060
8E59F1001A01133C009A905F /* CodeTree.m in Sources */,
80428061
B1890C3D2015D8C900F52ABA /* WikiMenuListCell.m in Sources */,
8062+
B1944147206BB89100147158 /* EALocalCodeViewController.m in Sources */,
80438063
4E93F2331B84243D00017916 /* KxMenu.m in Sources */,
80448064
D0C447B91C02C63000DC1C4B /* UserSearchCell.m in Sources */,
80458065
4E83AE7B1CF30F1A006BA3BB /* SettingEmailViewController.m in Sources */,
@@ -8155,6 +8175,7 @@
81558175
4E5C06EB1AC4009100F427C5 /* CannotLoginViewController.m in Sources */,
81568176
927AFF381BFF1CC200AAE593 /* ShopViewController.m in Sources */,
81578177
1309BA021CA2EF370034C7A3 /* Reviewer.m in Sources */,
8178+
B1944144206BB87F00147158 /* EALocalCodeListViewController.m in Sources */,
81588179
B12B640A1FE900D400ACFDCC /* AMPopTip+Exit.m in Sources */,
81598180
8EA6D12819E240C40076D59C /* AppDelegate.m in Sources */,
81608181
7EB02FE51B6D0F3E00D2166C /* AudioAmrUtil.m in Sources */,
@@ -8301,6 +8322,7 @@
83018322
8EA6D13A19E240C40076D59C /* Project_RootViewController.m in Sources */,
83028323
4ECF70401B180740000280FF /* EaseGitButtonsView.m in Sources */,
83038324
8EF83F8A19E92AA500E86DE7 /* SettingTagsViewController.m in Sources */,
8325+
B194414A206BB8BB00147158 /* EALocalCodeListCell.m in Sources */,
83048326
8EF643D319FF7E2900F7EEB0 /* ValueListCell.m in Sources */,
83058327
4EB52F3F1C7C464400B5EBEA /* TaskResourceReferenceViewController.m in Sources */,
83068328
4E217F0C1A70EDC700F6DF88 /* SVModalWebViewController.m in Sources */,
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//
2+
// EALocalCodeListViewController.h
3+
// Coding_iOS
4+
//
5+
// Created by Easeeeeeeeee on 2018/3/28.
6+
// Copyright © 2018年 Coding. All rights reserved.
7+
//
8+
9+
#import "BaseViewController.h"
10+
#import "Project.h"
11+
12+
@interface EALocalCodeListViewController : BaseViewController
13+
@property (strong, nonatomic) Project *curPro;
14+
@property (strong, nonatomic) GTRepository *curRepo;
15+
@property (strong, nonatomic) NSURL *curURL;
16+
17+
- (void)pullRepo;
18+
@end
Lines changed: 217 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,217 @@
1+
//
2+
// EALocalCodeListViewController.m
3+
// Coding_iOS
4+
//
5+
// Created by Easeeeeeeeee on 2018/3/28.
6+
// Copyright © 2018年 Coding. All rights reserved.
7+
//
8+
9+
#import "EALocalCodeListViewController.h"
10+
#import "EALocalCodeViewController.h"
11+
#import "EALocalCodeListCell.h"
12+
13+
@interface EALocalCodeListViewController ()<UITableViewDataSource, UITableViewDelegate, UISearchBarDelegate>
14+
@property (nonatomic, strong) UITableView *myTableView;
15+
@property (strong, nonatomic) UISearchBar *mySearchBar;
16+
17+
@property (strong, nonatomic) NSArray *fileList, *searchedFileList;
18+
@property (strong, nonatomic) NSMutableDictionary *isDirDict;
19+
@property (strong, nonatomic, readonly) NSArray *dataList;
20+
@property (assign, nonatomic, readonly) BOOL isSearching;
21+
@end
22+
23+
@implementation EALocalCodeListViewController
24+
25+
- (void)viewDidLoad {
26+
[super viewDidLoad];
27+
// Do any additional setup after loading the view.
28+
self.title = _curURL.lastPathComponent;
29+
_myTableView = ({
30+
UITableView *tableView = [UITableView new];
31+
tableView.backgroundColor = [UIColor clearColor];
32+
tableView.delegate = self;
33+
tableView.dataSource = self;
34+
[tableView registerClass:[EALocalCodeListCell class] forCellReuseIdentifier:[EALocalCodeListCell nameOfClass]];
35+
tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
36+
[self.view addSubview:tableView];
37+
[tableView mas_makeConstraints:^(MASConstraintMaker *make) {
38+
make.edges.equalTo(self.view);
39+
}];
40+
tableView.estimatedRowHeight = 0;
41+
tableView.estimatedSectionHeaderHeight = 0;
42+
tableView.estimatedSectionFooterHeight = 0;
43+
tableView;
44+
});
45+
_mySearchBar = ({
46+
UISearchBar *searchBar = [[UISearchBar alloc] init];
47+
searchBar.delegate = self;
48+
[searchBar sizeToFit];
49+
[searchBar setPlaceholder:@"寻找文件"];
50+
searchBar;
51+
});
52+
_myTableView.tableHeaderView = _mySearchBar;
53+
[self setupNavBtn];
54+
[self setupData];
55+
}
56+
57+
- (void)setupData{
58+
NSFileManager *fileManager = [NSFileManager defaultManager];
59+
self.fileList = [[fileManager contentsOfDirectoryAtURL:_curURL includingPropertiesForKeys:nil options:0 error:nil] sortedArrayUsingComparator:^NSComparisonResult(NSURL *obj1, NSURL *obj2) {
60+
NSDictionary *attr1 = [obj1 resourceValuesForKeys:@[NSURLIsDirectoryKey] error:nil];
61+
BOOL isDir1 = [attr1[NSURLIsDirectoryKey] boolValue];
62+
NSDictionary *attr2 = [obj2 resourceValuesForKeys:@[NSURLIsDirectoryKey] error:nil];
63+
BOOL isDir2 = [attr2[NSURLIsDirectoryKey] boolValue];
64+
NSComparisonResult result = [(isDir1? @0: @1) compare:(isDir2? @0: @1)];
65+
if (result == NSOrderedSame) {
66+
result = [obj1.lastPathComponent compare:obj2.lastPathComponent];
67+
}
68+
return result;
69+
}];
70+
}
71+
72+
- (BOOL)isSearching{
73+
return ![_mySearchBar.text isEmpty];
74+
}
75+
76+
- (NSArray *)dataList{
77+
return self.isSearching? _searchedFileList: _fileList;
78+
}
79+
80+
#pragma mark Nav
81+
- (void)setupNavBtn{
82+
if ([_curURL.absoluteString isEqualToString:_curPro.localURL.absoluteString]) {//根目录
83+
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"moreBtn_Nav"] style:UIBarButtonItemStylePlain target:self action:@selector(navBtnClicked)];
84+
}else{
85+
self.navigationItem.rightBarButtonItem = nil;
86+
}
87+
}
88+
89+
- (void)navBtnClicked{
90+
__weak typeof(self) weakSelf = self;
91+
[[UIActionSheet bk_actionSheetCustomWithTitle:nil buttonTitles:@[@"Pull"] destructiveTitle:@"删除 Repo" cancelTitle:@"取消" andDidDismissBlock:^(UIActionSheet *sheet, NSInteger index) {
92+
if (index == 0) {
93+
[weakSelf pullRepo];
94+
}else if (index == 1){
95+
[weakSelf deleteRepo];
96+
}
97+
}] showInView:self.view];
98+
}
99+
100+
- (void)pullRepo{
101+
if (![_curURL.absoluteString isEqualToString:_curPro.localURL.absoluteString]) {//不是根目录不 pull,任性
102+
return;
103+
}
104+
__weak typeof(self) weakSelf = self;
105+
MBProgressHUD *hud = [NSObject showHUDQueryStr:@"正在 pull..."];
106+
[_curPro gitPullBlock:^(BOOL result, NSString *tipStr) {
107+
[NSObject hideHUDQuery];
108+
if (tipStr) {
109+
[NSObject showHudTipStr:tipStr];
110+
}else{
111+
[NSObject showHudTipStr:@"已更新"];
112+
[weakSelf setupData];
113+
}
114+
} progressBlock:^(const git_transfer_progress *progress, BOOL *stop) {
115+
hud.detailsLabelText = [NSString stringWithFormat:@"%d / %d", progress->received_objects, progress->total_objects];
116+
}];
117+
}
118+
119+
- (void)deleteRepo{
120+
[_curPro deleteLocalRepo];
121+
[NSObject showHudTipStr:@"已删除"];
122+
[self.navigationController popViewControllerAnimated:YES];
123+
}
124+
125+
#pragma mark ScrollView Delegate
126+
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
127+
if (scrollView == _myTableView) {
128+
[self.mySearchBar resignFirstResponder];
129+
}
130+
}
131+
#pragma mark Table
132+
133+
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
134+
return self.isSearching? 44.0: 0.0;
135+
}
136+
137+
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
138+
if (self.isSearching) {
139+
UILabel *headerL = [UILabel labelWithSystemFontSize:14 textColorHexString:@"0xB5B5B5"];
140+
headerL.frame = CGRectMake(0, 0, kScreen_Width, 40);
141+
headerL.backgroundColor = [UIColor whiteColor];
142+
headerL.textAlignment = NSTextAlignmentCenter;
143+
headerL.text = [NSString stringWithFormat:@"共搜到 %lu 个与 \"%@\" 相关的文件", (unsigned long)self.searchedFileList.count, self.mySearchBar.text];
144+
[headerL doBorderWidth:kLine_MinHeight color:kColorDDD cornerRadius:0];
145+
return headerL;
146+
}else{
147+
return [UIView new];
148+
}
149+
}
150+
151+
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
152+
return self.dataList.count;
153+
}
154+
155+
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
156+
EALocalCodeListCell *cell = [tableView dequeueReusableCellWithIdentifier:[EALocalCodeListCell nameOfClass] forIndexPath:indexPath];
157+
cell.curURL = self.dataList[indexPath.row];
158+
cell.searchText = [_mySearchBar.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
159+
[tableView addLineforPlainCell:cell forRowAtIndexPath:indexPath withLeftSpace:kPaddingLeftWidth hasSectionLine:NO];
160+
return cell;
161+
}
162+
163+
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
164+
return 44.0;;
165+
}
166+
167+
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
168+
[tableView deselectRowAtIndexPath:indexPath animated:YES];
169+
NSURL *itemURL = self.dataList[indexPath.row];
170+
NSDictionary *attributes = [itemURL resourceValuesForKeys:@[NSURLIsDirectoryKey] error:nil];
171+
BOOL isDir = [attributes[NSURLIsDirectoryKey] boolValue];
172+
if (isDir) {
173+
EALocalCodeListViewController *vc = [EALocalCodeListViewController new];
174+
vc.curPro = _curPro;
175+
vc.curRepo = _curRepo;
176+
vc.curURL = itemURL;
177+
[self.navigationController pushViewController:vc animated:YES];
178+
}else{
179+
EALocalCodeViewController *vc = [EALocalCodeViewController new];
180+
vc.curPro = _curPro;
181+
vc.curRepo = _curRepo;
182+
vc.curURL = itemURL;
183+
[self.navigationController pushViewController:vc animated:YES];
184+
}
185+
}
186+
187+
#pragma mark UISearchBarDelegate
188+
189+
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText{
190+
[self searchFileWithStr:searchText];
191+
}
192+
193+
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar{
194+
[searchBar resignFirstResponder];
195+
[self searchFileWithStr:searchBar.text];
196+
}
197+
198+
- (void)searchFileWithStr:(NSString *)string{
199+
if ([string isEmpty]) {
200+
[self.myTableView reloadData];
201+
}else{
202+
NSString *strippedStr = [string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
203+
if (strippedStr.length > 0) {
204+
[self updateFilteredContentForSearchString:strippedStr];
205+
}
206+
}
207+
}
208+
209+
- (void)updateFilteredContentForSearchString:(NSString *)searchString{
210+
self.searchedFileList = [self.fileList filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(NSURL * _Nullable evaluatedObject, NSDictionary<NSString *,id> * _Nullable bindings) {
211+
NSString *shortPath = evaluatedObject.lastPathComponent;
212+
return ([shortPath rangeOfString:searchString options:NSCaseInsensitiveSearch].location != NSNotFound);
213+
}]];
214+
[self.myTableView reloadData];
215+
}
216+
217+
@end
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//
2+
// EALocalCodeViewController.h
3+
// Coding_iOS
4+
//
5+
// Created by Easeeeeeeeee on 2018/3/28.
6+
// Copyright © 2018年 Coding. All rights reserved.
7+
//
8+
9+
#import "BaseViewController.h"
10+
#import "Project.h"
11+
12+
@interface EALocalCodeViewController : BaseViewController
13+
@property (strong, nonatomic) Project *curPro;
14+
@property (strong, nonatomic) GTRepository *curRepo;
15+
@property (strong, nonatomic) NSURL *curURL;
16+
@end

0 commit comments

Comments
 (0)