finished new ui

This commit is contained in:
Diego Waxemberg
2014-11-26 17:57:16 -05:00
parent 99d3ac45c3
commit dae484445b
11 changed files with 192 additions and 55 deletions
+4 -2
View File
@@ -9,7 +9,7 @@
#import <Foundation/Foundation.h>
#import "Settings.h"
#import "AppDelegate.h"
#import "Hosts.h"
#import "Host.h"
@interface DataManager : NSObject
@@ -17,6 +17,8 @@
- (void) saveSettingsWithBitrate:(NSInteger)bitrate framerate:(NSInteger)framerate height:(NSInteger)height width:(NSInteger)width;
- (Settings*) retrieveSettings;
- (NSArray*) retrieveHosts;
- (void) saveHosts;
- (Host*) createHost:(NSString*)name hostname:(NSString*)address;
@end
+37 -12
View File
@@ -26,21 +26,20 @@ static NSInteger DEFAULT_WIDTH = 1280;
settingsToSave.bitrate = [NSNumber numberWithInteger:bitrate];
settingsToSave.height = [NSNumber numberWithInteger:height];
settingsToSave.width = [NSNumber numberWithInteger:width];
[self saveSettings:settingsToSave];
NSError* error;
if (![[self.appDelegate managedObjectContext] save:&error]) {
NSLog(@"ERROR: Unable to save settings to database");
}
[self.appDelegate saveContext];
}
- (Settings*) retrieveSettings {
NSFetchRequest* fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription* entity = [NSEntityDescription entityForName:@"Settings" inManagedObjectContext:[self.appDelegate managedObjectContext]];
[fetchRequest setEntity:entity];
[fetchRequest setAffectedStores:[NSArray arrayWithObjects:[[self.appDelegate persistentStoreCoordinator] persistentStoreForURL:[self.appDelegate getStoreURL]], nil]];
NSError* error;
NSArray* fetchedRecords = [[self.appDelegate managedObjectContext] executeFetchRequest:fetchRequest error:&error];
NSArray* fetchedRecords = [self fetchRecords:@"Settings"];
if (fetchedRecords.count == 0) {
// create a new settings object with the default values
NSEntityDescription* entity = [NSEntityDescription entityForName:@"Settings" inManagedObjectContext:[self.appDelegate managedObjectContext]];
Settings* settings = [[Settings alloc] initWithEntity:entity insertIntoManagedObjectContext:[self.appDelegate managedObjectContext]];
settings.framerate = [NSNumber numberWithInteger:DEFAULT_FRAMERATE];
settings.bitrate = [NSNumber numberWithInteger:DEFAULT_BITRATE];
settings.height = [NSNumber numberWithInteger:DEFAULT_HEIGHT];
@@ -52,14 +51,40 @@ static NSInteger DEFAULT_WIDTH = 1280;
}
}
- (void) saveSettings:(Settings*)settings {
- (Host*) createHost:(NSString*)name hostname:(NSString*)address {
NSEntityDescription* entity = [NSEntityDescription entityForName:@"Host" inManagedObjectContext:[self.appDelegate managedObjectContext]];
Host* host = [[Host alloc] initWithEntity:entity insertIntoManagedObjectContext:[self.appDelegate managedObjectContext]];
host.name = name;
host.address = address;
return host;
}
- (void) saveHosts {
NSError* error;
if (![[self.appDelegate managedObjectContext] save:&error]) {
NSLog(@"ERROR: Unable to save settings to database");
NSLog(@"ERROR: Unable to save hosts to database");
}
[self.appDelegate saveContext];
}
- (NSArray*) retrieveHosts {
return [self fetchRecords:@"Host"];
}
- (NSArray*) fetchRecords:(NSString*)entityName {
NSFetchRequest* fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription* entity = [NSEntityDescription entityForName:entityName inManagedObjectContext:[self.appDelegate managedObjectContext]];
[fetchRequest setEntity:entity];
[fetchRequest setAffectedStores:[NSArray arrayWithObjects:[[self.appDelegate persistentStoreCoordinator] persistentStoreForURL:[self.appDelegate getStoreURL]], nil]];
NSError* error;
NSArray* fetchedRecords = [[self.appDelegate managedObjectContext] executeFetchRequest:fetchRequest error:&error];
//TODO: handle errors
return fetchedRecords;
}
@end
@@ -1,5 +1,5 @@
//
// Hosts.h
// Host.h
// Limelight
//
// Created by Diego Waxemberg on 10/28/14.
@@ -10,7 +10,7 @@
#import <CoreData/CoreData.h>
@interface Hosts : NSManagedObject
@interface Host : NSManagedObject
@property (nonatomic, retain) NSString * address;
@property (nonatomic, retain) NSString * name;
@@ -1,15 +1,15 @@
//
// Hosts.m
// Host.m
// Limelight
//
// Created by Diego Waxemberg on 10/28/14.
// Copyright (c) 2014 Limelight Stream. All rights reserved.
//
#import "Hosts.h"
#import "Host.h"
@implementation Hosts
@implementation Host
@dynamic address;
@dynamic name;
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<model userDefinedModelVersionIdentifier="" type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="6252" systemVersion="14A388a" minimumToolsVersion="Automatic" macOSVersion="Automatic" iOSVersion="Automatic">
<entity name="Hosts" representedClassName="Hosts" syncable="YES">
<model userDefinedModelVersionIdentifier="" type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="6252" systemVersion="14C68k" minimumToolsVersion="Automatic" macOSVersion="Automatic" iOSVersion="Automatic">
<entity name="Host" representedClassName="Host" syncable="YES">
<attribute name="address" optional="YES" attributeType="String" syncable="YES"/>
<attribute name="name" optional="YES" attributeType="String" syncable="YES"/>
</entity>
@@ -11,7 +11,7 @@
<attribute name="width" optional="YES" attributeType="Integer 32" defaultValueString="0" syncable="YES"/>
</entity>
<elements>
<element name="Hosts" positionX="-63" positionY="-18" width="128" height="75"/>
<element name="Settings" positionX="142" positionY="-36" width="128" height="103"/>
<element name="Host" positionX="0" positionY="0" width="0" height="0"/>
<element name="Settings" positionX="0" positionY="0" width="0" height="0"/>
</elements>
</model>
@@ -116,7 +116,9 @@ static StreamConfiguration* streamConfig;
Computer* newHost = [[Computer alloc] initWithIp:host];
[hostList addObject:newHost];
[self updateHosts:[hostList allObjects]];
DataManager* dataMan = [[DataManager alloc] init];
[dataMan createHost:newHost.displayName hostname:newHost.hostName];
[dataMan saveHosts];
//TODO: get pair state
@@ -192,7 +194,8 @@ static StreamConfiguration* streamConfig;
appScrollView = [[UIScrollView alloc] init];
appScrollView.frame = CGRectMake(0, hostScrollView.frame.size.height, self.view.frame.size.width, self.view.frame.size.height / 2);
[appScrollView setShowsHorizontalScrollIndicator:NO];
[self retrieveSavedHosts];
[self updateHosts:[hostList allObjects]];
[self.view addSubview:hostScrollView];
[self.view addSubview:appScrollView];
@@ -200,7 +203,7 @@ static StreamConfiguration* streamConfig;
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[super viewDidAppear:animated];
[self.navigationController setNavigationBarHidden:NO animated:YES];
_mDNSManager = [[MDNSManager alloc] initWithCallback:self];
[_mDNSManager searchForHosts];
@@ -208,10 +211,22 @@ static StreamConfiguration* streamConfig;
- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
[super viewDidDisappear:animated];
[_mDNSManager stopSearching];
}
- (void) retrieveSavedHosts {
//TODO: Get rid of Computer and only use Host
DataManager* dataMan = [[DataManager alloc] init];
NSArray* hosts = [dataMan retrieveHosts];
for (Host* host in hosts) {
Computer* comp = [[Computer alloc] initWithIp:host.address];
comp.displayName = host.name;
[hostList addObject:comp];
}
}
- (void)updateHosts:(NSArray *)hosts {
[hostList addObjectsFromArray:hosts];
[[hostScrollView subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)];
@@ -15,7 +15,7 @@
@implementation SettingsViewController {
NSInteger _bitrate;
}
static NSString* bitrateFormat = @"Bitrate: %d bps";
static NSString* bitrateFormat = @"Bitrate: %d kbps";
- (void)viewDidLoad {