Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(127)

Side by Side Diff: remoting/client/ios/domain/host_info.mm

Issue 2681173002: Adding domain and facade supporting classes for remoting iOS app. (Closed)
Patch Set: Renaming domain objects based on feedback. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « remoting/client/ios/domain/host_info.h ('k') | remoting/client/ios/domain/user_info.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #if !defined(__has_feature) || !__has_feature(objc_arc)
6 #error "This file requires ARC support."
7 #endif
8
9 #import "remoting/client/ios/domain/host_info.h"
10
11 @implementation HostInfo
12
13 @synthesize createdTime = _createdTime;
14 @synthesize hostId = _hostId;
15 @synthesize hostName = _hostName;
16 @synthesize hostVersion = _hostVersion;
17 @synthesize jabberId = _jabberId;
18 @synthesize kind = _kind;
19 @synthesize publicKey = _publicKey;
20 @synthesize status = _status;
21 @synthesize updatedTime = _updatedTime;
22 @synthesize isOnline = _isOnline;
23
24 - (bool)isOnline {
25 _isOnline = (self.status && [self.status isEqualToString:@"ONLINE"]);
26 return _isOnline;
27 }
28
29 // Parse jsonData into Host list.
30 + (NSMutableArray<HostInfo*>*)parseListFromJSON:(NSMutableData*)data {
31 NSError* error;
32
33 NSDictionary* json = [NSJSONSerialization JSONObjectWithData:data
34 options:kNilOptions
35 error:&error];
36 NSDictionary* dataDict = [json objectForKey:@"data"];
37 NSArray* availableHosts = [dataDict objectForKey:@"items"];
38 NSMutableArray* hostList = [[NSMutableArray alloc] init];
39 NSUInteger idx = 0;
40 NSDictionary* svr;
41 NSUInteger count = [availableHosts count];
42
43 while (idx < count) {
44 svr = [availableHosts objectAtIndex:idx++];
45 HostInfo* host = [[HostInfo alloc] init];
46 host.createdTime = [svr objectForKey:@"createdTime"];
47 host.hostId = [svr objectForKey:@"hostId"];
48 host.hostName = [svr objectForKey:@"hostName"];
49 host.hostVersion = [svr objectForKey:@"hostVersion"];
50 host.jabberId = [svr objectForKey:@"jabberId"];
51 host.kind = [svr objectForKey:@"kind"];
52 host.publicKey = [svr objectForKey:@"publicKey"];
53 host.status = [svr objectForKey:@"status"];
54
55 NSString* ISO8601DateString = [svr objectForKey:@"updatedTime"];
56 if (ISO8601DateString != nil) {
57 NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];
58 [dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSSz"];
59 host.updatedTime = [dateFormatter dateFromString:ISO8601DateString];
60 }
61
62 [hostList addObject:host];
63 }
64
65 return hostList;
66 }
67
68 - (NSComparisonResult)compare:(HostInfo*)host {
69 if (self.isOnline != host.isOnline) {
70 return self.isOnline ? NSOrderedAscending : NSOrderedDescending;
71 } else {
72 return [self.hostName localizedCaseInsensitiveCompare:host.hostName];
73 }
74 }
75
76 @end
OLDNEW
« no previous file with comments | « remoting/client/ios/domain/host_info.h ('k') | remoting/client/ios/domain/user_info.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698