diff --git a/XBMC Remote/HostManagementViewController.h b/XBMC Remote/HostManagementViewController.h index acf785602..efee82a6f 100644 --- a/XBMC Remote/HostManagementViewController.h +++ b/XBMC Remote/HostManagementViewController.h @@ -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; diff --git a/XBMC Remote/HostManagementViewController.m b/XBMC Remote/HostManagementViewController.m index 29cf4f64c..db21ddf86 100644 --- a/XBMC Remote/HostManagementViewController.m +++ b/XBMC Remote/HostManagementViewController.m @@ -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 () @@ -63,7 +64,6 @@ - (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]; @@ -71,6 +71,23 @@ - (void)modifyHost:(NSIndexPath*)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 { @@ -78,9 +95,6 @@ - (NSInteger)numberOfSectionsInTableView:(UITableView*)tableView { } - (NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section { - if (AppDelegate.instance.arrayServerList.count == 0 && !tableView.editing) { - return 1; - } return AppDelegate.instance.arrayServerList.count; } @@ -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]; @@ -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; } @@ -169,7 +165,6 @@ - (void)deselectServer { [Utilities resetKodiServerParameters]; AppDelegate.instance.serverOnLine = NO; [Utilities saveLastServerIndex:nil]; - [serverListTableView reloadData]; } - (void)selectServer:(NSNotification*)notification { @@ -238,7 +233,6 @@ - (void)tableView:(UITableView*)tableView moveRowAtIndexPath:(NSIndexPath*)sourc } } - - (UITableViewCellEditingStyle)tableView:(UITableView*)aTableView editingStyleForRowAtIndexPath:(NSIndexPath*)indexPath { return UITableViewCellEditingStyleDelete; } @@ -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 @@ -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 { @@ -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]; @@ -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 { @@ -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:) @@ -750,7 +767,7 @@ - (void)authFailed:(NSNotification*)note { } - (void)connectionSuccess:(NSNotification*)note { - [serverListTableView reloadData]; + [self updateServerCellStatus]; // Gather active server storeServerSelection = [Utilities readLastServerIndex]; @@ -762,7 +779,7 @@ - (void)connectionSuccess:(NSNotification*)note { } - (void)connectionFailed:(NSNotification*)note { - [serverListTableView reloadData]; + [self updateServerCellStatus]; } - (BOOL)shouldAutorotate { diff --git a/XBMC Remote/NowPlaying.m b/XBMC Remote/NowPlaying.m index e38fc049a..7e6439c8a 100644 --- a/XBMC Remote/NowPlaying.m +++ b/XBMC Remote/NowPlaying.m @@ -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) { @@ -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]; diff --git a/XBMC Remote/RightMenuViewController.m b/XBMC Remote/RightMenuViewController.m index 18b608e05..f10e0e12f 100644 --- a/XBMC Remote/RightMenuViewController.m +++ b/XBMC Remote/RightMenuViewController.m @@ -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]; } diff --git a/XBMC Remote/serverListCellView.xib b/XBMC Remote/serverListCellView.xib index df6c52be7..fcf31ae80 100644 --- a/XBMC Remote/serverListCellView.xib +++ b/XBMC Remote/serverListCellView.xib @@ -16,13 +16,6 @@ -