2014-10-29 21:58:58 +01:00
|
|
|
//
|
|
|
|
// SignalsViewController.m
|
|
|
|
// Signal
|
|
|
|
//
|
|
|
|
// Created by Dylan Bourgeois on 27/10/14.
|
|
|
|
// Copyright (c) 2014 Open Whisper Systems. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import "AppDelegate.h"
|
|
|
|
#import "DemoDataFactory.h"
|
2014-11-21 00:51:23 +01:00
|
|
|
#import "InboxTableViewCell.h"
|
2014-10-29 21:58:58 +01:00
|
|
|
|
|
|
|
#import "MessagesViewController.h"
|
|
|
|
#import "SignalsViewController.h"
|
|
|
|
|
|
|
|
|
|
|
|
#define CELL_HEIGHT 71.0f
|
|
|
|
#define HEADER_HEIGHT 44.0f
|
|
|
|
|
|
|
|
|
|
|
|
static NSString *const kCellNibName = @"TableViewCell";
|
|
|
|
static NSString *const kSegueIndentifier = @"showSegue";
|
|
|
|
|
|
|
|
|
|
|
|
@interface SignalsViewController () {
|
|
|
|
NSArray * _dataArray;
|
|
|
|
NSUInteger numberOfCells;
|
|
|
|
|
|
|
|
}
|
|
|
|
@property (strong, nonatomic) DemoDataModel *demoData;
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation SignalsViewController
|
|
|
|
|
|
|
|
- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
|
|
|
|
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
|
|
|
|
|
|
|
|
if (self) {
|
|
|
|
AppDelegate *delegate = [[UIApplication sharedApplication] delegate];
|
|
|
|
delegate.signalVC = self;
|
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)viewDidLoad {
|
|
|
|
[super viewDidLoad];
|
|
|
|
_dataArray = [DemoDataFactory data];
|
|
|
|
numberOfCells = _dataArray.count;
|
|
|
|
[self tableViewSetUp];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)didReceiveMemoryWarning {
|
|
|
|
[super didReceiveMemoryWarning];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
-(void)tableViewSetUp
|
|
|
|
{
|
|
|
|
self._tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#pragma mark - Table view data source
|
|
|
|
|
|
|
|
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
|
|
|
return (NSInteger)numberOfCells;
|
|
|
|
}
|
|
|
|
|
2014-11-21 00:51:23 +01:00
|
|
|
- (InboxTableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
2014-10-29 21:58:58 +01:00
|
|
|
return [self inboxFeedCellForIndexPath:indexPath];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
|
return CELL_HEIGHT;
|
|
|
|
}
|
|
|
|
|
2014-11-21 00:51:23 +01:00
|
|
|
-(InboxTableViewCell*)inboxFeedCellForIndexPath:(NSIndexPath *)indexPath {
|
2014-10-29 21:58:58 +01:00
|
|
|
|
2014-11-21 00:51:23 +01:00
|
|
|
InboxTableViewCell *cell = [self._tableView dequeueReusableCellWithIdentifier:kCellNibName];
|
2014-10-29 21:58:58 +01:00
|
|
|
|
|
|
|
|
|
|
|
if (!cell) {
|
2014-11-21 00:51:23 +01:00
|
|
|
cell = [[InboxTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
|
2014-10-29 21:58:58 +01:00
|
|
|
reuseIdentifier:kCellNibName];
|
|
|
|
cell.delegate = self;
|
|
|
|
}
|
|
|
|
|
|
|
|
DemoDataModel *recent = _dataArray[(NSUInteger)indexPath.row];
|
|
|
|
[cell configureWithTestMessage:recent];
|
|
|
|
[cell configureForState:_segmentedControl.selectedSegmentIndex == 0 ? kInboxState : kArchiveState];
|
|
|
|
return cell;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#pragma mark - HomeFeedTableViewCellDelegate
|
|
|
|
|
2014-11-21 00:51:23 +01:00
|
|
|
- (void)tableViewCellTappedDelete:(InboxTableViewCell*)cell {
|
2014-10-29 21:58:58 +01:00
|
|
|
NSLog(@"Delete");
|
|
|
|
}
|
|
|
|
|
2014-11-21 00:51:23 +01:00
|
|
|
- (void)tableViewCellTappedArchive:(InboxTableViewCell*)cell {
|
2014-10-29 21:58:58 +01:00
|
|
|
NSLog(@"Archive");
|
|
|
|
}
|
|
|
|
|
|
|
|
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
|
|
|
|
{
|
|
|
|
[self performSegueWithIdentifier:kSegueIndentifier sender:self];
|
|
|
|
[tableView deselectRowAtIndexPath:indexPath animated:NO];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#pragma mark - Navigation
|
|
|
|
|
|
|
|
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
|
|
|
|
|
|
|
|
if ([segue.identifier isEqualToString:kSegueIndentifier])
|
|
|
|
{
|
|
|
|
MessagesViewController * vc = [segue destinationViewController];
|
|
|
|
NSIndexPath *selectedIndexPath = [self._tableView indexPathForSelectedRow];
|
|
|
|
if (selectedIndexPath) {
|
|
|
|
vc._senderTitleString = ((DemoDataModel*)_dataArray[(NSUInteger)selectedIndexPath.row])._sender;
|
|
|
|
} else if (_contactFromCompose) {
|
|
|
|
vc._senderTitleString = _contactFromCompose.fullName;
|
|
|
|
} else if (_groupFromCompose) {
|
|
|
|
vc._senderTitleString = _groupFromCompose.groupName;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark - IBAction
|
|
|
|
|
|
|
|
-(IBAction)segmentDidChange:(id)sender
|
|
|
|
{
|
|
|
|
switch (_segmentedControl.selectedSegmentIndex) {
|
|
|
|
case 0:
|
|
|
|
numberOfCells=5;
|
|
|
|
[self._tableView reloadData];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
numberOfCells=3;
|
|
|
|
[self._tableView reloadData];
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@end
|