mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-05-05 15:37:45 +02:00
Moved code under a subdirectory: Console
This commit is contained in:
@@ -0,0 +1,172 @@
|
||||
/*
|
||||
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:@"displayAllEvents"];
|
||||
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"hideRedactions"];
|
||||
[[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"];
|
||||
}
|
||||
|
||||
- (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)hideRedactions {
|
||||
return [[NSUserDefaults standardUserDefaults] boolForKey:@"hideRedactions"];
|
||||
}
|
||||
|
||||
- (void)setHideRedactions:(BOOL)hideRedactions {
|
||||
[[NSUserDefaults standardUserDefaults] setBool:hideRedactions forKey:@"hideRedactions"];
|
||||
}
|
||||
|
||||
- (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)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
|
||||
Reference in New Issue
Block a user