-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDLDirectoryTableViewController.m
More file actions
201 lines (150 loc) · 6.27 KB
/
DLDirectoryTableViewController.m
File metadata and controls
201 lines (150 loc) · 6.27 KB
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
//
// DLDirectoryTableViewController.m
// DivyaLoka
//
// Created by @playra on 28.03.14.
// Copyright (c) 2014 @playra. All rights reserved.
//
#import "DLDirectoryTableViewController.h"
@interface DLDirectoryTableViewController ()
@property (strong, nonatomic) NSString* pathProperty;
@property (strong, nonatomic) NSArray *contents;
@property (strong, nonatomic) NSString *selectedPath;
@property (strong, nonatomic) NSMutableArray *sectionsArrayProperty;
@property (strong, nonatomic) NSArray* namesArrayOfsectionInSearch;
@end
@implementation DLDirectoryTableViewController
- (id) initWithFolderPath:(NSString*) path
{
self = [super initWithStyle:UITableViewStyleGrouped];
if (self) {
self.pathProperty = path;
}
return self;
}
- (void) setPathProperty:(NSString *)pathProperty
{
_pathProperty = pathProperty;
NSArray* allContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:pathProperty error:nil];
NSMutableArray *removeDS_Store = [NSMutableArray array];
for (NSString *subpath in allContents) {
if ( ![[subpath lastPathComponent] hasPrefix:@"."] &&
![[subpath lastPathComponent] isEqualToString:@"Icons"] &&
![[subpath lastPathComponent] isEqualToString:@"Root.plist"] &&
![[subpath lastPathComponent] isEqualToString:@"en.lproj"])
{
[removeDS_Store addObject:[pathProperty stringByAppendingPathComponent:subpath]];
}
}
self.contents = removeDS_Store;
[self.tableView reloadData];
self.navigationItem.title = [[self.pathProperty lastPathComponent] stringByDeletingPathExtension];
}
- (void)viewDidLoad
{
[super viewDidLoad];
if (!self.pathProperty)
{
NSString *bundlePath = [[NSBundle mainBundle] pathForResource:@"Собрание Тайн" ofType:@"bundle"];
self.pathProperty = bundlePath;
}
}
- (void) viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
UIBarButtonItem* rightButton = [[UIBarButtonItem alloc]
initWithTitle:@"OM"
style:UIBarButtonItemStylePlain
target:self action:@selector(actionBackToRoot:)];
[rightButton setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
[UIFont fontWithName:@"Trebuchet MS" size:18], NSFontAttributeName,
[UIColor colorWithRed:56.0/255.0 green:56.0/255.0 blue:255.0/255.0 alpha:1.0], NSForegroundColorAttributeName,
nil]
forState:UIControlStateNormal];
self.navigationItem.rightBarButtonItem = rightButton;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (BOOL) isDirectoryAtIndexPath:(NSIndexPath*) indexPath
{
NSString* fileName = [self.contents objectAtIndex:indexPath.row];
BOOL isDirectory = NO;
[[NSFileManager defaultManager] fileExistsAtPath:fileName isDirectory:&isDirectory];
return isDirectory;
}
#pragma mark - Actions
- (void) actionBackToRoot:(UIBarButtonItem*) sender
{
NSArray *viewControllers = [[self navigationController] viewControllers];
for( int i=0; i < [viewControllers count]; i++ )
{
id obj = [viewControllers objectAtIndex: i ];
if([obj isKindOfClass:[DLDirectoryTableViewController class]]){
[[self navigationController] popToViewController:obj animated:YES];
return;
}
}
}
- (IBAction)backButtonItem:(UIBarButtonItem *)sender
{
[self.navigationController popViewControllerAnimated:YES];
}
#pragma mark - Table view data source
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.contents count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *identifer = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifer];
if (!cell)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifer];
}
NSString *fileName = [self.contents objectAtIndex:indexPath.row];
NSString* theFileName = [[fileName lastPathComponent] stringByDeletingPathExtension];
cell.textLabel.text = theFileName;
return cell;
}
#pragma mark - Navigation
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
if ([self isDirectoryAtIndexPath:indexPath])
{
NSString *fileName = [self.contents objectAtIndex:indexPath.row];
self.selectedPath = fileName;
[self performSegueWithIdentifier:@"navigateDeep" sender:nil];
}
else
{
NSString *fileNamePdf = [self.contents objectAtIndex:indexPath.row];
NSString* theFileName = [[fileNamePdf lastPathComponent] stringByDeletingPathExtension];
NSString *filePathPdf = [[NSBundle mainBundle] pathForResource:theFileName ofType:@"pdf"];
ReaderDocument *document = [ReaderDocument withDocumentFilePath:filePathPdf password:nil];
if (document != nil)
{
ReaderViewController *readerViewController = [[ReaderViewController alloc] initWithReaderDocument:document];
readerViewController.delegate = self;
readerViewController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
readerViewController.modalPresentationStyle = UIModalPresentationFullScreen;
[self presentViewController:readerViewController animated:YES completion:nil];
}
}
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
DLDirectoryTableViewController *dLDirectoryTableViewController = segue.destinationViewController;
dLDirectoryTableViewController.pathProperty = self.selectedPath;
}
- (void)dismissReaderViewController:(ReaderViewController *)viewController
{
viewController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
viewController.modalPresentationStyle = UIModalPresentationFullScreen;
[self dismissViewControllerAnimated:YES completion:nil];
}
@end