Skip to content

Commit

Permalink
Add reverse list handling
Browse files Browse the repository at this point in the history
  • Loading branch information
embeddedc committed Aug 18, 2022
1 parent e88af7b commit ff4151a
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions Apple-TV/VLCOpenNetworkStreamTVViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ @interface VLCOpenNetworkStreamTVViewController ()
{
NSMutableArray *_recentURLs;
NSMutableDictionary *_recentURLTitles;
BOOL newestFirst;
BOOL _newestFirst;
}
@property (nonatomic) NSIndexPath *currentlyFocusedIndexPath;
@end
Expand Down Expand Up @@ -53,7 +53,7 @@ - (void)viewDidLoad {
self.emptyListButton.accessibilityLabel = NSLocalizedString(@"BUTTON_RESET", nil);
self.reverseListSortingButton.accessibilityLabel = NSLocalizedString(@"BUTTON_REVERSE", nil);

newestFirst = false;
_newestFirst = false;

self.previouslyPlayedStreamsTableView.backgroundColor = [UIColor clearColor];
self.previouslyPlayedStreamsTableView.rowHeight = UITableViewAutomaticDimension;
Expand Down Expand Up @@ -112,8 +112,9 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"RecentlyPlayedURLsTableViewCell"];
}

NSString *content = [_recentURLs[indexPath.row] stringByRemovingPercentEncoding];
NSString *possibleTitle = _recentURLTitles[[@(indexPath.row) stringValue]];
NSInteger index = _newestFirst ? _recentURLs.count - 1 - indexPath.row : indexPath.row;
NSString *content = [_recentURLs[index] stringByRemovingPercentEncoding];
NSString *possibleTitle = _recentURLTitles[[@(index) stringValue]];

cell.detailTextLabel.text = content;
cell.textLabel.text = (possibleTitle != nil) ? possibleTitle : [content lastPathComponent];
Expand All @@ -124,7 +125,8 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self.previouslyPlayedStreamsTableView deselectRowAtIndexPath:indexPath animated:NO];
[self _openURLStringAndDismiss:_recentURLs[indexPath.row]];
NSInteger index = _newestFirst ? _recentURLs.count - 1 - indexPath.row : indexPath.row;
[self _openURLStringAndDismiss:_recentURLs[index]];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
Expand Down Expand Up @@ -211,13 +213,14 @@ - (void)emptyListAction:(id)sender

- (IBAction)reverseListSortingAction:(id)sender
{
newestFirst = !newestFirst;

if (newestFirst) {
_newestFirst = !_newestFirst;
if (_newestFirst) {
self.reverseListSortingButton.transform = CGAffineTransformMakeRotation( M_PI );
} else {
self.reverseListSortingButton.transform = CGAffineTransformIdentity;
}

[self.previouslyPlayedStreamsTableView reloadData];
}

#pragma mark - editing
Expand All @@ -237,7 +240,7 @@ - (NSString *)itemToDelete

NSString *ret = nil;
@synchronized(_recentURLs) {
NSInteger index = indexPathToDelete.item;
NSInteger index = _newestFirst ? _recentURLs.count - 1 - indexPathToDelete.item : indexPathToDelete.item;
if (index < _recentURLs.count) {
ret = _recentURLs[index];
}
Expand Down

0 comments on commit ff4151a

Please sign in to comment.