diff --git a/syMessaging/syMessaging/Base.lproj/Main.storyboard b/syMessaging/syMessaging/Base.lproj/Main.storyboard
index 811afaf9a..1cf784292 100644
--- a/syMessaging/syMessaging/Base.lproj/Main.storyboard
+++ b/syMessaging/syMessaging/Base.lproj/Main.storyboard
@@ -22,39 +22,92 @@
-
+
-
-
-
-
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
-
-
+
+
@@ -619,7 +672,7 @@
-
+
diff --git a/syMessaging/syMessaging/RoomViewController.h b/syMessaging/syMessaging/RoomViewController.h
index 782da00fa..36e4c8940 100644
--- a/syMessaging/syMessaging/RoomViewController.h
+++ b/syMessaging/syMessaging/RoomViewController.h
@@ -16,11 +16,9 @@
#import
-@interface RoomViewController : UIViewController
+@interface RoomViewController : UITableViewController
@property (strong, nonatomic) NSString *roomId;
-@property (weak, nonatomic) IBOutlet UILabel *detailDescriptionLabel;
-
@end
diff --git a/syMessaging/syMessaging/RoomViewController.m b/syMessaging/syMessaging/RoomViewController.m
index fc14ba2dd..d91a7c88d 100644
--- a/syMessaging/syMessaging/RoomViewController.m
+++ b/syMessaging/syMessaging/RoomViewController.m
@@ -20,6 +20,12 @@
@interface RoomViewController ()
+@property (weak, nonatomic) IBOutlet UITableView *tableView;
+@property (weak, nonatomic) IBOutlet UIView *tableFooter;
+@property (weak, nonatomic) IBOutlet UIButton *optionBtn;
+@property (weak, nonatomic) IBOutlet UITextField *messageTextField;
+@property (weak, nonatomic) IBOutlet UIButton *sendBtn;
+
@property (strong, nonatomic) MXRoomData *mxRoomData;
@end
@@ -28,7 +34,7 @@
#pragma mark - Managing the detail item
-- (void)setDetailItem:(NSString*)roomId {
+- (void)setRoomId:(NSString *)roomId {
_roomId = roomId;
// Update the view.
@@ -38,16 +44,21 @@
- (void)configureView {
// Update the user interface for the detail item.
if (self.roomId) {
- MatrixHandler *mxHandler = [MatrixHandler sharedHandler];
- self.mxRoomData = [[mxHandler mxData] getRoomData:self.roomId];
- self.detailDescriptionLabel.text = [mxHandler displayTextFor:self.mxRoomData.lastMessage inDetailMode:NO];
+ self.mxRoomData = [[[MatrixHandler sharedHandler] mxData] getRoomData:self.roomId];
+ } else {
+ self.mxRoomData = nil;
}
+
+ [self.tableView reloadData];
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self configureView];
+
+ _sendBtn.enabled = NO;
+ _sendBtn.alpha = 0.5;
}
- (void)dealloc {
@@ -59,4 +70,86 @@
// Dispose of any resources that can be recreated.
}
+- (void)viewWillAppear:(BOOL)animated {
+ [super viewWillAppear:animated];
+
+ // Scroll to the bottom
+ [self.tableView scrollRectToVisible:_messageTextField.frame animated:NO];
+
+ // Refresh
+ // TODO
+
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onTextFieldChange:) name:UITextFieldTextDidChangeNotification object:nil];
+}
+
+- (void)viewWillDisappear:(BOOL)animated {
+ [super viewWillDisappear:animated];
+
+ [[NSNotificationCenter defaultCenter] removeObserver:self name:UITextFieldTextDidChangeNotification object:nil];
+}
+
+- (void)dismissKeyboard {
+ // Hide the keyboard
+ [_messageTextField resignFirstResponder];
+}
+
+#pragma mark - Table view data source
+
+- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
+ return 1;
+}
+
+- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
+ if (self.mxRoomData){
+ return self.mxRoomData.messages.count;
+ }
+ return 0;
+}
+
+- (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
+ UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:@"RoomMessageCell" forIndexPath:indexPath];
+ MatrixHandler *mxHandler = [MatrixHandler sharedHandler];
+ MXEvent *mxEvent = [self.mxRoomData.messages objectAtIndex:indexPath.row];
+ cell.textLabel.text = [mxHandler displayTextFor:mxEvent inDetailMode:NO];
+
+ if ([mxEvent.user_id isEqualToString:mxHandler.userId]) {
+ cell.textLabel.textAlignment = NSTextAlignmentRight;
+ } else {
+ cell.textLabel.textAlignment = NSTextAlignmentLeft;
+ }
+
+ return cell;
+}
+
+#pragma mark - UITextField delegate
+
+- (void)onTextFieldChange:(NSNotification *)notif {
+ NSString *msg = _messageTextField.text;
+
+ if (msg.length) {
+ _sendBtn.enabled = YES;
+ _sendBtn.alpha = 1;
+ } else {
+ _sendBtn.enabled = NO;
+ _sendBtn.alpha = 0.5;
+ }
+}
+
+- (BOOL)textFieldShouldReturn:(UITextField*) textField {
+ // "Done" key has been pressed
+ [textField resignFirstResponder];
+ return YES;
+}
+
+#pragma mark -
+
+- (IBAction)onButtonPressed:(id)sender {
+ [self dismissKeyboard];
+
+ if (sender == _sendBtn) {
+ //TODO
+ } else if (sender == _optionBtn) {
+ //TODO
+ }
+}
@end