FRANotificationsTableViewController.m revision fb63998ce7684bddab24e10c0b593809df1b7bff
2229ffbfe08c2cd606c305f8934e627548002c9eCraig McDonnell/*
2229ffbfe08c2cd606c305f8934e627548002c9eCraig McDonnell * The contents of this file are subject to the terms of the Common Development and
2229ffbfe08c2cd606c305f8934e627548002c9eCraig McDonnell * Distribution License (the License). You may not use this file except in compliance with the
2229ffbfe08c2cd606c305f8934e627548002c9eCraig McDonnell * License.
2229ffbfe08c2cd606c305f8934e627548002c9eCraig McDonnell *
2229ffbfe08c2cd606c305f8934e627548002c9eCraig McDonnell * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
2229ffbfe08c2cd606c305f8934e627548002c9eCraig McDonnell * specific language governing permission and limitations under the License.
2229ffbfe08c2cd606c305f8934e627548002c9eCraig McDonnell *
2229ffbfe08c2cd606c305f8934e627548002c9eCraig McDonnell * When distributing Covered Software, include this CDDL Header Notice in each file and include
2229ffbfe08c2cd606c305f8934e627548002c9eCraig McDonnell * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
2229ffbfe08c2cd606c305f8934e627548002c9eCraig McDonnell * Header, with the fields enclosed by brackets [] replaced by your own identifying
2229ffbfe08c2cd606c305f8934e627548002c9eCraig McDonnell * information: "Portions copyright [year] [name of copyright owner]".
2229ffbfe08c2cd606c305f8934e627548002c9eCraig McDonnell *
2229ffbfe08c2cd606c305f8934e627548002c9eCraig McDonnell * Copyright 2016 ForgeRock AS.
2229ffbfe08c2cd606c305f8934e627548002c9eCraig McDonnell */
2229ffbfe08c2cd606c305f8934e627548002c9eCraig McDonnell
2229ffbfe08c2cd606c305f8934e627548002c9eCraig McDonnell#import "FRANotificationsTableViewController.h"
2229ffbfe08c2cd606c305f8934e627548002c9eCraig McDonnell#import "FRANotificationTableViewCell.h"
2229ffbfe08c2cd606c305f8934e627548002c9eCraig McDonnell
2229ffbfe08c2cd606c305f8934e627548002c9eCraig McDonnell@implementation FRANotificationsTableViewController
2229ffbfe08c2cd606c305f8934e627548002c9eCraig McDonnell
fb63998ce7684bddab24e10c0b593809df1b7bffCraig McDonnell#pragma mark -
fb63998ce7684bddab24e10c0b593809df1b7bffCraig McDonnell#pragma mark UITableViewDataSource
fb63998ce7684bddab24e10c0b593809df1b7bffCraig McDonnell
2229ffbfe08c2cd606c305f8934e627548002c9eCraig McDonnell- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
fb63998ce7684bddab24e10c0b593809df1b7bffCraig McDonnell // Present active notifications in top section and history in bottom section
fb63998ce7684bddab24e10c0b593809df1b7bffCraig McDonnell return 2;
2229ffbfe08c2cd606c305f8934e627548002c9eCraig McDonnell}
2229ffbfe08c2cd606c305f8934e627548002c9eCraig McDonnell
2229ffbfe08c2cd606c305f8934e627548002c9eCraig McDonnell- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
fb63998ce7684bddab24e10c0b593809df1b7bffCraig McDonnell // Hardcoded for example data
fb63998ce7684bddab24e10c0b593809df1b7bffCraig McDonnell return section == 0 ? 1 : 10;
fb63998ce7684bddab24e10c0b593809df1b7bffCraig McDonnell}
fb63998ce7684bddab24e10c0b593809df1b7bffCraig McDonnell
fb63998ce7684bddab24e10c0b593809df1b7bffCraig McDonnell- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
fb63998ce7684bddab24e10c0b593809df1b7bffCraig McDonnell return section == 0 ? @"" : @"COMPLETED";
2229ffbfe08c2cd606c305f8934e627548002c9eCraig McDonnell}
2229ffbfe08c2cd606c305f8934e627548002c9eCraig McDonnell
2229ffbfe08c2cd606c305f8934e627548002c9eCraig McDonnell- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
fb63998ce7684bddab24e10c0b593809df1b7bffCraig McDonnell
fb63998ce7684bddab24e10c0b593809df1b7bffCraig McDonnell UIColor* seaGreen = [UIColor colorWithRed:48.0/255.0 green:160.0/255.0 blue:157.0/255.0 alpha:1.0];
fb63998ce7684bddab24e10c0b593809df1b7bffCraig McDonnell UIColor* dashboardRed = [UIColor colorWithRed:169.0/255.0 green:68.0/255.0 blue:66.0/255.0 alpha:1.0];
fb63998ce7684bddab24e10c0b593809df1b7bffCraig McDonnell
2229ffbfe08c2cd606c305f8934e627548002c9eCraig McDonnell // TODO: Lookup relevant notification from SQLite DB
2229ffbfe08c2cd606c305f8934e627548002c9eCraig McDonnell static NSString *CellIdentifier = @"NotificationCell";
2229ffbfe08c2cd606c305f8934e627548002c9eCraig McDonnell FRANotificationTableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
fb63998ce7684bddab24e10c0b593809df1b7bffCraig McDonnell if ([self isPendingNotificationAtIndexPath:indexPath]) {
fb63998ce7684bddab24e10c0b593809df1b7bffCraig McDonnell // enable selection/segue from pending notifications
fb63998ce7684bddab24e10c0b593809df1b7bffCraig McDonnell cell.selectionStyle = UITableViewCellSelectionStyleDefault;
fb63998ce7684bddab24e10c0b593809df1b7bffCraig McDonnell [cell setUserInteractionEnabled:YES];
fb63998ce7684bddab24e10c0b593809df1b7bffCraig McDonnell cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
fb63998ce7684bddab24e10c0b593809df1b7bffCraig McDonnell
fb63998ce7684bddab24e10c0b593809df1b7bffCraig McDonnell cell.status.text = @"Pending";
fb63998ce7684bddab24e10c0b593809df1b7bffCraig McDonnell cell.image.image = [[UIImage imageNamed:@"PendingIcon"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
fb63998ce7684bddab24e10c0b593809df1b7bffCraig McDonnell cell.image.tintColor = [UIColor grayColor];
fb63998ce7684bddab24e10c0b593809df1b7bffCraig McDonnell cell.time.text = @"2 min ago";
fb63998ce7684bddab24e10c0b593809df1b7bffCraig McDonnell } else {
fb63998ce7684bddab24e10c0b593809df1b7bffCraig McDonnell // only enable selection/segue from pending notifications
fb63998ce7684bddab24e10c0b593809df1b7bffCraig McDonnell cell.selectionStyle = UITableViewCellSelectionStyleNone;
fb63998ce7684bddab24e10c0b593809df1b7bffCraig McDonnell [cell setUserInteractionEnabled:NO];
fb63998ce7684bddab24e10c0b593809df1b7bffCraig McDonnell cell.accessoryType = UITableViewCellAccessoryNone;
fb63998ce7684bddab24e10c0b593809df1b7bffCraig McDonnell
fb63998ce7684bddab24e10c0b593809df1b7bffCraig McDonnell if (indexPath.row == 3) {
fb63998ce7684bddab24e10c0b593809df1b7bffCraig McDonnell cell.status.text = @"Denied";
fb63998ce7684bddab24e10c0b593809df1b7bffCraig McDonnell cell.image.image = [[UIImage imageNamed:@"DeniedIcon"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
fb63998ce7684bddab24e10c0b593809df1b7bffCraig McDonnell cell.image.tintColor = dashboardRed;
fb63998ce7684bddab24e10c0b593809df1b7bffCraig McDonnell } else {
fb63998ce7684bddab24e10c0b593809df1b7bffCraig McDonnell cell.status.text = @"Approved";
fb63998ce7684bddab24e10c0b593809df1b7bffCraig McDonnell cell.image.image = [[UIImage imageNamed:@"ApprovedIcon"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
fb63998ce7684bddab24e10c0b593809df1b7bffCraig McDonnell cell.image.tintColor = seaGreen;
fb63998ce7684bddab24e10c0b593809df1b7bffCraig McDonnell }
fb63998ce7684bddab24e10c0b593809df1b7bffCraig McDonnell if (indexPath.row < 2) {
fb63998ce7684bddab24e10c0b593809df1b7bffCraig McDonnell cell.time.text = @"Yesterday";
fb63998ce7684bddab24e10c0b593809df1b7bffCraig McDonnell } else {
fb63998ce7684bddab24e10c0b593809df1b7bffCraig McDonnell cell.time.text = @"22/3/16";
fb63998ce7684bddab24e10c0b593809df1b7bffCraig McDonnell }
fb63998ce7684bddab24e10c0b593809df1b7bffCraig McDonnell }
2229ffbfe08c2cd606c305f8934e627548002c9eCraig McDonnell [cell layoutIfNeeded];
2229ffbfe08c2cd606c305f8934e627548002c9eCraig McDonnell return cell;
2229ffbfe08c2cd606c305f8934e627548002c9eCraig McDonnell}
2229ffbfe08c2cd606c305f8934e627548002c9eCraig McDonnell
fb63998ce7684bddab24e10c0b593809df1b7bffCraig McDonnell#pragma mark -
fb63998ce7684bddab24e10c0b593809df1b7bffCraig McDonnell#pragma mark UITableViewDelegate
fb63998ce7684bddab24e10c0b593809df1b7bffCraig McDonnell
fb63998ce7684bddab24e10c0b593809df1b7bffCraig McDonnell- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath {
fb63998ce7684bddab24e10c0b593809df1b7bffCraig McDonnell if ([self isPendingNotificationAtIndexPath:indexPath]) {
fb63998ce7684bddab24e10c0b593809df1b7bffCraig McDonnell // only enable selection/segue from pending notifications
fb63998ce7684bddab24e10c0b593809df1b7bffCraig McDonnell return indexPath;
fb63998ce7684bddab24e10c0b593809df1b7bffCraig McDonnell } else {
fb63998ce7684bddab24e10c0b593809df1b7bffCraig McDonnell return nil;
fb63998ce7684bddab24e10c0b593809df1b7bffCraig McDonnell }
fb63998ce7684bddab24e10c0b593809df1b7bffCraig McDonnell}
fb63998ce7684bddab24e10c0b593809df1b7bffCraig McDonnell
fb63998ce7684bddab24e10c0b593809df1b7bffCraig McDonnell-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
fb63998ce7684bddab24e10c0b593809df1b7bffCraig McDonnell // make table cell separator lines full width (normally, they leave a ~10% gap at the left edge)
fb63998ce7684bddab24e10c0b593809df1b7bffCraig McDonnell if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
fb63998ce7684bddab24e10c0b593809df1b7bffCraig McDonnell [cell setSeparatorInset:UIEdgeInsetsZero];
fb63998ce7684bddab24e10c0b593809df1b7bffCraig McDonnell }
fb63998ce7684bddab24e10c0b593809df1b7bffCraig McDonnell if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
fb63998ce7684bddab24e10c0b593809df1b7bffCraig McDonnell [cell setLayoutMargins:UIEdgeInsetsZero];
fb63998ce7684bddab24e10c0b593809df1b7bffCraig McDonnell }
fb63998ce7684bddab24e10c0b593809df1b7bffCraig McDonnell}
fb63998ce7684bddab24e10c0b593809df1b7bffCraig McDonnell
fb63998ce7684bddab24e10c0b593809df1b7bffCraig McDonnell#pragma mark -
fb63998ce7684bddab24e10c0b593809df1b7bffCraig McDonnell#pragma mark FRANotificationsTableViewController
fb63998ce7684bddab24e10c0b593809df1b7bffCraig McDonnell
fb63998ce7684bddab24e10c0b593809df1b7bffCraig McDonnell- (BOOL)isPendingNotificationAtIndexPath:(NSIndexPath *)indexPath {
fb63998ce7684bddab24e10c0b593809df1b7bffCraig McDonnell return indexPath.section == 0;
fb63998ce7684bddab24e10c0b593809df1b7bffCraig McDonnell}
fb63998ce7684bddab24e10c0b593809df1b7bffCraig McDonnell
2229ffbfe08c2cd606c305f8934e627548002c9eCraig McDonnell@end