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
36 changes: 34 additions & 2 deletions XBMC Remote/DetailViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -2681,7 +2681,7 @@ - (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSI
}
else if (episodesView) {
UILabel *trackNumber = (UILabel*)[cell viewWithTag:ALBUM_VIEW_CELL_TRACKNUMBER];
trackNumber.text = item[@"episode"];
trackNumber.text = item[@"specialEpisode"] ?: item[@"episode"];
}
else if (channelGuideView) {
runtimeyear.hidden = YES;
Expand Down Expand Up @@ -4823,6 +4823,25 @@ - (void)retrieveData:(NSString*)methodToCall parameters:(NSDictionary*)parameter
useBanner:tvshowsView
useIcon:recordingListView];

// Use TV Show episode's "specialsort", if present, to place a copy of a special
// within the common seasons. This is in line with Kodi behaviour.
if ([methodName isEqualToString:@"VideoLibrary.GetEpisodes"]) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be great to move this logic to the caller instead of having special case right inside the generic method. You could add an optional callback (block) that would allow modifying newDict.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, there are anyway several special cases in there (recordings, movie sets, empty TV shows, pvr/timers). I agree, this is not optimal, but I would rather not touch this now.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, can be done later

// Flag specials for sorting reasons and provide track number in "Sx" scheme.
BOOL isTVShowSpecial = [newDict[@"season"] integerValue] == 0;
newDict[@"isTVShowSpecial"] = @(isTVShowSpecial);
if (isTVShowSpecial) {
newDict[@"specialEpisode"] = [Utilities formatTVShowStringForSpecialEpisode:item[@"episode"]];
}

// In case "specialsort" is valid, add an item copy with according season/episode.
if ([item[@"specialsortseason"] intValue] > 0 && [item[@"specialsortepisode"] intValue] > 0) {
NSMutableDictionary *specialSortedDict = [newDict mutableCopy];
specialSortedDict[@"season"] = [Utilities getStringFromItem:item[@"specialsortseason"]];
specialSortedDict[@"episode"] = [Utilities getStringFromItem:item[@"specialsortepisode"]];
[resultStoreArray addObject:specialSortedDict];
}
}

// JSON API does not return the expected "filetype" when retrieving list of "sources".
// The correct "filetype" is "directory". But we also need to be aware this is a source
// and not a directory yet.
Expand Down Expand Up @@ -5107,7 +5126,20 @@ - (void)indexAndDisplayData {
}

if (episodesView) {
for (NSDictionary *item in self.richResults) {
// First run will ensure the specials are in correct order
SEL selector = [self buildSelectorForSortMethod:@"specialEpisode" inArray:copyRichResults];
Comment thread
kambala-decapitator marked this conversation as resolved.
copyRichResults = [self applySortByMethod:copyRichResults sortmethod:@"specialEpisode" ascending:YES selector:selector];

// Second run will ensure the specials are on top of the list
selector = [self buildSelectorForSortMethod:@"isTVShowSpecial" inArray:copyRichResults];
copyRichResults = [self applySortByMethod:copyRichResults sortmethod:@"isTVShowSpecial" ascending:NO selector:selector];

// Third run will sort by order of episodes
selector = [self buildSelectorForSortMethod:@"episode" inArray:copyRichResults];
copyRichResults = [self applySortByMethod:copyRichResults sortmethod:@"episode" ascending:YES selector:selector];

// Now pick the episodes top-down from the list into sections defined by seasons
for (NSDictionary *item in copyRichResults) {
NSString *c = [NSString stringWithFormat:@"%@", item[@"season"]];
BOOL found = [[self.sections allKeys] containsObject:c];
if (!found) {
Expand Down
1 change: 1 addition & 0 deletions XBMC Remote/Utilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ typedef NS_ENUM(NSInteger, LogoBackgroundType) {
+ (void)imageView:(UIImageView*)view AnimDuration:(NSTimeInterval)seconds Image:(UIImage*)image;
+ (float)getPercentElapsed:(NSDate*)startDate EndDate:(NSDate*)endDate;
+ (void)createTransparentToolbar:(UIToolbar*)toolbar;
+ (NSString*)formatTVShowStringForSpecialEpisode:(id)episode;
+ (NSString*)formatTVShowStringForSeasonTrailing:(id)season episode:(id)episode title:(NSString*)title;
+ (NSString*)formatTVShowStringForSeasonLeading:(id)season episode:(id)episode title:(NSString*)title;
+ (NSString*)formatTVShowStringForSeason:(id)season episode:(id)episode;
Expand Down
7 changes: 7 additions & 0 deletions XBMC Remote/Utilities.m
Original file line number Diff line number Diff line change
Expand Up @@ -1257,6 +1257,10 @@ + (void)createTransparentToolbar:(UIToolbar*)toolbar {
forToolbarPosition:UIBarPositionAny];
}

+ (NSString*)formatTVShowStringForSpecialEpisode:(id)episode {
return [NSString stringWithFormat:@"S%i", [episode intValue]];
}

+ (NSString*)formatTVShowStringForSeasonLeading:(id)season episode:(id)episode title:(NSString*)title {
NSString *seasonAndEpisode = [Utilities formatTVShowStringForSeason:season episode:episode];
NSString *text = [NSString stringWithFormat:@"%@%@%@", seasonAndEpisode, seasonAndEpisode.length ? @" " : @"", title];
Expand All @@ -1277,6 +1281,9 @@ + (NSString*)formatTVShowStringForSeason:(id)season episode:(id)episode {
if ([season intValue] && [episode intValue]) {
text = [NSString stringWithFormat:format, [season intValue], [episode intValue]];
}
else if (![season intValue] && [episode intValue]) {
text = [self formatTVShowStringForSpecialEpisode:episode];
}
}
return text;
}
Expand Down
12 changes: 12 additions & 0 deletions XBMC Remote/mainMenu.m
Original file line number Diff line number Diff line change
Expand Up @@ -4053,6 +4053,12 @@ + (NSMutableArray*)generateMenus {
@"title",
],
},
@"kodiExtrasPropertiesMinimumVersion": @{
@"12": @[
@"specialsortseason",
@"specialsortepisode",
],
},
@"extra_info_parameters": @{
@"properties": @[
@"episode",
Expand Down Expand Up @@ -4389,6 +4395,12 @@ + (NSMutableArray*)generateMenus {
@"title",
],
},
@"kodiExtrasPropertiesMinimumVersion": @{
@"12": @[
@"specialsortseason",
@"specialsortepisode",
],
},
@"extra_info_parameters": @{
@"properties": @[
@"episode",
Expand Down