Support new room creation

This commit is contained in:
giomfo 2014-10-13 14:45:29 +02:00
parent 9a3f3e4a9b
commit 19f40ef6aa
9 changed files with 332 additions and 51 deletions

View file

@ -62,28 +62,34 @@
<scene sceneID="3rt-8o-eGh">
<objects>
<tableViewController title="Home" id="ldZ-75-BUU" customClass="HomeViewController" sceneMemberID="viewController">
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="50" sectionHeaderHeight="30" sectionFooterHeight="22" id="LbI-fz-LaI">
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="50" sectionHeaderHeight="40" sectionFooterHeight="22" id="LbI-fz-LaI">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<view key="tableHeaderView" contentMode="scaleToFill" id="vtK-sz-hd2" userLabel="TableHeaderView">
<rect key="frame" x="0.0" y="64" width="600" height="90"/>
<rect key="frame" x="0.0" y="64" width="600" height="250"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" horizontalHuggingPriority="249" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" placeholder="Room alias" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="b5x-lU-scr">
<rect key="frame" x="8" y="30" width="461" height="30"/>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" horizontalHuggingPriority="249" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" placeholder="(e.g. lunchGroup)" minimumFontSize="10" translatesAutoresizingMaskIntoConstraints="NO" id="b5x-lU-scr">
<rect key="frame" x="109" y="48" width="483" height="30"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits"/>
<textInputTraits key="textInputTraits" returnKeyType="done"/>
<connections>
<outlet property="delegate" destination="ldZ-75-BUU" id="B12-Tr-ilf"/>
</connections>
</textField>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="fIu-Mb-2Ad">
<rect key="frame" x="512" y="52" width="53" height="33"/>
<rect key="frame" x="248" y="201" width="104" height="33"/>
<fontDescription key="fontDescription" type="boldSystem" pointSize="17"/>
<state key="normal" title="Create">
<state key="normal" title="Create Room">
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
</state>
<connections>
<action selector="onButtonPressed:" destination="ldZ-75-BUU" eventType="touchUpInside" id="lqf-dU-v8c"/>
</connections>
</button>
<segmentedControl opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="top" segmentControlStyle="plain" selectedSegmentIndex="0" translatesAutoresizingMaskIntoConstraints="NO" id="DFg-sq-K9p">
<rect key="frame" x="479" y="10" width="113" height="29"/>
<rect key="frame" x="244" y="165" width="113" height="29"/>
<constraints>
<constraint firstAttribute="width" constant="113" id="Rxh-Zw-vxF"/>
</constraints>
@ -91,17 +97,88 @@
<segment title="Public"/>
<segment title="Private"/>
</segments>
<connections>
<action selector="onButtonPressed:" destination="ldZ-75-BUU" eventType="valueChanged" id="TQ8-yb-WDh"/>
</connections>
</segmentedControl>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Room name:" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumFontSize="11" translatesAutoresizingMaskIntoConstraints="NO" id="C35-iH-iml">
<rect key="frame" x="8" y="52" width="93" height="20"/>
<constraints>
<constraint firstAttribute="width" constant="93" id="amO-Op-WAj"/>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="16"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" horizontalHuggingPriority="249" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" placeholder="(e.g. #foo:homeserver)" minimumFontSize="10" translatesAutoresizingMaskIntoConstraints="NO" id="Rfz-WH-4KQ">
<rect key="frame" x="109" y="86" width="483" height="30"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits" returnKeyType="done"/>
<connections>
<outlet property="delegate" destination="ldZ-75-BUU" id="cVW-bM-tAs"/>
</connections>
</textField>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Room alias:" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="7rd-HA-syv">
<rect key="frame" x="8" y="90" width="86" height="20"/>
<constraints>
<constraint firstAttribute="width" constant="86" id="TPd-b7-1nI"/>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="16"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" horizontalHuggingPriority="249" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" placeholder="(e.g. @bob:homeserver1; @john:homeserver2...)" minimumFontSize="10" translatesAutoresizingMaskIntoConstraints="NO" id="dWR-QZ-pru">
<rect key="frame" x="108" y="124" width="484" height="30"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits" returnKeyType="done"/>
<connections>
<outlet property="delegate" destination="ldZ-75-BUU" id="KC8-Da-ANh"/>
</connections>
</textField>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Participants:" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="fGe-VQ-gFa">
<rect key="frame" x="8" y="127" width="91" height="20"/>
<constraints>
<constraint firstAttribute="width" constant="91" id="AN1-NN-LU4"/>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="16"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text=" Room creation:" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="kg7-lM-hf3">
<rect key="frame" x="0.0" y="0.0" width="600" height="40"/>
<color key="backgroundColor" cocoaTouchSystemColor="groupTableViewBackgroundColor"/>
<constraints>
<constraint firstAttribute="height" constant="40" id="cGe-la-GXg"/>
</constraints>
<fontDescription key="fontDescription" type="boldSystem" pointSize="16"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstItem="DFg-sq-K9p" firstAttribute="top" secondItem="vtK-sz-hd2" secondAttribute="top" constant="10" id="0B7-Rc-qbd"/>
<constraint firstAttribute="trailing" secondItem="fIu-Mb-2Ad" secondAttribute="trailing" constant="35" id="ZeB-7G-AHj"/>
<constraint firstItem="DFg-sq-K9p" firstAttribute="leading" secondItem="b5x-lU-scr" secondAttribute="trailing" constant="10" id="fpt-fP-KK4"/>
<constraint firstAttribute="centerY" secondItem="b5x-lU-scr" secondAttribute="centerY" id="i6J-DF-oGV"/>
<constraint firstAttribute="trailing" secondItem="DFg-sq-K9p" secondAttribute="trailing" constant="8" id="lHF-iX-NXM"/>
<constraint firstItem="b5x-lU-scr" firstAttribute="leading" secondItem="vtK-sz-hd2" secondAttribute="leading" constant="8" id="yqk-6l-hdw"/>
<constraint firstAttribute="bottom" secondItem="fIu-Mb-2Ad" secondAttribute="bottom" constant="5" id="zE1-pl-eIQ" userLabel="Vertical Space - (8) - TableHeaderView - Create"/>
<constraint firstAttribute="centerX" secondItem="fIu-Mb-2Ad" secondAttribute="centerX" id="0Zj-0l-hL1"/>
<constraint firstItem="C35-iH-iml" firstAttribute="leading" secondItem="vtK-sz-hd2" secondAttribute="leading" constant="8" id="10F-cg-xi8"/>
<constraint firstAttribute="centerX" secondItem="DFg-sq-K9p" secondAttribute="centerX" id="3Nn-gk-cNd"/>
<constraint firstAttribute="trailing" secondItem="Rfz-WH-4KQ" secondAttribute="trailing" constant="8" id="8Cj-9w-2sM"/>
<constraint firstItem="fIu-Mb-2Ad" firstAttribute="top" secondItem="DFg-sq-K9p" secondAttribute="bottom" constant="8" id="97d-BQ-YZw"/>
<constraint firstItem="7rd-HA-syv" firstAttribute="leading" secondItem="vtK-sz-hd2" secondAttribute="leading" constant="8" id="9wf-HB-VfV"/>
<constraint firstAttribute="trailing" secondItem="kg7-lM-hf3" secondAttribute="trailing" id="Bye-La-Cpq"/>
<constraint firstItem="7rd-HA-syv" firstAttribute="top" secondItem="C35-iH-iml" secondAttribute="bottom" constant="18" id="D1v-3S-hWC"/>
<constraint firstItem="fGe-VQ-gFa" firstAttribute="top" secondItem="7rd-HA-syv" secondAttribute="bottom" constant="17" id="FgG-g0-kkz"/>
<constraint firstItem="dWR-QZ-pru" firstAttribute="top" secondItem="Rfz-WH-4KQ" secondAttribute="bottom" constant="8" id="Kct-mU-DmK"/>
<constraint firstAttribute="bottom" secondItem="fIu-Mb-2Ad" secondAttribute="bottom" constant="16" id="LQH-Fv-nZv"/>
<constraint firstItem="dWR-QZ-pru" firstAttribute="leading" secondItem="fGe-VQ-gFa" secondAttribute="trailing" constant="9" id="R8i-CJ-HKJ"/>
<constraint firstItem="C35-iH-iml" firstAttribute="top" secondItem="kg7-lM-hf3" secondAttribute="bottom" constant="12" id="TKy-y4-tSw"/>
<constraint firstItem="b5x-lU-scr" firstAttribute="leading" secondItem="C35-iH-iml" secondAttribute="trailing" constant="8" id="TtF-HH-BwR"/>
<constraint firstAttribute="trailing" secondItem="b5x-lU-scr" secondAttribute="trailing" constant="8" id="aVm-8K-x54"/>
<constraint firstItem="fGe-VQ-gFa" firstAttribute="leading" secondItem="vtK-sz-hd2" secondAttribute="leading" constant="8" id="cMU-K6-utc"/>
<constraint firstItem="Rfz-WH-4KQ" firstAttribute="top" secondItem="b5x-lU-scr" secondAttribute="bottom" constant="8" id="coO-Av-GkL"/>
<constraint firstItem="kg7-lM-hf3" firstAttribute="leading" secondItem="vtK-sz-hd2" secondAttribute="leading" id="eUa-j9-Bqh"/>
<constraint firstItem="kg7-lM-hf3" firstAttribute="top" secondItem="vtK-sz-hd2" secondAttribute="top" id="fjd-oM-mXa"/>
<constraint firstItem="Rfz-WH-4KQ" firstAttribute="leading" secondItem="7rd-HA-syv" secondAttribute="trailing" constant="15" id="fo8-s4-B8z"/>
<constraint firstAttribute="trailing" secondItem="dWR-QZ-pru" secondAttribute="trailing" constant="8" id="pZH-5N-xaG"/>
<constraint firstItem="b5x-lU-scr" firstAttribute="top" secondItem="kg7-lM-hf3" secondAttribute="bottom" constant="8" id="rMh-HL-qPT"/>
</constraints>
</view>
<prototypes>
@ -128,7 +205,16 @@
</tableView>
<navigationItem key="navigationItem" title="Home" id="vwK-UA-vG8"/>
<connections>
<outlet property="createRoomBtn" destination="fIu-Mb-2Ad" id="y8M-zV-eeq"/>
<outlet property="participantsLabel" destination="fGe-VQ-gFa" id="Wcb-dU-kdM"/>
<outlet property="participantsTextField" destination="dWR-QZ-pru" id="vOa-ko-qLr"/>
<outlet property="publicRoomsTable" destination="LbI-fz-LaI" id="WcR-YT-Ojc"/>
<outlet property="roomAliasLabel" destination="7rd-HA-syv" id="1FS-21-dtF"/>
<outlet property="roomAliasTextField" destination="Rfz-WH-4KQ" id="BF4-Wb-8gu"/>
<outlet property="roomCreationLabel" destination="kg7-lM-hf3" id="4uZ-AC-Xi7"/>
<outlet property="roomNameLabel" destination="C35-iH-iml" id="aQW-co-XF1"/>
<outlet property="roomNameTextField" destination="b5x-lU-scr" id="FMY-6L-4vf"/>
<outlet property="roomVisibilityControl" destination="DFg-sq-K9p" id="AtP-8V-AOV"/>
</connections>
</tableViewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="xpF-FS-Ykl" userLabel="First Responder" sceneMemberID="firstResponder"/>

View file

@ -16,7 +16,7 @@
#import <UIKit/UIKit.h>
@interface HomeViewController : UITableViewController
@interface HomeViewController : UITableViewController <UITextFieldDelegate>
@property (strong, nonatomic) NSArray *publicRooms;
@property (weak, nonatomic) IBOutlet UITableView *publicRoomsTable;

View file

@ -20,6 +20,16 @@
#import "AppDelegate.h"
@interface HomeViewController ()
@property (weak, nonatomic) IBOutlet UILabel *roomCreationLabel;
@property (weak, nonatomic) IBOutlet UILabel *roomNameLabel;
@property (weak, nonatomic) IBOutlet UILabel *roomAliasLabel;
@property (weak, nonatomic) IBOutlet UILabel *participantsLabel;
@property (weak, nonatomic) IBOutlet UITextField *roomNameTextField;
@property (weak, nonatomic) IBOutlet UITextField *roomAliasTextField;
@property (weak, nonatomic) IBOutlet UITextField *participantsTextField;
@property (weak, nonatomic) IBOutlet UISegmentedControl *roomVisibilityControl;
@property (weak, nonatomic) IBOutlet UIButton *createRoomBtn;
- (IBAction)onButtonPressed:(id)sender;
@end
@ -28,10 +38,12 @@
- (void)viewDidLoad {
[super viewDidLoad];
// UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addPublicRoom:)];
// self.navigationItem.rightBarButtonItem = addButton;
// Do any additional setup after loading the view, typically from a nib.
_roomCreationLabel.backgroundColor = [UIColor colorWithRed:0.9 green:0.9 blue:0.9 alpha:1.0];
_createRoomBtn.enabled = NO;
_createRoomBtn.alpha = 0.5;
// Init
_publicRooms = nil;
}
@ -40,17 +52,26 @@
// Dispose of any resources that can be recreated.
}
- (void)viewWillAppear:(BOOL)animated
{
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
// Ensure to display room creation section
[self.tableView scrollRectToVisible:_roomCreationLabel.frame animated:NO];
if ([[MatrixHandler sharedHandler] isLogged]) {
// Update alias placeholder
_roomAliasTextField.placeholder = [NSString stringWithFormat:@"(e.g. #foo:%@)", [[MatrixHandler sharedHandler] homeServer]];
// Refresh listed public rooms
[self refreshPublicRooms];
}
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onTextFieldChange:) name:UITextFieldTextDidChangeNotification object:nil];
}
- (void)addPublicRoom:(id)sender {
// TODO
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UITextFieldTextDidChangeNotification object:nil];
}
#pragma mark - Table view data source
@ -66,15 +87,23 @@
return 0;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
- (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 (_publicRooms) {
NSString *homeserver = [[MatrixHandler sharedHandler] homeServerURL];
if (homeserver.length) {
return [NSString stringWithFormat:@"Public Rooms (at %@)", homeserver];
sectionHeader.text = [NSString stringWithFormat:@" Public Rooms (at %@):", homeserver];
} else {
sectionHeader.text = @" Public Rooms:";
}
return @"Public Rooms";
} else {
sectionHeader.text = @" No Public Rooms";
}
return @"No Public Rooms";
return sectionHeader;
}
- (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
@ -106,10 +135,9 @@
#pragma mark - Internals
- (void)refreshPublicRooms
{
- (void)refreshPublicRooms {
// Retrieve public rooms
[[[MatrixHandler sharedHandler] homeServer] publicRooms:^(NSArray *rooms){
[[[MatrixHandler sharedHandler] mxHomeServer] publicRooms:^(NSArray *rooms){
_publicRooms = rooms;
[_publicRoomsTable reloadData];
}
@ -121,4 +149,154 @@
}
- (void)dismissKeyboard {
// Hide the keyboard
[_roomNameTextField resignFirstResponder];
[_roomAliasTextField resignFirstResponder];
[_participantsTextField resignFirstResponder];
}
- (NSString*)alias {
// Extract alias name from alias text field
NSString *alias = _roomAliasTextField.text;
if (alias.length > 1) {
// Remove '#' character
alias = [alias substringFromIndex:1];
// Remove homeserver
NSString *suffix = [NSString stringWithFormat:@":%@",[[MatrixHandler sharedHandler] homeServer]];
NSRange range = [alias rangeOfString:suffix];
alias = [alias stringByReplacingCharactersInRange:range withString:@""];
}
if (! alias.length) {
alias = nil;
}
return alias;
}
- (NSArray*)participantsList {
NSMutableArray *participants = [NSMutableArray array];
if (_participantsTextField.text.length) {
NSArray *components = [_participantsTextField.text componentsSeparatedByString:@";"];
for (NSString *component in components) {
// Remove white space from both ends
NSString *user = [component stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
if (user.length > 1 && [user hasPrefix:@"@"]) {
[participants addObject:user];
}
}
}
if (participants.count == 0) {
participants = nil;
}
return participants;
}
#pragma mark - UITextField delegate
- (void)onTextFieldChange:(NSNotification *)notif {
NSString *roomName = _roomNameTextField.text;
NSString *roomAlias = _roomAliasTextField.text;
NSString *participants = _participantsTextField.text;
if (roomName.length || roomAlias.length || participants.length) {
_createRoomBtn.enabled = YES;
_createRoomBtn.alpha = 1;
} else {
_createRoomBtn.enabled = NO;
_createRoomBtn.alpha = 0.5;
}
}
- (void)textFieldDidBeginEditing:(UITextField *)textField {
if (textField == _roomAliasTextField) {
textField.text = self.alias;
textField.placeholder = @"foo";
} else if (textField == _participantsTextField) {
if (textField.text.length == 0) {
textField.text = @"@";
}
}
}
- (void)textFieldDidEndEditing:(UITextField *)textField {
if (textField == _roomAliasTextField) {
// Compute the new phone number with this string change
NSString * alias = textField.text;
if (alias.length) {
// add homeserver as suffix
textField.text = [NSString stringWithFormat:@"#%@:%@", alias, [[MatrixHandler sharedHandler] homeServer]];
}
textField.placeholder = [NSString stringWithFormat:@"(e.g. #foo:%@)", [[MatrixHandler sharedHandler] homeServer]];
} else if (textField == _participantsTextField) {
NSArray *participants = self.participantsList;
textField.text = [participants componentsJoinedByString:@"; "];
}
}
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
// Auto complete participant IDs
if (textField == _participantsTextField) {
// Auto completion is active only when the change concerns the end of the current string
if (range.location == textField.text.length) {
NSString *participants = [textField.text stringByReplacingCharactersInRange:range withString:string];
if ([string isEqualToString:@";"]) {
// Add '@' character
participants = [participants stringByAppendingString:@" @"];
} else if ([string isEqualToString:@":"]) {
// Add homeserver
participants = [participants stringByAppendingString:[[MatrixHandler sharedHandler] homeServer]];
}
textField.text = participants;
// Update Create button status
[self onTextFieldChange:nil];
return NO;
}
}
return YES;
}
- (BOOL)textFieldShouldReturn:(UITextField*) textField {
// "Done" key has been pressed
[textField resignFirstResponder];
return YES;
}
#pragma mark -
- (IBAction)onButtonPressed:(id)sender {
[self dismissKeyboard];
if (sender == _createRoomBtn) {
NSString *roomName = _roomNameTextField.text;
if (! roomName.length) {
roomName = nil;
}
// Create new room
[[[MatrixHandler sharedHandler] mxSession]
createRoom:roomName
visibility:(_roomVisibilityControl.selectedSegmentIndex == 0) ? kMXRoomVisibilityPublic : kMXRoomVisibilityPrivate
room_alias_name:self.alias
topic:nil
invite:self.participantsList
success:^(MXCreateRoomResponse *response) {
// Open created room
[[AppDelegate theDelegate].masterTabBarController showRoomDetails:response.room_id];
} failure:^(NSError *error) {
NSLog(@"Create room (%@ %@ %@ (%d)) failed: %@", _roomNameTextField.text, self.alias, self.participantsList, _roomVisibilityControl.selectedSegmentIndex, error);
//Alert user
[[AppDelegate theDelegate] showErrorAsAlert:error];
}];
}
}
@end

View file

@ -19,7 +19,7 @@
#import "MatrixHandler.h"
#import "AppDelegate.h"
NSString* const defaultHomeserver = @"http://www.matrix.org";
NSString* const defaultHomeserver = @"http://matrix.org";
@interface LoginViewController ()
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *contentViewBottomConstraint;
@ -190,17 +190,18 @@ NSString* const defaultHomeserver = @"http://www.matrix.org";
if (sender == _loginBtn) {
MatrixHandler *matrix = [MatrixHandler sharedHandler];
if (matrix.homeServer)
if (matrix.mxHomeServer)
{
[_activityIndicator startAnimating];
[matrix.homeServer loginWithUser:matrix.userLogin andPassword:_passWordTextField.text
[matrix.mxHomeServer loginWithUser:matrix.userLogin andPassword:_passWordTextField.text
success:^(MXLoginResponse *credentials){
[_activityIndicator stopAnimating];
// Report credentials
[matrix setUserId:credentials.user_id];
[matrix setAccessToken:credentials.access_token];
[matrix setHomeServer:credentials.home_server];
[self dismissViewControllerAnimated:YES completion:nil];
}

View file

@ -25,6 +25,8 @@
- (void)showLoginScreen;
- (void)showRoomCreationForm;
- (void)showRoomDetails:(NSString*)roomId;
@end

View file

@ -28,8 +28,7 @@
// Do any additional setup after loading the view, typically from a nib.
}
- (void)viewDidAppear:(BOOL)animated
{
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
if (! [[MatrixHandler sharedHandler] isLogged]) {
@ -42,10 +41,17 @@
// Dispose of any resources that can be recreated.
}
#pragma mark -
- (void)showLoginScreen {
[self performSegueWithIdentifier:@"showLogin" sender:self];
}
- (void)showRoomCreationForm {
// Switch in Home Tab
[self setSelectedIndex:TABBAR_HOME_INDEX];
}
- (void)showRoomDetails:(NSString*)roomId {
// Switch on recent
[self setSelectedIndex:TABBAR_RECENTS_INDEX];

View file

@ -18,12 +18,13 @@
@interface MatrixHandler : NSObject
@property (strong, nonatomic) MXHomeServer *homeServer;
@property (strong, nonatomic) MXHomeServer *mxHomeServer;
@property (strong, nonatomic) MXSession *mxSession;
@property (strong, nonatomic) MXData *mxData;
@property (strong, nonatomic) NSString *homeServerURL;
@property (strong, nonatomic) NSString *homeServer;
@property (strong, nonatomic) NSString *userLogin;
@property (strong, nonatomic) NSString *userId;
@property (strong, nonatomic) NSString *accessToken;

View file

@ -27,7 +27,7 @@ static MatrixHandler *sharedHandler = nil;
@implementation MatrixHandler
@synthesize homeServerURL, userLogin, userId, accessToken;
@synthesize homeServerURL, homeServer, userLogin, userId, accessToken;
+ (id)sharedHandler {
@synchronized(self) {
@ -45,9 +45,9 @@ static MatrixHandler *sharedHandler = nil;
if (self = [super init]) {
_isInitialSyncDone = NO;
// Read potential homeserver in shared defaults object
// Read potential homeserver url in shared defaults object
if (self.homeServerURL) {
self.homeServer = [[MXHomeServer alloc] initWithHomeServer:self.homeServerURL];
self.mxHomeServer = [[MXHomeServer alloc] initWithHomeServer:self.homeServerURL];
if (self.accessToken) {
[self openSession];
@ -81,7 +81,7 @@ static MatrixHandler *sharedHandler = nil;
- (void)dealloc {
[self closeSession];
self.homeServer = nil;
self.mxHomeServer = nil;
}
#pragma mark -
@ -96,16 +96,28 @@ static MatrixHandler *sharedHandler = nil;
}
- (NSString *)homeServerURL {
return [[NSUserDefaults standardUserDefaults] objectForKey:@"homeserverurl"];
}
- (void)setHomeServerURL:(NSString *)inHomeserverURL {
if (inHomeserverURL.length) {
[[NSUserDefaults standardUserDefaults] setObject:inHomeserverURL forKey:@"homeserverurl"];
self.mxHomeServer = [[MXHomeServer alloc] initWithHomeServer:inHomeserverURL];
} else {
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"homeserverurl"];
self.mxHomeServer = nil;
}
}
- (NSString *)homeServer {
return [[NSUserDefaults standardUserDefaults] objectForKey:@"homeserver"];
}
- (void)setHomeServerURL:(NSString *)inHomeserver {
- (void)setHomeServer:(NSString *)inHomeserver {
if (inHomeserver.length) {
[[NSUserDefaults standardUserDefaults] setObject:inHomeserver forKey:@"homeserver"];
self.homeServer = [[MXHomeServer alloc] initWithHomeServer:self.homeServerURL];
} else {
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"homeserver"];
self.homeServer = nil;
}
}

View file

@ -52,7 +52,7 @@
// Do any additional setup after loading the view, typically from a nib.
self.navigationItem.leftBarButtonItem = self.editButtonItem;
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(insertNewObject:)];
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(createNewRoom:)];
self.navigationItem.rightBarButtonItem = addButton;
self.roomViewController = (RoomViewController *)[[self.splitViewController.viewControllers lastObject] topViewController];
@ -103,13 +103,8 @@
}
}
- (void)insertNewObject:(id)sender {
// if (!self.recents) {
// self.recents = [[NSMutableArray alloc] init];
// }
// [self.recents insertObject:[NSDate date] atIndex:0];
// NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
// [self.tableView insertRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
- (void)createNewRoom:(id)sender {
[[AppDelegate theDelegate].masterTabBarController showRoomCreationForm];
}
#pragma mark - KVO