fixed issue with apps duplicating in app list

This commit is contained in:
Diego Waxemberg 2015-07-11 18:47:05 -07:00
parent 8f12114a56
commit 9c6b718be2
6 changed files with 18 additions and 12 deletions

View File

@ -19,9 +19,10 @@
- (void) saveSettingsWithBitrate:(NSInteger)bitrate framerate:(NSInteger)framerate height:(NSInteger)height width:(NSInteger)width onscreenControls:(NSInteger)onscreenControls;
- (Settings*) retrieveSettings;
- (NSArray*) retrieveHosts;
- (void) saveHosts;
- (void) saveData;
- (Host*) createHost;
- (void) removeHost:(Host*)host;
- (App*) createApp;
- (void) removeApp:(App*)app;
@end

View File

@ -53,10 +53,10 @@
- (void) removeHost:(Host*)host {
[[self.appDelegate managedObjectContext] deleteObject:host];
[self saveHosts];
[self saveData];
}
- (void) saveHosts {
- (void) saveData {
NSError* error;
if (![[self.appDelegate managedObjectContext] save:&error]) {
Log(LOG_E, @"Unable to save hosts to database: %@", error);
@ -73,6 +73,10 @@
return [[App alloc] initWithEntity:entity insertIntoManagedObjectContext:[self.appDelegate managedObjectContext]];
}
- (void) removeApp:(App*)app {
[[self.appDelegate managedObjectContext] deleteObject:app];
}
- (NSArray*) fetchRecords:(NSString*)entityName {
NSFetchRequest* fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription* entity = [NSEntityDescription entityForName:entityName inManagedObjectContext:[self.appDelegate managedObjectContext]];

View File

@ -10,8 +10,6 @@
@interface AppListResponse : NSObject <Response>
@property Host* host;
- (void)populateWithData:(NSData *)data;
- (NSArray*) getAppList;
- (BOOL) isStatusOk;

View File

@ -14,7 +14,7 @@
@implementation AppListResponse {
NSMutableArray* _appList;
}
@synthesize data, statusCode, statusMessage, host;
@synthesize data, statusCode, statusMessage;
static const char* TAG_APP = "App";
static const char* TAG_APP_TITLE = "AppTitle";
@ -99,7 +99,6 @@ static const char* TAG_APP_IS_RUNNING = "IsRunning";
App* app = [dataMan createApp];
app.name = appName;
app.id = appId;
app.host = host;
app.isRunning = appIsRunning;
[_appList addObject:app];
}

View File

@ -125,7 +125,7 @@
[dataMan removeHost:host];
}
}
[dataMan saveHosts];
[dataMan saveData];
});
}

View File

@ -86,7 +86,6 @@ static NSMutableSet* hostList;
HttpManager* hMan = [[HttpManager alloc] initWithHost:_selectedHost.activeAddress uniqueId:_uniqueId deviceName:deviceName cert:_cert];
AppListResponse* appListResp = [[AppListResponse alloc] init];
appListResp.host = _selectedHost;
[hMan executeRequestSynchronously:[HttpRequest requestForResponse:appListResp withUrlRequest:[hMan newAppListRequest]]];
if (appListResp == nil || ![appListResp isStatusOk] || [appListResp getAppList] == nil) {
Log(LOG_W, @"Failed to get applist: %@", appListResp.statusMessage);
@ -118,6 +117,7 @@ static NSMutableSet* hostList;
}
- (void) mergeAppLists:(NSArray*) newList {
DataManager* database = [[DataManager alloc] init];
for (App* app in newList) {
BOOL appAlreadyInList = NO;
for (App* savedApp in _selectedHost.appList) {
@ -129,6 +129,8 @@ static NSMutableSet* hostList;
if (!appAlreadyInList) {
app.host = _selectedHost;
[_selectedHost addAppListObject:app];
} else {
[database removeApp:app];
}
}
@ -142,13 +144,15 @@ static NSMutableSet* hostList;
}
if (appWasRemoved) {
[_selectedHost removeAppListObject:app];
[database removeApp:app];
}
}
[database saveData];
}
- (void)showHostSelectionView {
[_appManager stopRetrieving];
[[[DataManager alloc] init] saveHosts];
[[[DataManager alloc] init] saveData];
_selectedHost = nil;
_computerNameButton.title = @"No Host Selected";
[self.collectionView reloadData];
@ -265,7 +269,7 @@ static NSMutableSet* hostList;
[_discMan discoverHost:hostAddress withCallback:^(Host* host, NSString* error){
if (host != nil) {
DataManager* dataMan = [[DataManager alloc] init];
[dataMan saveHosts];
[dataMan saveData];
dispatch_async(dispatch_get_main_queue(), ^{
@synchronized(hostList) {
[hostList addObject:host];
@ -472,7 +476,7 @@ static NSMutableSet* hostList;
[_discMan stopDiscovery];
// In case the host objects were updated in the background
[[[DataManager alloc] init] saveHosts];
[[[DataManager alloc] init] saveData];
}
- (void) retrieveSavedHosts {