Add new App settings: notifications, all events. Disabled by default (not implemented yet).

This commit is contained in:
giomfo 2014-10-29 17:48:11 +01:00
parent 2c86d0a24e
commit 8f546be53b
8 changed files with 355 additions and 30 deletions

View file

@ -31,6 +31,8 @@
F0CEA5AE19E6895E00E47915 /* logoHighRes.png in Resources */ = {isa = PBXBuildFile; fileRef = F0CEA5AC19E6895E00E47915 /* logoHighRes.png */; };
F0CEA5AF19E6895E00E47915 /* tab_recents.png in Resources */ = {isa = PBXBuildFile; fileRef = F0CEA5AD19E6895E00E47915 /* tab_recents.png */; };
F0CEA5B119E6898800E47915 /* tab_home.ico in Resources */ = {isa = PBXBuildFile; fileRef = F0CEA5B019E6898800E47915 /* tab_home.ico */; };
F0D3C30C1A011EF10000D49E /* AppSettings.m in Sources */ = {isa = PBXBuildFile; fileRef = F0D3C30B1A011EF10000D49E /* AppSettings.m */; };
F0D3C30F1A01330F0000D49E /* SettingsTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = F0D3C30E1A01330F0000D49E /* SettingsTableViewCell.m */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
@ -86,6 +88,10 @@
F0CEA5AC19E6895E00E47915 /* logoHighRes.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = logoHighRes.png; sourceTree = "<group>"; };
F0CEA5AD19E6895E00E47915 /* tab_recents.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = tab_recents.png; sourceTree = "<group>"; };
F0CEA5B019E6898800E47915 /* tab_home.ico */ = {isa = PBXFileReference; lastKnownFileType = image.ico; path = tab_home.ico; sourceTree = "<group>"; };
F0D3C30A1A011EF10000D49E /* AppSettings.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppSettings.h; sourceTree = "<group>"; };
F0D3C30B1A011EF10000D49E /* AppSettings.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppSettings.m; sourceTree = "<group>"; };
F0D3C30D1A01330F0000D49E /* SettingsTableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SettingsTableViewCell.h; sourceTree = "<group>"; };
F0D3C30E1A01330F0000D49E /* SettingsTableViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SettingsTableViewCell.m; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@ -165,6 +171,8 @@
F02D707519F1DC9E007B47D3 /* RoomMemberTableCell.m */,
F03EF5FD19F1762000A0EE52 /* RoomMessageTableCell.h */,
F03EF5FE19F1762000A0EE52 /* RoomMessageTableCell.m */,
F0D3C30D1A01330F0000D49E /* SettingsTableViewCell.h */,
F0D3C30E1A01330F0000D49E /* SettingsTableViewCell.m */,
);
path = View;
sourceTree = "<group>";
@ -196,6 +204,8 @@
F03EF5E919F171EB00A0EE52 /* ViewController */,
F07A80D919DD9DE700B621A1 /* AppDelegate.h */,
F07A80DA19DD9DE700B621A1 /* AppDelegate.m */,
F0D3C30A1A011EF10000D49E /* AppSettings.h */,
F0D3C30B1A011EF10000D49E /* AppSettings.m */,
F05B955D19DEED8A008761B0 /* MatrixHandler.h */,
F05B955E19DEED8A008761B0 /* MatrixHandler.m */,
F03EF60019F19E7C00A0EE52 /* MediaManager.h */,
@ -388,7 +398,9 @@
F03EF60219F19E7C00A0EE52 /* MediaManager.m in Sources */,
F03EF5F919F171EB00A0EE52 /* RecentsViewController.m in Sources */,
F02D707619F1DC9E007B47D3 /* RoomMemberTableCell.m in Sources */,
F0D3C30C1A011EF10000D49E /* AppSettings.m in Sources */,
F03EF5F719F171EB00A0EE52 /* LoginViewController.m in Sources */,
F0D3C30F1A01330F0000D49E /* SettingsTableViewCell.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

View file

@ -15,6 +15,7 @@
*/
#import "AppDelegate.h"
#import "AppSettings.h"
#import "RoomViewController.h"
#import "MatrixHandler.h"
#import "MediaManager.h"
@ -83,6 +84,8 @@
- (void)logout {
// Clear cache
[MediaManager clearCache];
// Reset App settings
[[AppSettings sharedSettings] reset];
// Logout Matrix
[[MatrixHandler sharedHandler] logout];
[self.masterTabBarController showLoginScreen];

View file

@ -0,0 +1,27 @@
/*
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 <UIKit/UIKit.h>
@interface AppSettings : NSObject
@property (nonatomic) BOOL enableNotifications;
@property (nonatomic) BOOL displayAllEvents;
+ (AppSettings *)sharedSettings;
- (void)reset;
@end

View file

@ -0,0 +1,66 @@
/*
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"
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 {
self.enableNotifications = NO;
self.displayAllEvents = NO;
}
#pragma mark -
- (BOOL)enableNotifications {
return [[NSUserDefaults standardUserDefaults] boolForKey:@"enableNotifications"];
}
- (void)setEnableNotifications:(BOOL)notifications {
[[NSUserDefaults standardUserDefaults] setBool:notifications forKey:@"enableNotifications"];
}
- (BOOL)displayAllEvents {
return [[NSUserDefaults standardUserDefaults] boolForKey:@"displayAllEvents"];
}
- (void)setDisplayAllEvents:(BOOL)displayAllEvents {
[[NSUserDefaults standardUserDefaults] setBool:displayAllEvents forKey:@"displayAllEvents"];
}
@end

View file

@ -740,33 +740,64 @@
<constraint firstItem="8M9-ZM-efS" firstAttribute="leading" secondItem="5Dl-D7-ahX" secondAttribute="trailing" constant="10" id="hCS-JS-UW3"/>
</constraints>
</view>
<view key="tableFooterView" contentMode="scaleToFill" id="Der-gn-Efb" userLabel="TableFooterView">
<rect key="frame" x="0.0" y="0.0" width="600" height="44"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="isk-vI-TAp">
<rect key="frame" x="272" y="6" width="56" height="33"/>
<fontDescription key="fontDescription" type="boldSystem" pointSize="17"/>
<state key="normal" title="Logout">
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
</state>
<connections>
<action selector="onButtonPressed:" destination="1TJ-Md-cjN" eventType="touchUpInside" id="BXE-sL-Ztk"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstAttribute="centerY" secondItem="isk-vI-TAp" secondAttribute="centerY" id="ObY-th-ac2"/>
<constraint firstAttribute="centerX" secondItem="isk-vI-TAp" secondAttribute="centerX" id="ynl-sA-uVu"/>
</constraints>
</view>
<prototypes>
<tableViewCell contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" reuseIdentifier="SettingsCell" id="XUG-wd-Xsh">
<tableViewCell contentMode="scaleToFill" selectionStyle="none" indentationWidth="10" reuseIdentifier="SettingsCellWithSwitch" id="XUG-wd-Xsh" customClass="SettingsTableCellWithSwitch">
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="XUG-wd-Xsh" id="Rsx-dG-Pfj">
<autoresizingMask key="autoresizingMask"/>
<subviews>
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" on="YES" translatesAutoresizingMaskIntoConstraints="NO" id="l1h-g3-1Cr">
<rect key="frame" x="543" y="6" width="51" height="31"/>
<connections>
<action selector="onButtonPressed:" destination="1TJ-Md-cjN" eventType="valueChanged" id="tOj-wD-WKn"/>
</connections>
</switch>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Rbz-hR-ZX2">
<rect key="frame" x="8" y="11" width="527" height="21"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<constraints>
<constraint firstItem="Rbz-hR-ZX2" firstAttribute="top" secondItem="Rsx-dG-Pfj" secondAttribute="top" constant="11" id="3uH-Vt-mLS"/>
<constraint firstAttribute="trailing" secondItem="l1h-g3-1Cr" secondAttribute="trailing" constant="8" id="IjW-eJ-gaN"/>
<constraint firstAttribute="bottom" secondItem="Rbz-hR-ZX2" secondAttribute="bottom" constant="11" id="KNs-SK-5ej"/>
<constraint firstItem="l1h-g3-1Cr" firstAttribute="top" secondItem="Rsx-dG-Pfj" secondAttribute="top" constant="6" id="Tyf-nr-Ajl"/>
<constraint firstItem="Rbz-hR-ZX2" firstAttribute="leading" secondItem="Rsx-dG-Pfj" secondAttribute="leading" constant="8" id="kDM-P4-qAP"/>
<constraint firstAttribute="bottom" secondItem="l1h-g3-1Cr" secondAttribute="bottom" constant="6" id="v5A-KU-HYQ"/>
<constraint firstItem="l1h-g3-1Cr" firstAttribute="leading" secondItem="Rbz-hR-ZX2" secondAttribute="trailing" constant="8" id="yH4-Vv-QGf"/>
</constraints>
</tableViewCellContentView>
<connections>
<outlet property="settingLabel" destination="Rbz-hR-ZX2" id="Rf1-HP-aYe"/>
<outlet property="settingSwitch" destination="l1h-g3-1Cr" id="trh-zz-dn2"/>
</connections>
</tableViewCell>
<tableViewCell contentMode="scaleToFill" selectionStyle="none" indentationWidth="10" reuseIdentifier="SettingsCellWithTextView" id="YFJ-c6-8tp" customClass="SettingsTableCellWithTextView">
<rect key="frame" x="0.0" y="0.0" width="600" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="YFJ-c6-8tp" id="A3V-Y7-p1i">
<autoresizingMask key="autoresizingMask"/>
<subviews>
<textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" scrollEnabled="NO" editable="NO" translatesAutoresizingMaskIntoConstraints="NO" id="SAI-hV-Jai">
<rect key="frame" x="0.0" y="0.0" width="600" height="43"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<string key="text">Lorem ipsum dolor sit er elit lamet, consectetaur cillium adipisicing pecu, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Nam liber te conscient to factor tum poen legum odioque civiuda.</string>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits" autocapitalizationType="sentences"/>
</textView>
</subviews>
<constraints>
<constraint firstAttribute="bottom" secondItem="SAI-hV-Jai" secondAttribute="bottom" id="4Oe-Dk-T3D"/>
<constraint firstAttribute="trailing" secondItem="SAI-hV-Jai" secondAttribute="trailing" id="Co5-ng-qtK"/>
<constraint firstItem="SAI-hV-Jai" firstAttribute="top" secondItem="A3V-Y7-p1i" secondAttribute="top" id="Gg9-ty-0Gr"/>
<constraint firstItem="SAI-hV-Jai" firstAttribute="leading" secondItem="A3V-Y7-p1i" secondAttribute="leading" id="LTO-yi-5ts"/>
</constraints>
</tableViewCellContentView>
<connections>
<outlet property="settingTextView" destination="SAI-hV-Jai" id="UL1-hb-UbE"/>
</connections>
</tableViewCell>
</prototypes>
<connections>
@ -776,9 +807,7 @@
</tableView>
<navigationItem key="navigationItem" title="Settings" id="7NM-zW-wJT"/>
<connections>
<outlet property="logoutBtn" destination="isk-vI-TAp" id="r80-vw-NHY"/>
<outlet property="saveBtn" destination="hjw-sm-lJ0" id="xN7-pc-PMD"/>
<outlet property="tableFooter" destination="Der-gn-Efb" id="nen-wZ-GLy"/>
<outlet property="tableHeader" destination="ZP5-e3-ge9" id="nd0-lU-aW3"/>
<outlet property="tableView" destination="etG-ZU-b2r" id="5hz-jQ-qVT"/>
<outlet property="userDisplayName" destination="8M9-ZM-efS" id="rAQ-cX-3Ay"/>
@ -787,7 +816,7 @@
</tableViewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="ZKJ-22-Asy" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="875" y="842"/>
<point key="canvasLocation" x="875" y="841"/>
</scene>
<!--SettingsNav-->
<scene sceneID="b0q-mf-7ii">

View file

@ -0,0 +1,29 @@
/*
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 <UIKit/UIKit.h>
@interface SettingsTableViewCell : UITableViewCell
@end
@interface SettingsTableCellWithSwitch : SettingsTableViewCell
@property (strong, nonatomic) IBOutlet UILabel *settingLabel;
@property (strong, nonatomic) IBOutlet UISwitch *settingSwitch;
@end
@interface SettingsTableCellWithTextView : SettingsTableViewCell
@property (strong, nonatomic) IBOutlet UITextView *settingTextView;
@end

View file

@ -0,0 +1,26 @@
/*
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 "SettingsTableViewCell.h"
@implementation SettingsTableViewCell
@end
@implementation SettingsTableCellWithSwitch
@end
@implementation SettingsTableCellWithTextView
@end

View file

@ -17,22 +17,35 @@
#import "SettingsViewController.h"
#import "AppDelegate.h"
#import "AppSettings.h"
#import "MatrixHandler.h"
#import "MediaManager.h"
#import "SettingsTableViewCell.h"
#define SETTINGS_SECTION_NOTIFICATIONS_INDEX 0
#define SETTINGS_SECTION_MESSAGES_INDEX 1
#define SETTINGS_SECTION_CONFIGURATION_INDEX 2
#define SETTINGS_SECTION_COMMANDS_INDEX 3
NSString* const kConfigurationFormatText = @"Home server: %@\r\nIdentity server: %@\r\nUser ID: %@\r\nAccess token: %@";
NSString* const kCommandsDescriptionText = @"The following commands are available in the room chat:\r\n\r\n /nick <display_name>: change your display name\r\n /me <action>: send the action you are doing. /me will be replaced by your display name\r\n /join <room_alias>: join a room\r\n /kick <user_id> [<reason>]: kick the user\r\n /ban <user_id> [<reason>]: ban the user\r\n /unban <user_id>: unban the user\r\n /op <user_id> <power_level>: set user power level\r\n /deop <user_id>: reset user power level to the room default value";
@interface SettingsViewController () {
id imageLoader;
NSString *currentDisplayName;
NSString *currentPictureURL;
UIButton *logoutBtn;
UISwitch *notificationsSwitch;
UISwitch *allEventsSwitch;
}
@property (strong, nonatomic) IBOutlet UITableView *tableView;
@property (weak, nonatomic) IBOutlet UIView *tableHeader;
@property (weak, nonatomic) IBOutlet UIButton *userPicture;
@property (weak, nonatomic) IBOutlet UITextField *userDisplayName;
@property (weak, nonatomic) IBOutlet UIButton *saveBtn;
@property (weak, nonatomic) IBOutlet UIView *tableFooter;
@property (weak, nonatomic) IBOutlet UIButton *logoutBtn;
- (IBAction)onButtonPressed:(id)sender;
@ -44,6 +57,14 @@
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
// Add logout button in nav bar
logoutBtn = [UIButton buttonWithType:UIButtonTypeSystem];
logoutBtn.frame = CGRectMake(0, 0, 60, 44);
[logoutBtn setTitle:@"Logout" forState:UIControlStateNormal];
[logoutBtn setTitle:@"Logout" forState:UIControlStateHighlighted];
[logoutBtn addTarget:self action:@selector(onButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:logoutBtn];
[self reset];
}
@ -63,6 +84,10 @@
[MediaManager cancel:imageLoader];
imageLoader = nil;
}
logoutBtn = nil;
notificationsSwitch = nil;
allEventsSwitch = nil;
}
- (void)viewWillAppear:(BOOL)animated {
@ -112,6 +137,9 @@
//Alert user
[[AppDelegate theDelegate] showErrorAsAlert:error];
}];
// Refresh settings
[self.tableView reloadData];
}
#pragma mark -
@ -132,7 +160,7 @@
self.userDisplayName.text = nil;
}
#pragma mark -
#pragma mark - Actions
- (IBAction)onButtonPressed:(id)sender {
[self dismissKeyboard];
@ -153,9 +181,13 @@
}];
}
// TODO check picture change
} else if (sender == _logoutBtn) {
} else if (sender == logoutBtn) {
[self reset];
[[AppDelegate theDelegate] logout];
} else if (sender == notificationsSwitch) {
[AppSettings sharedSettings].enableNotifications = notificationsSwitch.on;
} else if (sender == allEventsSwitch) {
[AppSettings sharedSettings].displayAllEvents = allEventsSwitch.on;
}
}
@ -173,7 +205,108 @@
{
// "Done" key has been pressed
[textField resignFirstResponder];
return YES;
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 4;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if (section == SETTINGS_SECTION_NOTIFICATIONS_INDEX) {
return 1;
} else if (section == SETTINGS_SECTION_MESSAGES_INDEX) {
return 1;
} else if (section == SETTINGS_SECTION_CONFIGURATION_INDEX) {
return 1;
} else if (section == SETTINGS_SECTION_COMMANDS_INDEX) {
return 1;
}
return 0;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section == SETTINGS_SECTION_NOTIFICATIONS_INDEX) {
return 44;
} else if (indexPath.section == SETTINGS_SECTION_MESSAGES_INDEX) {
return 44;
} else if (indexPath.section == SETTINGS_SECTION_CONFIGURATION_INDEX) {
UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, MAXFLOAT)];
textView.font = [UIFont systemFontOfSize:14];
MatrixHandler *mxHandler = [MatrixHandler sharedHandler];
textView.text = [NSString stringWithFormat:kConfigurationFormatText, mxHandler.homeServerURL, nil, mxHandler.userId, mxHandler.accessToken];
CGSize contentSize = [textView sizeThatFits:textView.frame.size];
return contentSize.height + 1;
} else if (indexPath.section == SETTINGS_SECTION_COMMANDS_INDEX) {
UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, MAXFLOAT)];
textView.font = [UIFont systemFontOfSize:14];
textView.text = kCommandsDescriptionText;
CGSize contentSize = [textView sizeThatFits:textView.frame.size];
return contentSize.height + 1;
}
return 44;
}
- (CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 30;
}
- (CGFloat) tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
return 1;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UILabel *sectionHeader = [[UILabel alloc] initWithFrame:[tableView rectForHeaderInSection:section]];
sectionHeader.font = [UIFont boldSystemFontOfSize:16];
sectionHeader.backgroundColor = [UIColor colorWithRed:0.9 green:0.9 blue:0.9 alpha:1.0];
if (section == SETTINGS_SECTION_NOTIFICATIONS_INDEX) {
sectionHeader.text = @" Notifications";
} else if (section == SETTINGS_SECTION_MESSAGES_INDEX) {
sectionHeader.text = @" Messages";
} else if (section == SETTINGS_SECTION_CONFIGURATION_INDEX) {
sectionHeader.text = @" Configuration";
} else if (section == SETTINGS_SECTION_COMMANDS_INDEX) {
sectionHeader.text = @" Commands";
} else {
sectionHeader = nil;
}
return sectionHeader;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
SettingsTableViewCell *cell = nil;
if (indexPath.section == SETTINGS_SECTION_NOTIFICATIONS_INDEX) {
SettingsTableCellWithSwitch *notificationsCell = [tableView dequeueReusableCellWithIdentifier:@"SettingsCellWithSwitch" forIndexPath:indexPath];
notificationsCell.settingLabel.text = @"Enable notifications";
notificationsCell.settingSwitch.on = [[AppSettings sharedSettings] enableNotifications];
notificationsSwitch = notificationsCell.settingSwitch;
cell = notificationsCell;
} else if (indexPath.section == SETTINGS_SECTION_MESSAGES_INDEX) {
SettingsTableCellWithSwitch *allEventsCell = [tableView dequeueReusableCellWithIdentifier:@"SettingsCellWithSwitch" forIndexPath:indexPath];
allEventsCell.settingLabel.text = @"Display all events";
allEventsCell.settingSwitch.on = [[AppSettings sharedSettings] displayAllEvents];
allEventsSwitch = allEventsCell.settingSwitch;
cell = allEventsCell;
} else if (indexPath.section == SETTINGS_SECTION_CONFIGURATION_INDEX) {
SettingsTableCellWithTextView *configCell = [tableView dequeueReusableCellWithIdentifier:@"SettingsCellWithTextView" forIndexPath:indexPath];
MatrixHandler *mxHandler = [MatrixHandler sharedHandler];
configCell.settingTextView.text = [NSString stringWithFormat:kConfigurationFormatText, mxHandler.homeServerURL, nil, mxHandler.userId, mxHandler.accessToken];
cell = configCell;
} else if (indexPath.section == SETTINGS_SECTION_COMMANDS_INDEX) {
SettingsTableCellWithTextView *commandsCell = [tableView dequeueReusableCellWithIdentifier:@"SettingsCellWithTextView" forIndexPath:indexPath];
commandsCell.settingTextView.text = kCommandsDescriptionText;
cell = commandsCell;
}
return cell;
}
@end