Kaydet (Commit) 12695783 authored tarafından siqi's avatar siqi

retain servers in userdefaults

Change-Id: I2f6947423e3b5e1613de5658c691a3b6fca94d8b
üst 86f02abe
...@@ -13,9 +13,10 @@ ...@@ -13,9 +13,10 @@
#import "SlideShow.h" #import "SlideShow.h"
#import "CommandTransmitter.h" #import "CommandTransmitter.h"
#import "CommandInterpreter.h" #import "CommandInterpreter.h"
#import "libreoffice_sdremoteViewController.h"
#import <dispatch/dispatch.h> #import <dispatch/dispatch.h>
#define ExistingServersKey @"CommunicationManager.ExistingServers"
@interface CommunicationManager() @interface CommunicationManager()
@property (nonatomic, strong) Client* client; @property (nonatomic, strong) Client* client;
...@@ -42,7 +43,7 @@ ...@@ -42,7 +43,7 @@
static dispatch_once_t _singletonPredicate; static dispatch_once_t _singletonPredicate;
dispatch_once(&_singletonPredicate, ^{ dispatch_once(&_singletonPredicate, ^{
sharedComManager = [[super allocWithZone:nil] init]; sharedComManager = [[super allocWithZone:nil] initWithExistingServers];
}); });
return sharedComManager; return sharedComManager;
...@@ -56,7 +57,7 @@ ...@@ -56,7 +57,7 @@
NSLog(@"Connected"); NSLog(@"Connected");
self.transmitter = [[CommandTransmitter alloc] initWithClient:self.client]; self.transmitter = [[CommandTransmitter alloc] initWithClient:self.client];
self.state = CONNECTED; self.state = CONNECTED;
[self.delegate setPinLabelText:[NSString stringWithFormat:@"%@", [self getPairingPin]]]; // [self.delegate setPinLabelText:[NSString stringWithFormat:@"%@", [self getPairingPin]]];
} }
} else if ([[note name] isEqualToString:@"connection.status.disconnected"]){ } else if ([[note name] isEqualToString:@"connection.status.disconnected"]){
if (self.state != DISCONNECTED) { if (self.state != DISCONNECTED) {
...@@ -91,13 +92,12 @@ ...@@ -91,13 +92,12 @@
- (id) initWithExistingServers - (id) initWithExistingServers
{ {
self = [self init]; self = [self init];
NSUserDefaults * userDefaluts = [NSUserDefaults standardUserDefaults]; NSUserDefaults * userDefaluts = [NSUserDefaults standardUserDefaults];
if(!userDefaluts) if(!userDefaluts)
NSLog(@"userDefaults nil"); NSLog(@"userDefaults nil");
NSData *dataRepresentingExistingServers = [userDefaluts objectForKey:@"ExistingServers"]; NSData *dataRepresentingExistingServers = [userDefaluts objectForKey:ExistingServersKey];
if (dataRepresentingExistingServers != nil) if (dataRepresentingExistingServers != nil)
{ {
NSArray *oldSavedArray = [NSKeyedUnarchiver unarchiveObjectWithData:dataRepresentingExistingServers]; NSArray *oldSavedArray = [NSKeyedUnarchiver unarchiveObjectWithData:dataRepresentingExistingServers];
...@@ -144,7 +144,8 @@ ...@@ -144,7 +144,8 @@
{ {
Server * s = [[Server alloc] initWithProtocol:NETWORK atAddress:addr ofName:name]; Server * s = [[Server alloc] initWithProtocol:NETWORK atAddress:addr ofName:name];
[self.servers addObject:s]; [self.servers addObject:s];
NSLog(@"Having %lu servers now", (unsigned long)[self.servers count]); [[NSUserDefaults standardUserDefaults] setObject:[NSKeyedArchiver archivedDataWithRootObject:self.servers] forKey:ExistingServersKey];
[[NSUserDefaults standardUserDefaults] synchronize];
} }
@end @end
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
<rect key="frame" x="0.0" y="64" width="320" height="504"/> <rect key="frame" x="0.0" y="64" width="320" height="504"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/> <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<prototypes> <prototypes>
<tableViewCell contentMode="scaleToFill" selectionStyle="blue" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" reuseIdentifier="server_item_cell" textLabel="Rg3-PU-OuS" detailTextLabel="9Mc-gD-acc" style="IBUITableViewCellStyleValue1" id="Pvl-Uw-Ghs"> <tableViewCell contentMode="scaleToFill" selectionStyle="blue" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" reuseIdentifier="server_item_cell" editingAccessoryType="disclosureIndicator" textLabel="Rg3-PU-OuS" detailTextLabel="9Mc-gD-acc" style="IBUITableViewCellStyleValue1" id="Pvl-Uw-Ghs">
<rect key="frame" x="0.0" y="22" width="320" height="44"/> <rect key="frame" x="0.0" y="22" width="320" height="44"/>
<autoresizingMask key="autoresizingMask"/> <autoresizingMask key="autoresizingMask"/>
<view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center"> <view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center">
......
...@@ -22,6 +22,9 @@ ...@@ -22,6 +22,9 @@
- (IBAction)save:(id)sender { - (IBAction)save:(id)sender {
NSString *serverName = [self.nameCell.textField text]; NSString *serverName = [self.nameCell.textField text];
NSString *serverAddr = [self.addrCell.textField text]; NSString *serverAddr = [self.addrCell.textField text];
if (!serverName) {
serverName = @"Computer";
}
NSLog(@"New server name:%@ ip:%@", serverName, serverAddr); NSLog(@"New server name:%@ ip:%@", serverName, serverAddr);
[self.comManager addServersWithName:serverName AtAddress:serverAddr]; [self.comManager addServersWithName:serverName AtAddress:serverAddr];
[self.navigationController popViewControllerAnimated:YES]; [self.navigationController popViewControllerAnimated:YES];
...@@ -241,6 +244,7 @@ titleForHeaderInSection:(NSInteger)section ...@@ -241,6 +244,7 @@ titleForHeaderInSection:(NSInteger)section
NSInteger tag = INT_MIN; NSInteger tag = INT_MIN;
NSString *text = nil; NSString *text = nil;
NSString *placeholder = nil; NSString *placeholder = nil;
UIKeyboardType keyboardType;
// Pick the editable cell and the values for its textField // Pick the editable cell and the values for its textField
// //
...@@ -255,6 +259,7 @@ titleForHeaderInSection:(NSInteger)section ...@@ -255,6 +259,7 @@ titleForHeaderInSection:(NSInteger)section
text = [self.server serverName]; text = [self.server serverName];
tag = ServerName; tag = ServerName;
placeholder = @"Server Name (optional)"; placeholder = @"Server Name (optional)";
keyboardType = UIKeyboardTypeDefault;
} }
else else
{ {
...@@ -262,6 +267,7 @@ titleForHeaderInSection:(NSInteger)section ...@@ -262,6 +267,7 @@ titleForHeaderInSection:(NSInteger)section
text = [self.server serverAddress]; text = [self.server serverAddress];
tag = ServerAddr; tag = ServerAddr;
placeholder = @"IP Address"; placeholder = @"IP Address";
keyboardType = UIKeyboardTypeNumbersAndPunctuation;
} }
break; break;
} }
...@@ -269,6 +275,7 @@ titleForHeaderInSection:(NSInteger)section ...@@ -269,6 +275,7 @@ titleForHeaderInSection:(NSInteger)section
[cell.textField setPlaceholder:placeholder]; [cell.textField setPlaceholder:placeholder];
[cell setTag:tag]; [cell setTag:tag];
[cell.textField setText:text]; [cell.textField setText:text];
[cell.textField setKeyboardType:keyboardType];
return cell; return cell;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment