Skip to content

Commit

Permalink
Merge pull request #1109 from wutschel/rework_messages_2
Browse files Browse the repository at this point in the history
Maintenance: Use centralized approach to show messages
Bugfix: Show power menu related messages again
  • Loading branch information
kambala-decapitator authored Sep 14, 2024
2 parents 7e6c95b + b332902 commit deedff0
Show file tree
Hide file tree
Showing 17 changed files with 170 additions and 176 deletions.
2 changes: 0 additions & 2 deletions XBMC Remote/DetailViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#import "Utilities.h"
#import "BDKCollectionIndexView.h"
#import "FloatingHeaderFlowLayout.h"
#import "MessagesView.h"
#import <SafariServices/SafariServices.h>

@class NowPlaying;
Expand Down Expand Up @@ -98,7 +97,6 @@
NSDateFormatter *xbmcDateFormatter;
NSDateFormatter *localHourMinuteFormatter;
NSIndexPath *autoScrollTable;
MessagesView *messagesView;
__weak IBOutlet UILabel *noItemsLabel;
BOOL stackscrollFullscreen;
BOOL forceCollection;
Expand Down
27 changes: 7 additions & 20 deletions XBMC Remote/DetailViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -481,16 +481,6 @@ - (void)addExtraProperties:(NSMutableArray*)mutableProperties newParams:(NSMutab
}
}

- (UIViewController*)topMostController {
UIViewController *topController = UIApplication.sharedApplication.keyWindow.rootViewController;

while (topController.presentedViewController) {
topController = topController.presentedViewController;
}

return topController;
}

- (void)setFilternameLabel:(NSString*)labelText runFullscreenButtonCheck:(BOOL)check forceHide:(BOOL)forceHide {
self.navigationItem.title = [Utilities stripBBandHTML:labelText];
if (IS_IPHONE) {
Expand Down Expand Up @@ -1635,7 +1625,7 @@ - (void)didSelectItemAtIndexPath:(NSIndexPath*)indexPath item:(NSDictionary*)ite
// Selected favourite item is an unknown type -> throw an error
else {
NSString *message = [NSString stringWithFormat:@"%@ (type = '%@')", LOCALIZED_STR(@"Cannot do that"), item[@"type"]];
[messagesView showMessage:message timeout:2.0 color:[Utilities getSystemRed:0.95]];
[Utilities showMessage:message color:[Utilities getSystemRed:0.95]];
}
}
else if (methods[@"method"] != nil && ![parameters[@"forceActionSheet"] boolValue] && !stackscrollFullscreen) {
Expand Down Expand Up @@ -3254,7 +3244,7 @@ - (void)showActionSheet:(NSIndexPath*)indexPath sheetActions:(NSArray*)sheetActi
UIImageView *isRecordingImageView = (UIImageView*)[cell viewWithTag:EPG_VIEW_CELL_RECORDING_ICON];
BOOL isRecording = isRecordingImageView == nil ? NO : !isRecordingImageView.hidden;
CGPoint sheetOrigin = CGPointMake(rectOriginX, rectOriginY);
UIViewController *showFromCtrl = [self topMostController];
UIViewController *showFromCtrl = [Utilities topMostController];
[self showActionSheetOptions:title options:sheetActions recording:isRecording origin:sheetOrigin fromcontroller:showFromCtrl fromview:self.view];
}
else if (indexPath != nil) { // No actions found, revert back to standard play action
Expand Down Expand Up @@ -3284,7 +3274,7 @@ - (void)longPressSeason:(UILongPressGestureRecognizer*)sender {
title = [NSString stringWithFormat:@"%@\n%@", title, season];
}

UIViewController *showFromCtrl = [self topMostController];
UIViewController *showFromCtrl = [Utilities topMostController];
UIView *showFromView = nil;
if (IS_IPHONE) {
showFromView = self.view;
Expand Down Expand Up @@ -3366,7 +3356,7 @@ - (void)handleLongPress:(UILongPressGestureRecognizer*)activeRecognizer {
}
UIImageView *isRecordingImageView = (UIImageView*)[cell viewWithTag:EPG_VIEW_CELL_RECORDING_ICON];
BOOL isRecording = isRecordingImageView == nil ? NO : !isRecordingImageView.hidden;
UIViewController *showFromCtrl = [self topMostController];
UIViewController *showFromCtrl = [Utilities topMostController];
UIView *showFromView = nil;
if (IS_IPHONE) {
showFromView = self.view;
Expand Down Expand Up @@ -3786,7 +3776,7 @@ - (void)saveCustomButton:(NSDictionary*)button {
customButton *arrayButtons = [customButton new];
[arrayButtons.buttons addObject:button];
[arrayButtons saveData];
[messagesView showMessage:LOCALIZED_STR(@"Button added") timeout:2.0 color:[Utilities getSystemGreen:0.95]];
[Utilities showMessage:LOCALIZED_STR(@"Button added") color:[Utilities getSystemGreen:0.95]];
if (IS_IPAD) {
[[NSNotificationCenter defaultCenter] postNotificationName: @"UIInterfaceCustomButtonAdded" object: nil];
}
Expand Down Expand Up @@ -4525,10 +4515,10 @@ - (void)playlistAndPlay:(NSDictionary*)playlistParams playbackParams:(NSDictiona
- (void)SimpleAction:(NSString*)action params:(NSDictionary*)parameters success:(NSString*)successMessage failure:(NSString*)failureMessage {
[[Utilities getJsonRPC] callMethod:action withParameters:parameters onCompletion:^(NSString *methodName, NSInteger callId, id methodResult, DSJSONRPCError *methodError, NSError *error) {
if (error == nil && methodError == nil) {
[messagesView showMessage:successMessage timeout:2.0 color:[Utilities getSystemGreen:0.95]];
[Utilities showMessage:successMessage color:[Utilities getSystemGreen:0.95]];
}
else {
[messagesView showMessage:failureMessage timeout:2.0 color:[Utilities getSystemRed:0.95]];
[Utilities showMessage:failureMessage color:[Utilities getSystemRed:0.95]];
}
}];
}
Expand Down Expand Up @@ -6063,9 +6053,6 @@ - (void)viewDidLoad {
[self setIpadInterface:itemSizes[@"ipad"]];
}

messagesView = [[MessagesView alloc] initWithFrame:CGRectMake(0, 0, viewWidth, DEFAULT_MSG_HEIGHT) deltaY:0 deltaX:0];
[self.view addSubview:messagesView];

// As default both list and grid views animate from right to left.
frame = dataList.frame;
frame.origin.x = viewWidth;
Expand Down
2 changes: 0 additions & 2 deletions XBMC Remote/HostManagementViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#import "ECSlidingViewController.h"
#import "MasterViewController.h"
#import "RightMenuViewController.h"
#import "MessagesView.h"
#import "DSJSONRPC.h"

@class HostViewController;
Expand All @@ -28,7 +27,6 @@
__weak IBOutlet UIButton *addHostButton;
__weak IBOutlet UIView *supportedVersionView;
__weak IBOutlet UILabel *supportedVersionLabel;
MessagesView *messagesView;
__weak IBOutlet UIToolbar *bottomToolbar;
__weak IBOutlet UIImageView *bottomToolbarShadowImageView;
UITextView *serverInfoView;
Expand Down
8 changes: 2 additions & 6 deletions XBMC Remote/HostManagementViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -524,10 +524,6 @@ - (void)viewDidLoad {
frame.origin.y -= bottomPadding;
serverInfoButton.frame = frame;

messagesView = [[MessagesView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, HOSTMANAGERVC_MSG_HEIGHT + deltaY) deltaY:deltaY deltaX:0];
messagesView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
[self.view addSubview:messagesView];

CGFloat toolbarHeight = bottomToolbar.frame.size.height;
serverInfoView = [[UITextView alloc] initWithFrame:CGRectMake(MARGIN, deltaY + MARGIN, self.view.frame.size.width - 2 * MARGIN, self.view.frame.size.height - deltaY - toolbarHeight - 2 * MARGIN)];
serverInfoView.autoresizingMask = UIViewAutoresizingFlexibleWidth |
Expand Down Expand Up @@ -685,7 +681,7 @@ - (void)powerControl {
actionView = [Utilities createAlertOK:LOCALIZED_STR(@"Select an XBMC Server from the list") message:nil];
}
else {
actionView = [Utilities createPowerControl:self messageView:messagesView];
actionView = [Utilities createPowerControl:self];
}
[self presentViewController:actionView animated:YES completion:nil];
}
Expand Down Expand Up @@ -767,7 +763,7 @@ - (void)enableTCPconnection {

- (void)connectionError:(NSNotification*)note {
NSDictionary *theData = note.userInfo;
[messagesView showMessage:theData[@"error_message"] timeout:2.0 color:[Utilities getSystemRed:0.95]];
[Utilities showMessage:theData[@"error_message"] color:[Utilities getSystemRed:0.95]];
}

- (void)authFailed:(NSNotification*)note {
Expand Down
2 changes: 2 additions & 0 deletions XBMC Remote/MasterViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#import "ECSlidingViewController.h"
#import "tcpJSONRPC.h"
#import "CustomNavigationController.h"
#import "MessagesView.h"

@class DetailViewController;
@class NowPlaying;
Expand All @@ -31,6 +32,7 @@
BOOL itemIsActive;
CustomNavigationController *navController;
UIImageView *globalConnectionStatus;
MessagesView *messagesView;
}

@property (nonatomic, strong) NSMutableArray *mainMenu;
Expand Down
59 changes: 59 additions & 0 deletions XBMC Remote/MasterViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@ - (void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*)

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

// Add MessagesView to root view to be able to show messages on top
[self addMessagesToRootView];
}];
}

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

#pragma mark - Helper

- (void)addMessagesToRootView {
// Add MessagesView to root view to be able to show messages on top
UIView *rootView = [Utilities topMostController].view;
[rootView addSubview:messagesView];
}

- (void)addConnectionStatusToRootView {
// Add connection status icon to root view of new controller
UIView *rootView = UIApplication.sharedApplication.keyWindow.rootViewController.view;
Expand Down Expand Up @@ -289,6 +298,16 @@ - (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self.slidingViewController.anchorRightPeekAmount = ANCHOR_RIGHT_PEEK;
self.slidingViewController.underLeftWidthLayout = ECFullWidth;

// Update dimension of message view
CGFloat deltaY = [Utilities getTopPaddingWithNavBar:self.navigationController];
[messagesView updateWithFrame:CGRectMake(0,
0,
UIScreen.mainScreen.bounds.size.width,
DEFAULT_MSG_HEIGHT + deltaY)
deltaY:deltaY
deltaX:0];
[self addMessagesToRootView];
}

- (void)viewWillDisappear:(BOOL)animated {
Expand Down Expand Up @@ -328,6 +347,8 @@ - (void)viewDidLoad {
CONNECTION_STATUS_SIZE)];
[self addConnectionStatusToRootView];

messagesView = [[MessagesView alloc] initWithFrame:CGRectZero deltaY:0 deltaX:0];

[[NSNotificationCenter defaultCenter] addObserver: self
selector: @selector(handleWillResignActive:)
name: @"UIApplicationWillResignActiveNotification"
Expand Down Expand Up @@ -361,10 +382,48 @@ - (void)viewDidLoad {
name: @"KodiStartDefaultController"
object: nil];

[[NSNotificationCenter defaultCenter] addObserver: self
selector: @selector(handleLibraryNotification:)
name: @"AudioLibrary.OnScanFinished"
object: nil];

[[NSNotificationCenter defaultCenter] addObserver: self
selector: @selector(handleLibraryNotification:)
name: @"AudioLibrary.OnCleanFinished"
object: nil];

[[NSNotificationCenter defaultCenter] addObserver: self
selector: @selector(handleLibraryNotification:)
name: @"VideoLibrary.OnScanFinished"
object: nil];

[[NSNotificationCenter defaultCenter] addObserver: self
selector: @selector(handleLibraryNotification:)
name: @"VideoLibrary.OnCleanFinished"
object: nil];

[[NSNotificationCenter defaultCenter] addObserver: self
selector: @selector(showNotificationMessage:)
name: @"UIShowMessage"
object: nil];

self.view.backgroundColor = [Utilities getGrayColor:36 alpha:1];
[menuList selectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] animated:YES scrollPosition:UITableViewScrollPositionNone];
}

- (void)handleLibraryNotification:(NSNotification*)note {
[Utilities showMessage:note.name color:[Utilities getSystemGreen:0.95]];
}

- (void)showNotificationMessage:(NSNotification*)note {
NSDictionary *params = note.userInfo;
if (!params) {
return;
}
[self addMessagesToRootView];
[messagesView showMessage:params[@"message"] timeout:2.0 color:params[@"color"]];
}

- (void)connectionStatus:(NSNotification*)note {
NSDictionary *theData = note.userInfo;
NSString *infoText = theData[@"message"];
Expand Down
2 changes: 0 additions & 2 deletions XBMC Remote/NowPlaying.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#import "UIImageView+WebCache.h"
#import "RightMenuViewController.h"
#import "OBSlider.h"
#import "MessagesView.h"

@class ShowInfoViewController;
@class RemoteController;
Expand Down Expand Up @@ -98,7 +97,6 @@
BOOL ignoreAutoscrollPlaylist;
int storePosSeconds;
long storedItemID;
MessagesView *messagesView;
BOOL isRemotePlayer;
}

Expand Down
12 changes: 3 additions & 9 deletions XBMC Remote/NowPlaying.m
Original file line number Diff line number Diff line change
Expand Up @@ -2267,7 +2267,7 @@ - (void)tableView:(UITableView*)tableView moveRowAtIndexPath:(NSIndexPath*)sourc
else {
[playlistTableView reloadData];
[playlistTableView selectRowAtIndexPath:storeSelection animated:YES scrollPosition:UITableViewScrollPositionMiddle];
[messagesView showMessage:LOCALIZED_STR(@"Cannot do that") timeout:2.0 color:[Utilities getSystemRed:0.95]];
[Utilities showMessage:LOCALIZED_STR(@"Cannot do that") color:[Utilities getSystemRed:0.95]];
}
}];
}
Expand Down Expand Up @@ -2297,7 +2297,7 @@ - (void)tableView:(UITableView*)tableView commitEditingStyle:(UITableViewCellEdi
else {
[playlistTableView reloadData];
[playlistTableView selectRowAtIndexPath:storeSelection animated:YES scrollPosition:UITableViewScrollPositionMiddle];
[messagesView showMessage:LOCALIZED_STR(@"Cannot do that") timeout:2.0 color:[Utilities getSystemRed:0.95]];
[Utilities showMessage:LOCALIZED_STR(@"Cannot do that") color:[Utilities getSystemRed:0.95]];
}
}];
}
Expand Down Expand Up @@ -2647,12 +2647,6 @@ - (void)viewWillAppear:(BOOL)animated {
height:nowPlayingView.frame.size.height];
}

UIView *rootView = IS_IPHONE ? UIApplication.sharedApplication.keyWindow.rootViewController.view : self.view;
CGFloat deltaY = IS_IPHONE ? UIApplication.sharedApplication.statusBarFrame.size.height : 0;
messagesView = [[MessagesView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, DEFAULT_MSG_HEIGHT + deltaY) deltaY:deltaY deltaX:0];
messagesView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
[rootView addSubview:messagesView];

[[NSNotificationCenter defaultCenter] addObserver: self
selector: @selector(handleEnterForeground:)
name: @"UIApplicationWillEnterForegroundNotification"
Expand Down Expand Up @@ -2734,7 +2728,7 @@ - (void)powerControl {
if (AppDelegate.instance.obj.serverIP.length == 0) {
return;
}
UIAlertController *actionView = [Utilities createPowerControl:self messageView:messagesView];
UIAlertController *actionView = [Utilities createPowerControl:self];
[self presentViewController:actionView animated:YES completion:nil];
}

Expand Down
2 changes: 0 additions & 2 deletions XBMC Remote/RemoteController.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

#import <UIKit/UIKit.h>
#import "DSJSONRPC.h"
#import "MessagesView.h"

typedef enum {
remoteTop,
Expand Down Expand Up @@ -49,7 +48,6 @@ typedef enum {
BOOL isGestureViewActive;
NSDictionary *subsDictionary;
NSDictionary *audiostreamsDictionary;
MessagesView *messagesView;
}

- (IBAction)startVibrate:(id)sender;
Expand Down
Loading

0 comments on commit deedff0

Please sign in to comment.