Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvement: Global connection status for iPhone #1027

Merged
merged 5 commits into from
Apr 21, 2024
Merged
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
23 changes: 1 addition & 22 deletions XBMC Remote/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -5940,20 +5940,9 @@ - (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(N
nowPlayingItem1.family = FamilyNowPlaying;
nowPlayingItem1.mainMethod = @[
@{
@"offline": @[
@{
@"label": @"ServerInfo",
@"bgColor": [self setColorRed:0.208 Green:0.208 Blue:0.208],
@"fontColor": [self setColorRed:0.702 Green:0.702 Blue:0.702],
},
],
@"offline": @[],

@"online": @[
@{
@"label": @"ServerInfo",
@"bgColor": [self setColorRed:0.208 Green:0.208 Blue:0.208],
@"fontColor": [self setColorRed:0.702 Green:0.702 Blue:0.702],
},
@{
@"label": @"VolumeControl",
@"icon": @"volume",
Expand Down Expand Up @@ -5981,23 +5970,13 @@ - (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(N
remoteControlItem1.mainMethod = @[
@{
@"offline": @[
@{
@"label": @"ServerInfo",
@"bgColor": [self setColorRed:0.208 Green:0.208 Blue:0.208],
@"fontColor": [self setColorRed:0.702 Green:0.702 Blue:0.702],
},
@{
@"label": LOCALIZED_STR(@"LED Torch"),
@"icon": @"torch",
},
],

@"online": @[
@{
@"label": @"ServerInfo",
@"bgColor": [self setColorRed:0.208 Green:0.208 Blue:0.208],
@"fontColor": [self setColorRed:0.702 Green:0.702 Blue:0.702],
},
@{
@"label": @"VolumeControl",
@"icon": @"volume",
Expand Down
3 changes: 1 addition & 2 deletions XBMC Remote/MasterViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,9 @@
HostManagementViewController *hostManagementViewController;
BOOL itemIsActive;
CustomNavigationController *navController;
UIImageView *globalConnectionStatus;
}

- (void)changeServerStatus:(BOOL)status infoText:(NSString*)infoText icon:(NSString*)iconName;

@property (nonatomic, strong) NSMutableArray *mainMenu;
@property (strong, nonatomic) DetailViewController *detailViewController;
@property (strong, nonatomic) NowPlaying *nowPlaying;
Expand Down
47 changes: 39 additions & 8 deletions XBMC Remote/MasterViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#define CONNECTION_ICON_SIZE 18
#define MENU_ICON_SIZE 30
#define ICON_MARGIN 10
#define CONNECTION_STATUS_PADDING 4
#define CONNECTION_STATUS_SIZE 8

@interface MasterViewController () {
NSMutableArray *_objects;
Expand All @@ -51,6 +53,8 @@ - (void)changeServerStatus:(BOOL)status infoText:(NSString*)infoText icon:(NSStr
infoText, @"message",
iconName, @"icon_connection",
nil];
AppDelegate.instance.serverOnLine = status;
AppDelegate.instance.serverName = infoText;
NSString *notificationName;
if (status) {
[self.tcpJSONRPCconnection startNetworkCommunicationWithServer:AppDelegate.instance.obj.serverRawIP serverPort:AppDelegate.instance.obj.tcpPort];
Expand All @@ -61,8 +65,6 @@ - (void)changeServerStatus:(BOOL)status infoText:(NSString*)infoText icon:(NSStr
notificationName = @"XBMCServerConnectionFailed";
}
[[NSNotificationCenter defaultCenter] postNotificationName:notificationName object:nil userInfo:params];
AppDelegate.instance.serverOnLine = status;
AppDelegate.instance.serverName = infoText;
itemIsActive = NO;
[Utilities setStyleOfMenuItems:menuList active:status];
if (status) {
Expand Down Expand Up @@ -102,15 +104,13 @@ - (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSI
UILabel *title = (UILabel*)[cell viewWithTag:XIB_MAIN_MENU_CELL_TITLE];
if (indexPath.row == 0) {
// Adapt layout for first cell (showing connection status)
[self setFrameSizes:cell height:PHONE_MENU_INFO_HEIGHT iconsize:CONNECTION_ICON_SIZE];
[self setFrameSizes:cell height:PHONE_MENU_INFO_HEIGHT iconsize:MENU_ICON_SIZE];

// Set icon, background color and text content
title.font = [UIFont fontWithName:@"Roboto-Regular" size:13];
title.numberOfLines = 2;
title.text = [Utilities getConnectionStatusServerName];
iconName = [Utilities getConnectionStatusIconName];
icon.highlightedImage = nil;
icon.image = [UIImage imageNamed:iconName];
[self setConnectionIcon:icon];
cell.backgroundColor = [Utilities getGrayColor:53 alpha:1];
}
else {
Expand Down Expand Up @@ -188,6 +188,9 @@ - (void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*)
self.slidingViewController.topViewController.view.frame = frame;
[self.slidingViewController resetTopView];
itemIsActive = NO;

// Add connection status icon to root view of new controller
[self addConnectionStatusToRootView];
}];
}

Expand Down Expand Up @@ -222,6 +225,27 @@ - (CGFloat)tableView:(UITableView*)tableView heightForRowAtIndexPath:(NSIndexPat

#pragma mark - Helper

- (void)addConnectionStatusToRootView {
// Add connection status icon to root view of new controller
UIView *rootView = UIApplication.sharedApplication.keyWindow.rootViewController.view;
[rootView addSubview:globalConnectionStatus];
}

- (void)setConnectionIcon:(UIImageView*)icon {
// Load icon for top row in main menu
UIImage *image = [UIImage imageNamed:@"st_kodi_action"];
if (!AppDelegate.instance.serverOnLine) {
icon.image = [Utilities colorizeImage:image withColor:UIColor.grayColor];
}
else {
icon.image = [Utilities colorizeImage:image withColor:KODI_BLUE_COLOR];
}

// Load icon for global connection status
NSString *statusIconName = [Utilities getConnectionStatusIconName];
globalConnectionStatus.image = [UIImage imageNamed:statusIconName];
}

- (void)setFrameSizes:(UITableViewCell*)cell height:(CGFloat)height iconsize:(CGFloat)iconsize {
UIImageView *icon = (UIImageView*)[cell viewWithTag:XIB_MAIN_MENU_CELL_ICON];
UILabel *title = (UILabel*)[cell viewWithTag:XIB_MAIN_MENU_CELL_TITLE];
Expand Down Expand Up @@ -300,6 +324,14 @@ - (void)viewDidLoad {
AppDelegate.instance.obj = [GlobalData getInstance];
checkServerParams = @{@"properties": @[@"version", @"volume"]};
menuList.scrollsToTop = NO;

// Add connection status icon to root view
globalConnectionStatus = [[UIImageView alloc] initWithFrame:CGRectMake(CONNECTION_STATUS_PADDING,
[Utilities getTopPadding],
CONNECTION_STATUS_SIZE,
CONNECTION_STATUS_SIZE)];
[self addConnectionStatusToRootView];

[[NSNotificationCenter defaultCenter] addObserver: self
selector: @selector(handleWillResignActive:)
name: @"UIApplicationWillResignActiveNotification"
Expand Down Expand Up @@ -339,11 +371,10 @@ - (void)viewDidLoad {

- (void)connectionStatus:(NSNotification*)note {
NSDictionary *theData = note.userInfo;
NSString *icon_connection = theData[@"icon_connection"];
NSString *infoText = theData[@"message"];
UITableViewCell *cell = [menuList cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
UIImageView *icon = (UIImageView*)[cell viewWithTag:XIB_MAIN_MENU_CELL_ICON];
icon.image = [UIImage imageNamed:icon_connection];
[self setConnectionIcon:icon];
UILabel *title = (UILabel*)[cell viewWithTag:XIB_MAIN_MENU_CELL_TITLE];
title.text = infoText;

Expand Down
89 changes: 10 additions & 79 deletions XBMC Remote/RightMenuViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#import "Utilities.h"

#define TOOLBAR_HEIGHT 44.0
#define SERVER_INFO_HEIGHT 44.0
#define RIGHT_MENU_ITEM_HEIGHT 50.0
#define RIGHT_MENU_ICON_SIZE 18.0
#define RIGHT_MENU_ICON_SPACING 16.0
Expand Down Expand Up @@ -50,10 +49,7 @@ - (id)initWithNibName:(NSString*)nibNameOrNil bundle:(NSBundle*)nibBundleOrNil {

- (CGFloat)tableView:(UITableView*)tableView heightForRowAtIndexPath:(NSIndexPath*)indexPath {
NSString *rowContent = tableData[indexPath.row][@"label"];
if ([rowContent isEqualToString:@"ServerInfo"]) {
return SERVER_INFO_HEIGHT;
}
else if ([rowContent isEqualToString:@"RemoteControl"]) {
if ([rowContent isEqualToString:@"RemoteControl"]) {
return UIScreen.mainScreen.bounds.size.height - [self getRemoteViewOffsetY];
}
else if ([rowContent isEqualToString:@"VolumeControl"]) {
Expand All @@ -71,16 +67,7 @@ - (NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)
}

- (void)tableView:(UITableView*)tableView willDisplayCell:(UITableViewCell*)cell forRowAtIndexPath:(NSIndexPath*)indexPath {
NSDictionary *rgbColor = tableData[indexPath.row][@"bgColor"];
if (rgbColor.count) {
cell.backgroundColor = [UIColor colorWithRed:[rgbColor[@"red"] floatValue]
green:[rgbColor[@"green"] floatValue]
blue:[rgbColor[@"blue"] floatValue]
alpha:1];
}
else { // xcode xib bug with ipad?
cell.backgroundColor = UIColor.clearColor;
}
cell.backgroundColor = [Utilities getGrayColor:36 alpha:1];
}

- (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath {
Expand Down Expand Up @@ -136,26 +123,7 @@ - (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSI
NSString *iconName = @"blank";

// Tailor cell layout for content type
if ([tableData[indexPath.row][@"label"] isEqualToString:@"ServerInfo"]) {
// Enable connection status icon and place it
status.frame = CGRectMake(STATUS_SPACING,
(SERVER_INFO_HEIGHT - RIGHT_MENU_ICON_SIZE) / 2,
RIGHT_MENU_ICON_SIZE,
RIGHT_MENU_ICON_SIZE);
status.image = [UIImage imageNamed:[Utilities getConnectionStatusIconName]];
status.alpha = 1.0;
status.hidden = NO;

// Adapt text field to align with connection status
title.frame = CGRectMake(CGRectGetMaxX(status.frame) + STATUS_SPACING,
(SERVER_INFO_HEIGHT - RIGHT_MENU_ITEM_HEIGHT) / 2,
CGRectGetMaxX(cell.frame) - CGRectGetMaxX(status.frame) - 2 * STATUS_SPACING,
RIGHT_MENU_ITEM_HEIGHT);
title.font = [UIFont fontWithName:@"Roboto-Regular" size:13];
title.textAlignment = NSTextAlignmentLeft;
title.text = AppDelegate.instance.serverName;
}
else if ([tableData[indexPath.row][@"label"] isEqualToString:@"VolumeControl"]) {
if ([tableData[indexPath.row][@"label"] isEqualToString:@"VolumeControl"]) {
volumeSliderView = [[VolumeSliderView alloc] initWithFrame:CGRectZero leftAnchor:ANCHOR_RIGHT_PEEK isSliderType:YES];
[volumeSliderView startTimer];
[cell.contentView addSubview:volumeSliderView];
Expand Down Expand Up @@ -207,19 +175,11 @@ - (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSI
title.text = tableData[indexPath.row][@"label"];
iconName = tableData[indexPath.row][@"icon"];
}
if ([tableData[indexPath.row][@"fontColor"] count]) {
UIColor *fontColor = [UIColor colorWithRed:[tableData[indexPath.row][@"fontColor"][@"red"] floatValue]
green:[tableData[indexPath.row][@"fontColor"][@"green"] floatValue]
blue:[tableData[indexPath.row][@"fontColor"][@"blue"] floatValue]
alpha:1];
title.textColor = fontColor;
title.highlightedTextColor = fontColor;
}
else {
UIColor *fontColor = [Utilities getGrayColor:125 alpha:1];
title.textColor = fontColor;
title.highlightedTextColor = fontColor;
}

UIColor *fontColor = [Utilities getGrayColor:125 alpha:1];
title.textColor = fontColor;
title.highlightedTextColor = fontColor;

if ([tableData[indexPath.row][@"label"] isEqualToString:LOCALIZED_STR(@"LED Torch")]) {
icon.alpha = 0.8;
if (torchIsOn) {
Expand Down Expand Up @@ -272,11 +232,11 @@ - (UIView*)createTableFooterView:(CGFloat)footerHeight {
#pragma mark - Helper

- (CGFloat)getRemoteViewOffsetY {
// Layout is (top-down): status bar > server info > volume slider > (menu items) > remote view
// Layout is (top-down): status bar > volume slider > (menu items) > remote view
CGFloat statusBarHeight = [Utilities getTopPadding];
CGFloat sliderHeight = volumeSliderView.frame.size.height;
CGFloat menuItemsHeight = [Utilities hasRemoteToolBar] ? 0 : 3 * RIGHT_MENU_ITEM_HEIGHT;
return statusBarHeight + SERVER_INFO_HEIGHT + sliderHeight + menuItemsHeight;
return statusBarHeight + sliderHeight + menuItemsHeight;
}

#pragma mark - Table actions
Expand Down Expand Up @@ -323,16 +283,12 @@ - (void)loadRightMenuContentConnected:(BOOL)isConnected {
tableData = [NSMutableArray new];
for (NSDictionary *item in menuItem.mainMethod[0][menuKey]) {
NSString *label = item[@"label"] ?: @"";
NSDictionary *bgColor = item[@"bgColor"] ?: @{};
NSDictionary *fontColor = item[@"fontColor"] ?: @{};
NSString *icon = item[@"icon"] ?: @"blank";
NSDictionary *action = item[@"action"] ?: @{};
NSNumber *showTop = item[@"revealViewTop"] ?: @NO;

NSDictionary *itemDict = @{
@"label": label,
@"bgColor": bgColor,
@"fontColor": fontColor,
@"icon": icon,
@"action": action,
@"revealViewTop": showTop,
Expand Down Expand Up @@ -376,8 +332,6 @@ - (void)loadCustomButtons {

NSMutableDictionary *itemDict = [@{
@"label": label,
@"bgColor": @{},
@"fontColor": @{},
@"icon": icon,
@"isSetting": isSetting,
@"revealViewTop": @NO,
Expand Down Expand Up @@ -620,8 +574,6 @@ - (void)viewDidLoad {

infoCustomButton = @{
@"label": LOCALIZED_STR(@"No custom button defined.\r\nPress \"...more\" below to add new ones."),
@"bgColor": @{},
@"fontColor": @{},
@"icon": @"default-right-menu-icon",
@"action": @{},
@"revealViewTop": @NO,
Expand Down Expand Up @@ -748,34 +700,13 @@ - (NSIndexPath*)getIndexPathForKey:(NSString*)key withValue:(NSString*)value inA
return foundIndex;
}

- (void)updateConnectionStatusAndName:(NSDictionary*)theData {
if (theData != nil) {
NSString *serverTxt = theData[@"message"];
NSString *icon_connection = theData[@"icon_connection"];
NSIndexPath *serverRow = [self getIndexPathForKey:@"label" withValue:@"ServerInfo" inArray:tableData];
if (serverRow != nil) {
UITableViewCell *cell = [menuTableView cellForRowAtIndexPath:serverRow];
if (serverTxt.length) {
UILabel *title = (UILabel*)[cell viewWithTag:XIB_RIGHT_MENU_CELL__TITLE];
title.text = serverTxt;
}
if (icon_connection.length) {
UIImageView *icon = (UIImageView*)[cell viewWithTag:XIB_RIGHT_MENU_CELL__ICON];
icon.image = [UIImage imageNamed:icon_connection];
}
}
}
}

- (void)connectionSuccess:(NSNotification*)note {
[self updateConnectionStatusAndName:note.userInfo];
[self loadRightMenuContentConnected:YES];
[menuTableView reloadData];
moreButton.enabled = YES;
}

- (void)connectionFailed:(NSNotification*)note {
[self updateConnectionStatusAndName:note.userInfo];
if (AppDelegate.instance.obj.serverIP.length != 0) {
[self loadRightMenuContentConnected:YES];
[menuTableView reloadData];
Expand Down
24 changes: 12 additions & 12 deletions XBMC Remote/ViewControllerIPad.m
Original file line number Diff line number Diff line change
Expand Up @@ -117,28 +117,28 @@ - (void)changeServerStatus:(BOOL)status infoText:(NSString*)infoText icon:(NSStr
infoText, @"message",
iconName, @"icon_connection",
nil];
AppDelegate.instance.serverOnLine = status;
AppDelegate.instance.serverName = infoText;
NSString *notificationName;
if (status) {
[self.tcpJSONRPCconnection startNetworkCommunicationWithServer:AppDelegate.instance.obj.serverRawIP serverPort:AppDelegate.instance.obj.tcpPort];
[[NSNotificationCenter defaultCenter] postNotificationName: @"XBMCServerConnectionSuccess" object:nil userInfo:params];
AppDelegate.instance.serverOnLine = YES;
AppDelegate.instance.serverName = infoText;
notificationName = @"XBMCServerConnectionSuccess";
[volumeSliderView startTimer];
[xbmcInfo setTitle:infoText forState:UIControlStateNormal];
[Utilities setStyleOfMenuItems:menuViewController.tableView active:YES];
// Send trigger to start the defalt controller
[[NSNotificationCenter defaultCenter] postNotificationName: @"KodiStartDefaultController" object:nil userInfo:params];
}
else {
[self.tcpJSONRPCconnection stopNetworkCommunication];
[[NSNotificationCenter defaultCenter] postNotificationName: @"XBMCServerConnectionFailed" object:nil userInfo:params];
AppDelegate.instance.serverOnLine = NO;
AppDelegate.instance.serverName = infoText;
[xbmcInfo setTitle:infoText forState:UIControlStateNormal];
[Utilities setStyleOfMenuItems:menuViewController.tableView active:NO];
notificationName = @"XBMCServerConnectionFailed";
if (!extraTimer.valid) {
extraTimer = [NSTimer scheduledTimerWithTimeInterval:CONNECTION_TIMEOUT target:self selector:@selector(offStackView) userInfo:nil repeats:NO];
}
}
[[NSNotificationCenter defaultCenter] postNotificationName:notificationName object:nil userInfo:params];
[xbmcInfo setTitle:infoText forState:UIControlStateNormal];
[Utilities setStyleOfMenuItems:menuViewController.tableView active:status];
if (status) {
// Send trigger to start the defalt controller
kambala-decapitator marked this conversation as resolved.
Show resolved Hide resolved
[[NSNotificationCenter defaultCenter] postNotificationName: @"KodiStartDefaultController" object:nil userInfo:params];
}
}

- (void)offStackView {
Expand Down