Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions XBMC Remote/HostManagementViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
NSIndexPath *storeServerSelection;
__weak IBOutlet UIActivityIndicatorView *connectingActivityIndicator;
AppInfoViewController *appInfoView;
UILabel *noFoundLabel;
__weak IBOutlet UIButton *addHostButton;
__weak IBOutlet UIView *supportedVersionView;
__weak IBOutlet UILabel *supportedVersionLabel;
Expand Down
115 changes: 66 additions & 49 deletions XBMC Remote/HostManagementViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@
// + 2 to cover two single-line separators
#define HOSTMANAGERVC_MSG_HEIGHT (supportedVersionView.frame.size.height + 2)
#define MARGIN 5
#define LABEL_SPACING 8
#define LABEL_HEIGHT 42
#define IPAD_POPOVER_WIDTH 400
#define IPAD_POPOVER_HEIGHT 500

#define XIB_HOST_MGMT_CELL_ICON 1
#define XIB_HOST_MGMT_CELL_LABEL 2
#define XIB_HOST_MGMT_CELL_IP 3
#define XIB_HOST_MGMT_CELL_NO_SERVER_FOUND 4

@interface HostManagementViewController ()

Expand Down Expand Up @@ -63,24 +64,37 @@ - (void)modifyHost:(NSIndexPath*)item {
[Utilities resetKodiServerParameters];
[Utilities saveLastServerIndex:nil];
[connectingActivityIndicator stopAnimating];
[serverListTableView reloadData];
[[NSNotificationCenter defaultCenter] postNotificationName:@"XBMCServerHasChanged" object:nil];
}
HostViewController *hostController = [[HostViewController alloc] initWithNibName:@"HostViewController" bundle:nil];
hostController.detailItem = item;
[self.navigationController pushViewController:hostController animated:YES];
}

#pragma mark - Helper

- (void)updateServerCellStatus {
for (NSIndexPath *indexPath in serverListTableView.indexPathsForVisibleRows) {
UITableViewCell *cell = [serverListTableView cellForRowAtIndexPath:indexPath];
UIImageView *iconView = (UIImageView*)[cell viewWithTag:XIB_HOST_MGMT_CELL_ICON];
NSIndexPath *selectedPath = storeServerSelection;
if (selectedPath && indexPath.row == selectedPath.row) {
NSString *iconName = [Utilities getConnectionStatusIconName];
iconView.image = [UIImage imageNamed:iconName];
}
else {
iconView.image = [UIImage imageNamed:@"connection_off"];
}
}
}

#pragma mark - Table view methods & data source

- (NSInteger)numberOfSectionsInTableView:(UITableView*)tableView {
return 1;
}

- (NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section {
if (AppDelegate.instance.arrayServerList.count == 0 && !tableView.editing) {
return 1;
}
return AppDelegate.instance.arrayServerList.count;
}

Expand All @@ -93,15 +107,12 @@ - (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSI
if (cell == nil) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"serverListCellView" owner:self options:nil];
cell = nib[0];
UILabel *cellNoServerFound = (UILabel*)[cell viewWithTag:XIB_HOST_MGMT_CELL_NO_SERVER_FOUND];
UILabel *cellLabel = (UILabel*)[cell viewWithTag:XIB_HOST_MGMT_CELL_LABEL];
UILabel *cellIP = (UILabel*)[cell viewWithTag:XIB_HOST_MGMT_CELL_IP];

cellNoServerFound.highlightedTextColor = [Utilities get1stLabelColor];
cellLabel.highlightedTextColor = [Utilities get1stLabelColor];
cellIP.highlightedTextColor = [Utilities get2ndLabelColor];

cellNoServerFound.textColor = [Utilities getSystemGray1];
cellLabel.textColor = [Utilities getSystemGray1];
cellIP.textColor = [Utilities getSystemGray2];

Expand All @@ -112,40 +123,25 @@ - (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSI
}
}
UIImageView *iconView = (UIImageView*)[cell viewWithTag:XIB_HOST_MGMT_CELL_ICON];
UILabel *cellNoServerFound = (UILabel*)[cell viewWithTag:XIB_HOST_MGMT_CELL_NO_SERVER_FOUND];
UILabel *cellLabel = (UILabel*)[cell viewWithTag:XIB_HOST_MGMT_CELL_LABEL];
UILabel *cellIP = (UILabel*)[cell viewWithTag:XIB_HOST_MGMT_CELL_IP];
if (AppDelegate.instance.arrayServerList.count == 0) {
iconView.hidden = YES;
cellNoServerFound.hidden = NO;
cellNoServerFound.text = LOCALIZED_STR(@"No saved hosts found");
cellLabel.text = @"";
cellIP.text = @"";
cell.accessoryType = UITableViewCellAccessoryNone;
editTableButton.enabled = NO;
return cell;
cellLabel.textAlignment = NSTextAlignmentLeft;
NSDictionary *item = AppDelegate.instance.arrayServerList[indexPath.row];
cellLabel.text = item[@"serverDescription"];
cellIP.text = item[@"serverIP"];
NSIndexPath *selectedPath = storeServerSelection;
if (selectedPath && indexPath.row == selectedPath.row) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
NSString *iconName = [Utilities getConnectionStatusIconName];
iconView.image = [UIImage imageNamed:iconName];
[serverListTableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionMiddle];
}
else {
iconView.hidden = NO;
cellNoServerFound.hidden = YES;
cellLabel.textAlignment = NSTextAlignmentLeft;
NSDictionary *item = AppDelegate.instance.arrayServerList[indexPath.row];
cellLabel.text = item[@"serverDescription"];
cellIP.text = item[@"serverIP"];
NSIndexPath *selectedPath = storeServerSelection;
if (selectedPath && indexPath.row == selectedPath.row) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
NSString *iconName = [Utilities getConnectionStatusIconName];
iconView.image = [UIImage imageNamed:iconName];
[serverListTableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionMiddle];
}
else {
cell.accessoryType = UITableViewCellAccessoryNone;
iconView.image = [UIImage imageNamed:@"connection_off"];
[serverListTableView deselectRowAtIndexPath:indexPath animated:YES];
}
editTableButton.enabled = YES;
cell.accessoryType = UITableViewCellAccessoryNone;
iconView.image = [UIImage imageNamed:@"connection_off"];
[serverListTableView deselectRowAtIndexPath:indexPath animated:YES];
}
editTableButton.enabled = YES;
return cell;
}

Expand All @@ -169,7 +165,6 @@ - (void)deselectServer {
[Utilities resetKodiServerParameters];
AppDelegate.instance.serverOnLine = NO;
[Utilities saveLastServerIndex:nil];
[serverListTableView reloadData];
}

- (void)selectServer:(NSNotification*)notification {
Expand Down Expand Up @@ -238,7 +233,6 @@ - (void)tableView:(UITableView*)tableView moveRowAtIndexPath:(NSIndexPath*)sourc
}
}


- (UITableViewCellEditingStyle)tableView:(UITableView*)aTableView editingStyleForRowAtIndexPath:(NSIndexPath*)indexPath {
return UITableViewCellEditingStyleDelete;
}
Expand All @@ -249,12 +243,12 @@ - (BOOL)tableView:(UITableView*)tableView canEditRowAtIndexPath:(NSIndexPath*)in

- (void)tableView:(UITableView*)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath*)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
[AppDelegate.instance.arrayServerList removeObjectAtIndex:indexPath.row];
[AppDelegate.instance saveServerList];
if (indexPath.row < AppDelegate.instance.arrayServerList.count) {
[AppDelegate.instance.arrayServerList removeObjectAtIndex:indexPath.row];
[AppDelegate.instance saveServerList];
}
if (indexPath.row < [tableView numberOfRowsInSection:indexPath.section]) {
[tableView performBatchUpdates:^{
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationRight];
} completion:nil];
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationRight];
}

// Be aware! Sending "XBMCServerHasChanged" results in calling reloadData. Therefore ensure this is not called
Expand All @@ -275,8 +269,11 @@ - (void)tableView:(UITableView*)tableView commitEditingStyle:(UITableViewCellEdi
}
}
// Are there still editable entries?
editTableButton.selected = editTableButton.enabled = AppDelegate.instance.arrayServerList.count > 0;
}
if (AppDelegate.instance.arrayServerList.count == 0) {
editTableButton.selected = editTableButton.enabled = NO;
[Utilities alphaView:noFoundLabel AnimDuration:0.2 Alpha:1.0];
}
}
}

- (void)tableView:(UITableView*)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath*)indexPath {
Expand All @@ -295,7 +292,6 @@ - (IBAction)editTable:(id)sender forceClose:(BOOL)forceClose {
if (serverListTableView.editing || forceClose) {
[serverListTableView setEditing:NO animated:YES];
editTableButton.selected = NO;
[serverListTableView reloadData];
}
else {
[serverListTableView setEditing:YES animated:YES];
Expand Down Expand Up @@ -464,6 +460,13 @@ - (void)viewWillAppear:(BOOL)animated {
UIImageView *xbmcLogoView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"kodi_logo_wide"]];
self.navigationItem.titleView = xbmcLogoView;
}
if (AppDelegate.instance.arrayServerList.count == 0) {
editTableButton.selected = editTableButton.enabled = NO;
noFoundLabel.alpha = 1.0;
}
else {
noFoundLabel.alpha = 0.0;
}
}

- (void)viewDidAppear:(BOOL)animated {
Expand Down Expand Up @@ -603,6 +606,20 @@ - (void)viewDidLoad {
longPressGesture.delegate = self;
[longPressGesture addTarget:self action:@selector(handleLongPress)];
[self.view addGestureRecognizer:longPressGesture];

noFoundLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMinX(serverListTableView.frame) + LABEL_SPACING,
CGRectGetMinY(serverListTableView.frame),
CGRectGetWidth(serverListTableView.frame) - 2 * LABEL_SPACING,
LABEL_HEIGHT)];
noFoundLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
noFoundLabel.text = LOCALIZED_STR(@"No saved hosts found");
noFoundLabel.textColor = UIColor.lightGrayColor;
noFoundLabel.font = [UIFont systemFontOfSize:17];
noFoundLabel.textAlignment = NSTextAlignmentCenter;
noFoundLabel.adjustsFontSizeToFitWidth = YES;
noFoundLabel.minimumScaleFactor = FONT_SCALING_MIN;
noFoundLabel.numberOfLines = 2;
[self.view addSubview:noFoundLabel];

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(revealMenu:)
Expand Down Expand Up @@ -750,7 +767,7 @@ - (void)authFailed:(NSNotification*)note {
}

- (void)connectionSuccess:(NSNotification*)note {
[serverListTableView reloadData];
[self updateServerCellStatus];

// Gather active server
storeServerSelection = [Utilities readLastServerIndex];
Expand All @@ -762,7 +779,7 @@ - (void)connectionSuccess:(NSNotification*)note {
}

- (void)connectionFailed:(NSNotification*)note {
[serverListTableView reloadData];
[self updateServerCellStatus];
}

- (BOOL)shouldAutorotate {
Expand Down
10 changes: 3 additions & 7 deletions XBMC Remote/NowPlaying.m
Original file line number Diff line number Diff line change
Expand Up @@ -2197,8 +2197,7 @@ - (void)tableView:(UITableView*)tableView moveRowAtIndexPath:(NSIndexPath*)sourc
[[Utilities getJsonRPC] callMethod:actionRemove withParameters:paramsRemove onCompletion:^(NSString *methodName, NSInteger callId, id methodResult, DSJSONRPCError *methodError, NSError *error) {
if (error == nil && methodError == nil) {
[[Utilities getJsonRPC] callMethod:actionInsert withParameters:paramsInsert];
NSInteger numObj = playlistData.count;
if (sourceIndexPath.row < numObj) {
if (sourceIndexPath.row < playlistData.count) {
[playlistData removeObjectAtIndex:sourceIndexPath.row];
}
if (destinationIndexPath.row <= playlistData.count) {
Expand Down Expand Up @@ -2229,14 +2228,11 @@ - (void)tableView:(UITableView*)tableView commitEditingStyle:(UITableViewCellEdi
};
[[Utilities getJsonRPC] callMethod:actionRemove withParameters:paramsRemove onCompletion:^(NSString *methodName, NSInteger callId, id methodResult, DSJSONRPCError *methodError, NSError *error) {
if (error == nil && methodError == nil) {
NSInteger numObj = playlistData.count;
if (indexPath.row < numObj) {
if (indexPath.row < playlistData.count) {
[playlistData removeObjectAtIndex:indexPath.row];
}
if (indexPath.row < [playlistTableView numberOfRowsInSection:indexPath.section]) {
[playlistTableView performBatchUpdates:^{
[playlistTableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationRight];
} completion:nil];
[playlistTableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationRight];
}
if (storeSelection && indexPath.row < storeSelection.row) {
storeSelection = [NSIndexPath indexPathForRow:storeSelection.row - 1 inSection:storeSelection.section];
Expand Down
4 changes: 1 addition & 3 deletions XBMC Remote/RightMenuViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -303,9 +303,7 @@ - (void)tableView:(UITableView*)tableView commitEditingStyle:(UITableViewCellEdi
[tableData removeObjectAtIndex:indexPath.row];
}
if (indexPath.row < [tableView numberOfRowsInSection:indexPath.section]) {
[tableView performBatchUpdates:^{
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationRight];
} completion:nil];
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationRight];
}
[self deleteCustomButton:indexPath.row];
}
Expand Down
7 changes: 0 additions & 7 deletions XBMC Remote/serverListCellView.xib
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,6 @@
<rect key="frame" x="0.0" y="0.0" width="280" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label hidden="YES" opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" tag="4" contentMode="left" fixedFrame="YES" text="No server found" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" minimumScaleFactor="0.80000000000000004" translatesAutoresizingMaskIntoConstraints="NO" id="6">
<rect key="frame" x="0.0" y="0.0" width="280" height="44"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="16"/>
<color key="textColor" red="0.66666668653488159" green="0.66666668653488159" blue="0.66666668653488159" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color key="highlightedColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</label>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" tag="2" contentMode="left" fixedFrame="YES" text="My XBMC" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" minimumScaleFactor="0.90000000000000002" translatesAutoresizingMaskIntoConstraints="NO" id="4ry-PI-TW9">
<rect key="frame" x="35" y="2" width="245" height="20"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxY="YES"/>
Expand Down