From 3cd3a0fae2aa39fecc72b005d3c7ca60c41bfc4a Mon Sep 17 00:00:00 2001 From: Bob Jelica Date: Tue, 19 Jul 2011 23:27:11 +0200 Subject: [PATCH] fixed: #108 - tab switching can be slow fixed: grid remembers last position + bunch of other tweaks --- PlexATV/Classes/HWAppliance.mm | 2 +- PlexATV/Classes/HWMediaGridController.h | 3 - PlexATV/Classes/HWMediaGridController.m | 31 +++----- PlexATV/Classes/HWPlexDir.h | 4 ++ PlexATV/Classes/HWPlexDir.m | 71 ++++++++++++++----- PlexATV/Classes/HWSettingsController.m | 4 +- PlexATV/Classes/HWUserDefaults.m | 4 +- .../_deb/PLEX.frapplication/DEBIAN/control | 4 +- 8 files changed, 72 insertions(+), 51 deletions(-) diff --git a/PlexATV/Classes/HWAppliance.mm b/PlexATV/Classes/HWAppliance.mm index 0504dc9..6e7582a 100644 --- a/PlexATV/Classes/HWAppliance.mm +++ b/PlexATV/Classes/HWAppliance.mm @@ -1,4 +1,4 @@ -#define LOCAL_DEBUG_ENABLED 1 +#define LOCAL_DEBUG_ENABLED 0 #import "HWAppliance.h" #import "BackRowExtras.h" diff --git a/PlexATV/Classes/HWMediaGridController.h b/PlexATV/Classes/HWMediaGridController.h index ba88a23..2d86c9e 100644 --- a/PlexATV/Classes/HWMediaGridController.h +++ b/PlexATV/Classes/HWMediaGridController.h @@ -17,9 +17,6 @@ BRCursorControl * _cursorControl; BRScrollControl * _scroller; BRPanelControl * _panelControl; - int _lastFocusedControlIndex; - BOOL _shelfWasFocused; - BOOL _gridWasFocused; } @property (retain) PlexMediaContainer *shelfMediaContainer; diff --git a/PlexATV/Classes/HWMediaGridController.m b/PlexATV/Classes/HWMediaGridController.m index 1c0968c..7902072 100644 --- a/PlexATV/Classes/HWMediaGridController.m +++ b/PlexATV/Classes/HWMediaGridController.m @@ -44,9 +44,6 @@ - (id)initWithPlexAllMovies:(PlexMediaContainer *)allMovies andRecentMovies:(Ple self = [self init]; if (self) { DLog(); - _gridWasFocused = NO; - _shelfWasFocused = NO; - _lastFocusedControlIndex = - 1; self.shelfMediaContainer = recentMovies; self.gridMediaContainer = allMovies; @@ -88,11 +85,13 @@ -(void)dealloc { - (void)wasPushed { [[MachineManager sharedMachineManager] setMachineStateMonitorPriority:NO]; [super wasPushed]; + [self _removeAllControls]; + [self drawSelf]; } - (void)wasPopped { - _gridControl = nil; - _shelfControl = nil; + //_gridControl = nil; + //_shelfControl = nil; [super wasPopped]; } @@ -107,15 +106,7 @@ - (void)wasBuried { -(void)controlWasActivated { - DLog(@"controlWasActivated"); - DLog(@"grid was focused: %@", _gridWasFocused ? @"YES" : @"NO"); - DLog(@"shelf was focused: %@", _shelfWasFocused ? @"YES" : @"NO"); - DLog(@"last focused index: %d", _lastFocusedControlIndex); - if (_gridWasFocused) - [_gridControl set] - [self _removeAllControls]; - [self drawSelf]; - + [super controlWasActivated]; } @@ -272,9 +263,9 @@ - (void) drawSelf [_scroller setFollowsFocus:YES]; [_scroller setContent:_panelControl]; [_scroller setAcceptsFocus:YES]; - + [self layoutSubcontrols]; - + #if LOCAL_DEBUG_ENABLED DLog(@"drawSelf done"); #endif @@ -357,20 +348,16 @@ -(BOOL)brEventAction:(BREvent *)action NSArray *mediaObjects; if ([_shelfControl isFocused]) { - index = [_shelfControl focusedIndex]; + index = [_shelfControl focusedIndex]; mediaObjects = self.shelfMediaObjects; - _shelfWasFocused = YES; - _lastFocusedControlIndex = index; #if LOCAL_DEBUG_ENABLED DLog(@"item in shelf selected. mediaObjects: %d, index:%d",[mediaObjects count], index); #endif } else if ([_gridControl isFocused]) { - index = [_gridControl _indexOfFocusedControl]; + index = [_gridControl _indexOfFocusedControl]; mediaObjects = self.gridMediaObjects; - _gridWasFocused = YES; - _lastFocusedControlIndex = index; #if LOCAL_DEBUG_ENABLED DLog(@"item in grid selected. mediaObjects: %d, index:%d",[mediaObjects count], index); #endif diff --git a/PlexATV/Classes/HWPlexDir.h b/PlexATV/Classes/HWPlexDir.h index ecb7d7d..9b21575 100644 --- a/PlexATV/Classes/HWPlexDir.h +++ b/PlexATV/Classes/HWPlexDir.h @@ -33,16 +33,20 @@ @interface HWPlexDir: SMFMediaMenuController { PlexMediaContainer* rootContainer; PlexMediaObject* playbackItem; + NSDictionary* previewControlData; } @property (retain) BRTabControl *tabBar; @property (retain) PlexMediaContainer* rootContainer; @property (retain) NSArray *items; +@property (retain) NSDictionary* previewControlData; - (id)initWithRootContainer:(PlexMediaContainer*)container andTabBar:(BRTabControl *)aTabBar; - (void)showModifyViewedStatusViewForRow:(long)row; - (void)reselectCurrentTabBarItem; +- (void)createParadeForData:(NSMutableDictionary *)data; +- (void)finishedCreatingParade:(NSDictionary *)data; //list provider - (float)heightForRow:(long)row; diff --git a/PlexATV/Classes/HWPlexDir.m b/PlexATV/Classes/HWPlexDir.m index e77ab10..53394a3 100644 --- a/PlexATV/Classes/HWPlexDir.m +++ b/PlexATV/Classes/HWPlexDir.m @@ -36,13 +36,14 @@ #import "PlexThemeMusicPlayer.h" #import "PlexAudioSubsController.h" -#define LOCAL_DEBUG_ENABLED 0 +#define LOCAL_DEBUG_ENABLED 1 #define ModifyViewStatusOptionDialog @"ModifyViewStatusOptionDialog" @implementation HWPlexDir @synthesize rootContainer; @synthesize tabBar; @synthesize items; +@synthesize previewControlData; #pragma mark - #pragma mark Object/Class Lifecycle @@ -131,7 +132,7 @@ -(void)layoutSubcontrols { //tab bar same width as list [self.tabBar setFrame:CGRectMake(listFrame.origin.x+22.f, 567.f, 516.f, 25.f)]; - + } } @@ -267,40 +268,72 @@ - (id)itemForRow:(long)row { return pmo.menuItem; } +#define kParadeItemIndex @"kParadeItemIndex" +#define kParadeItem @"kParadeItem" +#define kParadeControl @"kParadeControl" - (id)previewControlForItem:(long)item { id preview = nil; + + //stop the timer for parade control, which was setup for previously selected item + [NSObject cancelPreviousPerformRequestsWithTarget:self]; + PlexMediaObject* pmo = [self.items objectAtIndex:item]; //we force set the hash so two movies with same title don't end up with the same preview [self setValue:[pmo description] forKey:@"_previewControlItemHash"]; if ([tabBar selectedTabItemIndex] == TabBarOtherFiltersItemsIndex) { - //parade -#if LOCAL_DEBUG_ENABLED - DLog(@"using parade preview for [%@]", pmo); -#endif - NSMutableArray *imageProxies = [NSMutableArray array]; - PlexMediaContainer *subItemsContainer = [pmo contents]; - NSArray *subItems = subItemsContainer.directories; + //show parade only after it's been built in the background + //see ticket #108 - Tab switching can be slow - for (PlexMediaObject *pmo in subItems) { - PlexPreviewAsset *previewAsset = [pmo previewAsset]; - [imageProxies addObject:[previewAsset imageProxy]]; - } - preview = [[[BRMediaParadeControl alloc] init] autorelease]; - [preview setImageProxies:imageProxies]; + if (self.previewControlData != nil && [[self.previewControlData objectForKey:kParadeItemIndex] longValue] == item) { + //we have already created preview for this item, just return that + return [self.previewControlData objectForKey:kParadeControl]; + } + NSNumber *itemIndex = [NSNumber numberWithLong:item]; //need object to be able to store it in dict + NSMutableDictionary *data = [[NSMutableDictionary alloc] initWithObjectsAndKeys:pmo, kParadeItem, itemIndex, kParadeItemIndex, nil]; - } else { -#if LOCAL_DEBUG_ENABLED - DLog(@"using standard preview for [%@]", pmo); -#endif + //creating parade in bg, once done this will set self.previewControlData and refresh the preview control + [self performSelectorInBackground:@selector(createParadeForData:) withObject:data]; + } else { //single coverart preview = pmo.previewControl; //already autoreleased } return preview; } +- (void)finishedCreatingParade:(NSDictionary *)data { + self.previewControlData = data; + [self updatePreviewController]; +} + +- (void)createParadeForData:(NSMutableDictionary *)data { + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + PlexMediaObject *pmo = [data objectForKey:kParadeItem]; + + NSMutableArray *imageProxies = [NSMutableArray array]; + PlexMediaContainer *subItemsContainer = [pmo contents]; + NSArray *subItems = subItemsContainer.directories; + + for (PlexMediaObject *pmo in subItems) { + PlexPreviewAsset *previewAsset = [pmo previewAsset]; + [imageProxies addObject:[previewAsset imageProxy]]; + } + + id preview = [[[BRMediaParadeControl alloc] init] autorelease]; + [preview setImageProxies:imageProxies]; + +#if LOCAL_DEBUG_ENABLED + DLog(@"parade control created"); +#endif + + [data setObject:preview forKey:kParadeControl]; + [self performSelectorOnMainThread:@selector(finishedCreatingParade:) withObject:data waitUntilDone:NO]; + + [pool drain]; +} + #pragma mark - #pragma mark BRMenuListItemProvider Delegate - (BOOL)rowSelectable:(long)selectable { diff --git a/PlexATV/Classes/HWSettingsController.m b/PlexATV/Classes/HWSettingsController.m index f0919f7..61fd07b 100644 --- a/PlexATV/Classes/HWSettingsController.m +++ b/PlexATV/Classes/HWSettingsController.m @@ -24,7 +24,7 @@ @implementation HWSettingsController @synthesize topLevelController; -#define PlexPluginVersion @"0.8.0" +#define PlexPluginVersion @"0.8.0 RC1" #define ServersIndex 0 #define ViewSettingsIndex 1 @@ -194,7 +194,7 @@ -(id)previewControlForItem:(long)item case PluginVersionNumberIndex: { // =========== quality setting =========== [asset setTitle:@"Credit to:"]; - [asset setSummary:@"quequick, b0bben and ccjensen"]; + [asset setSummary:@"quequick, b0bben and ccjensen, brent112, boots and all the ppl in the forums. <3 you all"]; break; } default: diff --git a/PlexATV/Classes/HWUserDefaults.m b/PlexATV/Classes/HWUserDefaults.m index a284a4d..0c7794f 100644 --- a/PlexATV/Classes/HWUserDefaults.m +++ b/PlexATV/Classes/HWUserDefaults.m @@ -94,7 +94,7 @@ - (void)_setDefaults {} + (void)setupPlexClient { DLog(@"registering ourselves with the PMS"); - [PlexRequest setApplicationName:@"Plex-ATV" version:@"0.8"]; + [PlexRequest setApplicationName:@"Plex-ATV" version:@"0.8RC1"]; //tell pms we like direct-stream and we will be sending caps to it [[PlexPrefs defaultPreferences] setAllowDirectStreaming:YES]; @@ -164,7 +164,7 @@ + (NSDictionary *)defaultValues { [NSNumber numberWithBool:YES], PreferencesViewListPosterZoomingEnabled, [NSNumber numberWithBool:NO], PreferencesPlaybackAudioAC3Enabled, [NSNumber numberWithBool:NO], PreferencesPlaybackAudioDTSEnabled, - [NSNumber numberWithInt:9], PreferencesPlaybackVideoQualityProfile, + [NSNumber numberWithInt:8], PreferencesPlaybackVideoQualityProfile, [NSNumber numberWithBool:NO], PreferencesSecuritySettingsLockEnabled, [NSNumber numberWithInt:0], PreferencesSecurityPasscode, [NSDictionary dictionary], PersistedTabBarLastSelections, diff --git a/PlexATV/_deb/PLEX.frapplication/DEBIAN/control b/PlexATV/_deb/PLEX.frapplication/DEBIAN/control index 66fbc1c..20ebb1c 100644 --- a/PlexATV/_deb/PLEX.frapplication/DEBIAN/control +++ b/PlexATV/_deb/PLEX.frapplication/DEBIAN/control @@ -1,10 +1,10 @@ Package: com.plex.client-plugin Name: AppleTV PLEX Plugin -Version: 0.0.8.0.5 +Version: 0.0.8.0.RC1 Priority: optional Size: 1083178 Installed-Size: 2662 -Depends: beigelist,com.nito,org.tomcool.smframework (>= 0.7.7-2) +Depends: beigelist,com.nito,org.tomcool.smframework (= 0.7.7-2) Replaces: plex-client-plugin Architecture: iphoneos-arm Description: A PLEX Client for Lowtide (beta)