element-ios/matrixConsole/AppSettings.m
giomfo 4b76c6b24d Console: Improve offline mode:
- remove loading wheel when network is unreachable.
- color in red the navigation bar when the app is offline.

Buf Fix SYIOS- 66 - Console: last outgoing message is stuck as local echo whereas the message has been delivered.
2015-02-12 11:16:28 +01:00

205 lines
6.4 KiB
Objective-C

/*
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"
#import "MatrixSDKHandler.h"
// get ISO country name
#import <CoreTelephony/CTCarrier.h>
#import <CoreTelephony/CTTelephonyNetworkInfo.h>
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 {
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"enableInAppNotifications"];
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"specificWordsToAlertOn"];
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"displayAllEvents"];
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"hideRedactedInformation"];
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"hideUnsupportedEvents"];
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"sortMembersUsingLastSeenTime"];
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"displayLeftUsers"];
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"maxMediaCacheSize"];
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"syncLocalContacts"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
#pragma mark -
- (BOOL)enableInAppNotifications {
return [[NSUserDefaults standardUserDefaults] boolForKey:@"enableInAppNotifications"];
}
- (void)setEnableInAppNotifications:(BOOL)notifications {
[[MatrixSDKHandler sharedHandler] enableInAppNotifications:notifications];
[[NSUserDefaults standardUserDefaults] setBool:notifications forKey:@"enableInAppNotifications"];
}
- (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"];
}
}
- (BOOL)displayAllEvents {
return [[NSUserDefaults standardUserDefaults] boolForKey:@"displayAllEvents"];
}
- (void)setDisplayAllEvents:(BOOL)displayAllEvents {
[[NSUserDefaults standardUserDefaults] setBool:displayAllEvents forKey:@"displayAllEvents"];
// Flush and restore Matrix data
[[MatrixSDKHandler sharedHandler] reload:NO];
}
- (BOOL)hideRedactedInformation {
return [[NSUserDefaults standardUserDefaults] boolForKey:@"hideRedactedInformation"];
}
- (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"];
}
- (BOOL)sortMembersUsingLastSeenTime {
return [[NSUserDefaults standardUserDefaults] boolForKey:@"sortMembersUsingLastSeenTime"];
}
- (void)setSortMembersUsingLastSeenTime:(BOOL)sortMembersUsingLastSeen {
[[NSUserDefaults standardUserDefaults] setBool:sortMembersUsingLastSeen forKey:@"sortMembersUsingLastSeenTime"];
}
- (BOOL)displayLeftUsers {
return [[NSUserDefaults standardUserDefaults] boolForKey:@"displayLeftUsers"];
}
- (void)setDisplayLeftUsers:(BOOL)displayLeftUsers {
[[NSUserDefaults standardUserDefaults] setBool:displayLeftUsers forKey:@"displayLeftUsers"];
}
- (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"];
}
- (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"];
}
- (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"];
}
@end