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,43 +419,39 @@
- (void)setShouldObserveDBModifications:(BOOL)shouldObserveDBModifications - (void)setShouldObserveDBModifications:(BOOL)shouldObserveDBModifications
{ {
_shouldObserveDBModifications = shouldObserveDBModifications; if (_shouldObserveDBModifications == shouldObserveDBModifications) {
return;
[self ensureObserveDBModifications]; }
}
- (void)ensureObserveDBModifications _shouldObserveDBModifications = shouldObserveDBModifications;
{
if (self.shouldObserveDBModifications) {
if (self.threadMappings != nil) {
// Before we begin observing database modifications, make sure
// our mapping and table state is up-to-date.
//
// We need to `beginLongLivedReadTransaction` before we update our
// mapping in order to jump to the most recent commit.
[self.uiDatabaseConnection beginLongLivedReadTransaction];
[self.uiDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
[self.threadMappings updateWithTransaction:transaction];
}];
}
[[self tableView] reloadData]; if (!self.shouldObserveDBModifications) {
return;
} }
[[NSNotificationCenter defaultCenter] removeObserver:self name:YapDatabaseModifiedNotification object:nil]; // If we're entering "active" mode (e.g. view is visible and app is in foreground),
if (self.shouldObserveDBModifications) { // reset all state updated by yapDatabaseModified:.
[[NSNotificationCenter defaultCenter] addObserver:self if (self.threadMappings != nil) {
selector:@selector(yapDatabaseModified:) // Before we begin observing database modifications, make sure
name:YapDatabaseModifiedNotification // our mapping and table state is up-to-date.
object:nil]; //
// We need to `beginLongLivedReadTransaction` before we update our
// mapping in order to jump to the most recent commit.
[self.uiDatabaseConnection beginLongLivedReadTransaction];
[self.uiDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
[self.threadMappings updateWithTransaction:transaction];
}];
} }
[[self tableView] reloadData];
[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