commit 10939d32fc9552260081b195d92258fe9e585d4d
parent 346561a9b8a026d5303db716f1750a68e231c7f6
Author: Kyle Milz <kyle@Kyles-MacBook-Pro.local>
Date: Sun, 9 Aug 2015 21:46:31 -0600
ios-ng: implement some more message types
Diffstat:
8 files changed, 384 insertions(+), 35 deletions(-)
diff --git a/ios-ng/NewItemTableViewController.h b/ios-ng/NewItemTableViewController.h
@@ -0,0 +1,8 @@
+#import <UIKit/UIKit.h>
+#import "ListItem.h"
+
+@interface NewItemTableViewController : UITableViewController
+
+@property ListItem *shared_list;
+
+@end
diff --git a/ios-ng/NewItemTableViewController.m b/ios-ng/NewItemTableViewController.m
@@ -0,0 +1,92 @@
+#import "NewItemTableViewController.h"
+
+@interface NewItemTableViewController ()
+
+@end
+
+@implementation NewItemTableViewController
+
+- (void)viewDidLoad {
+ [super viewDidLoad];
+
+ // Uncomment the following line to preserve selection between presentations.
+ // self.clearsSelectionOnViewWillAppear = NO;
+
+ // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
+ // self.navigationItem.rightBarButtonItem = self.editButtonItem;
+}
+
+- (void)didReceiveMemoryWarning {
+ [super didReceiveMemoryWarning];
+ // Dispose of any resources that can be recreated.
+}
+
+#pragma mark - Table view data source
+
+- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
+#warning Potentially incomplete method implementation.
+ // Return the number of sections.
+ return 0;
+}
+
+- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
+#warning Incomplete method implementation.
+ // Return the number of rows in the section.
+ return 0;
+}
+
+/*
+- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
+ UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:<#@"reuseIdentifier"#> forIndexPath:indexPath];
+
+ // Configure the cell...
+
+ return cell;
+}
+*/
+
+/*
+// Override to support conditional editing of the table view.
+- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
+ // Return NO if you do not want the specified item to be editable.
+ return YES;
+}
+*/
+
+/*
+// Override to support editing the table view.
+- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
+ if (editingStyle == UITableViewCellEditingStyleDelete) {
+ // Delete the row from the data source
+ [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
+ } else if (editingStyle == UITableViewCellEditingStyleInsert) {
+ // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
+ }
+}
+*/
+
+/*
+// Override to support rearranging the table view.
+- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
+}
+*/
+
+/*
+// Override to support conditional rearranging of the table view.
+- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
+ // Return NO if you do not want the item to be re-orderable.
+ return YES;
+}
+*/
+
+/*
+#pragma mark - Navigation
+
+// In a storyboard-based application, you will often want to do a little preparation before navigation
+- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
+ // Get the new view controller using [segue destinationViewController].
+ // Pass the selected object to the new view controller.
+}
+*/
+
+@end
diff --git a/ios-ng/shlist.xcodeproj/project.pbxproj b/ios-ng/shlist.xcodeproj/project.pbxproj
@@ -7,6 +7,7 @@
objects = {
/* Begin PBXBuildFile section */
+ 27AAC22C1B50ABAF00D99171 /* NewItemTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 27AAC22B1B50ABAF00D99171 /* NewItemTableViewController.m */; };
27B039FF1B43B6830054B6D2 /* ContactsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 27B039FE1B43B6830054B6D2 /* ContactsViewController.m */; };
27B03A021B43B8660054B6D2 /* AddressBook.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 27B03A001B43B8660054B6D2 /* AddressBook.framework */; };
27B03A031B43B8660054B6D2 /* AddressBookUI.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 27B03A011B43B8660054B6D2 /* AddressBookUI.framework */; };
@@ -37,6 +38,8 @@
/* End PBXContainerItemProxy section */
/* Begin PBXFileReference section */
+ 27AAC22A1B50ABAF00D99171 /* NewItemTableViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NewItemTableViewController.h; sourceTree = "<group>"; };
+ 27AAC22B1B50ABAF00D99171 /* NewItemTableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NewItemTableViewController.m; sourceTree = "<group>"; };
27B039FD1B43B6830054B6D2 /* ContactsViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ContactsViewController.h; sourceTree = SOURCE_ROOT; };
27B039FE1B43B6830054B6D2 /* ContactsViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ContactsViewController.m; sourceTree = SOURCE_ROOT; };
27B03A001B43B8660054B6D2 /* AddressBook.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AddressBook.framework; path = System/Library/Frameworks/AddressBook.framework; sourceTree = SDKROOT; };
@@ -93,6 +96,8 @@
27C70EF61B32AF7F00DADEB3 = {
isa = PBXGroup;
children = (
+ 27AAC22A1B50ABAF00D99171 /* NewItemTableViewController.h */,
+ 27AAC22B1B50ABAF00D99171 /* NewItemTableViewController.m */,
27B03A001B43B8660054B6D2 /* AddressBook.framework */,
27B03A011B43B8660054B6D2 /* AddressBookUI.framework */,
27C70F331B36513200DADEB3 /* DBManager.h */,
@@ -269,6 +274,7 @@
files = (
BF7776B91B38928D00526CB0 /* ListDetailTableViewController.m in Sources */,
27C70F351B36513200DADEB3 /* DBManager.m in Sources */,
+ 27AAC22C1B50ABAF00D99171 /* NewItemTableViewController.m in Sources */,
BF7776BC1B38D0DB00526CB0 /* ListItem.m in Sources */,
27C70F0B1B32AF8000DADEB3 /* ShlistServer.m in Sources */,
27C70F2A1B33D1C900DADEB3 /* SharedList.m in Sources */,
diff --git a/ios-ng/shlist/Base.lproj/Main.storyboard b/ios-ng/shlist/Base.lproj/Main.storyboard
@@ -15,25 +15,28 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<prototypes>
- <tableViewCell contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" reuseIdentifier="ListDetailPrototypeCell" textLabel="rxW-Ue-XrL" detailTextLabel="Q7z-lr-GKp" style="IBUITableViewCellStyleValue1" id="s1K-8G-gXq">
+ <tableViewCell contentMode="scaleToFill" selectionStyle="default" accessoryType="disclosureIndicator" indentationWidth="10" reuseIdentifier="ListDetailPrototypeCell" textLabel="rxW-Ue-XrL" detailTextLabel="Q7z-lr-GKp" style="IBUITableViewCellStyleValue2" id="s1K-8G-gXq">
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="s1K-8G-gXq" id="H4s-wq-8Lq">
<autoresizingMask key="autoresizingMask"/>
<subviews>
- <label opaque="NO" multipleTouchEnabled="YES" contentMode="left" text="Title" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="rxW-Ue-XrL">
+ <label opaque="NO" multipleTouchEnabled="YES" contentMode="left" text="Title" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="rxW-Ue-XrL">
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
- <fontDescription key="fontDescription" type="system" pointSize="16"/>
- <color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
+ <fontDescription key="fontDescription" type="system" pointSize="12"/>
+ <color key="textColor" red="0.0" green="0.47843137254901963" blue="1" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
- <label opaque="NO" multipleTouchEnabled="YES" contentMode="left" text="Detail" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="Q7z-lr-GKp">
+ <label opaque="NO" multipleTouchEnabled="YES" contentMode="left" text="Detail" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="Q7z-lr-GKp">
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
- <fontDescription key="fontDescription" type="system" pointSize="16"/>
- <color key="textColor" red="0.55686274509803924" green="0.55686274509803924" blue="0.57647058823529407" alpha="1" colorSpace="calibratedRGB"/>
+ <fontDescription key="fontDescription" type="system" pointSize="12"/>
+ <color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</tableViewCellContentView>
+ <connections>
+ <segue destination="2Mz-oY-P1s" kind="show" id="3ew-8g-3Od"/>
+ </connections>
</tableViewCell>
</prototypes>
<connections>
@@ -41,16 +44,87 @@
<outlet property="delegate" destination="pMK-tA-j4s" id="T4n-F1-eqf"/>
</connections>
</tableView>
+ <toolbarItems/>
+ <navigationItem key="navigationItem" title="Title" id="66A-da-3AW">
+ <barButtonItem key="rightBarButtonItem" systemItem="add" id="iiv-LM-IOO">
+ <connections>
+ <segue destination="KAJ-Ph-mEk" kind="presentation" id="jZG-FG-nAX"/>
+ </connections>
+ </barButtonItem>
+ </navigationItem>
</tableViewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="H64-xB-1er" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="1188" y="-70"/>
</scene>
- <!--Shared Lists-->
+ <!--Add Item-->
+ <scene sceneID="OeV-vW-TVD">
+ <objects>
+ <tableViewController title="Add Item" id="8Gi-Gc-mRg" customClass="NewItemTableViewController" sceneMemberID="viewController">
+ <tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="grouped" separatorStyle="default" rowHeight="44" sectionHeaderHeight="10" sectionFooterHeight="10" id="sGb-Al-WmL">
+ <rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
+ <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
+ <color key="backgroundColor" cocoaTouchSystemColor="groupTableViewBackgroundColor"/>
+ <prototypes>
+ <tableViewCell contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" id="hpv-Jh-N2Z">
+ <autoresizingMask key="autoresizingMask"/>
+ <tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="hpv-Jh-N2Z" id="bBG-J9-Qvq">
+ <autoresizingMask key="autoresizingMask"/>
+ <subviews>
+ <textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="2XT-Rw-cxe">
+ <rect key="frame" x="8" y="7" width="97" height="30"/>
+ <fontDescription key="fontDescription" type="system" pointSize="14"/>
+ <textInputTraits key="textInputTraits"/>
+ </textField>
+ </subviews>
+ </tableViewCellContentView>
+ </tableViewCell>
+ <tableViewCell contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" id="40G-4d-KXw">
+ <autoresizingMask key="autoresizingMask"/>
+ <tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="40G-4d-KXw" id="xcB-Zu-7Yt">
+ <autoresizingMask key="autoresizingMask"/>
+ <subviews>
+ <switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" on="YES" translatesAutoresizingMaskIntoConstraints="NO" id="CA8-dS-VRO">
+ <rect key="frame" x="543" y="6" width="51" height="31"/>
+ </switch>
+ <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="Item is shared" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="MsQ-Iq-XOk">
+ <rect key="frame" x="8" y="11" width="108" height="21"/>
+ <fontDescription key="fontDescription" type="system" pointSize="17"/>
+ <color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
+ <nil key="highlightedColor"/>
+ </label>
+ </subviews>
+ </tableViewCellContentView>
+ </tableViewCell>
+ </prototypes>
+ <connections>
+ <outlet property="dataSource" destination="8Gi-Gc-mRg" id="v6S-Tx-yoO"/>
+ <outlet property="delegate" destination="8Gi-Gc-mRg" id="tyD-6N-VIH"/>
+ </connections>
+ </tableView>
+ <navigationItem key="navigationItem" id="eut-8p-blz">
+ <barButtonItem key="leftBarButtonItem" systemItem="cancel" id="tos-la-Do9">
+ <connections>
+ <segue destination="lUt-lN-Y7n" kind="unwind" unwindAction="unwindToList:" id="2oI-IJ-XHn"/>
+ </connections>
+ </barButtonItem>
+ <barButtonItem key="rightBarButtonItem" systemItem="save" id="911-15-WDf">
+ <connections>
+ <segue destination="lUt-lN-Y7n" kind="unwind" unwindAction="unwindToList:" id="bjl-dy-AY4"/>
+ </connections>
+ </barButtonItem>
+ </navigationItem>
+ </tableViewController>
+ <placeholder placeholderIdentifier="IBFirstResponder" id="HuD-ay-3nZ" userLabel="First Responder" sceneMemberID="firstResponder"/>
+ <exit id="lUt-lN-Y7n" userLabel="Exit" sceneMemberID="exit"/>
+ </objects>
+ <point key="canvasLocation" x="2798" y="-225"/>
+ </scene>
+ <!--Lists-->
<scene sceneID="hc1-Lv-WtP">
<objects>
<tableViewController id="x0J-ua-E8Q" customClass="SharedListsTableViewController" sceneMemberID="viewController">
- <tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="44" sectionHeaderHeight="22" sectionFooterHeight="22" id="D4a-1U-mWV">
+ <tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" allowsSelectionDuringEditing="YES" rowHeight="44" sectionHeaderHeight="22" sectionFooterHeight="22" id="D4a-1U-mWV">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
@@ -75,7 +149,7 @@
</subviews>
</tableViewCellContentView>
<connections>
- <segue destination="pMK-tA-j4s" kind="show" id="ORk-KR-Twe"/>
+ <segue destination="pMK-tA-j4s" kind="show" identifier="show list segue" id="ORk-KR-Twe"/>
</connections>
</tableViewCell>
<tableViewCell contentMode="scaleToFill" selectionStyle="blue" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" reuseIdentifier="IndirectListPrototypeCell" textLabel="WuW-Sd-sxB" detailTextLabel="rf3-DG-Fgi" style="IBUITableViewCellStyleSubtitle" id="kbj-EX-eeF">
@@ -106,11 +180,11 @@
</connections>
</tableView>
<toolbarItems/>
- <navigationItem key="navigationItem" title="Shared Lists" id="uhM-V6-aB7">
+ <navigationItem key="navigationItem" title="Lists" id="uhM-V6-aB7">
<barButtonItem key="leftBarButtonItem" systemItem="edit" id="XHh-J3-UVD"/>
<barButtonItem key="rightBarButtonItem" systemItem="add" id="hNc-gt-QbU">
<connections>
- <segue destination="zuT-Jr-cfg" kind="presentation" id="Tbe-NZ-dy8"/>
+ <segue destination="zuT-Jr-cfg" kind="presentation" identifier="add lists segue" id="Tbe-NZ-dy8"/>
</connections>
</barButtonItem>
</navigationItem>
@@ -299,5 +373,49 @@
</objects>
<point key="canvasLocation" x="1188" y="811"/>
</scene>
+ <!--Navigation Controller-->
+ <scene sceneID="ePv-rp-4Gj">
+ <objects>
+ <navigationController automaticallyAdjustsScrollViewInsets="NO" id="KAJ-Ph-mEk" sceneMemberID="viewController">
+ <toolbarItems/>
+ <navigationBar key="navigationBar" contentMode="scaleToFill" id="9K2-go-fVL">
+ <rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
+ <autoresizingMask key="autoresizingMask"/>
+ </navigationBar>
+ <nil name="viewControllers"/>
+ <connections>
+ <segue destination="8Gi-Gc-mRg" kind="relationship" relationship="rootViewController" id="7nF-P4-5L6"/>
+ </connections>
+ </navigationController>
+ <placeholder placeholderIdentifier="IBFirstResponder" id="AR0-99-D0J" userLabel="First Responder" sceneMemberID="firstResponder"/>
+ </objects>
+ <point key="canvasLocation" x="1973" y="-524"/>
+ </scene>
+ <!--Edit List Item-->
+ <scene sceneID="aq6-TL-408">
+ <objects>
+ <tableViewController title="Edit List Item" id="2Mz-oY-P1s" sceneMemberID="viewController">
+ <tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="44" sectionHeaderHeight="22" sectionFooterHeight="22" id="0da-SL-Cmm">
+ <rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
+ <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
+ <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
+ <prototypes>
+ <tableViewCell contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" id="s9f-Ak-39U">
+ <autoresizingMask key="autoresizingMask"/>
+ <tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="s9f-Ak-39U" id="Ozs-uw-bz5">
+ <autoresizingMask key="autoresizingMask"/>
+ </tableViewCellContentView>
+ </tableViewCell>
+ </prototypes>
+ <connections>
+ <outlet property="dataSource" destination="2Mz-oY-P1s" id="Dyk-6V-CQ7"/>
+ <outlet property="delegate" destination="2Mz-oY-P1s" id="EVY-Ms-veo"/>
+ </connections>
+ </tableView>
+ </tableViewController>
+ <placeholder placeholderIdentifier="IBFirstResponder" id="kX3-kT-KaE" userLabel="First Responder" sceneMemberID="firstResponder"/>
+ </objects>
+ <point key="canvasLocation" x="1971" y="143"/>
+ </scene>
</scenes>
</document>
diff --git a/ios-ng/shlist/ListDetailTableViewController.h b/ios-ng/shlist/ListDetailTableViewController.h
@@ -1,7 +1,12 @@
#import <UIKit/UIKit.h>
+#import "SharedList.h"
@interface ListDetailTableViewController : UITableViewController
+@property SharedList *list_metadata;
@property NSMutableArray *list_items;
+- (IBAction)unwindToList:(UIStoryboardSegue *)segue;
+- (void) setMetadata:(SharedList *)metadata;
+
@end
diff --git a/ios-ng/shlist/ListDetailTableViewController.m b/ios-ng/shlist/ListDetailTableViewController.m
@@ -51,6 +51,17 @@
// Dispose of any resources that can be recreated.
}
+- (IBAction)unwindToList:(UIStoryboardSegue *)segue {
+
+}
+
+- (void) setMetadata:(SharedList *)metadata
+{
+ _list_metadata = metadata;
+ self.title = _list_metadata.list_name;
+
+}
+
#pragma mark - Table view data source
- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView
diff --git a/ios-ng/shlist/SharedListsTableViewController.m b/ios-ng/shlist/SharedListsTableViewController.m
@@ -2,6 +2,7 @@
#import "SharedList.h"
#import "NewListViewController.h"
#import "ShlistServer.h"
+#import "ListDetailTableViewController.h"
@interface SharedListsTableViewController ()
@@ -26,6 +27,9 @@
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *destinationPath = [documentsDirectory stringByAppendingPathComponent:@"shlist_key"];
+ // NSError *error = nil;
+ // [[NSFileManager defaultManager] removeItemAtPath:destinationPath error:&error];
+
if (![[NSFileManager defaultManager] fileExistsAtPath:destinationPath]) {
// do a fake registration
NSData *msg_register = [NSData dataWithBytes:"\x00\x00\x00\x0a" "4037082094" length:15];
@@ -54,16 +58,6 @@
// ShlistServer *server = [[ShlistServer alloc] init];
[_server writeToServer:msg];
-
- SharedList *list1 = [[SharedList alloc] init];
- list1.list_name = @"Camping";
- list1.list_members = @"David, Greg";
- [self.indirect_lists addObject:list1];
-
- SharedList *list2 = [[SharedList alloc] init];
- list2.list_name = @"Wedding";
- list2.list_members = @"Stephanie, Beatrice";
- [self.indirect_lists addObject:list2];
}
- (IBAction) unwindToList:(UIStoryboardSegue *)segue
@@ -78,7 +72,7 @@
[self.shared_lists addObject:list];
[self.tableView reloadData];
- // send new list message
+ // new list message
NSMutableData *msg = [NSMutableData data];
[msg appendBytes:"\x00\x01" length:2];
@@ -95,12 +89,13 @@
// append new list name
[msg appendData:[list.list_name dataUsingEncoding:NSUTF8StringEncoding]];
+ // send message
[_server writeToServer:msg];
NSLog(@"unwindToList(): done");
}
-- (void)viewDidLoad
+- (void) viewDidLoad
{
[super viewDidLoad];
@@ -117,7 +112,7 @@
[self load_initial_data];
}
-- (void)didReceiveMemoryWarning
+- (void) didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
@@ -136,12 +131,18 @@
return [self.shared_lists count];
}
else if (section == 1) {
- return 2;
+ return [self.indirect_lists count];
}
return 0;
}
+- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
+{
+ NSLog(@"did cell selection");
+ [tableView deselectRowAtIndexPath:indexPath animated:NO];
+}
+
- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell;
@@ -202,15 +203,24 @@
return @"";
}
+- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView
+ editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
+{
+ if ([indexPath section] == 0) {
+ return UITableViewCellEditingStyleDelete;
+ }
+ return UITableViewCellEditingStyleInsert;
+}
+
// Override to support conditional editing of the table view.
- (BOOL) tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
- if ([indexPath section] == 0) {
+ // if ([indexPath section] == 0) {
// editable
return YES;
- }
+ // }
- return NO;
+ // return NO;
}
// Override to support editing the table view.
@@ -218,11 +228,61 @@
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source
- [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
+ // [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
+
+ NSIndexPath *path = [self.tableView indexPathForSelectedRow];
+ SharedList *selected_list = [self.shared_lists objectAtIndex:[path row]];
+
+ NSLog(@"info: leaving list '%@'", selected_list.list_name);
+
+ // delete list message
+ NSMutableData *msg = [NSMutableData data];
+ [msg appendBytes:"\x00\x05" length:2];
+
+ // length = device id + null separator + list id
+ uint16_t length_network_endian = htons([_device_id length] + [selected_list.list_id length] + 1);
+ [msg appendBytes:&length_network_endian length:2];
+
+ // append device id
+ [msg appendData:_device_id];
+
+ // append null separator
+ [msg appendBytes:"\0" length:1];
+
+ // append new list name
+ [msg appendData:[selected_list.list_id dataUsingEncoding:NSUTF8StringEncoding]];
+
+ // send message
+ [_server writeToServer:msg];
+
// [self.shared_lists removeObjectAtIndex:[indexPath row]];
} else if (editingStyle == UITableViewCellEditingStyleInsert) {
- NSLog(@"editing style insert");
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
+
+ NSIndexPath *path = [self.tableView indexPathForSelectedRow];
+ SharedList *selected_list = [self.indirect_lists objectAtIndex:[path row]];
+
+ NSLog(@"info: joining list '%@'", selected_list.list_name);
+
+ // join list message
+ NSMutableData *msg = [NSMutableData data];
+ [msg appendBytes:"\x00\x04" length:2];
+
+ // length = device id + null separator + list id
+ uint16_t length_network_endian = htons([_device_id length] + [selected_list.list_id length] + 1);
+ [msg appendBytes:&length_network_endian length:2];
+
+ // append device id
+ [msg appendData:_device_id];
+
+ // append null separator
+ [msg appendBytes:"\0" length:1];
+
+ // append new list name
+ [msg appendData:[selected_list.list_id dataUsingEncoding:NSUTF8StringEncoding]];
+
+ // send message
+ [_server writeToServer:msg];
}
}
@@ -245,6 +305,20 @@
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
+ if ([[segue identifier] isEqualToString:@"show list segue"]) {
+
+ NSIndexPath *path = [self.tableView indexPathForSelectedRow];
+ SharedList *selected_list = [self.shared_lists objectAtIndex:[path row]];
+
+ // only list detail table view controller has this method
+ [segue.destinationViewController setMetadata:selected_list];
+ }
+ // DetailObject *detail = [self detailForIndexPath:path];
+
+
+ // ListDetailTableViewController *list_detail_tvc = [segue destinationViewController];
+ // list_detail_tvc.navigationItem.title = @"Test Title";
+
NSLog(@"preparing for segue");
}
diff --git a/ios-ng/shlist/ShlistServer.m b/ios-ng/shlist/ShlistServer.m
@@ -69,7 +69,7 @@
uint16_t msg_type = ntohs(msg_metadata[0]);
uint16_t msg_length = ntohs(msg_metadata[1]);
- if (msg_type > 4) {
+ if (msg_type > 6) {
NSLog(@"warn: read: out of range msg type %i", msg_type);
break;
}
@@ -102,7 +102,7 @@
NSLog(@"warn: read: couldn't allocate output string");
break;
}
- NSLog(@"info: read: message is %@", output);
+ // NSLog(@"info: read: message is %@", output);
if (msg_type == 0) {
// write key to file
@@ -117,6 +117,10 @@
// }
}
+ if (msg_type == 1) {
+ NSLog(@"info: got new list response, not doing anything with it");
+ }
+
if (msg_type == 3) {
NSLog(@"info: read: processing bulk list update message");
@@ -140,13 +144,12 @@
NSArray *broken_down_list = [str componentsSeparatedByString:@":"];
-
SharedList *shared_list = [[SharedList alloc] init];
shared_list.list_name = [broken_down_list objectAtIndex:0];
shared_list.list_id = [broken_down_list objectAtIndex:1];
shared_list.list_members = [broken_down_list objectAtIndex:2];
- NSLog(@"info: network: got list '%@'", shared_list.list_name);
+ NSLog(@"info: network: got direct list '%@'", shared_list.list_name);
[shlist_tvc.shared_lists addObject:shared_list];
// [direct_shared_lists addObject:shared_list];
@@ -155,6 +158,19 @@
}
if ([indirect_list_str length] != 0) {
NSArray *indirect_lists = [indirect_list_str componentsSeparatedByString:@"\0"];
+ [shlist_tvc.indirect_lists removeAllObjects];
+
+ for (id str in indirect_lists) {
+ NSArray *broken_down_list = [str componentsSeparatedByString:@":"];
+
+ SharedList *shared_list = [[SharedList alloc] init];
+ shared_list.list_name = [broken_down_list objectAtIndex:0];
+ shared_list.list_id = [broken_down_list objectAtIndex:1];
+ shared_list.list_members = [broken_down_list objectAtIndex:2];
+
+ NSLog(@"info: network: got indirect list '%@'", shared_list.list_name);
+ [shlist_tvc.indirect_lists addObject:shared_list];
+ }
}
[shlist_tvc.tableView reloadData];
@@ -168,6 +184,25 @@
// NSLog(@"info: %i direct lists, %i indirect lists");
}
+
+ if (msg_type == 4) {
+ NSLog(@"info: got response from join list request, '%@'", output);
+
+ /*
+ for (id list in shlist_tvc.indirect_lists) {
+ if (list.list_name == output) {
+ [shlist_tvc.indirect_lists removeObject:list];
+ break;
+ }
+ }
+ shlist_tvc.shared_lists
+ [shlist_tvc.tableView reloadData];
+ */
+ }
+
+ if (msg_type == 5) {
+ NSLog(@"info: got response from leave list request");
+ }
}
break;
case NSStreamEventHasSpaceAvailable: