summaryrefslogtreecommitdiff
path: root/Juick/ViewControllers/RevealPanelViewController.m
diff options
context:
space:
mode:
Diffstat (limited to 'Juick/ViewControllers/RevealPanelViewController.m')
-rw-r--r--Juick/ViewControllers/RevealPanelViewController.m182
1 files changed, 182 insertions, 0 deletions
diff --git a/Juick/ViewControllers/RevealPanelViewController.m b/Juick/ViewControllers/RevealPanelViewController.m
new file mode 100644
index 0000000..d890f97
--- /dev/null
+++ b/Juick/ViewControllers/RevealPanelViewController.m
@@ -0,0 +1,182 @@
+//
+// RevealPanelViewController.m
+// Juick
+//
+// Created by Vitaly Takmazov on 04.11.13.
+// Copyright (c) 2013 com.juick. All rights reserved.
+//
+
+#import "SWRevealViewController.h"
+
+#import "RevealPanelViewController.h"
+#import "MessagesViewController.h"
+
+#import "ColorScheme.h"
+#import "NSURL+PathParameters.h"
+#import "NavCell.h"
+#import "Message.h"
+#import "User.h"
+
+
+static NSString *CellIdentifier = @"NavCell";
+
+@interface RevealPanelViewController ()
+
+@end
+
+@implementation RevealPanelViewController
+
+- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
+{
+ self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
+ if (self) {
+ // Custom initialization
+ }
+ return self;
+}
+
+- (void)viewDidLoad
+{
+ [super viewDidLoad];
+ [self.view setBackgroundColor:[ColorScheme mainBackground]];
+ self.tableView = [[UITableView alloc] init];
+ [self.tableView setBackgroundColor:[ColorScheme mainBackground]];
+ self.tableView.delegate = self;
+ self.tableView.dataSource = self;
+ [self.tableView setSeparatorInset:UIEdgeInsetsZero];
+ self.tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
+ self.tableView.separatorColor =[UIColor darkGrayColor];
+ [self.tableView registerNib:[UINib nibWithNibName:@"NavCell" bundle:nil] forCellReuseIdentifier:CellIdentifier];
+ [self.view addSubview:self.tableView];
+ self.signButton = [[UIButton alloc] init];
+ [self.signButton addTarget:self action:@selector(signInOut) forControlEvents:UIControlEventTouchUpInside];
+ [self.view addSubview:self.signButton];
+ [self refreshInfo];
+}
+
+-(void) refreshInfo {
+ NSString *text;
+ UIColor *color;
+
+ if ([User isAuthenticated]) {
+ text = @"Sign Out";
+ color = [UIColor redColor];
+ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
+ [User get:[[PDKeychainBindings sharedKeychainBindings] stringForKey:@"com.juick.username"] callback:^(User *user) {
+ if (user != nil) {
+ /*[self.titleView.image setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://i.juick.com/as/%@.png", user.uid]]];
+ [self.titleView.title setText:user.uname];*/
+ }
+ }];
+ });
+ } else {
+ text = @"Sign In";
+ color = [UIColor greenColor];
+ }
+ [self.signButton setTitle:text forState:UIControlStateNormal];
+ [self.signButton setBackgroundColor:color];
+}
+
+-(void) signInOut {
+ [self refreshInfo];
+ [self pushLoginForm];
+}
+
+-(void) viewWillLayoutSubviews {
+ [super viewWillLayoutSubviews];
+ self.tableView.frame = CGRectMake(0, 0, self.view.bounds.size.width, 400);
+ self.signButton.frame = CGRectMake(0, self.view.bounds.size.height - 40, self.view.bounds.size.width, 40);
+}
+
+- (void)didReceiveMemoryWarning
+{
+ [super didReceiveMemoryWarning];
+ // Dispose of any resources that can be recreated.
+}
+
+
+- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
+ return 1;
+}
+
+- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
+ return 4;
+}
+
+- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
+ return 32 + 10*2; // icon size + insets
+}
+
+- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
+ NavCell * cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
+ NSInteger row = indexPath.row;
+ [cell.contentView setBackgroundColor:[UIColor whiteColor]];
+ cell.icon.font = [UIFont fontWithName:kFontAwesomeFamilyName size:32.f];
+ cell.icon.textColor = [ColorScheme linkColor];
+ cell.descriptionText.textColor = [ColorScheme linkColor];
+ if (row == 0) {
+ cell.descriptionText.text = @"My feed";
+ cell.icon.text = [NSString fontAwesomeIconStringForEnum:FAIconHome];
+
+ } else if (row == 1) {
+ cell.descriptionText.text = @"Popular";
+ cell.icon.text = [NSString fontAwesomeIconStringForEnum:FAIconComments];
+ } else if (row == 2) {
+ cell.descriptionText.text = @"Discover";
+ cell.icon.text = [NSString fontAwesomeIconStringForEnum:FAIconSearch];
+ } else if (row == 3) {
+ cell.descriptionText.text = @"Images";
+ cell.icon.text = [NSString fontAwesomeIconStringForEnum:FAIconPicture];
+ }
+ UIView *bgColorView = [[UIView alloc] init];
+ bgColorView.backgroundColor = [UIColor blackColor];
+ bgColorView.layer.masksToBounds = YES;
+ [cell setSelectedBackgroundView:bgColorView];
+ [cell.contentView setNeedsLayout];
+ [cell.contentView layoutIfNeeded];
+ return cell;
+}
+
+- (void) pushLoginForm {
+ [self.revealViewController revealToggle:self];
+ UIViewController *loginView = [[LoginViewController alloc] init];
+ UINavigationController *messages = (UINavigationController *)self.revealViewController.frontViewController;
+ [messages pushViewController:loginView animated:YES];
+}
+
+- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
+ NSInteger row = indexPath.row;
+ NSString *targetPath;
+ NSDictionary *targetParams;
+ NSString *targetTitle;
+ if (row == 0) {
+ if ([[PDKeychainBindings sharedKeychainBindings] stringForKey:@"com.juick.username"] == nil) {
+ [self pushLoginForm];
+ return;
+ } else {
+ targetTitle = @"My feed";
+ targetPath = [Message feedUrl];
+ }
+
+ }
+ if (row == 1) {
+ targetTitle = @"Popular";
+ targetPath = [Message messagesUrl];
+ targetParams = [NSDictionary dictionaryWithObjectsAndKeys:@"1", @"popular", nil];
+ } else if (row == 2) {
+ targetTitle = @"Discover";
+ targetPath = [Message messagesUrl];
+ }
+ if (row == 3) {
+ targetTitle = @"Images";
+ targetPath = [Message messagesUrl];
+ targetParams = [NSDictionary dictionaryWithObjectsAndKeys:@"photo", @"media", nil];
+ }
+ SWRevealViewController *reveal = self.revealViewController;
+ UINavigationController *front = (UINavigationController *)reveal.frontViewController;
+ MessagesViewController *messages = (MessagesViewController *)[front.viewControllers objectAtIndex:0];
+ [messages loadFromPath:targetPath withParams:targetParams withTitle:targetTitle];
+ [reveal revealToggle:self];
+}
+
+@end