Add object detection, tracking, mobile notifications, and search to any security camera.
improved event loading
roryclearfda1d7173c2d
diff --git a/clearcam/GalleryViewController.m b/clearcam/GalleryViewController.mindex 23dd2ab..2105de7 100644--- a/clearcam/GalleryViewController.m+++ b/clearcam/GalleryViewController.m@@ -79,6 +79,7 @@@property (nonatomic, strong) UIRefreshControl *refreshControl;@property (nonatomic, assign) BOOL isLoadingVideos;@property (nonatomic, strong) NSMutableSet<NSString *> *loadedFilenames;+@property (nonatomic, strong) NSTimer *refreshTimer;@end@implementation GalleryViewController@@ -128,8 +129,29 @@[self getEvents];}];[self updateTableViewBackground];+ [self setupRefreshTimer];}+- (void)dealloc {+ [self.refreshTimer invalidate];+ self.refreshTimer = nil;+}++- (void)setupRefreshTimer {+ self.refreshTimer = [NSTimer scheduledTimerWithTimeInterval:10.0+ target:self+ selector:@selector(refreshTimerFired)+ userInfo:nil+ repeats:YES];+}++- (void)refreshTimerFired {+ if (!self.isLoadingVideos) {+ [self getEvents];+ }+}++- (void)updateTableViewBackground {if (self.videoFiles.count == 0) {UILabel *messageLabel = [[UILabel alloc] initWithFrame:self.eventsViewController.view.bounds];diff --git a/clearcam/StoreManager.m b/clearcam/StoreManager.mindex fe8e6f9..8ed7e75 100644--- a/clearcam/StoreManager.m+++ b/clearcam/StoreManager.m@@ -229,19 +229,17 @@ NSString *const StoreManagerSubscriptionStatusDidChangeNotification = @"StoreMan- (void)verifySubscriptionWithCompletionIfSubbed:(void (^)(BOOL isActive, NSDate *expiryDate))completion {NSDate *expiry = [[NSUserDefaults standardUserDefaults] objectForKey:@"expiry"];BOOL isSubscribed = [[NSUserDefaults standardUserDefaults] boolForKey:@"isSubscribed"];- BOOL sessionExpiredOrNow = !expiry || [expiry compare:[NSDate date]] != NSOrderedDescending;- if (isSubscribed || [StoreManager sharedInstance].last_check_time || [[NSDate date] timeIntervalSince1970] - [StoreManager sharedInstance].last_check_time > 120.0 || ![[StoreManager sharedInstance] retrieveSessionTokenFromKeychain]) {- if (sessionExpiredOrNow || ![[StoreManager sharedInstance] retrieveSessionTokenFromKeychain]) {- [self verifySubscriptionWithCompletion:^(BOOL isActive, NSDate *expiryDate) {- if (completion) {- completion(isActive, expiryDate);- }- }];- } else {- if (completion) {- completion(isSubscribed, expiry);- }- }+ NSTimeInterval lastCheck = [StoreManager sharedInstance].last_check_time;+ BOOL sessionExpired = !expiry || [expiry compare:[NSDate date]] != NSOrderedDescending;+ BOOL sessionTokenMissing = ![[StoreManager sharedInstance] retrieveSessionTokenFromKeychain];+ BOOL shouldCheckRemote = sessionExpired || sessionTokenMissing || ([[NSDate date] timeIntervalSince1970] - lastCheck > 120.0);++ if (shouldCheckRemote) {+ [self verifySubscriptionWithCompletion:^(BOOL isActive, NSDate *expiryDate) {+ if (completion) completion(isActive, expiryDate);+ }];+ } else {+ if (completion) completion(isSubscribed, expiry);}}