2014-11-24 09:38:23 +00:00
|
|
|
/*
|
|
|
|
Copyright 2014 OpenMarket Ltd
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#import "AppSettings.h"
|
2015-01-23 14:36:05 +00:00
|
|
|
#import "MatrixSDKHandler.h"
|
2014-11-24 09:38:23 +00:00
|
|
|
|
2015-01-29 12:40:38 +00:00
|
|
|
|
|
|
|
// get ISO country name
|
|
|
|
#import <CoreTelephony/CTCarrier.h>
|
|
|
|
#import <CoreTelephony/CTTelephonyNetworkInfo.h>
|
|
|
|
|
2014-11-24 09:38:23 +00:00
|
|
|
static AppSettings *sharedSettings = nil;
|
|
|
|
|
|
|
|
@implementation AppSettings
|
|
|
|
|
|
|
|
+ (AppSettings *)sharedSettings {
|
|
|
|
@synchronized(self) {
|
|
|
|
if(sharedSettings == nil)
|
|
|
|
{
|
|
|
|
sharedSettings = [[super allocWithZone:NULL] init];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return sharedSettings;
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
|
|
|
|
-(AppSettings *)init {
|
|
|
|
if (self = [super init]) {
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)dealloc {
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)reset {
|
2014-12-16 21:54:26 +00:00
|
|
|
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"enableInAppNotifications"];
|
2015-01-09 14:58:15 +00:00
|
|
|
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"specificWordsToAlertOn"];
|
2014-12-16 21:54:26 +00:00
|
|
|
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"displayAllEvents"];
|
2015-01-28 17:39:23 +00:00
|
|
|
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"hideRedactedInformation"];
|
|
|
|
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"hideUnsupportedEvents"];
|
2014-12-16 21:54:26 +00:00
|
|
|
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"sortMembersUsingLastSeenTime"];
|
2014-12-17 13:40:39 +00:00
|
|
|
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"displayLeftUsers"];
|
2015-01-26 17:06:13 +00:00
|
|
|
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"maxMediaCacheSize"];
|
|
|
|
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"syncLocalContacts"];
|
2014-12-16 21:54:26 +00:00
|
|
|
[[NSUserDefaults standardUserDefaults] synchronize];
|
2014-11-24 09:38:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
|
2014-12-12 13:18:34 +00:00
|
|
|
- (BOOL)enableInAppNotifications {
|
|
|
|
return [[NSUserDefaults standardUserDefaults] boolForKey:@"enableInAppNotifications"];
|
2014-11-24 09:38:23 +00:00
|
|
|
}
|
|
|
|
|
2014-12-12 13:18:34 +00:00
|
|
|
- (void)setEnableInAppNotifications:(BOOL)notifications {
|
2015-01-23 14:36:05 +00:00
|
|
|
[[MatrixSDKHandler sharedHandler] enableInAppNotifications:notifications];
|
2014-12-12 13:18:34 +00:00
|
|
|
[[NSUserDefaults standardUserDefaults] setBool:notifications forKey:@"enableInAppNotifications"];
|
2014-11-24 09:38:23 +00:00
|
|
|
}
|
|
|
|
|
2015-01-09 14:58:15 +00:00
|
|
|
- (NSArray*)specificWordsToAlertOn {
|
|
|
|
NSArray* res = [[NSUserDefaults standardUserDefaults] objectForKey:@"specificWordsToAlertOn"];
|
|
|
|
|
|
|
|
// avoid returning nil
|
|
|
|
if (!res) {
|
|
|
|
res = [[NSArray alloc] init];
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setSpecificWordsToAlertOn:(NSArray*)words {
|
|
|
|
|
|
|
|
if (!words.count) {
|
|
|
|
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"specificWordsToAlertOn"];
|
|
|
|
} else {
|
|
|
|
[[NSUserDefaults standardUserDefaults] setObject:words forKey:@"specificWordsToAlertOn"];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-24 09:38:23 +00:00
|
|
|
- (BOOL)displayAllEvents {
|
|
|
|
return [[NSUserDefaults standardUserDefaults] boolForKey:@"displayAllEvents"];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setDisplayAllEvents:(BOOL)displayAllEvents {
|
|
|
|
[[NSUserDefaults standardUserDefaults] setBool:displayAllEvents forKey:@"displayAllEvents"];
|
|
|
|
// Flush and restore Matrix data
|
2015-01-23 14:36:05 +00:00
|
|
|
[[MatrixSDKHandler sharedHandler] forceInitialSync:NO];
|
2014-11-24 09:38:23 +00:00
|
|
|
}
|
|
|
|
|
2015-01-28 17:39:23 +00:00
|
|
|
- (BOOL)hideRedactedInformation {
|
|
|
|
return [[NSUserDefaults standardUserDefaults] boolForKey:@"hideRedactedInformation"];
|
2014-11-24 09:38:23 +00:00
|
|
|
}
|
|
|
|
|
2015-01-28 17:39:23 +00:00
|
|
|
- (void)setHideRedactedInformation:(BOOL)hideRedactedInformation {
|
|
|
|
[[NSUserDefaults standardUserDefaults] setBool:hideRedactedInformation forKey:@"hideRedactedInformation"];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)hideUnsupportedEvents {
|
|
|
|
return [[NSUserDefaults standardUserDefaults] boolForKey:@"hideUnsupportedEvents"];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setHideUnsupportedEvents:(BOOL)hideUnsupportedEvents {
|
|
|
|
[[NSUserDefaults standardUserDefaults] setBool:hideUnsupportedEvents forKey:@"hideUnsupportedEvents"];
|
2014-11-24 09:38:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)sortMembersUsingLastSeenTime {
|
|
|
|
return [[NSUserDefaults standardUserDefaults] boolForKey:@"sortMembersUsingLastSeenTime"];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setSortMembersUsingLastSeenTime:(BOOL)sortMembersUsingLastSeen {
|
|
|
|
[[NSUserDefaults standardUserDefaults] setBool:sortMembersUsingLastSeen forKey:@"sortMembersUsingLastSeenTime"];
|
|
|
|
}
|
|
|
|
|
2014-12-17 13:40:39 +00:00
|
|
|
- (BOOL)displayLeftUsers {
|
|
|
|
return [[NSUserDefaults standardUserDefaults] boolForKey:@"displayLeftUsers"];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setDisplayLeftUsers:(BOOL)displayLeftUsers {
|
|
|
|
[[NSUserDefaults standardUserDefaults] setBool:displayLeftUsers forKey:@"displayLeftUsers"];
|
|
|
|
}
|
|
|
|
|
2015-01-26 17:06:13 +00:00
|
|
|
|
|
|
|
- (BOOL)requestedLocalContactsSync {
|
|
|
|
id val = [[NSUserDefaults standardUserDefaults] valueForKey:@"syncLocalContacts"];
|
|
|
|
|
|
|
|
// the value has never been set
|
|
|
|
if (!val) {
|
|
|
|
[[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"syncLocalContacts"];
|
|
|
|
}
|
|
|
|
|
|
|
|
return (nil != val);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)syncLocalContacts {
|
|
|
|
return [[NSUserDefaults standardUserDefaults] boolForKey:@"syncLocalContacts"];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setSyncLocalContacts:(BOOL)syncLocalContacts {
|
|
|
|
[[NSUserDefaults standardUserDefaults] setBool:syncLocalContacts forKey:@"syncLocalContacts"];
|
|
|
|
}
|
|
|
|
|
2015-01-29 12:40:38 +00:00
|
|
|
- (NSString*)countryCode {
|
|
|
|
NSString* res = [[NSUserDefaults standardUserDefaults] stringForKey:@"countryCode"];
|
|
|
|
|
|
|
|
// does not exist : try to get the SIM card information
|
|
|
|
if (!res) {
|
|
|
|
// get the current MCC
|
|
|
|
CTTelephonyNetworkInfo *netInfo = [[CTTelephonyNetworkInfo alloc] init];
|
|
|
|
CTCarrier *carrier = [netInfo subscriberCellularProvider];
|
|
|
|
|
|
|
|
if (carrier) {
|
|
|
|
res = [[carrier isoCountryCode] uppercaseString];
|
|
|
|
|
|
|
|
if (res) {
|
|
|
|
[self setCountryCode:res];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setCountryCode:(NSString *)countryCode{
|
|
|
|
[[NSUserDefaults standardUserDefaults] setObject:countryCode forKey:@"countryCode"];
|
|
|
|
}
|
|
|
|
|
2015-01-19 07:58:45 +00:00
|
|
|
- (NSInteger)maxAllowedMediaCacheSize {
|
|
|
|
return 1024 * 1024 * 1024;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSInteger)currentMaxMediaCacheSize {
|
|
|
|
|
|
|
|
NSInteger res = [[NSUserDefaults standardUserDefaults] integerForKey:@"maxMediaCacheSize"];
|
|
|
|
|
|
|
|
// no default value, assume that 1 GB is enough
|
|
|
|
if (res == 0) {
|
|
|
|
res = [AppSettings sharedSettings].maxAllowedMediaCacheSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setCurrentMaxMediaCacheSize:(NSInteger)aMaxCacheSize {
|
|
|
|
if ((aMaxCacheSize == 0) && (aMaxCacheSize > [AppSettings sharedSettings].maxAllowedMediaCacheSize)) {
|
|
|
|
aMaxCacheSize = [AppSettings sharedSettings].maxAllowedMediaCacheSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
[[NSUserDefaults standardUserDefaults] setInteger:aMaxCacheSize forKey:@"maxMediaCacheSize"];
|
|
|
|
}
|
|
|
|
|
2014-11-24 09:38:23 +00:00
|
|
|
@end
|