Settings: Let user pick notification style

Also lets user search for contacts by phone number.
This commit is contained in:
dtsbourg 2014-12-08 21:16:18 +01:00 committed by Frederic Jacobs
parent 03073a9c05
commit 29b8fb6eab
11 changed files with 207 additions and 9 deletions

View File

@ -477,6 +477,10 @@
E1CD329618BCFF9900B1A496 /* SoundInstance.m in Sources */ = {isa = PBXBuildFile; fileRef = E1CD329518BCFF9900B1A496 /* SoundInstance.m */; };
F995AC2FFD6D4442B012604A /* libPods.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 8313AE91B4954215858A5662 /* libPods.a */; };
FC15B7BF1A1F80F200F59801 /* defaultConctact_light@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = FC15B7BE1A1F80F200F59801 /* defaultConctact_light@2x.png */; };
FC1615181A37935600F1761D /* NotificationPreviewViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = FC1615171A37935600F1761D /* NotificationPreviewViewController.m */; };
FC16151C1A37945D00F1761D /* notification_no_preview_with_name@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = FC1615191A37945D00F1761D /* notification_no_preview_with_name@2x.png */; };
FC16151D1A37945D00F1761D /* notification_no_preview_no_name@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = FC16151A1A37945D00F1761D /* notification_no_preview_no_name@2x.png */; };
FC16151E1A37945D00F1761D /* notification_with_preview@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = FC16151B1A37945D00F1761D /* notification_with_preview@2x.png */; };
FC18803C1A31D94D0044CE86 /* SignalTabBarController.m in Sources */ = {isa = PBXBuildFile; fileRef = FC18803B1A31D94D0044CE86 /* SignalTabBarController.m */; };
FC1F90C01A22342B004F8253 /* group_photo@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = FC1F90BF1A22342B004F8253 /* group_photo@2x.png */; };
FC1F90C61A223991004F8253 /* settings_tab@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = FC1F90C41A223991004F8253 /* settings_tab@2x.png */; };
@ -1145,6 +1149,11 @@
E1CD329418BCFF9900B1A496 /* SoundInstance.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SoundInstance.h; sourceTree = "<group>"; };
E1CD329518BCFF9900B1A496 /* SoundInstance.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SoundInstance.m; sourceTree = "<group>"; };
FC15B7BE1A1F80F200F59801 /* defaultConctact_light@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "defaultConctact_light@2x.png"; sourceTree = "<group>"; };
FC1615161A37935600F1761D /* NotificationPreviewViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NotificationPreviewViewController.h; sourceTree = "<group>"; };
FC1615171A37935600F1761D /* NotificationPreviewViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NotificationPreviewViewController.m; sourceTree = "<group>"; };
FC1615191A37945D00F1761D /* notification_no_preview_with_name@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "notification_no_preview_with_name@2x.png"; sourceTree = "<group>"; };
FC16151A1A37945D00F1761D /* notification_no_preview_no_name@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "notification_no_preview_no_name@2x.png"; sourceTree = "<group>"; };
FC16151B1A37945D00F1761D /* notification_with_preview@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "notification_with_preview@2x.png"; sourceTree = "<group>"; };
FC18803A1A31D94D0044CE86 /* SignalTabBarController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SignalTabBarController.h; path = "view controllers/SignalTabBarController.h"; sourceTree = "<group>"; };
FC18803B1A31D94D0044CE86 /* SignalTabBarController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SignalTabBarController.m; path = "view controllers/SignalTabBarController.m"; sourceTree = "<group>"; };
FC1F90BF1A22342B004F8253 /* group_photo@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "group_photo@2x.png"; sourceTree = "<group>"; };
@ -2131,6 +2140,9 @@
FCA52AE41A2B676C00CCADFA /* message_error@2x.png */,
B633C5411A1D190B0059AC12 /* mute_off@2x.png */,
B633C5421A1D190B0059AC12 /* mute_on@2x.png */,
FC16151A1A37945D00F1761D /* notification_no_preview_no_name@2x.png */,
FC1615191A37945D00F1761D /* notification_no_preview_with_name@2x.png */,
FC16151B1A37945D00F1761D /* notification_with_preview@2x.png */,
B633C54B1A1D190B0059AC12 /* photo@2x.png */,
B633C54C1A1D190B0059AC12 /* quit@2x.png */,
B633C54E1A1D190B0059AC12 /* red-delete@2x.png */,
@ -2589,6 +2601,8 @@
children = (
FC31962E1A0814130094C78E /* SettingsTableViewController.h */,
FC31962F1A0814130094C78E /* SettingsTableViewController.m */,
FC1615161A37935600F1761D /* NotificationPreviewViewController.h */,
FC1615171A37935600F1761D /* NotificationPreviewViewController.m */,
);
name = Settings;
sourceTree = "<group>";
@ -2844,7 +2858,9 @@
B633C5CE1A1D190B0059AC12 /* quit@2x.png in Resources */,
E148750A18A06966002CC4F3 /* InCallViewController.xib in Resources */,
FCA52AEB1A2B676C00CCADFA /* checkmark_light@2x.png in Resources */,
FC16151C1A37945D00F1761D /* notification_no_preview_with_name@2x.png in Resources */,
B633C5D01A1D190B0059AC12 /* red-delete@2x.png in Resources */,
FC16151E1A37945D00F1761D /* notification_with_preview@2x.png in Resources */,
B633C59D1A1D190B0059AC12 /* endcall@2x.png in Resources */,
B633C5B41A1D190B0059AC12 /* keypad@2x.png in Resources */,
B633C5DA1A1D190B0059AC12 /* settings_dark@2x.png in Resources */,
@ -2865,6 +2881,7 @@
B66DBF4A19D5BBC8006EA940 /* Images.xcassets in Resources */,
FCA52AE71A2B676C00CCADFA /* call_failed@2x.png in Resources */,
70B8FEE21909FE360042E3F0 /* 171756__nenadsimic__picked-coin-echo-2.wav in Resources */,
FC16151D1A37945D00F1761D /* notification_no_preview_no_name@2x.png in Resources */,
B633C5801A1D190B0059AC12 /* archive@2x.png in Resources */,
FC1F90C71A223991004F8253 /* signals_tab@2x.png in Resources */,
B633C5C31A1D190B0059AC12 /* mute_off@2x.png in Resources */,
@ -3104,6 +3121,7 @@
76EB058218170B33006006FC /* Environment.m in Sources */,
76EB064418170B33006006FC /* ThreadManager.m in Sources */,
E197B61E18BBEC6D00F073E5 /* AudioRouter.m in Sources */,
FC1615181A37935600F1761D /* NotificationPreviewViewController.m in Sources */,
E197B60D18BBEC1A00F073E5 /* AudioSocket.m in Sources */,
FCF72A081A01A765006BC849 /* ContactsTableViewController.m in Sources */,
FC31962D1A06A2190094C78E /* FingerprintViewController.m in Sources */,

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

View File

@ -3,6 +3,12 @@
#import "PropertyListPreferences.h"
#import "Zid.h"
typedef NS_ENUM(NSUInteger, NotificationType) {
NotificationNoNameNoPreview,
NotificationNameNoPreview,
NotificationNamePreview,
};
@class PhoneNumber;
@interface PropertyListPreferences (PropertyUtil)
@ -18,6 +24,9 @@
-(BOOL)screenSecurityIsEnabled;
-(void)setScreenSecurity:(BOOL)flag;
-(NotificationType)notificationPreviewType;
-(void)setNotificationPreviewType:(NotificationType)type;
-(NSString*)lastRanVersion;
-(NSString*)setAndGetCurrentVersion;

View File

@ -23,6 +23,7 @@
#define PUSH_REVOKED_KEY @"Push Revoked Key"
#define SCREEN_SECURITY_KEY @"Screen Security Key"
#define DEBUG_IS_ENABLED_KEY @"Debugging Log Enabled Key"
#define NOTIFICATION_PREVIEW_TYPE_KEY @"Notification Preview Type Key"
#define kSignalVersionKey @"SignalUpdateVersionKey"
@ -117,6 +118,21 @@
}
}
-(NotificationType)notificationPreviewType {
NSNumber *preference = [self tryGetValueForKey:NOTIFICATION_PREVIEW_TYPE_KEY];
if (preference) {
return [preference unsignedIntegerValue];
} else {
return NotificationNamePreview;
}
}
-(void)setNotificationPreviewType:(NotificationType)type
{
[self setValueForKey:NOTIFICATION_PREVIEW_TYPE_KEY toValue:@(type)];
}
-(void)setScreenSecurity:(BOOL)flag{
[self setValueForKey:SCREEN_SECURITY_KEY toValue:@(flag)];
}

View File

@ -31,6 +31,9 @@
#import "NSData+messagePadding.h"
#import "Environment.h"
#import "PreferencesUtil.h"
#import <CocoaLumberjack/DDLog.h>
#define ddLogLevel LOG_LEVEL_VERBOSE
@ -276,11 +279,30 @@
}
- (void)notifyUserForIncomingMessage:(TSIncomingMessage*)message from:(NSString*)name{
UILocalNotification *notification = [[UILocalNotification alloc] init];
notification.alertBody = [NSString stringWithFormat:@"%@: %@", name, message.body];
notification.alertBody = [self alertBodyForNotificationSetting:[Environment.preferences notificationPreviewType] withMessage:message from:name];
notification.soundName = @"default";
notification.category = Signal_Message_Category;
[[UIApplication sharedApplication] presentLocalNotificationNow:notification];
}
-(NSString*)alertBodyForNotificationSetting:(NotificationType)setting withMessage:(TSIncomingMessage*)message from:(NSString*)name
{
switch (setting) {
case NotificationNoNameNoPreview:
return @"New message";
break;
case NotificationNameNoPreview:
return [NSString stringWithFormat:@"New message from %@", name];
break;
case NotificationNamePreview:
return [NSString stringWithFormat:@"%@ : %@", name, message.body];
break;
default:
DDLogWarn(@"Unexpected notification type %ld", setting);
break;
}
}
@end

View File

@ -125,14 +125,15 @@ static NSString *const CONTACT_BROWSE_TABLE_CELL_IDENTIFIER = @"ContactTableView
- (void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope
{
NSPredicate *resultPredicate = [NSPredicate predicateWithFormat:@"fullName contains[c] %@", searchText];
searchResults = [self.latestContacts filteredArrayUsingPredicate:resultPredicate];
NSPredicate *numberPredicate = [NSPredicate predicateWithFormat:@"ANY SELF.userTextPhoneNumbers contains[cd] %@ OR fullName contains[c] %@", searchText, searchText];
searchResults = [self.latestContacts filteredArrayUsingPredicate:numberPredicate];
if (!searchResults.count && _searchController.searchBar.text.length == 0) {
searchResults = self.latestContacts;
}
}
#pragma mark - Contact functions
- (void)setupContacts {
@ -180,7 +181,7 @@ static NSString *const CONTACT_BROWSE_TABLE_CELL_IDENTIFIER = @"ContactTableView
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
if ([[self contactsForSectionIndex:(NSUInteger)section] count]) {
if ([[self contactsForSectionIndex:(NSUInteger)section] count] && !self.searchController.isActive) {
return self.latestSortedAlphabeticalContactKeys[(NSUInteger)section];
} else {
return nil;

View File

@ -0,0 +1,13 @@
//
// NotificationPreviewViewController.h
// Signal
//
// Created by Dylan Bourgeois on 09/12/14.
// Copyright (c) 2014 Open Whisper Systems. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface NotificationPreviewViewController : UITableViewController
@end

View File

@ -0,0 +1,118 @@
//
// NotificationPreviewViewController.m
// Signal
//
// Created by Dylan Bourgeois on 09/12/14.
// Copyright (c) 2014 Open Whisper Systems. All rights reserved.
//
#import "NotificationPreviewViewController.h"
#import "UIUtil.h"
#import "PreferencesUtil.h"
#import "Environment.h"
@interface NotificationPreviewViewController ()
@property (nonatomic) NSIndexPath *defaultSelectedIndexPath;
@end
@implementation NotificationPreviewViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationItem.title = @"Notification Style";
self.tableView.tableFooterView = [[UIView alloc]initWithFrame:CGRectZero];
self.clearsSelectionOnViewWillAppear = NO;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
NSInteger currentSetting = (NSInteger)[Environment.preferences notificationPreviewType];
_defaultSelectedIndexPath = [NSIndexPath indexPathForRow:0 inSection:currentSetting+1];
[self selectRowAtIndexPath:_defaultSelectedIndexPath];
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 4;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 1;
}
- (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section
{
UITableViewHeaderFooterView *header = (UITableViewHeaderFooterView *)view;
[header.textLabel setTextColor:[UIColor blackColor]];
[header.textLabel setFont:[UIFont ows_thinFontWithSize:14.0f]];
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (_defaultSelectedIndexPath != nil && ![_defaultSelectedIndexPath isEqual:indexPath])
{
[self deselectRowAtIndexPath:_defaultSelectedIndexPath];
_defaultSelectedIndexPath = nil;
}
UITableViewCell * cell = [self.tableView cellForRowAtIndexPath:indexPath];
cell.accessoryType = UITableViewCellAccessoryCheckmark;
switch (indexPath.section) {
case 1:
[Environment.preferences setNotificationPreviewType:NotificationNoNameNoPreview];
break;
case 2:
[Environment.preferences setNotificationPreviewType:NotificationNameNoPreview];
break;
case 3:
[Environment.preferences setNotificationPreviewType:NotificationNamePreview];
break;
default:
break;
}
}
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell * cell = [self.tableView cellForRowAtIndexPath:indexPath];
cell.accessoryType = UITableViewCellAccessoryNone;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section == 0) {
return 120.0f;
} else {
return 80.0f;
}
}
#pragma mark - Cell selection proxy
-(void)selectRowAtIndexPath:(NSIndexPath*)indexPath
{
[self.tableView.delegate tableView:self.tableView didSelectRowAtIndexPath:indexPath];
}
-(void)deselectRowAtIndexPath:(NSIndexPath*)indexPath
{
[self.tableView.delegate tableView:self.tableView didDeselectRowAtIndexPath:indexPath];
}
@end

View File

@ -22,14 +22,15 @@
#define kNumberOfSections 2
#define kClearHistoryLogCellRow 1
#define kSendDebugLogCellRow 3
#define kUnregisterCell 4
#define kClearHistoryLogCellRow 2
#define kMessageDisplayCellRow 3
#define kSendDebugLogCellRow 4
#define kUnregisterCell 5
typedef enum {
kProfileRows = 1,
kSecurityRows = 5,
kSecurityRows = 6,
} kRowsForSection;
typedef enum {