From 85957d57f4661c0df8fe7e022728ffceafb2faf8 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Tue, 1 Nov 2011 19:32:01 +0100 Subject: Use timer to reload list of files when the library view is open. We can't use applicationDidBecomeActive in iOS 5 to trigger a reload, since the file sync can happen in the background. --- ios/main.m | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'ios') diff --git a/ios/main.m b/ios/main.m index 6f5fc97e..72cbaa42 100644 --- a/ios/main.m +++ b/ios/main.m @@ -14,11 +14,11 @@ static dispatch_queue_t queue; static fz_glyph_cache *glyphcache = NULL; static UIImage *loadingImage = nil; -static UIBarButtonItem *flexibleSpace = nil; static NSString *docdir = nil; @interface MuLibraryController : UITableViewController { + NSTimer *timer; NSArray *files; } - (void) openDocument: (NSString*)filename; @@ -192,6 +192,23 @@ static UIImage *renderPage(pdf_xref *xref, int number, float width, float height @implementation MuLibraryController +- (void) viewWillAppear: (BOOL)animated +{ + [self reload]; + + timer = [NSTimer timerWithTimeInterval: 1 + target: self selector: @selector(reload) userInfo: nil + repeats: YES]; + + [[NSRunLoop currentRunLoop] addTimer: timer forMode: NSDefaultRunLoopMode]; +} + +- (void) viewWillDisappear: (BOOL)animated +{ + [timer invalidate]; + timer = nil; +} + - (void) reload { [self setTitle: @"MuPDF"]; @@ -754,10 +771,6 @@ static UIImage *renderPage(pdf_xref *xref, int number, float width, float height loadingImage = [[UIImage imageNamed: @"loading.png"] retain]; - flexibleSpace = [[UIBarButtonItem alloc] - initWithBarButtonSystemItem: UIBarButtonSystemItemFlexibleSpace - target: nil action: nil]; - library = [[MuLibraryController alloc] initWithStyle: UITableViewStylePlain]; navigator = [[UINavigationController alloc] initWithRootViewController: library]; @@ -791,7 +804,6 @@ static UIImage *renderPage(pdf_xref *xref, int number, float width, float height - (void)applicationDidBecomeActive:(UIApplication *)application { printf("applicationDidBecomeActive!\n"); - [library reload]; } - (void)applicationWillTerminate:(UIApplication *)application -- cgit v1.2.3