Skip to content

Commit 7280704

Browse files
committed
adapt to iOS 7 changes
1 parent 429f39c commit 7280704

14 files changed

+418
-606
lines changed

[email protected]

5.45 KB
Loading

SparkleShare.xcodeproj/project.pbxproj

+228-194
Large diffs are not rendered by default.

SparkleShare/Classes/FilePreview.m

+13
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,21 @@ - (id) initWithFile: (SSFile *) file {
3737
}
3838
else {
3939
self.localURL = [NSURL fileURLWithPath: tempFileName];
40+
//reencode text files which QLPreviewController seems to only be able to display
41+
//properly with utf16 encoding
42+
if( [file.mime isEqualToString:@"text/plain"] ) {
43+
if( [[[NSString alloc] initWithData:file.content encoding:NSUTF8StringEncoding] writeToURL:self.localURL atomically:YES encoding:NSUTF16StringEncoding error:&error] )
44+
{
45+
// Continue presenting the QLPreviewController from localFileURL
46+
}
47+
else
48+
{
49+
NSLog( @"An error occured: %@", error );
50+
}
51+
}
4052
}
4153
}
54+
4255
return self;
4356
}
4457

SparkleShare/Classes/FileViewController.m

+1-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
@implementation FileViewController
1414
@synthesize filePreview = _filePreview;
1515

16-
17-
1816
- (void)didReceiveMemoryWarning {
1917
// Releases the view if it doesn't have a superview.
2018
[super didReceiveMemoryWarning];
@@ -60,6 +58,7 @@ - (NSInteger)numberOfPreviewItemsInPreviewController: (QLPreviewController *) co
6058

6159
- (id <QLPreviewItem>)previewController: (QLPreviewController *) controller previewItemAtIndex: (NSInteger) index;
6260
{
61+
//TODO: controller.editButtonItem
6362
if (index == 0 && self.filePreview) {
6463
return self.filePreview;
6564
}

SparkleShare/Classes/FolderViewController.h

+10-3
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,19 @@
99
#import <UIKit/UIKit.h>
1010
#import "SSFolder.h"
1111
#import "SSFile.h"
12-
#import "PullToRefreshTableViewController.h"
12+
#import "EGORefreshTableHeaderView.h"
1313

14-
@interface FolderViewController : PullToRefreshTableViewController <SSFolderInfoDelegate, SSFolderItemsDelegate, SSFileDelegate>
14+
@interface FolderViewController : UITableViewController <EGORefreshTableHeaderDelegate, SSFolderInfoDelegate, SSFolderItemsDelegate, SSFileDelegate> {
15+
16+
EGORefreshTableHeaderView *_refreshHeaderView;
17+
BOOL _reloading;
18+
}
1519

1620
@property (strong) SSFolder *folder;
21+
@property int iconSize;
22+
1723
- (id)initWithFolder: (SSFolder *) folder;
24+
- (void)reloadTableViewDataSource;
25+
- (void)doneLoadingTableViewData;
1826

19-
@property int iconSize;
2027
@end

SparkleShare/Classes/FolderViewController.m

+58-5
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,16 @@ - (void)viewDidLoad {
3939
else
4040
self.iconSize = 40;
4141

42+
if (_refreshHeaderView == nil) {
43+
44+
EGORefreshTableHeaderView *view = [[EGORefreshTableHeaderView alloc] initWithFrame:CGRectMake(0.0f, 0.0f - self.tableView.bounds.size.height, self.view.frame.size.width, self.tableView.bounds.size.height)];
45+
view.delegate = self;
46+
[self.tableView addSubview:view];
47+
_refreshHeaderView = view;
48+
}
49+
50+
// update the last update date
51+
[_refreshHeaderView refreshLastUpdatedDate];
4252
}
4353

4454
- (void)viewDidUnload {
@@ -72,7 +82,6 @@ - (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation) interfa
7282

7383
#pragma mark - Table view data source
7484

75-
7685
// Customize the number of sections in the table view.
7786
- (NSInteger)numberOfSectionsInTableView: (UITableView *) tableView {
7887
return 1;
@@ -158,7 +167,7 @@ - (void) folder: (SSFolder *) folder itemsLoaded: (NSArray *) items {
158167
}
159168
}
160169
[SVProgressHUD dismiss];
161-
[self dataSourceDidFinishLoadingNewData];
170+
[self doneLoadingTableViewData];
162171
}
163172

164173
- (void) reloadOneItem: (SSFolderItem *) item {
@@ -171,8 +180,7 @@ - (void) reloadOneItem: (SSFolderItem *) item {
171180

172181
- (void) folderLoadingFailed: (SSFolder *) folder {
173182
[SVProgressHUD dismissWithError:@"Folder data loading failed"];
174-
[self dataSourceDidFinishLoadingNewData];
175-
183+
[self doneLoadingTableViewData];
176184
}
177185

178186
- (void) folder: (SSFolder *) folder countLoaded: (int) count {
@@ -192,7 +200,7 @@ - (void) folderInfoLoadingFailed: (SSFolder *) folder {
192200

193201
- (void) file: (SSFile *) file contentLoaded: (NSData *) content {
194202
FilePreview *filePreview = [[FilePreview alloc] initWithFile: file];
195-
203+
196204
FileViewController *newFileViewController = [[FileViewController alloc] initWithFilePreview: filePreview filename: file.name];
197205
[SVProgressHUD dismiss];
198206
[self.navigationController pushViewController: newFileViewController animated: YES];
@@ -208,8 +216,53 @@ - (void) fileContentLoadingFailed: (SSFile *) file {
208216

209217
- (void) reloadTableViewDataSource
210218
{
219+
_reloading = YES;
211220
[self.folder loadItems];
212221
}
213222

223+
- (void)doneLoadingTableViewData
224+
{
225+
_reloading = NO;
226+
[_refreshHeaderView egoRefreshScrollViewDataSourceDidFinishedLoading:self.tableView];
227+
}
228+
229+
#pragma mark -
230+
#pragma mark UIScrollViewDelegate Methods
231+
232+
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
233+
234+
[_refreshHeaderView egoRefreshScrollViewDidScroll:scrollView];
235+
236+
}
237+
238+
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
239+
240+
[_refreshHeaderView egoRefreshScrollViewDidEndDragging:scrollView];
241+
242+
}
243+
244+
245+
#pragma mark -
246+
#pragma mark EGORefreshTableHeaderDelegate Methods
247+
248+
- (void)egoRefreshTableHeaderDidTriggerRefresh:(EGORefreshTableHeaderView*)view{
249+
250+
[self reloadTableViewDataSource];
251+
[self performSelector:@selector(doneLoadingTableViewData) withObject:nil afterDelay:3.0];
252+
253+
}
254+
255+
- (BOOL)egoRefreshTableHeaderDataSourceIsLoading:(EGORefreshTableHeaderView*)view{
256+
257+
return _reloading; // should return if data source model is reloading
258+
259+
}
260+
261+
- (NSDate*)egoRefreshTableHeaderDataSourceLastUpdated:(EGORefreshTableHeaderView*)view{
262+
263+
return [NSDate date]; // should return date data source was last changed
264+
265+
}
266+
214267

215268
@end

SparkleShare/Classes/SSConnection.m

+2-1
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,10 @@ - (void) linkDeviceWithAddress: (NSURL *) anAddress code: (NSString *) code {
105105
[self testConnection];
106106
}
107107
failure:^(NSURLRequest *request, NSURLResponse *response, NSError *error, id JSON) {
108+
NSLog(@"JSON Request error: %@", error);
108109
[self.delegate connectionLinkingFailed:self];
109110
}
110-
];
111+
];
111112

112113
[queue addOperation: operation];
113114
}

SparkleShare/Classes/SSJSONRequestOperation.m

+19-22
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ + (SSJSONRequestOperation *)JSONRequestOperationWithRequest: (NSURLRequest *) ur
3939
}
4040
}
4141
failure:^(AFHTTPRequestOperation * operation, NSError * error) {
42-
if (failure) {
43-
failure (operation.request, operation.response, error, [(SSJSONRequestOperation *) operation responseJSON]);
42+
if (failure) {
43+
failure (operation.request, operation.response, error, [(SSJSONRequestOperation *) operation responseJSON]);
4444
}
4545
}
4646
];
@@ -127,30 +127,27 @@ - (void)setCompletionBlockWithSuccess: ( void (^)(AFHTTPRequestOperation * opera
127127
if (self.error) {
128128
if (failure) {
129129
dispatch_async (dispatch_get_main_queue (), ^(void) {
130-
failure (self, self.error);
131-
}
132-
);
130+
failure (self, self.error);
131+
});
133132
}
134133
}
135134
else {
136135
dispatch_async (json_request_operation_processing_queue (), ^(void) {
137-
id JSON = self.responseJSON;
138-
139-
dispatch_async (dispatch_get_main_queue (), ^(void) {
140-
if (self.JSONError) {
141-
if (failure) {
142-
failure (self, self.JSONError);
143-
}
144-
}
145-
else {
146-
if (success) {
147-
success (self, JSON);
148-
}
149-
}
150-
}
151-
);
152-
}
153-
);
136+
id JSON = self.responseJSON;
137+
138+
dispatch_async (dispatch_get_main_queue (), ^(void) {
139+
if (self.JSONError) {
140+
if (failure) {
141+
failure (self, self.JSONError);
142+
}
143+
}
144+
else {
145+
if (success) {
146+
success (self, JSON);
147+
}
148+
}
149+
});
150+
});
154151
}
155152
};
156153
}

SparkleShare/Classes/SparkleShareAppDelegate.m

-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ @implementation SparkleShareAppDelegate
2222

2323
- (BOOL)application: (UIApplication *) application didFinishLaunchingWithOptions: (NSDictionary *) launchOptions {
2424
self.window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]];
25-
2625

2726
StartingViewController *startingViewController = [[StartingViewController alloc] init];
2827
self.window.rootViewController = startingViewController;
@@ -32,8 +31,6 @@ - (BOOL)application: (UIApplication *) application didFinishLaunchingWithOptions
3231
connection.delegate = self;
3332
[connection estabilishConnection];
3433

35-
36-
3734
return YES;
3835
}
3936

0 commit comments

Comments
 (0)