Add possible fixes for the ‘empty home view’ issue.

// FREEBIE
pull/1/head
Matthew Chen 8 years ago
parent f52814bb70
commit 90dabe1c81

@ -125,6 +125,10 @@
selector:@selector(applicationDidEnterBackground:) selector:@selector(applicationDidEnterBackground:)
name:UIApplicationDidEnterBackgroundNotification name:UIApplicationDidEnterBackgroundNotification
object:nil]; object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(yapDatabaseModified:)
name:YapDatabaseModifiedNotification
object:nil];
} }
- (void)dealloc - (void)dealloc
@ -415,14 +419,18 @@
- (void)setShouldObserveDBModifications:(BOOL)shouldObserveDBModifications - (void)setShouldObserveDBModifications:(BOOL)shouldObserveDBModifications
{ {
if (_shouldObserveDBModifications == shouldObserveDBModifications) {
return;
}
_shouldObserveDBModifications = shouldObserveDBModifications; _shouldObserveDBModifications = shouldObserveDBModifications;
[self ensureObserveDBModifications]; if (!self.shouldObserveDBModifications) {
return;
} }
- (void)ensureObserveDBModifications // If we're entering "active" mode (e.g. view is visible and app is in foreground),
{ // reset all state updated by yapDatabaseModified:.
if (self.shouldObserveDBModifications) {
if (self.threadMappings != nil) { if (self.threadMappings != nil) {
// Before we begin observing database modifications, make sure // Before we begin observing database modifications, make sure
// our mapping and table state is up-to-date. // our mapping and table state is up-to-date.
@ -436,22 +444,14 @@
} }
[[self tableView] reloadData]; [[self tableView] reloadData];
}
[[NSNotificationCenter defaultCenter] removeObserver:self name:YapDatabaseModifiedNotification object:nil];
if (self.shouldObserveDBModifications) {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(yapDatabaseModified:)
name:YapDatabaseModifiedNotification
object:nil];
}
[self checkIfEmptyView]; [self checkIfEmptyView];
[self updateInboxCountLabel];
} }
- (void)applicationWillEnterForeground:(NSNotification *)notification - (void)applicationWillEnterForeground:(NSNotification *)notification
{ {
self.isAppInBackground = NO; self.isAppInBackground = NO;
[self checkIfEmptyView];
} }
- (void)applicationDidEnterBackground:(NSNotification *)notification - (void)applicationDidEnterBackground:(NSNotification *)notification
@ -845,6 +845,10 @@
[self.contactsManager requestSystemContactsOnce]; [self.contactsManager requestSystemContactsOnce];
} }
if (!self.shouldObserveDBModifications) {
return;
}
[[self.uiDatabaseConnection ext:TSThreadDatabaseViewExtensionName] getSectionChanges:&sectionChanges [[self.uiDatabaseConnection ext:TSThreadDatabaseViewExtensionName] getSectionChanges:&sectionChanges
rowChanges:&rowChanges rowChanges:&rowChanges
forNotifications:notifications forNotifications:notifications
@ -855,6 +859,9 @@
[self updateInboxCountLabel]; [self updateInboxCountLabel];
if ([sectionChanges count] == 0 && [rowChanges count] == 0) { if ([sectionChanges count] == 0 && [rowChanges count] == 0) {
[self.uiDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
[self.threadMappings updateWithTransaction:transaction];
}];
[self checkIfEmptyView]; [self checkIfEmptyView];
return; return;
} }

Loading…
Cancel
Save