From 566f122683240ea47f391033ec4e11ef424e7a5c Mon Sep 17 00:00:00 2001
From: Vitaly Takmazov
Date: Wed, 30 Oct 2013 00:50:34 +0400
Subject: Working main feed
---
Juick/AppDelegate.m | 2 +-
Juick/Base.lproj/Main.storyboard | 104 ---------------------------
Juick/DetailViewController.h | 16 -----
Juick/DetailViewController.m | 51 -------------
Juick/Juick-Info.plist | 2 +
Juick/Main.storyboard | 81 +++++++++++++++++++++
Juick/MasterViewController.h | 1 -
Juick/MasterViewController.m | 152 +++++++++++++++++++++++----------------
Juick/Message.h | 20 ++++++
Juick/Message.m | 30 ++++++++
Juick/MessageCell.h | 21 ++++++
Juick/MessageCell.m | 134 ++++++++++++++++++++++++++++++++++
12 files changed, 378 insertions(+), 236 deletions(-)
delete mode 100644 Juick/Base.lproj/Main.storyboard
delete mode 100644 Juick/DetailViewController.h
delete mode 100644 Juick/DetailViewController.m
create mode 100644 Juick/Main.storyboard
create mode 100644 Juick/Message.h
create mode 100644 Juick/Message.m
create mode 100644 Juick/MessageCell.h
create mode 100644 Juick/MessageCell.m
(limited to 'Juick')
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 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ 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
-
-@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 @@
1.0
LSRequiresIPhoneOS
+ NSMainNibFile~ipad
+ Main-iPad
UIMainStoryboardFile
Main
UIRequiredDeviceCapabilities
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 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ 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
@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
+#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
+
+
+#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
--
cgit v1.2.3