Sort public rooms, display topic (if any)

This commit is contained in:
giomfo
2014-10-16 11:15:39 +02:00
parent 6d038a5d41
commit 432509f607
3 changed files with 80 additions and 17 deletions

View File

@@ -219,7 +219,7 @@
<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="40" sectionFooterHeight="22" id="LbI-fz-LaI">
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="44" 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"/>
@@ -339,14 +339,14 @@
</constraints>
</view>
<prototypes>
<tableViewCell contentMode="scaleToFill" selectionStyle="blue" indentationLevel="1" indentationWidth="0.0" reuseIdentifier="PublicRoomCell" textLabel="UoS-rO-98c" style="IBUITableViewCellStyleDefault" id="Y5I-fR-nF2">
<tableViewCell contentMode="scaleToFill" selectionStyle="blue" indentationLevel="1" indentationWidth="0.0" reuseIdentifier="PublicRoomCellBasic" textLabel="UoS-rO-98c" style="IBUITableViewCellStyleDefault" id="Y5I-fR-nF2">
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="Y5I-fR-nF2" id="k9k-ye-AWt">
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" text="Title" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="UoS-rO-98c">
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="boldSystem" pointSize="20"/>
<fontDescription key="fontDescription" type="system" pointSize="19"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<color key="highlightedColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</label>
@@ -354,6 +354,27 @@
</tableViewCellContentView>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</tableViewCell>
<tableViewCell contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" reuseIdentifier="PublicRoomCellSubtitle" textLabel="XSB-xW-yiT" detailTextLabel="sfe-5d-fmq" style="IBUITableViewCellStyleSubtitle" id="ZA7-Uv-Ncb">
<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="ZA7-Uv-Ncb" id="N4f-z9-lYd">
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" text="Title" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="XSB-xW-yiT">
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="19"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" text="Subtitle" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="sfe-5d-fmq">
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="16"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</tableViewCellContentView>
</tableViewCell>
</prototypes>
<connections>
<outlet property="dataSource" destination="ldZ-75-BUU" id="NGi-hL-2dc"/>

View File

@@ -18,8 +18,5 @@
@interface HomeViewController : UITableViewController <UITextFieldDelegate>
@property (strong, nonatomic) NSArray *publicRooms;
@property (weak, nonatomic) IBOutlet UITableView *publicRoomsTable;
@end

View File

@@ -19,7 +19,15 @@
#import "MatrixHandler.h"
#import "AppDelegate.h"
@interface HomeViewController ()
@interface HomeViewController () {
NSArray *publicRooms;
// List of public room names to highlight in displayed list
NSArray* highlightedPublicRooms;
}
@property (weak, nonatomic) IBOutlet UITableView *publicRoomsTable;
@property (weak, nonatomic) IBOutlet UILabel *roomCreationLabel;
@property (weak, nonatomic) IBOutlet UILabel *roomNameLabel;
@property (weak, nonatomic) IBOutlet UILabel *roomAliasLabel;
@@ -44,7 +52,8 @@
_createRoomBtn.alpha = 0.5;
// Init
_publicRooms = nil;
publicRooms = nil;
highlightedPublicRooms = @[@"#matrix:matrix.org"]; // Add here a room name to highlight its display in public room list
}
- (void)didReceiveMemoryWarning {
@@ -52,6 +61,11 @@
// Dispose of any resources that can be recreated.
}
- (void)dealloc{
publicRooms = nil;
highlightedPublicRooms = nil;
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
@@ -81,10 +95,7 @@
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if (_publicRooms){
return _publicRooms.count;
}
return 0;
return publicRooms.count;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
@@ -92,7 +103,7 @@
sectionHeader.font = [UIFont boldSystemFontOfSize:16];
sectionHeader.backgroundColor = [UIColor colorWithRed:0.9 green:0.9 blue:0.9 alpha:1.0];
if (_publicRooms) {
if (publicRooms) {
NSString *homeserver = [MatrixHandler sharedHandler].homeServerURL;
if (homeserver.length) {
sectionHeader.text = [NSString stringWithFormat:@" Public Rooms (at %@):", homeserver];
@@ -106,12 +117,40 @@
return sectionHeader;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
// Cell is larger for public room with topic
MXPublicRoom *publicRoom = [publicRooms objectAtIndex:indexPath.row];
if (publicRoom.topic) {
return 60;
}
return 44;
}
- (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [_publicRoomsTable dequeueReusableCellWithIdentifier:@"PublicRoomCell" forIndexPath:indexPath];
MXPublicRoom *publicRoom = [publicRooms objectAtIndex:indexPath.row];
UITableViewCell *cell;
MXPublicRoom *publicRoom = [_publicRooms objectAtIndex:indexPath.row];
// Check whether this public room has topic
if (publicRoom.topic) {
cell = [_publicRoomsTable dequeueReusableCellWithIdentifier:@"PublicRoomCellSubtitle" forIndexPath:indexPath];
cell.detailTextLabel.text = publicRoom.topic;
} else {
cell = [_publicRoomsTable dequeueReusableCellWithIdentifier:@"PublicRoomCellBasic" forIndexPath:indexPath];
}
// Set room display name
cell.textLabel.text = [publicRoom displayname];
// Highlight?
if (cell.textLabel.text && [highlightedPublicRooms indexOfObject:cell.textLabel.text] != NSNotFound) {
cell.textLabel.font = [UIFont boldSystemFontOfSize:20];
cell.detailTextLabel.font = [UIFont boldSystemFontOfSize:17];
} else {
cell.textLabel.font = [UIFont systemFontOfSize:19];
cell.detailTextLabel.font = [UIFont systemFontOfSize:16];
}
return cell;
}
@@ -121,7 +160,7 @@
MatrixHandler *mxHandler = [MatrixHandler sharedHandler];
// Check whether the user has already joined the selected public room
MXPublicRoom *publicRoom = [_publicRooms objectAtIndex:indexPath.row];
MXPublicRoom *publicRoom = [publicRooms objectAtIndex:indexPath.row];
if ([mxHandler.mxData getRoomData:publicRoom.room_id]) {
// Open selected room
[[AppDelegate theDelegate].masterTabBarController showRoom:publicRoom.room_id];
@@ -145,7 +184,13 @@
- (void)refreshPublicRooms {
// Retrieve public rooms
[[MatrixHandler sharedHandler].mxHomeServer publicRooms:^(NSArray *rooms){
_publicRooms = rooms;
publicRooms = [rooms sortedArrayUsingComparator:^NSComparisonResult(id a, id b) {
MXPublicRoom *firstRoom = (MXPublicRoom*)a;
MXPublicRoom *secondRoom = (MXPublicRoom*)b;
return [firstRoom.displayname compare:secondRoom.displayname options:NSCaseInsensitiveSearch];
}];
[_publicRoomsTable reloadData];
}
failure:^(NSError *error){