diff options
author | Vitaly Takmazov | 2013-10-30 00:50:34 +0400 |
---|---|---|
committer | Vitaly Takmazov | 2013-10-30 00:50:34 +0400 |
commit | 566f122683240ea47f391033ec4e11ef424e7a5c (patch) | |
tree | fbe00959f88b3a16d2d4768c1cc223781a377160 /Juick | |
parent | 7e7b734fc859234c9424b2ed98f5a2afef911de0 (diff) |
Working main feed
Diffstat (limited to 'Juick')
-rw-r--r-- | Juick/AppDelegate.m | 2 | ||||
-rw-r--r-- | Juick/Base.lproj/Main.storyboard | 104 | ||||
-rw-r--r-- | Juick/DetailViewController.h | 16 | ||||
-rw-r--r-- | Juick/DetailViewController.m | 51 | ||||
-rw-r--r-- | Juick/Juick-Info.plist | 2 | ||||
-rw-r--r-- | Juick/Main.storyboard | 81 | ||||
-rw-r--r-- | Juick/MasterViewController.h | 1 | ||||
-rw-r--r-- | Juick/MasterViewController.m | 152 | ||||
-rw-r--r-- | Juick/Message.h | 20 | ||||
-rw-r--r-- | Juick/Message.m | 30 | ||||
-rw-r--r-- | Juick/MessageCell.h | 21 | ||||
-rw-r--r-- | Juick/MessageCell.m | 134 |
12 files changed, 378 insertions, 236 deletions
diff --git a/Juick/AppDelegate.m b/Juick/AppDelegate.m index 40b5fae..23cef5e 100644 --- a/Juick/AppDelegate.m +++ b/Juick/AppDelegate.m @@ -7,12 +7,12 @@ // #import "AppDelegate.h" +#import "MasterViewController.h" @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { - // Override point for customization after application launch. return YES; } diff --git a/Juick/Base.lproj/Main.storyboard b/Juick/Base.lproj/Main.storyboard deleted file mode 100644 index 3d5f90c..0000000 --- a/Juick/Base.lproj/Main.storyboard +++ /dev/null @@ -1,104 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" standalone="no"?> -<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="4451" systemVersion="13A461" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" initialViewController="rS3-R9-Ivy"> - <dependencies> - <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="3676"/> - </dependencies> - <scenes> - <!--Navigation Controller--> - <scene sceneID="cUi-kZ-frf"> - <objects> - <navigationController id="rS3-R9-Ivy" sceneMemberID="viewController"> - <navigationBar key="navigationBar" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" id="yXu-0R-QUA"> - <autoresizingMask key="autoresizingMask"/> - </navigationBar> - <connections> - <segue destination="pGg-6v-bdr" kind="relationship" relationship="rootViewController" id="RxB-wf-QIq"/> - </connections> - </navigationController> - <placeholder placeholderIdentifier="IBFirstResponder" id="eq9-QA-ai8" sceneMemberID="firstResponder"/> - </objects> - <point key="canvasLocation" x="-1" y="64"/> - </scene> - <!--class Prefix:identifier Master View Controller - Master--> - <scene sceneID="VgW-fR-Quf"> - <objects> - <tableViewController title="Master" id="pGg-6v-bdr" customClass="MasterViewController" sceneMemberID="viewController"> - <tableView key="view" opaque="NO" clipsSubviews="YES" clearsContextBeforeDrawing="NO" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" rowHeight="44" sectionHeaderHeight="22" sectionFooterHeight="22" id="mLL-gJ-YKr"> - <rect key="frame" x="0.0" y="0.0" width="320" height="568"/> - <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> - <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/> - <prototypes> - <tableViewCell contentMode="scaleToFill" selectionStyle="blue" accessoryType="disclosureIndicator" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" reuseIdentifier="Cell" textLabel="2pz-XF-uhl" style="IBUITableViewCellStyleDefault" id="m0d-ak-lc9"> - <rect key="frame" x="0.0" y="86" width="320" height="44"/> - <autoresizingMask key="autoresizingMask"/> - <view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center"> - <rect key="frame" x="0.0" y="0.0" width="287" height="43"/> - <autoresizingMask key="autoresizingMask"/> - <subviews> - <label opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" text="Title" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="2pz-XF-uhl"> - <rect key="frame" x="15" y="0.0" width="270" height="43"/> - <autoresizingMask key="autoresizingMask"/> - <fontDescription key="fontDescription" type="boldSystem" pointSize="20"/> - <color key="textColor" cocoaTouchSystemColor="darkTextColor"/> - <color key="highlightedColor" red="1" green="1" blue="1" alpha="1" colorSpace="calibratedRGB"/> - </label> - </subviews> - <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/> - </view> - <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/> - <connections> - <segue destination="Ah7-4n-0Wa" kind="push" identifier="showDetail" id="jUr-3t-vfg"/> - </connections> - </tableViewCell> - </prototypes> - <sections/> - <connections> - <outlet property="dataSource" destination="pGg-6v-bdr" id="P41-gY-KXY"/> - <outlet property="delegate" destination="pGg-6v-bdr" id="Y6K-Cp-Qkv"/> - </connections> - </tableView> - <navigationItem key="navigationItem" title="Master" id="tQt-TN-PWz"/> - </tableViewController> - <placeholder placeholderIdentifier="IBFirstResponder" id="6Cn-md-YlS" sceneMemberID="firstResponder"/> - </objects> - <point key="canvasLocation" x="459" y="64"/> - </scene> - <!--class Prefix:identifier Detail View Controller - Detail--> - <scene sceneID="Cn3-H9-jdl"> - <objects> - <viewController title="Detail" id="Ah7-4n-0Wa" customClass="DetailViewController" sceneMemberID="viewController"> - <view key="view" contentMode="scaleToFill" id="MMQ-IT-qOo"> - <rect key="frame" x="0.0" y="0.0" width="320" height="568"/> - <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/> - <subviews> - <label clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleToFill" text="Detail view content goes here" textAlignment="center" lineBreakMode="tailTruncation" minimumFontSize="10" translatesAutoresizingMaskIntoConstraints="NO" id="Lei-5M-9Gs"> - <rect key="frame" x="20" y="276" width="280" height="17"/> - <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/> - <fontDescription key="fontDescription" type="system" size="system"/> - <color key="textColor" cocoaTouchSystemColor="darkTextColor"/> - <nil key="highlightedColor"/> - </label> - </subviews> - <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/> - <constraints> - <constraint firstItem="Lei-5M-9Gs" firstAttribute="leading" secondItem="MMQ-IT-qOo" secondAttribute="leading" constant="20" symbolic="YES" id="62x-JV-TTJ"/> - <constraint firstItem="Lei-5M-9Gs" firstAttribute="centerY" secondItem="MMQ-IT-qOo" secondAttribute="centerY" id="JzS-HC-Rnl"/> - <constraint firstAttribute="trailing" secondItem="Lei-5M-9Gs" secondAttribute="trailing" constant="20" symbolic="YES" id="pXB-RP-Zz6"/> - </constraints> - </view> - <navigationItem key="navigationItem" title="Detail" id="cra-N8-TIN"/> - <connections> - <outlet property="detailDescriptionLabel" destination="Lei-5M-9Gs" id="sCT-F7-F6f"/> - </connections> - </viewController> - <placeholder placeholderIdentifier="IBFirstResponder" id="lrm-kH-fPn" sceneMemberID="firstResponder"/> - </objects> - <point key="canvasLocation" x="902" y="64"/> - </scene> - </scenes> - <simulatedMetricsContainer key="defaultSimulatedMetrics"> - <simulatedStatusBarMetrics key="statusBar"/> - <simulatedOrientationMetrics key="orientation"/> - <simulatedScreenMetrics key="destination" type="retina4"/> - </simulatedMetricsContainer> -</document>
\ No newline at end of file diff --git a/Juick/DetailViewController.h b/Juick/DetailViewController.h deleted file mode 100644 index 1246805..0000000 --- a/Juick/DetailViewController.h +++ /dev/null @@ -1,16 +0,0 @@ -// -// DetailViewController.h -// Juick -// -// Created by Vitaly Takmazov on 26.10.13. -// Copyright (c) 2013 com.juick. All rights reserved. -// - -#import <UIKit/UIKit.h> - -@interface DetailViewController : UIViewController - -@property (strong, nonatomic) id detailItem; - -@property (weak, nonatomic) IBOutlet UILabel *detailDescriptionLabel; -@end diff --git a/Juick/DetailViewController.m b/Juick/DetailViewController.m deleted file mode 100644 index 4d510c9..0000000 --- a/Juick/DetailViewController.m +++ /dev/null @@ -1,51 +0,0 @@ -// -// DetailViewController.m -// Juick -// -// Created by Vitaly Takmazov on 26.10.13. -// Copyright (c) 2013 com.juick. All rights reserved. -// - -#import "DetailViewController.h" - -@interface DetailViewController () -- (void)configureView; -@end - -@implementation DetailViewController - -#pragma mark - Managing the detail item - -- (void)setDetailItem:(id)newDetailItem -{ - if (_detailItem != newDetailItem) { - _detailItem = newDetailItem; - - // Update the view. - [self configureView]; - } -} - -- (void)configureView -{ - // Update the user interface for the detail item. - - if (self.detailItem) { - self.detailDescriptionLabel.text = [self.detailItem description]; - } -} - -- (void)viewDidLoad -{ - [super viewDidLoad]; - // Do any additional setup after loading the view, typically from a nib. - [self configureView]; -} - -- (void)didReceiveMemoryWarning -{ - [super didReceiveMemoryWarning]; - // Dispose of any resources that can be recreated. -} - -@end diff --git a/Juick/Juick-Info.plist b/Juick/Juick-Info.plist index 846633e..f23f598 100644 --- a/Juick/Juick-Info.plist +++ b/Juick/Juick-Info.plist @@ -24,6 +24,8 @@ <string>1.0</string> <key>LSRequiresIPhoneOS</key> <true/> + <key>NSMainNibFile~ipad</key> + <string>Main-iPad</string> <key>UIMainStoryboardFile</key> <string>Main</string> <key>UIRequiredDeviceCapabilities</key> diff --git a/Juick/Main.storyboard b/Juick/Main.storyboard new file mode 100644 index 0000000..cac2c7f --- /dev/null +++ b/Juick/Main.storyboard @@ -0,0 +1,81 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="4514" systemVersion="12F45" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" initialViewController="Qpj-SN-g7s"> + <dependencies> + <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="3746"/> + </dependencies> + <scenes> + <!--Master View Controller - Root View Controller--> + <scene sceneID="mFC-R0-94t"> + <objects> + <tableViewController id="zP3-J3-AlH" customClass="MasterViewController" sceneMemberID="viewController"> + <tableView key="view" opaque="NO" clipsSubviews="YES" clearsContextBeforeDrawing="NO" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="44" sectionHeaderHeight="22" sectionFooterHeight="22" id="xve-h9-u9y"> + <rect key="frame" x="0.0" y="0.0" width="320" height="568"/> + <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> + <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/> + <prototypes> + <tableViewCell contentMode="scaleToFill" selectionStyle="blue" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" id="hPo-AH-JGS"> + <rect key="frame" x="0.0" y="86" width="320" height="44"/> + <autoresizingMask key="autoresizingMask"/> + <tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="hPo-AH-JGS" id="xzw-7U-vR0"> + <rect key="frame" x="0.0" y="0.0" width="320" height="43"/> + <autoresizingMask key="autoresizingMask"/> + </tableViewCellContentView> + </tableViewCell> + </prototypes> + </tableView> + <navigationItem key="navigationItem" title="Root View Controller" id="Fbj-Lo-jp7"/> + </tableViewController> + <placeholder placeholderIdentifier="IBFirstResponder" id="IPJ-Mn-WGD" userLabel="First Responder" sceneMemberID="firstResponder"/> + </objects> + <point key="canvasLocation" x="-463" y="-520"/> + </scene> + <!--Table View Controller--> + <scene sceneID="CD2-1U-nQh"> + <objects> + <tableViewController id="bNv-gr-Gk5" sceneMemberID="viewController"> + <tableView key="view" opaque="NO" clipsSubviews="YES" clearsContextBeforeDrawing="NO" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="44" sectionHeaderHeight="22" sectionFooterHeight="22" id="akB-3D-ShF"> + <rect key="frame" x="0.0" y="0.0" width="320" height="568"/> + <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> + <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/> + <prototypes> + <tableViewCell contentMode="scaleToFill" selectionStyle="blue" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" id="7nM-K0-Cs7"> + <rect key="frame" x="0.0" y="22" width="320" height="44"/> + <autoresizingMask key="autoresizingMask"/> + <tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="7nM-K0-Cs7" id="9Oc-sb-RWf"> + <rect key="frame" x="0.0" y="0.0" width="320" height="43"/> + <autoresizingMask key="autoresizingMask"/> + </tableViewCellContentView> + </tableViewCell> + </prototypes> + <connections> + <outlet property="dataSource" destination="bNv-gr-Gk5" id="I2K-66-RJv"/> + <outlet property="delegate" destination="bNv-gr-Gk5" id="XnG-ma-SEL"/> + </connections> + </tableView> + </tableViewController> + <placeholder placeholderIdentifier="IBFirstResponder" id="3Ep-3c-Tc4" userLabel="First Responder" sceneMemberID="firstResponder"/> + </objects> + <point key="canvasLocation" x="75" y="-520"/> + </scene> + <!--Navigation Controller--> + <scene sceneID="x3r-t4-FOl"> + <objects> + <navigationController definesPresentationContext="YES" id="Qpj-SN-g7s" sceneMemberID="viewController"> + <navigationBar key="navigationBar" contentMode="scaleToFill" id="Kvi-Yn-XO9"> + <autoresizingMask key="autoresizingMask"/> + </navigationBar> + <connections> + <segue destination="zP3-J3-AlH" kind="relationship" relationship="rootViewController" id="Uza-Dn-uOg"/> + </connections> + </navigationController> + <placeholder placeholderIdentifier="IBFirstResponder" id="hiT-dp-hgn" userLabel="First Responder" sceneMemberID="firstResponder"/> + </objects> + <point key="canvasLocation" x="-1153" y="-520"/> + </scene> + </scenes> + <simulatedMetricsContainer key="defaultSimulatedMetrics"> + <simulatedStatusBarMetrics key="statusBar"/> + <simulatedOrientationMetrics key="orientation"/> + <simulatedScreenMetrics key="destination" type="retina4"/> + </simulatedMetricsContainer> +</document>
\ No newline at end of file diff --git a/Juick/MasterViewController.h b/Juick/MasterViewController.h index be49967..a79b5c7 100644 --- a/Juick/MasterViewController.h +++ b/Juick/MasterViewController.h @@ -9,5 +9,4 @@ #import <UIKit/UIKit.h> @interface MasterViewController : UITableViewController - @end diff --git a/Juick/MasterViewController.m b/Juick/MasterViewController.m index 41b2ef5..bd75f82 100644 --- a/Juick/MasterViewController.m +++ b/Juick/MasterViewController.m @@ -6,108 +6,134 @@ // Copyright (c) 2013 com.juick. All rights reserved. // +#import "SWRevealViewController.h" + #import "MasterViewController.h" -#import "DetailViewController.h" +#import "MessageCell.h" + +#import "Message.h" + +static NSString *CellIdentifier = @"MessageCell"; @interface MasterViewController () { - NSMutableArray *_objects; + NSMutableArray *messages; } @end @implementation MasterViewController -- (void)awakeFromNib -{ - [super awakeFromNib]; -} - (void)viewDidLoad { [super viewDidLoad]; - // Do any additional setup after loading the view, typically from a nib. - self.navigationItem.leftBarButtonItem = self.editButtonItem; - - UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(insertNewObject:)]; - self.navigationItem.rightBarButtonItem = addButton; + self.title = @"Messages"; + // Change button color + + // Set the gesture + messages = [[NSMutableArray alloc] init]; + NSError *error; + NSURL *url = [NSURL URLWithString:@"http://api.juick.com/messages"]; + NSString *data = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:&error]; + if (data == nil) { + NSLog(@"Download Error: %@", error); + return; + } + NSArray *resultObject = [NSJSONSerialization JSONObjectWithData:[data dataUsingEncoding:NSUTF8StringEncoding] options:kNilOptions error:&error]; + if (resultObject == nil) { + NSLog(@"JSON Error: %@", error); + return; + } + + for (NSDictionary *message in resultObject) { + Message *msg = [[Message alloc] initWithDictionary:message]; + [messages addObject:msg]; + } + //UINib *cellNib = [UINib nibWithNibName:@"MessageCell" bundle:nil]; + //[self.tableView registerNib:cellNib forCellReuseIdentifier:@"MessageCell"]; + [self.tableView registerClass:[MessageCell class] forCellReuseIdentifier:CellIdentifier]; + } -- (void)didReceiveMemoryWarning +- (void)viewDidAppear:(BOOL)animated { - [super didReceiveMemoryWarning]; - // Dispose of any resources that can be recreated. + [super viewDidAppear:animated]; + + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(contentSizeCategoryChanged:) + name:UIContentSizeCategoryDidChangeNotification + object:nil]; } -- (void)insertNewObject:(id)sender +- (void)viewDidDisappear:(BOOL)animated { - if (!_objects) { - _objects = [[NSMutableArray alloc] init]; - } - [_objects insertObject:[NSDate date] atIndex:0]; - NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0]; - [self.tableView insertRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic]; + [super viewDidDisappear:animated]; + + [[NSNotificationCenter defaultCenter] removeObserver:self + name:UIContentSizeCategoryDidChangeNotification + object:nil]; } -#pragma mark - Table View - -- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView +- (void)didReceiveMemoryWarning { - return 1; + [super didReceiveMemoryWarning]; + // Dispose of any resources that can be recreated. } -- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section +- (void)contentSizeCategoryChanged:(NSNotification *)notification { - return _objects.count; + [self.tableView reloadData]; } -- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath -{ - UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath]; - - NSDate *object = _objects[indexPath.row]; - cell.textLabel.text = [object description]; - return cell; +-(void) parserDidEndDocument:(NSXMLParser *)parser { + [self.tableView reloadData]; } -- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath -{ - // Return NO if you do not want the specified item to be editable. - return YES; +- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { + return 1; } -- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath -{ - if (editingStyle == UITableViewCellEditingStyleDelete) { - [_objects removeObjectAtIndex:indexPath.row]; - [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. - } +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { + return messages.count; } -/* -// Override to support rearranging the table view. -- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath -{ +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { + MessageCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; + [cell updateFonts]; + Message *msg = [messages objectAtIndex:indexPath.row]; + cell.titleLabel.text = msg.user; + cell.bodyLabel.text = msg.text; + [cell setNeedsUpdateConstraints]; + return cell; } -*/ -/* -// Override to support conditional rearranging of the table view. -- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath +- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { - // Return NO if you do not want the item to be re-orderable. - return YES; + + MessageCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; + + [cell updateFonts]; + + Message *msg = [messages objectAtIndex:indexPath.row]; + cell.titleLabel.text = msg.user; + cell.bodyLabel.text = msg.text; + + cell.bodyLabel.preferredMaxLayoutWidth = tableView.bounds.size.width - (kLabelHorizontalInsets * 2.0f); + + [cell setNeedsUpdateConstraints]; + [cell updateConstraintsIfNeeded]; + [cell.contentView setNeedsLayout]; + [cell.contentView layoutIfNeeded]; + + CGFloat height = [cell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height; + + return height; } -*/ -- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender +- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath { - if ([[segue identifier] isEqualToString:@"showDetail"]) { - NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow]; - NSDate *object = _objects[indexPath.row]; - [[segue destinationViewController] setDetailItem:object]; - } + return 500.0f; } + @end diff --git a/Juick/Message.h b/Juick/Message.h new file mode 100644 index 0000000..4ec31e6 --- /dev/null +++ b/Juick/Message.h @@ -0,0 +1,20 @@ +// +// Message.h +// Juick +// +// Created by Vitaly Takmazov on 29.10.13. +// Copyright (c) 2013 com.juick. All rights reserved. +// + +#import <Foundation/Foundation.h> +#import "NSString+HTML.h" + +@interface Message : NSObject + +@property(nonatomic, copy) NSDecimalNumber *MID; +@property(nonatomic, copy) NSDecimalNumber *RID; +@property(nonatomic, copy) NSString *user; +@property(nonatomic, copy) NSString *text; + +-(id) initWithDictionary:(NSDictionary *)dictionary; +@end diff --git a/Juick/Message.m b/Juick/Message.m new file mode 100644 index 0000000..e87834b --- /dev/null +++ b/Juick/Message.m @@ -0,0 +1,30 @@ +// +// Message.m +// Juick +// +// Created by Vitaly Takmazov on 29.10.13. +// Copyright (c) 2013 com.juick. All rights reserved. +// + +#import "Message.h" + +@implementation Message + +-(id)initWithDictionary:(NSDictionary *)dictionary +{ + Message *result = [[Message alloc] init]; + result.MID = [dictionary objectForKey:@"mid"]; + result.RID = [dictionary objectForKey:@"rid"]; + NSString *text = [[dictionary objectForKey:@"body"] stringByDecodingHTMLEntities]; + NSDictionary *userDict = [dictionary objectForKey:@"user"]; + result.user = [userDict objectForKey:@"uname"]; + NSArray *tagsArray = [dictionary objectForKey:@"tags"]; + if ([tagsArray count] > 0) { + result.text = [[NSString alloc] initWithFormat:@"%@\n%@", [tagsArray componentsJoinedByString:@", "], text]; + } else { + result.text = text; + } + return result; +} + +@end diff --git a/Juick/MessageCell.h b/Juick/MessageCell.h new file mode 100644 index 0000000..6f93048 --- /dev/null +++ b/Juick/MessageCell.h @@ -0,0 +1,21 @@ +// +// MessageCell.h +// Juick +// +// Created by Vitaly Takmazov on 29.10.13. +// Copyright (c) 2013 com.juick. All rights reserved. +// + +#import <UIKit/UIKit.h> + + +#define kLabelHorizontalInsets 20.0f + +@interface MessageCell : UITableViewCell + +@property (strong, nonatomic) IBOutlet UILabel *titleLabel; +@property (strong, nonatomic) IBOutlet UILabel *bodyLabel; + +- (void)updateFonts; + +@end diff --git a/Juick/MessageCell.m b/Juick/MessageCell.m new file mode 100644 index 0000000..a8b2522 --- /dev/null +++ b/Juick/MessageCell.m @@ -0,0 +1,134 @@ +// +// MessageCell.m +// Juick +// +// Created by Vitaly Takmazov on 29.10.13. +// Copyright (c) 2013 com.juick. All rights reserved. +// + +#import "MessageCell.h" + +@interface MessageCell () + +@property (nonatomic, assign) BOOL didSetupConstraints; + +@end + +@implementation MessageCell + +- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier +{ + self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; + if (self) { + self.titleLabel = [[UILabel alloc] initWithFrame:CGRectZero]; + [self.titleLabel setTranslatesAutoresizingMaskIntoConstraints:NO]; + [self.titleLabel setLineBreakMode:NSLineBreakByTruncatingTail]; + [self.titleLabel setNumberOfLines:1]; + [self.titleLabel setTextAlignment:NSTextAlignmentLeft]; + [self.titleLabel setTextColor:[UIColor blackColor]]; + [self.titleLabel setBackgroundColor:[UIColor clearColor]]; + + self.bodyLabel = [[UILabel alloc] initWithFrame:CGRectZero]; + [self.bodyLabel setTranslatesAutoresizingMaskIntoConstraints:NO]; + [self.bodyLabel setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisVertical]; + [self.bodyLabel setLineBreakMode:NSLineBreakByTruncatingTail]; + [self.bodyLabel setNumberOfLines:0]; + [self.bodyLabel setTextAlignment:NSTextAlignmentLeft]; + [self.bodyLabel setTextColor:[UIColor darkGrayColor]]; + [self.bodyLabel setBackgroundColor:[UIColor clearColor]]; + [self.contentView addSubview:self.titleLabel]; + [self.contentView addSubview:self.bodyLabel]; + + [self updateFonts]; + } + return self; +} + +- (void)setSelected:(BOOL)selected animated:(BOOL)animated +{ + [super setSelected:selected animated:animated]; + + // Configure the view for the selected state +} + +- (void)updateConstraints { + [super updateConstraints]; + + if (self.didSetupConstraints) return; + + [self.contentView addConstraint:[NSLayoutConstraint + constraintWithItem:self.titleLabel + attribute:NSLayoutAttributeLeading + relatedBy:NSLayoutRelationEqual + toItem:self.contentView + attribute:NSLayoutAttributeLeading + multiplier:1.0f + constant:kLabelHorizontalInsets]]; + + [self.contentView addConstraint:[NSLayoutConstraint + constraintWithItem:self.titleLabel + attribute:NSLayoutAttributeTop + relatedBy:NSLayoutRelationEqual + toItem:self.contentView + attribute:NSLayoutAttributeTop + multiplier:1.0f + constant:(kLabelHorizontalInsets / 2)]]; + + [self.contentView addConstraint:[NSLayoutConstraint + constraintWithItem:self.titleLabel + attribute:NSLayoutAttributeTrailing + relatedBy:NSLayoutRelationEqual + toItem:self.contentView + attribute:NSLayoutAttributeTrailing + multiplier:1.0f + constant:-kLabelHorizontalInsets]]; + + ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + [self.contentView addConstraint:[NSLayoutConstraint + constraintWithItem:self.bodyLabel + attribute:NSLayoutAttributeLeading + relatedBy:NSLayoutRelationEqual + toItem:self.contentView + attribute:NSLayoutAttributeLeading + multiplier:1.0f + constant:kLabelHorizontalInsets]]; + + [self.contentView addConstraint:[NSLayoutConstraint + constraintWithItem:self.bodyLabel + attribute:NSLayoutAttributeTop + relatedBy:NSLayoutRelationEqual + toItem:self.titleLabel + attribute:NSLayoutAttributeBottom + multiplier:1.0f + constant:(kLabelHorizontalInsets / 4)]]; + + [self.contentView addConstraint:[NSLayoutConstraint + constraintWithItem:self.bodyLabel + attribute:NSLayoutAttributeTrailing + relatedBy:NSLayoutRelationEqual + toItem:self.contentView + attribute:NSLayoutAttributeTrailing + multiplier:1.0f + constant:-kLabelHorizontalInsets]]; + + [self.contentView addConstraint:[NSLayoutConstraint + constraintWithItem:self.bodyLabel + attribute:NSLayoutAttributeBottom + relatedBy:NSLayoutRelationEqual + toItem:self.contentView + attribute:NSLayoutAttributeBottom + multiplier:1.0f + constant:-(kLabelHorizontalInsets / 2)]]; + + self.didSetupConstraints = YES; +} + + +- (void)updateFonts +{ + self.titleLabel.font = [UIFont preferredFontForTextStyle:UIFontTextStyleHeadline]; + self.bodyLabel.font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody]; +} + +@end |