session-ios/Signal/src/view controllers/UITests/SignalsViewController.m

506 lines
19 KiB
Mathematica
Raw Normal View History

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.
//
2014-11-24 21:51:43 +01:00
#import "UIUtil.h"
#import "InboxTableViewCell.h"
2014-10-29 21:58:58 +01:00
#import "ContactsManager.h"
2014-10-29 21:58:58 +01:00
#import "MessagesViewController.h"
#import "SignalsViewController.h"
#import "InCallViewController.h"
#import "TSStorageManager.h"
#import "TSAccountManager.h"
#import "TSDatabaseView.h"
#import "TSMessagesManager+sendMessages.h"
#import "VersionMigrations.h"
2015-01-31 03:50:48 +01:00
#import "PreferencesUtil.h"
#import "NSDate+millisecondTimeStamp.h"
2014-10-29 21:58:58 +01:00
#import <YapDatabase/YapDatabaseViewChange.h>
#import "YapDatabaseViewConnection.h"
#define CELL_HEIGHT 72.0f
2014-10-29 21:58:58 +01:00
#define HEADER_HEIGHT 44.0f
static NSString *const kSegueIndentifier = @"showSegue";
static NSString* const kShowSignupFlowSegue = @"showSignupFlow";
2014-10-29 21:58:58 +01:00
2014-12-05 23:38:13 +01:00
@interface SignalsViewController ()
2014-12-05 23:38:13 +01:00
@property (nonatomic, strong) YapDatabaseConnection *editingDbConnection;
@property (nonatomic, strong) YapDatabaseConnection *uiDatabaseConnection;
@property (nonatomic, strong) YapDatabaseViewMappings *threadMappings;
@property (nonatomic) CellState viewingThreadsIn;
@property (nonatomic) long inboxCount;
@property (nonatomic, retain) UISegmentedControl *segmentedControl;
@property (nonatomic) NSArray<id<UIPreviewActionItem>> *previewActions;
2014-10-29 21:58:58 +01:00
@end
@implementation SignalsViewController
- (void)awakeFromNib{
[[Environment getCurrent] setSignalsViewController:self];
}
2014-10-29 21:58:58 +01:00
- (void)viewDidLoad {
[super viewDidLoad];
[self.navigationController.navigationBar setTranslucent:NO];
2014-12-05 23:38:13 +01:00
[self tableViewSetUp];
self.editingDbConnection = TSStorageManager.sharedManager.newDatabaseConnection;
[self.uiDatabaseConnection beginLongLivedReadTransaction];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(yapDatabaseModified:)
name:TSUIDatabaseConnectionDidUpdateNotification
object:nil];
[self selectedInbox:self];
[[[Environment getCurrent] contactsManager].getObservableContacts watchLatestValue:^(id latestValue) {
[self.tableView reloadData];
} onThread:[NSThread mainThread] untilCancelled:nil];
self.segmentedControl = [[UISegmentedControl alloc] initWithItems:@[NSLocalizedString(@"WHISPER_NAV_BAR_TITLE", nil),
NSLocalizedString(@"ARCHIVE_NAV_BAR_TITLE", nil)]];
[self.segmentedControl addTarget:self action:@selector(swappedSegmentedControl) forControlEvents:UIControlEventValueChanged];
self.navigationItem.titleView = self.segmentedControl;
[self.segmentedControl setSelectedSegmentIndex:0];
if ([self.traitCollection
respondsToSelector:@selector(forceTouchCapability)] &&
(self.traitCollection.forceTouchCapability ==
UIForceTouchCapabilityAvailable))
{
[self registerForPreviewingWithDelegate:self sourceView:self.view];
}
}
- (UIViewController *)previewingContext:
(id<UIViewControllerPreviewing>)previewingContext
viewControllerForLocation:(CGPoint)location {
NSIndexPath *indexPath = [self.tableView
indexPathForRowAtPoint:location];
MessagesViewController * vc = [[MessagesViewController alloc] initWithNibName:nil bundle:nil];
TSThread *thread = [self threadForIndexPath:indexPath];
[vc setupWithThread:thread];
[vc peekSetup];
return vc;
}
- (void)previewingContext:(id<UIViewControllerPreviewing>)previewingContext
commitViewController:(UIViewController *)viewControllerToCommit {
MessagesViewController *vc = (MessagesViewController*)viewControllerToCommit;
[vc popped];
[self.navigationController pushViewController:vc
animated:NO];
}
- (NSArray<id<UIPreviewActionItem>> *)previewActionItems {
return self.previewActions;
}
- (NSArray<id<UIPreviewActionItem>> *)previewActions {
if (_previewActions == nil) {
UIPreviewAction *printAction = [UIPreviewAction
actionWithTitle:@"Print"
style:UIPreviewActionStyleDefault
handler:^(UIPreviewAction * _Nonnull action,
UIViewController * _Nonnull previewViewController) {
// ... code to handle action here
}];
_previewActions = @[printAction];
}
return _previewActions;
}
2015-10-31 23:13:28 +01:00
- (void)composeNew {
if (self.presentedViewController) {
[self dismissViewControllerAnimated:YES completion:nil];
}
[self.navigationController popToRootViewControllerAnimated:YES];
[self performSegueWithIdentifier:@"composeNew" sender:self];
}
- (void)swappedSegmentedControl {
if (self.segmentedControl.selectedSegmentIndex == 0) {
[self selectedInbox:nil];
} else {
[self selectedArchive:nil];
}
2014-11-24 21:51:43 +01:00
}
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self checkIfEmptyView];
if (![TSAccountManager isRegistered]){
[self performSegueWithIdentifier:kShowSignupFlowSegue sender:self];
return;
}
[self updateInboxCountLabel];
iOS 9 Support - Fixing size classes rendering bugs. - Supporting native iOS San Francisco font. - Quick Reply - Settings now slide to the left as suggested in original designed opposed to modal. - Simplification of restraints on many screens. - Full-API compatiblity with iOS 9 and iOS 8 legacy support. - Customized AddressBook Permission prompt when restrictions are enabled. If user installed Signal previously and already approved access to Contacts, don't bugg him again. - Fixes crash in migration for users who installed Signal <2.1.3 but hadn't signed up yet. - Xcode 7 / iOS 9 Travis Support - Bitcode Support is disabled until it is better understood how exactly optimizations are performed. In a first time, we will split out the crypto code into a separate binary to make it easier to optimize the non-sensitive code. Blog post with more details coming. - Partial ATS support. We are running our own Certificate Authority at Open Whisper Systems. Signal is doing certificate pinning to verify that certificates were signed by our own CA. Unfortunately Apple's App Transport Security requires to hand over chain verification to their framework with no control over the trust store. We have filed a radar to get ATS features with pinned certificates. In the meanwhile, ATS is disabled on our domain. We also followed Amazon's recommendations for our S3 domain we use to upload/download attachments. (#891) - Implement a unified `AFSecurityOWSPolicy` pinning strategy accross libraries (AFNetworking RedPhone/TextSecure & SocketRocket).
2015-09-01 19:22:08 +02:00
[[self tableView] reloadData];
}
2014-10-29 21:58:58 +01:00
-(void)tableViewSetUp
{
self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
2014-10-29 21:58:58 +01:00
}
2015-01-24 04:26:04 +01:00
#pragma mark - Table View Data Source
2014-10-29 21:58:58 +01:00
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return (NSInteger)[self.threadMappings numberOfSections];
2014-10-29 21:58:58 +01:00
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return (NSInteger)[self.threadMappings numberOfItemsInSection:(NSUInteger)section];
2014-10-29 21:58:58 +01:00
}
- (InboxTableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath {
2014-10-29 21:58:58 +01:00
InboxTableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:NSStringFromClass([InboxTableViewCell class])];
2014-11-25 19:06:09 +01:00
TSThread *thread = [self threadForIndexPath:indexPath];
2014-10-29 21:58:58 +01:00
if (!cell) {
iOS 9 Support - Fixing size classes rendering bugs. - Supporting native iOS San Francisco font. - Quick Reply - Settings now slide to the left as suggested in original designed opposed to modal. - Simplification of restraints on many screens. - Full-API compatiblity with iOS 9 and iOS 8 legacy support. - Customized AddressBook Permission prompt when restrictions are enabled. If user installed Signal previously and already approved access to Contacts, don't bugg him again. - Fixes crash in migration for users who installed Signal <2.1.3 but hadn't signed up yet. - Xcode 7 / iOS 9 Travis Support - Bitcode Support is disabled until it is better understood how exactly optimizations are performed. In a first time, we will split out the crypto code into a separate binary to make it easier to optimize the non-sensitive code. Blog post with more details coming. - Partial ATS support. We are running our own Certificate Authority at Open Whisper Systems. Signal is doing certificate pinning to verify that certificates were signed by our own CA. Unfortunately Apple's App Transport Security requires to hand over chain verification to their framework with no control over the trust store. We have filed a radar to get ATS features with pinned certificates. In the meanwhile, ATS is disabled on our domain. We also followed Amazon's recommendations for our S3 domain we use to upload/download attachments. (#891) - Implement a unified `AFSecurityOWSPolicy` pinning strategy accross libraries (AFNetworking RedPhone/TextSecure & SocketRocket).
2015-09-01 19:22:08 +02:00
cell = [InboxTableViewCell inboxTableViewCell];
2014-10-29 21:58:58 +01:00
cell.delegate = self;
}
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
[cell configureWithThread:thread];
[cell configureForState:self.viewingThreadsIn == kInboxState ? kInboxState : kArchiveState];
});
2015-03-20 14:32:57 +01:00
if ((unsigned long)indexPath.row == [self.threadMappings numberOfItemsInSection:0]-1) {
cell.separatorInset = UIEdgeInsetsMake(0.f, cell.bounds.size.width, 0.f, 0.f);
}
2014-10-29 21:58:58 +01:00
return cell;
}
2014-10-29 21:58:58 +01:00
- (TSThread*)threadForIndexPath:(NSIndexPath*)indexPath {
__block TSThread *thread = nil;
[self.uiDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
thread = [[transaction extension:TSThreadDatabaseViewExtensionName] objectAtIndexPath:indexPath withMappings:self.threadMappings];
}];
return thread;
2014-10-29 21:58:58 +01:00
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return CELL_HEIGHT;
}
2014-10-29 21:58:58 +01:00
#pragma mark Table Swipe to Delete
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
return;
}
- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
{
// add the ability to delete the cell
UITableViewRowAction *deleteAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@" " handler:^(UITableViewRowAction *action, NSIndexPath *swipedIndexPath){
[self tableViewCellTappedDelete:swipedIndexPath];
}];
UIImage* buttonImage = [[UIImage imageNamed:@"cellBtnDelete"] resizedImageToSize:CGSizeMake(82.0f, 72.0f)];
deleteAction.backgroundColor = [[UIColor alloc] initWithPatternImage:buttonImage];
return @[deleteAction];
}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
return YES;
}
2014-10-29 21:58:58 +01:00
#pragma mark - HomeFeedTableViewCellDelegate
2015-01-24 04:26:04 +01:00
- (void)tableViewCellTappedDelete:(NSIndexPath*)indexPath {
2014-11-25 17:28:42 +01:00
TSThread *thread = [self threadForIndexPath:indexPath];
if([thread isKindOfClass:[TSGroupThread class]]) {
TSOutgoingMessage *message = [[TSOutgoingMessage alloc] initWithTimestamp:[NSDate ows_millisecondTimeStamp] inThread:thread messageBody:@"" attachments:[[NSMutableArray alloc] init]];
message.groupMetaMessage = TSGroupMessageQuit;
iOS 9 Support - Fixing size classes rendering bugs. - Supporting native iOS San Francisco font. - Quick Reply - Settings now slide to the left as suggested in original designed opposed to modal. - Simplification of restraints on many screens. - Full-API compatiblity with iOS 9 and iOS 8 legacy support. - Customized AddressBook Permission prompt when restrictions are enabled. If user installed Signal previously and already approved access to Contacts, don't bugg him again. - Fixes crash in migration for users who installed Signal <2.1.3 but hadn't signed up yet. - Xcode 7 / iOS 9 Travis Support - Bitcode Support is disabled until it is better understood how exactly optimizations are performed. In a first time, we will split out the crypto code into a separate binary to make it easier to optimize the non-sensitive code. Blog post with more details coming. - Partial ATS support. We are running our own Certificate Authority at Open Whisper Systems. Signal is doing certificate pinning to verify that certificates were signed by our own CA. Unfortunately Apple's App Transport Security requires to hand over chain verification to their framework with no control over the trust store. We have filed a radar to get ATS features with pinned certificates. In the meanwhile, ATS is disabled on our domain. We also followed Amazon's recommendations for our S3 domain we use to upload/download attachments. (#891) - Implement a unified `AFSecurityOWSPolicy` pinning strategy accross libraries (AFNetworking RedPhone/TextSecure & SocketRocket).
2015-09-01 19:22:08 +02:00
[[TSMessagesManager sharedManager] sendMessage:message inThread:thread success:nil failure:nil];
}
2014-12-05 23:38:13 +01:00
[self.editingDbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
[thread removeWithTransaction:transaction];
}];
_inboxCount -= (self.viewingThreadsIn == kArchiveState) ? 1 : 0;
[self checkIfEmptyView];
2014-10-29 21:58:58 +01:00
}
- (void)tableViewCellTappedArchive:(InboxTableViewCell*)cell {
2014-12-05 23:38:13 +01:00
NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
TSThread *thread = [self threadForIndexPath:indexPath];
BOOL viewingThreadsIn = self.viewingThreadsIn;
2014-12-05 23:38:13 +01:00
[self.editingDbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
viewingThreadsIn == kInboxState ? [thread archiveThreadWithTransaction:transaction] : [thread unarchiveThreadWithTransaction:transaction];
iOS 9 Support - Fixing size classes rendering bugs. - Supporting native iOS San Francisco font. - Quick Reply - Settings now slide to the left as suggested in original designed opposed to modal. - Simplification of restraints on many screens. - Full-API compatiblity with iOS 9 and iOS 8 legacy support. - Customized AddressBook Permission prompt when restrictions are enabled. If user installed Signal previously and already approved access to Contacts, don't bugg him again. - Fixes crash in migration for users who installed Signal <2.1.3 but hadn't signed up yet. - Xcode 7 / iOS 9 Travis Support - Bitcode Support is disabled until it is better understood how exactly optimizations are performed. In a first time, we will split out the crypto code into a separate binary to make it easier to optimize the non-sensitive code. Blog post with more details coming. - Partial ATS support. We are running our own Certificate Authority at Open Whisper Systems. Signal is doing certificate pinning to verify that certificates were signed by our own CA. Unfortunately Apple's App Transport Security requires to hand over chain verification to their framework with no control over the trust store. We have filed a radar to get ATS features with pinned certificates. In the meanwhile, ATS is disabled on our domain. We also followed Amazon's recommendations for our S3 domain we use to upload/download attachments. (#891) - Implement a unified `AFSecurityOWSPolicy` pinning strategy accross libraries (AFNetworking RedPhone/TextSecure & SocketRocket).
2015-09-01 19:22:08 +02:00
2014-12-05 23:38:13 +01:00
}];
[self checkIfEmptyView];
}
- (NSNumber*)updateInboxCountLabel {
NSUInteger numberOfItems = [[TSMessagesManager sharedManager] unreadMessagesCount];
NSNumber *badgeNumber = [NSNumber numberWithUnsignedInteger:numberOfItems];
NSString *unreadString = NSLocalizedString(@"WHISPER_NAV_BAR_TITLE", nil);
if (![badgeNumber isEqualToNumber:@0]) {
NSString *badgeValue = [badgeNumber stringValue];
unreadString = [unreadString stringByAppendingFormat:@" (%@)", badgeValue];
}
[_segmentedControl setTitle:unreadString forSegmentAtIndex:0];
iOS 9 Support - Fixing size classes rendering bugs. - Supporting native iOS San Francisco font. - Quick Reply - Settings now slide to the left as suggested in original designed opposed to modal. - Simplification of restraints on many screens. - Full-API compatiblity with iOS 9 and iOS 8 legacy support. - Customized AddressBook Permission prompt when restrictions are enabled. If user installed Signal previously and already approved access to Contacts, don't bugg him again. - Fixes crash in migration for users who installed Signal <2.1.3 but hadn't signed up yet. - Xcode 7 / iOS 9 Travis Support - Bitcode Support is disabled until it is better understood how exactly optimizations are performed. In a first time, we will split out the crypto code into a separate binary to make it easier to optimize the non-sensitive code. Blog post with more details coming. - Partial ATS support. We are running our own Certificate Authority at Open Whisper Systems. Signal is doing certificate pinning to verify that certificates were signed by our own CA. Unfortunately Apple's App Transport Security requires to hand over chain verification to their framework with no control over the trust store. We have filed a radar to get ATS features with pinned certificates. In the meanwhile, ATS is disabled on our domain. We also followed Amazon's recommendations for our S3 domain we use to upload/download attachments. (#891) - Implement a unified `AFSecurityOWSPolicy` pinning strategy accross libraries (AFNetworking RedPhone/TextSecure & SocketRocket).
2015-09-01 19:22:08 +02:00
[_segmentedControl reloadInputViews];
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:badgeNumber.integerValue];
return badgeNumber;
2014-10-29 21:58:58 +01:00
}
2014-11-25 17:28:42 +01:00
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath{
2014-10-29 21:58:58 +01:00
[self performSegueWithIdentifier:kSegueIndentifier sender:self];
[tableView deselectRowAtIndexPath:indexPath animated:NO];
}
#pragma mark - Navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
2014-11-25 17:28:42 +01:00
if ([segue.identifier isEqualToString:kSegueIndentifier]){
2014-11-25 16:38:33 +01:00
MessagesViewController * vc = [segue destinationViewController];
NSIndexPath *selectedIndexPath = [self.tableView indexPathForSelectedRow];
2014-11-26 16:00:10 +01:00
TSThread *thread = [self threadForIndexPath:selectedIndexPath];
if (self.contactIdentifierFromCompose){
2014-11-26 16:00:10 +01:00
[vc setupWithTSIdentifier:self.contactIdentifierFromCompose];
[vc setComposeOnOpen:self.composeMessage];
2014-11-26 16:00:10 +01:00
self.contactIdentifierFromCompose = nil;
self.composeMessage = NO;
2014-10-29 21:58:58 +01:00
}
else if (self.groupFromCompose) {
[vc setupWithTSGroup:self.groupFromCompose];
[vc setComposeOnOpen:self.composeMessage];
self.groupFromCompose = nil;
self.composeMessage = NO;
}
else if (thread) {
[vc setupWithThread:thread];
[vc setComposeOnOpen:NO];
}
else if([sender isKindOfClass:[TSGroupThread class]]){
[vc setupWithThread:sender];
[vc setComposeOnOpen:YES];
}
}
else if ([segue.identifier isEqualToString:kCallSegue]) {
InCallViewController* vc = [segue destinationViewController];
[vc configureWithLatestCall:_latestCall];
_latestCall = nil;
2014-10-29 21:58:58 +01:00
}
}
#pragma mark - IBAction
-(IBAction)selectedInbox:(id)sender {
self.viewingThreadsIn = kInboxState;
[self changeToGrouping:TSInboxGroup];
}
-(IBAction)selectedArchive:(id)sender {
self.viewingThreadsIn = kArchiveState;
[self changeToGrouping:TSArchiveGroup];
}
-(void) changeToGrouping:(NSString*)grouping {
self.threadMappings = [[YapDatabaseViewMappings alloc] initWithGroups:@[grouping]
view:TSThreadDatabaseViewExtensionName];
[self.threadMappings setIsReversed:YES forGroup:grouping];
iOS 9 Support - Fixing size classes rendering bugs. - Supporting native iOS San Francisco font. - Quick Reply - Settings now slide to the left as suggested in original designed opposed to modal. - Simplification of restraints on many screens. - Full-API compatiblity with iOS 9 and iOS 8 legacy support. - Customized AddressBook Permission prompt when restrictions are enabled. If user installed Signal previously and already approved access to Contacts, don't bugg him again. - Fixes crash in migration for users who installed Signal <2.1.3 but hadn't signed up yet. - Xcode 7 / iOS 9 Travis Support - Bitcode Support is disabled until it is better understood how exactly optimizations are performed. In a first time, we will split out the crypto code into a separate binary to make it easier to optimize the non-sensitive code. Blog post with more details coming. - Partial ATS support. We are running our own Certificate Authority at Open Whisper Systems. Signal is doing certificate pinning to verify that certificates were signed by our own CA. Unfortunately Apple's App Transport Security requires to hand over chain verification to their framework with no control over the trust store. We have filed a radar to get ATS features with pinned certificates. In the meanwhile, ATS is disabled on our domain. We also followed Amazon's recommendations for our S3 domain we use to upload/download attachments. (#891) - Implement a unified `AFSecurityOWSPolicy` pinning strategy accross libraries (AFNetworking RedPhone/TextSecure & SocketRocket).
2015-09-01 19:22:08 +02:00
[self.uiDatabaseConnection asyncReadWithBlock:^(YapDatabaseReadTransaction *transaction){
2014-12-05 23:38:13 +01:00
[self.threadMappings updateWithTransaction:transaction];
dispatch_async(dispatch_get_main_queue(), ^{
[self.tableView reloadData];
[self checkIfEmptyView];
});
2014-12-05 23:38:13 +01:00
}];
2014-10-29 21:58:58 +01:00
}
#pragma mark Database delegates
- (YapDatabaseConnection *)uiDatabaseConnection {
NSAssert([NSThread isMainThread], @"Must access uiDatabaseConnection on main thread!");
if (!_uiDatabaseConnection) {
YapDatabase *database = TSStorageManager.sharedManager.database;
_uiDatabaseConnection = [database newConnection];
[_uiDatabaseConnection beginLongLivedReadTransaction];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(yapDatabaseModified:)
name:YapDatabaseModifiedNotification
object:database];
}
return _uiDatabaseConnection;
}
- (void)yapDatabaseModified:(NSNotification *)notification {
2014-11-25 17:28:42 +01:00
NSArray *notifications = [self.uiDatabaseConnection beginLongLivedReadTransaction];
NSArray *sectionChanges = nil;
2014-11-25 17:28:42 +01:00
NSArray *rowChanges = nil;
[[self.uiDatabaseConnection ext:TSThreadDatabaseViewExtensionName] getSectionChanges:&sectionChanges
rowChanges:&rowChanges
forNotifications:notifications
withMappings:self.threadMappings];
if ([sectionChanges count] == 0 && [rowChanges count] == 0){
return;
}
[self.tableView beginUpdates];
for (YapDatabaseViewSectionChange *sectionChange in sectionChanges)
{
switch (sectionChange.type)
{
case YapDatabaseViewChangeDelete :
{
[self.tableView deleteSections:[NSIndexSet indexSetWithIndex:sectionChange.index]
withRowAnimation:UITableViewRowAnimationAutomatic];
break;
}
case YapDatabaseViewChangeInsert :
{
[self.tableView insertSections:[NSIndexSet indexSetWithIndex:sectionChange.index]
withRowAnimation:UITableViewRowAnimationAutomatic];
break;
}
case YapDatabaseViewChangeUpdate:
case YapDatabaseViewChangeMove:
break;
}
}
for (YapDatabaseViewRowChange *rowChange in rowChanges)
{
switch (rowChange.type)
{
case YapDatabaseViewChangeDelete :
{
[self.tableView deleteRowsAtIndexPaths:@[ rowChange.indexPath ]
withRowAnimation:UITableViewRowAnimationAutomatic];
_inboxCount += (self.viewingThreadsIn == kArchiveState) ? 1 : 0;
break;
}
case YapDatabaseViewChangeInsert :
{
[self.tableView insertRowsAtIndexPaths:@[ rowChange.newIndexPath ]
withRowAnimation:UITableViewRowAnimationAutomatic];
_inboxCount -= (self.viewingThreadsIn == kArchiveState) ? 1 : 0;
break;
}
case YapDatabaseViewChangeMove :
{
[self.tableView deleteRowsAtIndexPaths:@[ rowChange.indexPath ]
withRowAnimation:UITableViewRowAnimationAutomatic];
[self.tableView insertRowsAtIndexPaths:@[ rowChange.newIndexPath ]
withRowAnimation:UITableViewRowAnimationAutomatic];
break;
}
case YapDatabaseViewChangeUpdate :
{
[self.tableView reloadRowsAtIndexPaths:@[ rowChange.indexPath ]
withRowAnimation:UITableViewRowAnimationNone];
break;
}
}
}
[self.tableView endUpdates];
[self updateInboxCountLabel];
[self checkIfEmptyView];
}
2014-11-25 19:06:09 +01:00
- (IBAction)unwindSettingsDone:(UIStoryboardSegue *)segue {
}
- (IBAction)unwindMessagesView:(UIStoryboardSegue *)segue {
}
- (void)checkIfEmptyView{
[_tableView setHidden:NO];
if (self.viewingThreadsIn == kInboxState && [self.threadMappings numberOfItemsInGroup:TSInboxGroup]==0) {
[self setEmptyBoxText];
[_tableView setHidden:YES];
}
else if (self.viewingThreadsIn == kArchiveState && [self.threadMappings numberOfItemsInGroup:TSArchiveGroup]==0) {
[self setEmptyBoxText];
[_tableView setHidden:YES];
2014-11-25 19:06:09 +01:00
}
}
-(void) setEmptyBoxText {
_emptyBoxLabel.textColor = [UIColor grayColor];
_emptyBoxLabel.font = [UIFont ows_regularFontWithSize:18.f];
_emptyBoxLabel.textAlignment = NSTextAlignmentCenter;
_emptyBoxLabel.numberOfLines = 4;
NSString* firstLine = @"";
NSString* secondLine = @"";
if(self.viewingThreadsIn == kInboxState) {
if([Environment.preferences getHasSentAMessage]) {
firstLine = NSLocalizedString(@"EMPTY_INBOX_FIRST_TITLE", @"");
secondLine = NSLocalizedString(@"EMPTY_INBOX_FIRST_TEXT", @"");
}
else {
firstLine = NSLocalizedString(@"EMPTY_ARCHIVE_FIRST_TITLE", @"");
secondLine = NSLocalizedString(@"EMPTY_ARCHIVE_FIRST_TEXT", @"");
}
}
else {
if([Environment.preferences getHasArchivedAMessage]) {
firstLine = NSLocalizedString(@"EMPTY_INBOX_TITLE", @"");
secondLine = NSLocalizedString(@"EMPTY_INBOX_TEXT", @"");
}
else {
firstLine = NSLocalizedString(@"EMPTY_ARCHIVE_TITLE", @"");
secondLine = NSLocalizedString(@"EMPTY_ARCHIVE_TEXT", @"");
}
}
NSMutableAttributedString *fullLabelString = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@\n%@",firstLine,secondLine]];
[fullLabelString addAttribute:NSFontAttributeName value:[UIFont ows_boldFontWithSize:15.f] range:NSMakeRange(0,firstLine.length)];
[fullLabelString addAttribute:NSFontAttributeName value:[UIFont ows_regularFontWithSize:14.f] range:NSMakeRange(firstLine.length + 1, secondLine.length)];
[fullLabelString addAttribute:NSForegroundColorAttributeName value:[UIColor blackColor] range:NSMakeRange(0,firstLine.length)];
[fullLabelString addAttribute:NSForegroundColorAttributeName value:[UIColor ows_darkGrayColor] range:NSMakeRange(firstLine.length + 1, secondLine.length)];
_emptyBoxLabel.attributedText = fullLabelString;
2014-11-25 19:06:09 +01:00
}
2014-10-29 21:58:58 +01:00
@end